ExoContainer extends AbstractContainer { public <T> T getComponentInstanceOfType(Class<T> componentType) { return getComponentInstanceOfType(componentType, true); } ExoContainer();  ExoContainer(ExoContainer parent); static Set<String> getProfilesFromProperty(); static Set<String> getProfiles(); static boolean hasProfileInProperty(String profileName); static boolean hasProfile(String profileName); ExoContainerContext getContext(); synchronized void dispose(); synchronized void start(boolean init); synchronized void initialize(); synchronized void start(); synchronized void stop(); void addComponentLifecylePlugin(ComponentLifecyclePlugin plugin); void addContainerLifecylePlugin(ContainerLifecyclePlugin plugin); ComponentAdapter<T> registerComponentImplementation(Class<T> componentImplementation); ComponentAdapter<T> registerComponentInstance(T componentInstance); T createComponent(Class<T> clazz); ComponentAdapter<?> getComponentAdapter(Object componentKey); Object getComponentInstance(Object componentKey); @Managed @ManagedName("RegisteredComponentNames") @ManagedDescription("Return the list of the registered component names") Set<String> getRegisteredComponentNames(); ExoContainer getParent(); boolean canBeStarted(); boolean canBeStopped(); boolean canBeDisposed(); ContextManager getContextManager(); boolean isContextManagerLoaded(); T getComponentInstanceOfType(Class<T> componentType); T getComponentInstanceOfType(Class<T> componentType, boolean autoRegistration); ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType); ComponentAdapter<T> getComponentAdapterOfType(Class<T> componentType, boolean autoRegistration); T getComponentInstance(Object componentKey, Class<T> bindType); T getComponentInstance(Object componentKey, Class<T> bindType, boolean autoRegistration); ComponentAdapter<T> getComponentAdapter(Object componentKey, Class<T> bindType); ComponentAdapter<T> getComponentAdapter(Object componentKey, Class<T> bindType, boolean autoRegistration);  }
@Test public void testStackOverFlow3() { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml"); SOE2 soe2 = (SOE2)container.getComponentInstanceOfType(SOE2.class); assertNotNull(soe2); assertNotNull(soe2.soe1); assertEquals(1, soe2.soe1.plugins.size()); SOEPlugin soe1Plugin = soe2.soe1.plugins.get(0); assertNotNull(soe1Plugin); assertNotNull(soe1Plugin.soe2); assertSame(soe2.soe1, soe1Plugin.soe2.soe1); assertSame(container.getComponentInstanceOfType(SOE1.class), soe2.soe1); }
@Test public void testStackOverFlow2B() throws Exception { final URL rootURL = getClass().getResource("test-exo-container.xml"); final URL portalURL = getClass().getResource("test-exo-container-portal-mode.xml"); assertNotNull(rootURL); assertNotNull(portalURL); COUNTER = new AtomicInteger(); new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("Case-B").build(); final ExoContainer container = PortalContainer.getInstance(); SOE1B soe1 = (SOE1B)container.getComponentInstanceOfType(SOE1B.class); assertNotNull(soe1); assertTrue(soe1.startOrder >= 1); assertEquals(1, soe1.plugins.size()); SOEPluginB soe1Plugin = soe1.plugins.get(0); assertNotNull(soe1Plugin); assertNotNull(soe1Plugin.soe2); assertTrue(soe1Plugin.soe2.startOrder >= 1); assertSame(soe1, soe1Plugin.soe2.soe1); assertSame(container.getComponentInstanceOfType(SOE2B.class), soe1Plugin.soe2); }
@Test public void testStackOverFlow3B() throws Exception { final URL rootURL = getClass().getResource("test-exo-container.xml"); final URL portalURL = getClass().getResource("test-exo-container-portal-mode.xml"); assertNotNull(rootURL); assertNotNull(portalURL); COUNTER = new AtomicInteger(); new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("Case-B").build(); final ExoContainer container = PortalContainer.getInstance(); SOE2B soe2 = (SOE2B)container.getComponentInstanceOfType(SOE2B.class); assertNotNull(soe2); assertTrue(soe2.startOrder >= 1); assertNotNull(soe2.soe1); assertEquals(1, soe2.soe1.plugins.size()); SOEPluginB soe1Plugin = soe2.soe1.plugins.get(0); assertNotNull(soe1Plugin); assertNotNull(soe1Plugin.soe2); assertSame(soe2.soe1, soe1Plugin.soe2.soe1); assertTrue(soe2.soe1.startOrder >= 1); assertSame(container.getComponentInstanceOfType(SOE1B.class), soe2.soe1); }
@Test public void testStackOverFlow2C() throws Exception { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml"); SOE1C soe1 = (SOE1C)container.getComponentInstanceOfType(SOE1C.class); assertNotNull(soe1); assertEquals(2, soe1.plugins.size()); SOEPluginC soe1Plugin = (SOEPluginC)soe1.plugins.get(1); assertNotNull(soe1Plugin); assertNotNull(soe1Plugin.soe2); assertSame(soe1, soe1Plugin.soe2.soe1); assertSame(container.getComponentInstanceOfType(SOE2C.class), soe1Plugin.soe2); }
@Test public void testStackOverFlow3C() throws Exception { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml"); SOE2C soe2 = (SOE2C)container.getComponentInstanceOfType(SOE2C.class); assertNotNull(soe2); assertNotNull(soe2.soe1); assertEquals(2, soe2.soe1.plugins.size()); SOEPluginC soe1Plugin = (SOEPluginC)soe2.soe1.plugins.get(1); assertNotNull(soe1Plugin); assertNotNull(soe1Plugin.soe2); assertSame(soe2.soe1, soe1Plugin.soe2.soe1); assertSame(container.getComponentInstanceOfType(SOE1C.class), soe2.soe1); }
@Test public void testStackOverFlow4() { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml", "testStackOverflowError"); MyService ms = (MyService)container.getComponentInstanceOfType(MyService.class); assertNotNull(ms); assertTrue(ms instanceof MyServiceImpl); MyServiceImpl msi = (MyServiceImpl)ms; assertNotNull(msi.componentPlugin); assertTrue(msi.componentPlugin instanceof MyPlugin); MyPlugin mp = (MyPlugin)msi.componentPlugin; assertSame(mp.svc, ms); }
@Test public void testCyclicRef() { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml", "testCyclicRef"); A a = (A)container.getComponentInstanceOfType(A.class); assertNotNull(a); B b = (B)container.getComponentInstanceOfType(B.class); assertNotNull(b); assertSame(a, b.a); }
@Test public void testContainerNameSuffix() { final URL rootURL = getClass().getResource("test-exo-container.xml"); final URL portalURL = getClass().getResource("test-exo-container.xml"); assertNotNull(rootURL); assertNotNull(portalURL); final ExoContainer rContainer = new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("testContainerNameSuffix") .build(); final ExoContainer pContainer = PortalContainer.getInstance(); TCNS t1 = rContainer.getComponentInstanceOfType(TCNS.class); assertNotNull(t1); assertEquals("empty${container.name.suffix}", t1.value); assertNotNull(t1.dep); assertEquals("empty${container.name.suffix}", t1.dep.value); TCNS t2 = pContainer.getComponentInstanceOfType(TCNS.class); assertNotNull(t2); assertEquals("empty_portal", t2.value); assertNotNull(t2.dep); assertEquals("empty_portal", t2.dep.value); }
@Test public void testStartOrder2() { COUNTER = new AtomicInteger(); ExoContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml", "testStartOrder2"); TSO2_A a = container.getComponentInstanceOfType(TSO2_A.class); assertNotNull(a); TSO2_B b = container.getComponentInstanceOfType(TSO2_B.class); assertNotNull(b); TSO2_C c = container.getComponentInstanceOfType(TSO2_C.class); assertNotNull(c); TSO2_D d = container.getComponentInstanceOfType(TSO2_D.class); assertNotNull(d); assertTrue(a.startOrder > 0); assertTrue(c.startOrder > 0); assertTrue(d.startOrder > 0); assertTrue(c.startOrder < a.startOrder); assertTrue(d.startOrder < a.startOrder); assertTrue(c.startOrder < d.startOrder); TSO2_A2 a2 = container.getComponentInstanceOfType(TSO2_A2.class); assertNotNull(a2); TSO2_B2 b2 = container.getComponentInstanceOfType(TSO2_B2.class); assertNotNull(b2); TSO2_C2 c2 = container.getComponentInstanceOfType(TSO2_C2.class); assertNotNull(c2); assertTrue(a2.startOrder > 0); assertTrue(b2.startOrder > 0); assertTrue(c2.startOrder > 0); assertTrue(c2.startOrder < b2.startOrder); assertTrue(b2.startOrder < a2.startOrder); }
@Test public void testStartOrder3() { COUNTER = new AtomicInteger(); ExoContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml", "testStartOrder3"); TSO3_A a = container.getComponentInstanceOfType(TSO3_A.class); assertNotNull(a); TSO3_B b = container.getComponentInstanceOfType(TSO3_B.class); assertNotNull(b); TSO3_C c = container.getComponentInstanceOfType(TSO3_C.class); assertNotNull(c); assertTrue(a.startOrder > 0); assertTrue(b.startOrder > 0); assertTrue(c.startOrder > 0); assertTrue(c.startOrder < b.startOrder); assertTrue(b.startOrder < a.startOrder); }
@Test public void testStates() throws Exception { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml", "testStates"); TSC1 value = (TSC1)container.getComponentInstanceOfType(TSC1.class); assertNotNull(value); TSC2Plugin plugin = value.plugin; assertNotNull(plugin); assertNotNull(plugin.tsc2); assertNotNull(plugin.tsc2.plugin); TSC2 value2 = (TSC2)container.getComponentInstanceOfType(TSC2.class); assertNotNull(value2); assertSame(value2, plugin.tsc2); TSC2Plugin plugin2 = value2.plugin; assertNotNull(plugin2); assertNotNull(plugin2.tsc2); assertSame(value2, plugin2.tsc2); assertSame(plugin.tsc2.plugin, plugin2); }
@Test public void testContainers() throws Exception { final URL rootURL = getClass().getResource("test-exo-container.xml"); final URL portalURL = getClass().getResource("test-exo-container.xml"); assertNotNull(rootURL); assertNotNull(portalURL); new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("testContainers").build(); ExoContainer container = PortalContainer.getInstance(); CCTC1 c1 = (CCTC1)container.getComponentInstanceOfType(CCTC1.class); assertNotNull(c1); assertNotNull(c1.container); assertNotNull(c1.c2); assertNotNull(c1.c2.container); assertNotNull(c1.c3); assertNotNull(c1.c3.container); assertSame(c1.container, c1.c2.container); assertSame(c1.container, c1.c3.container); assertSame(container, c1.container); }
@Test public void testScopeWithNoContextManager() throws Exception { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml"); ContextManager manager = container.getComponentInstanceOfType(ContextManager.class); assertNull(manager); testScope(container, manager, true); testScope(container, manager, false); }
@Test public void testDefinitionByType() { final URL rootURL = getClass().getResource("empty-config.xml"); final URL portalURL = getClass().getResource("test-exo-container.xml"); assertNotNull(rootURL); assertNotNull(portalURL); final RootContainer rootContainer = new ContainerBuilder().withRoot(rootURL).withPortal(portalURL). profiledBy("testAutoRegistration").build(); final ExoContainer container = PortalContainer.getInstance(); assertNotNull(container.getComponentInstanceOfType(AutoRegistration1.class)); assertTrue(container.getComponentInstanceOfType(AutoRegistration1.class).started); assertNotNull(container.getComponentInstanceOfType(AutoRegistration1.class).plugin); assertEquals("AutoRegistration1", container.getComponentInstanceOfType(AutoRegistration1.class).plugin.getName()); assertNull(rootContainer.getComponentInstanceOfType(AutoRegistration1.class)); try { container.getComponentInstanceOfType(AutoRegistration2.class); fail("An exception is expected as the class is an abstract class"); } catch (Exception e) { } try { container.getComponentInstanceOfType(AutoRegistration3.class); fail("An exception is expected as the class is an interface"); } catch (Exception e) { } try { container.getComponentInstanceOfType(AutoRegistration4.class); fail("An exception is expected as the type is not correct"); } catch (Exception e) { } assertNull(container.getComponentInstanceOfType(AutoRegistration5.class, false)); assertNotNull(container.getComponentInstanceOfType(AutoRegistration5.class)); assertTrue(container.getComponentInstanceOfType(AutoRegistration6.class) instanceof AutoRegistration6Type); try { container.getComponentInstanceOfType(AutoRegistration7.class); fail("An exception is expected as the class is an abstract class"); } catch (Exception e) { } try { container.getComponentInstanceOfType(AutoRegistration8.class); fail("An exception is expected as the class is an interface"); } catch (Exception e) { } assertNull(container.getComponentInstanceOfType(AutoRegistration9.class, false)); assertNotNull(container.getComponentInstanceOfType(AutoRegistration9.class)); }
@Test public void testSerializationRecursivity() { URL rootURL = getClass().getResource("test-exo-container.xml"); URL portalURL = getClass().getResource("empty-config.xml"); assertNotNull(rootURL); assertNotNull(portalURL); new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("testSerializationRecursivity").build(); final RootContainer container = RootContainer.getInstance(); String xmlConfig = container.getConfigurationXML(); SerializationRecursivity1 sr1 = container.getComponentInstanceOfType(SerializationRecursivity1.class); sr1.sr2.sr3 = container.getComponentInstanceOfType(SerializationRecursivity3.class); assertEquals(xmlConfig,container.getConfigurationXML()); final PortalContainer pcontainer = PortalContainer.getInstance(); xmlConfig = pcontainer.getConfigurationXML(); sr1 = container.getComponentInstanceOfType(SerializationRecursivity1.class); sr1.sr2.sr3 = container.getComponentInstanceOfType(SerializationRecursivity3.class); assertEquals(xmlConfig,pcontainer.getConfigurationXML()); }
@Test public void testStackOverFlow() { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml"); MyClass value = (MyClass)container.getComponentInstanceOfType(MyClass.class); assertNotNull(value); MyClassPlugin plugin = value.plugin_; assertNotNull(plugin); assertNotNull(plugin.cmanager_); assertSame(value, plugin.myClass_); MyClassPlugin2 plugin2 = value.plugin2_; assertNotNull(plugin2); assertNotNull(plugin2.cmanager_); assertSame(value, plugin2.myClass_); }
@Test public void testStackOverFlowB() throws Exception { final URL rootURL = getClass().getResource("empty-config.xml"); final URL portalURL = getClass().getResource("test-exo-container.xml"); assertNotNull(rootURL); assertNotNull(portalURL); new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).profiledBy("testStackOverFlowB").build(); final ExoContainer container = PortalContainer.getInstance(); MyClassB value = (MyClassB)container.getComponentInstanceOfType(MyClassB.class); assertNotNull(value); assertTrue(value.started); MyClassPluginB plugin = value.plugin_; assertNotNull(plugin); assertNotNull(plugin.cmanager_); assertSame(value, plugin.myClass_); MyClassPlugin2B plugin2 = value.plugin2_; assertNotNull(plugin2); assertNotNull(plugin2.cmanager_); assertSame(value, plugin2.myClass_); }
@Test public void testStackOverFlow2() { final RootContainer container = AbstractTestContainer.createRootContainer(getClass(), "test-exo-container.xml"); SOE1 soe1 = (SOE1)container.getComponentInstanceOfType(SOE1.class); assertNotNull(soe1); assertEquals(1, soe1.plugins.size()); SOEPlugin soe1Plugin = soe1.plugins.get(0); assertNotNull(soe1Plugin); assertNotNull(soe1Plugin.soe2); assertSame(soe1, soe1Plugin.soe2.soe1); assertSame(container.getComponentInstanceOfType(SOE2.class), soe1Plugin.soe2); }