1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package ch.elca.el4j.tests.remoting.jaxws;
18
19 import junit.framework.Assert;
20
21 import org.hibernate.LazyInitializationException;
22 import org.junit.Test;
23
24 import ch.elca.el4j.services.remoting.jaxb.hibernate.HibernateJAXBAccessor;
25 import ch.elca.el4j.tests.person.dom.Brain;
26 import ch.elca.el4j.tests.person.dom.Person;
27 import ch.elca.el4j.tests.remoting.jaxws.service.LazyPerson;
28
29
30
31
32
33
34
35
36
37 public class LazyInitializationTest extends AbstractJaxwsTest {
38 @Override
39 protected String[] getIncludeConfigLocations() {
40 return new String[] {"classpath*:mandatory/*.xml",
41 "classpath*:scenarios/db/raw/*.xml",
42 "classpath*:scenarios/dataaccess/*.xml",
43 "classpath*:scenarios/dataaccess/hibernate/*.xml",
44 "classpath*:scenarios/dataaccess/hibernate/refdb/*.xml",
45 "scenarios/client/remotingtests-jaxws-hibernate-client-config.xml"};
46 }
47
48
49
50
51 @Test
52 public void testLazyPersonService() {
53 LazyPerson lazyPerson = getLazyPerson();
54
55 Person person = lazyPerson.getPerson(true);
56 Assert.assertNotNull(person.getBrain());
57
58 person = lazyPerson.getPerson(false);
59 Assert.assertNull(person.getBrain());
60
61 Brain b = new Brain();
62 b.setIq(100);
63 person.setBrain(b);
64 lazyPerson.setPerson(person);
65
66 person = lazyPerson.getPerson(false);
67 Assert.assertNull(person.getBrain());
68
69 person = lazyPerson.getPerson(true);
70 Assert.assertEquals(b.getIq(), person.getBrain().getIq());
71 }
72
73
74
75
76
77 public LazyPerson getLazyPerson() {
78 return (LazyPerson) getApplicationContext().getBean("lazyPerson");
79 }
80
81 }