View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2009 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
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   * This class is a test for marshaling uninitialized entities using JAXB using the {@link HibernateJAXBAccessor}
31   * to avoid {@link LazyInitializationException}s.
32   *
33   * @svnLink $Revision: 4181 $;$Date: 2010-10-28 09:12:24 +0200 (Do, 28. Okt 2010) $;$Author: sstelca $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/tests/remoting_jaxws/functional-tests/src/test/java/ch/elca/el4j/tests/remoting/jaxws/LazyInitializationTest.java $
34   *
35   * @author Stefan Wismer (SWI)
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  	 * Perform the test.
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  	 * Get the LazyPerson to use.
75  	 * @return LazyPerson to use
76  	 */
77  	public LazyPerson getLazyPerson() {
78  		return (LazyPerson) getApplicationContext().getBean("lazyPerson");
79  	}
80  	
81  }