View Javadoc

1   package org.minetti.astrodevice.server.core;
2   
3   import static org.junit.Assert.*;
4   import junit.framework.Assert;
5   import org.apache.log4j.Logger;
6   import org.junit.BeforeClass;
7   import org.junit.Test;
8   
9   /**
10   * Unit test for {@link org.minetti.astrodevice.server.core.ServerClassLoader ServerClassLoader} class.
11   * @author Jean-Philippe MINETTI
12   */
13  public final class ServerClassLoaderTest {
14  
15  	/**
16  	 * Class name to test.
17  	 */
18  	private static final String EXAMPLE_CLASS = "org.minetti.astrodevice.server.hibernate.dao.DaoFactoryImpl";
19  
20  	/**
21  	 * Logger.
22  	 */
23  	private final Logger logger = Logger.getLogger(ServerClassLoaderTest.class);
24  
25  	/**
26  	 * Initializes before class creation.
27  	 */
28  	@BeforeClass
29  	public static void setUpBeforeClass() {
30  		System.setProperty("basedir", System.getProperty("user.dir"));
31  		About.getInstance().load();
32  	}
33  
34  	/**
35  	 * Test method for {@link org.minetti.astrodevice.server.core.ServerClassLoader#initialize()}.
36  	 * @throws ClassNotFoundException Exception if an error occurred.
37  	 */
38  	@Test
39  	public void testInitialize() throws ClassNotFoundException {
40  		ServerClassLoader.initialize();
41  		try {
42  			Class.forName(ServerClassLoaderTest.EXAMPLE_CLASS);
43  			fail(ServerClassLoaderTest.EXAMPLE_CLASS + " found in orginal ClassLoader");
44  		}
45  		catch (final ClassNotFoundException e) {
46  			// NOP
47  		}
48  		final Object obj = Class.forName(ServerClassLoaderTest.EXAMPLE_CLASS, true, new ServerClassLoader());
49  		Assert.assertNotNull(ServerClassLoaderTest.EXAMPLE_CLASS + " not found in new ClassLoader", obj);
50  	}
51  
52  	/**
53  	 * Test method for {@link org.minetti.astrodevice.server.core.ServerClassLoader#toString()}.
54  	 */
55  	@Test
56  	public void testToString() {
57  		this.logger.info(new ServerClassLoader().toString());
58  		ServerClassLoader.initialize();
59  		this.logger.info(new ServerClassLoader().toString());
60  	}
61  
62  }