1 17 18 package org.sape.carbon.core.component.factory.test; 19 20 import org.sape.carbon.core.component.Component; 21 import org.sape.carbon.core.component.factory.ComponentFactory; 22 import org.sape.carbon.core.component.factory.DefaultComponentFactory; 23 import org.sape.carbon.core.component.lifecycle.LifecycleInterceptor; 24 import org.sape.carbon.core.component.lifecycle.LifecycleStateEnum; 25 import org.sape.carbon.core.config.interceptor.ConfigurationInterceptor; 26 import org.sape.carbon.core.exception.InvalidParameterException; 27 28 import junit.framework.Test; 29 import junit.framework.TestCase; 30 import junit.framework.TestSuite; 31 32 41 public class DefaultComponentFactoryTest extends TestCase { 42 private ComponentFactory componentFactory; 43 44 public DefaultComponentFactoryTest(String name) { 45 super(name); 46 } 47 48 60 public void testComponentCreation() { 61 Component testComponent = 62 this.componentFactory.getInstance(ALL_INTERFACES_COMPONENT); 63 64 if (testComponent == null) { 66 TestCase.fail("Component was null"); 67 } 68 69 if (!(testComponent instanceof ComponentFactoryTestComponent)) { 72 TestCase.fail("Component did not implement expected function " + 73 "interface: " + 74 ComponentFactoryTestComponent.class.getName()); 75 } 76 77 if (!(testComponent instanceof ComponentFactoryTestComponentConfig)) { 79 TestCase.fail("Component did not implement expected function " + 80 "interface: " + 81 ComponentFactoryTestComponentConfig.class.getName()); 82 } 83 84 105 106 107 if (!(testComponent instanceof LifecycleInterceptor)) { 109 TestCase.fail("Component did not implement expected interceptor " + 110 "interface: " + LifecycleInterceptor.class.getName()); 111 } 112 if (!(testComponent instanceof ConfigurationInterceptor)) { 113 TestCase.fail("Component did not implement expected interceptor " + 114 "interface: " + ConfigurationInterceptor.class.getName()); 115 } 116 117 if (((LifecycleInterceptor) testComponent).getLifecycleState() != 119 LifecycleStateEnum.STOPPED) { 120 TestCase.fail("Component was not in the " + 121 "LifecycleStateEnum.STOPPED state"); 122 } 123 } 124 125 129 public void testComponentNotFound() { 130 boolean passedTest = false; 131 try { 132 this.componentFactory.getInstance(""); 133 } catch(InvalidParameterException ipe) { 134 passedTest = true; 135 } 136 if (!passedTest) { 137 TestCase.fail("InvalidParameterException was not thrown"); 138 } 139 } 140 141 public void testMethodNameCollision() { 142 this.componentFactory.getInstance(NAME_COLLISION_TEST_COMPONENT) ; 143 } 144 145 protected void setUp() { 146 this.componentFactory = new DefaultComponentFactory(); 147 } 148 149 private static final String ALL_INTERFACES_COMPONENT = 151 "/core/test/AllInterfacesComponent"; 152 private static final String NAME_COLLISION_TEST_COMPONENT = 153 "/core/test/NameCollisionTestComponent"; 154 155 156 160 public static Test suite() { 161 TestSuite masterSuite = new TestSuite("DefaultComponentFactoryTest"); 162 Test singleThreadedTests = getSingleThreadedTests(); 164 if (singleThreadedTests != null) { 165 masterSuite.addTest(singleThreadedTests); 166 } 167 Test multiThreadedTests = getMultiThreadedTests(); 169 if (multiThreadedTests != null) { 170 masterSuite.addTest(multiThreadedTests); 171 } 172 return masterSuite; 173 } 174 175 185 private static Test getSingleThreadedTests() { 186 TestSuite suite = new TestSuite(); 187 188 suite.addTest(new DefaultComponentFactoryTest("testComponentCreation")); 189 suite.addTest(new DefaultComponentFactoryTest("testComponentNotFound")); 190 suite.addTest(new DefaultComponentFactoryTest("testMethodNameCollision")); 191 192 return suite; 193 } 194 195 199 private static Test getMultiThreadedTests() { 200 return null; 201 } 202 203 211 private static void addTest(TestSuite suite, String testName, int number) { 212 for (int count = 0; count < number; count++) { 213 suite.addTest(new DefaultComponentFactoryTest(testName)); 214 } 215 } 216 } 217 | Popular Tags |