01: /*
02: * Copyright 2005-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package net.sf.dozer.functional_tests.recursive;
17:
18: import net.sf.dozer.functional_tests.AbstractMapperTest;
19: import net.sf.dozer.functional_tests.DataObjectInstantiator;
20: import net.sf.dozer.functional_tests.NoProxyDataObjectInstantiator;
21:
22: /**
23: * Test the dozer behaviour when confronted with structures similar to ours. As of now (dozer 3.0) the behaviour is not
24: * optimal and still require special treatments in special cases.
25: *
26: * @author ADE
27: */
28: public class RecursiveTest extends AbstractMapperTest {
29:
30: private ClassAA createTestClassAA() {
31:
32: // Create sample assureSocialDTO
33: ClassAA classA = (ClassAA) newInstance(ClassAA.class);
34:
35: classA.setNom("gbs");
36: classA.setPrenom("prn");
37:
38: ClassB classB = (ClassB) newInstance(ClassB.class);
39: classA.addSubs(classB);
40: classB.setRue("rue");
41: classB.setVille("ville");
42: return classA;
43: }
44:
45: /**
46: * this test should validate dozerXX correct behaviour in front of recursive class references in a subclass. With
47: * dozer3.0 the first reference is not used but the recursion is correct on the next levels.
48: *
49: */
50: public void testConvertWithSubClass() {
51: mapper = getMapper(new String[] { "recursivemappings.xml",
52: "recursivemappings2.xml" });
53: ClassAA testAA = createTestClassAA();
54: // the == is on purpose, we test that the referenced parent of the first item of the subs is the parent instance
55: // itself
56: ClassB testClassB = (ClassB) testAA.getSubs().iterator().next();
57: assertTrue(testClassB.getParent() == testAA);
58: ClassAAPrime testAAPrime = (ClassAAPrime) mapper.map(testAA,
59: ClassAAPrime.class, null);
60: // testing the new dozer3.0 bi-directionnal reference through a set
61: assertEquals(testAA.getSubs().size(), testAAPrime.getSubs()
62: .size());
63: // the equality is true at the data level
64: ClassBPrime testClassBPrime = (ClassBPrime) testAAPrime
65: .getSubs().iterator().next();
66: assertTrue(testClassBPrime.getParent().equals(testAAPrime));
67: // we want the referenced parent of the first item of the subs to be the parent instance itself
68: ClassBPrime testClassBPrime2 = (ClassBPrime) testAAPrime
69: .getSubs().iterator().next();
70: assertTrue(testClassBPrime2.getParent() == testAAPrime);
71: }
72:
73: protected DataObjectInstantiator getDataObjectInstantiator() {
74: return NoProxyDataObjectInstantiator.INSTANCE;
75: }
76:
77: }
|