1 17 18 package org.sape.carbon.core.component.startup.test; 19 20 import org.sape.carbon.core.component.ComponentKeeper; 21 import org.sape.carbon.core.component.Lookup; 22 import org.sape.carbon.core.component.startup.StartupService; 23 import org.sape.carbon.core.component.startup.StartupServiceConfiguration; 24 import org.sape.carbon.core.component.startup.StartupServiceConfiguration.StartupComponentConfiguration; 25 import org.sape.carbon.core.config.Config; 26 27 import junit.extensions.ActiveTestSuite; 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 32 41 public class StartupServiceTest extends TestCase { 42 public StartupServiceTest(String name) { 43 super(name); 44 } 45 46 57 public void testLoadedStartupComponents() { 58 StartupServiceConfiguration startupConfig = 59 (StartupServiceConfiguration) Config 60 .getInstance() 61 .fetchConfiguration( 62 STARTUP_SERVICE_NAME); 63 64 StartupComponentConfiguration[] startupComponents = 65 startupConfig.getStartupComponent(); 66 67 ComponentKeeper keeper = Lookup.getInstance().getComponentKeeper(); 68 69 StartupService startup = 70 (StartupService) keeper.fetchComponent(STARTUP_SERVICE_NAME); 71 72 for (int i = 0; i < startupComponents.length; i++) { 74 if (keeper 75 .getComponentNames() 76 .contains(startupComponents[i].getComponentName())) { 77 78 keeper.destroyComponent(startupComponents[i].getComponentName()); 79 } 80 } 81 82 startup.startComponents(); 84 85 for (int i = 0; i < startupComponents.length; i++) { 87 if (startupComponents[i].isEnabled()) { 88 TestCase.assertTrue( 89 "Startup component was not loaded: [" 90 + startupComponents[i].getComponentName() + "]", 91 keeper.getComponentNames().contains( 92 startupComponents[i].getComponentName())); 93 } 94 } 95 } 96 97 private static final String STARTUP_SERVICE_NAME = 99 "/core/test/TestStartupService"; 100 101 105 public static Test suite() { 106 TestSuite masterSuite = new TestSuite("StartupServiceTest"); 107 Test singleThreadedTests = getSingleThreadedTests(); 109 if (singleThreadedTests != null) { 110 masterSuite.addTest(singleThreadedTests); 111 } 112 Test multiThreadedTests = getMultiThreadedTests(); 114 if (multiThreadedTests != null) { 115 masterSuite.addTest(multiThreadedTests); 116 } 117 return masterSuite; 118 } 119 120 125 private static Test getSingleThreadedTests() { 126 TestSuite suite = new TestSuite(); 127 128 134 suite.addTest(new StartupServiceTest("testLoadedStartupComponents")); 135 136 return suite; 137 } 138 139 144 private static Test getMultiThreadedTests() { 145 TestSuite suite = new ActiveTestSuite(); 146 147 153 154 return suite; 155 } 156 157 165 private static void addTest( 166 TestSuite suite, 167 String testName, 168 int number) { 169 for (int count = 0; count < number; count++) { 170 suite.addTest(new StartupServiceTest(testName)); 171 } 172 } 173 } | Popular Tags |