1 64 package com.jcorporate.expresso.kernel.test; 65 66 import com.jcorporate.expresso.kernel.DataContext; 67 import com.jcorporate.expresso.kernel.RootContainerInterface; 68 import com.jcorporate.expresso.kernel.SystemFactory; 69 import com.jcorporate.expresso.kernel.management.ExpressoRuntimeMap; 70 import junit.framework.TestCase; 71 72 78 79 public class TestComponentSystem extends TestCase { 80 81 public TestComponentSystem(String _name) { 82 super(_name); 83 } 84 85 88 protected void setUp() { 89 } 90 91 94 protected void tearDown() { 95 } 96 97 public void testInitRoot() { 98 RootContainerInterface globalContainer = null; 99 try { 100 globalContainer = SystemFactory.buildExpressoComponentSystem( 101 this.getClass().getResource("Test1ExpressoServices.xml"), 102 this.getClass().getResource("TestLog4jConfig.xml"), 103 System.getProperty("junit.argv.logDir", "/d:/expresso/log")); 104 105 assertTrue(globalContainer != null); 106 assertTrue(globalContainer.getExpressoServicesConfig() != null); 107 assertTrue(globalContainer.getContainerImplementation() != null); 108 assertTrue(globalContainer.getSetupValues() != null); 109 assertTrue("abcdefg".equals(globalContainer.getSetupValue("test1"))); 110 assertTrue(globalContainer.getLogManager() != null); 111 assertTrue(globalContainer.getParent() == null); 112 assertTrue(globalContainer.getMetaData() != null); 113 assertTrue(globalContainer.getExpressoServicesConfig() != null); 114 globalContainer.destroy(); 115 } catch (Exception ex) { 116 ex.printStackTrace(); 117 fail("Caught Exception constructing Global Container"); 118 } 119 120 } 121 122 123 public void testInit() { 124 RootContainerInterface globalContainer = null; 125 try { 126 globalContainer = SystemFactory.buildExpressoComponentSystem( 127 this.getClass().getResource("Test1ExpressoServices.xml"), 128 this.getClass().getResource("TestLog4jConfig.xml"), 129 "D:/Expresso/log"); 130 131 132 DataContext dc = (DataContext) globalContainer.locateComponent("default"); 133 assertTrue("DataContext should be non-null", dc != null); 134 assertTrue("DataContext should have setup tables" 135 , dc.getHasSetupTables().booleanValue() == true); 136 137 assertTrue("Security Context should be the default database", 138 dc.getSecurityContext().equals("default")); 139 140 assertTrue("Should have correct description as set by services.xml" 141 , dc.getContextDescription().equals("A Sample Default Database")); 142 143 assertTrue("Should have correct test setup value: got " + dc.getSetupValue("test1") + "instead", 144 "Test Setup Value".equals(dc.getSetupValue("test1"))); 145 146 TestComponent tc = (TestComponent) dc.locateComponent("TestComponent"); 147 assertTrue("Test Component must not be null", tc != null); 148 149 150 globalContainer.destroy(); 151 } catch (Exception ex) { 152 ex.printStackTrace(); 153 fail("Caught Exception constructing Global Container"); 154 } 155 156 } 157 158 163 public void testGC() { 164 RootContainerInterface globalContainer = null; 165 try { 166 globalContainer = SystemFactory.buildExpressoComponentSystem( 167 this.getClass().getResource("Test1ExpressoServices.xml"), 168 this.getClass().getResource("TestLog4jConfig.xml"), 169 "D:/Expresso/log"); 170 171 assertTrue(globalContainer != null); 172 globalContainer = null; 173 ExpressoRuntimeMap.unregisterRuntime(null); 174 System.gc(); 175 System.runFinalization(); 176 177 assertTrue(ExpressoRuntimeMap.getDefaultRuntime() == null); 178 } catch (Exception ex) { 179 ex.printStackTrace(); 180 fail("Caught Exception constructing Global Container"); 181 } 182 183 } 184 185 190 public void testMultipleInits() { 191 RootContainerInterface globalContainer = null; 192 193 try { 194 globalContainer = SystemFactory.buildExpressoComponentSystem( 195 this.getClass().getResource("Test1ExpressoServices.xml"), 196 this.getClass().getResource("TestLog4jConfig.xml"), 197 "D:/Expresso/log"); 198 199 RootContainerInterface testContainer = SystemFactory.buildExpressoComponentSystem( 200 this.getClass().getResource("Test2ExpressoServices.xml"), 201 this.getClass().getResource("TestLog4jConfig.xml"), 202 "D:/Expresso/log"); 203 204 RootContainerInterface retrievedContainer = ExpressoRuntimeMap.getDefaultRuntime(); 205 assertTrue("Retrieved container should be the global test container", 206 retrievedContainer == globalContainer); 207 208 retrievedContainer = ExpressoRuntimeMap.getRuntime("sampleRuntime"); 209 assertTrue(retrievedContainer != null); 210 assertTrue("Retrieved container should be the second created container", 211 retrievedContainer == testContainer); 212 213 testContainer.destroy(); 214 retrievedContainer = ExpressoRuntimeMap.getRuntime("sampleRuntime"); 215 assertTrue("sampleRuntime should no longer exist", retrievedContainer == null); 216 globalContainer.destroy(); 217 } catch (Exception ex) { 218 ex.printStackTrace(); 219 fail("Caught Exception constructing Containers"); 220 } 221 } 222 223 224 227 public static void main(String [] argv) { 228 String [] testCaseList = {TestComponentSystem.class.getName()}; 229 junit.textui.TestRunner.main(testCaseList); 230 } 231 } | Popular Tags |