1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package kortsoft.kmx.bootstrap;
17
18 import java.io.File;
19 import java.util.Properties;
20
21 import kortsoft.kmx.AbstractTestCase;
22 import kortsoft.kmx.test.FileUtil;
23
24 /***
25 * Test KmxLauncher main methods with both usages.
26 * <a href="KmxLauncherTest.java.html"><b><i>View Source</i></b></a>
27 *
28 * @author Alvaro
29 * @version $Revision: 1.1 $
30 *
31 */
32 public class KmxLauncherTest extends AbstractTestCase {
33
34 File testProperties;
35 File defaultProperties;
36 File testJarLib;
37
38 /***
39 * @param testName
40 */
41 public KmxLauncherTest() {
42 super("KmxLauncherTest");
43 }
44
45 public void testMainWithoutParams(){
46 try {
47 KmxLauncher.main(new String[0]);
48 } catch (Exception e) {
49 fail("Not Expected Exception: "+e);
50 }
51 assertKmxMainLifeCycle();
52 }
53
54 public void testMainWithParam(){
55 try {
56 KmxLauncher.main(new String[]{"target/test-classes/kmxlauncher_test.properties"});
57 } catch (Exception e) {
58 fail("Not Expected Exception: "+e);
59 }
60 assertKmxMainLifeCycle();
61 }
62
63 /***
64 *
65 */
66 private void assertKmxMainLifeCycle() {
67 assertTrue("KmxMain not started",MockKmxMain.startup);
68 try {
69 KmxLauncher.finalizador.run();
70 assertTrue("KmxMain not closed",MockKmxMain.closed);
71 } catch (RuntimeException e1) {
72 fail("Error executing finalizer: "+e1);
73 }
74 }
75
76
77
78
79
80 protected void setUp() throws Exception {
81 Properties prop=new Properties();
82 prop.put(KmxLauncher.LIB_DIR_PARAM,"target/test-classes/lib");
83 prop.put(KmxLauncher.RESOURCES_DIR_PARAM,"target/test-classes/resources");
84 prop.put(KmxLauncher.MAIN_CLASS_PARAM,MockKmxMain.class.getName());
85 testProperties=new File("target/test-classes/kmxlauncher_test.properties");
86 defaultProperties=new File("target/classes"+KmxLauncher.PROP_FILE_NAME);
87 FileUtil.write(defaultProperties,prop);
88 FileUtil.write(testProperties,prop);
89 FileUtil.mkdirs("target/test-classes/resources");
90 FileUtil.mkdirs("target/test-classes/lib");
91 testJarLib=new File("target/test-classes/lib/testJarLib.jar");
92 Properties testProperties=new Properties();
93 testProperties.put(MockKmxMain.TEST_PROPERTY,MockKmxMain.TEST_PROPERTY_VALUE);
94 FileUtil.writeAsJAR(testJarLib,MockKmxMain.TEST_PROPERTY_FILE,testProperties);
95 }
96
97
98
99
100
101 protected void tearDown() throws Exception {
102 testProperties.delete();
103 defaultProperties.delete();
104 testJarLib.delete();
105 MockKmxMain.startup=false;
106 MockKmxMain.closed=false;
107 }
108 }