@Test public void should_sanitize_pico_exception_on_start_failure() { ComponentContainer container = new ComponentContainer(); container.add(UnstartableComponent.class); // do not expect a PicoException thrown.expect(IllegalStateException.class); container.startComponents(); }
@Test public void testChild() { ComponentContainer parent = new ComponentContainer(); parent.startComponents(); ComponentContainer child = parent.createChild(); child.addSingleton(StartableComponent.class); child.startComponents(); assertThat(child.getParent()).isSameAs(parent); assertThat(parent.getChild()).isSameAs(child); assertThat(child.getComponentByType(ComponentContainer.class)).isSameAs(child); assertThat(parent.getComponentByType(ComponentContainer.class)).isSameAs(parent); assertThat(child.getComponentByType(StartableComponent.class)).isNotNull(); assertThat(parent.getComponentByType(StartableComponent.class)).isNull(); parent.stopComponents(); }
@Test public void testRemoveChild() { ComponentContainer parent = new ComponentContainer(); parent.startComponents(); ComponentContainer child = parent.createChild(); assertThat(parent.getChild()).isSameAs(child); parent.removeChild(); assertThat(parent.getChild()).isNull(); }
@Test public void display_plugin_name_when_failing_to_add_extension() { ComponentContainer container = new ComponentContainer(); PluginInfo plugin = mock(PluginInfo.class); container.startComponents(); thrown.expect(IllegalStateException.class); thrown.expectMessage( "Unable to register extension org.sonar.core.platform.ComponentContainerTest$UnstartableComponent"); container.addExtension(plugin, UnstartableComponent.class); }
@Test public void should_start_and_stop() { ComponentContainer container = spy(new ComponentContainer()); container.addSingleton(StartableComponent.class); container.startComponents(); assertThat(container.getComponentByType(StartableComponent.class).started).isTrue(); assertThat(container.getComponentByType(StartableComponent.class).stopped).isFalse(); verify(container).doBeforeStart(); verify(container).doAfterStart(); container.stopComponents(); assertThat(container.getComponentByType(StartableComponent.class).stopped).isTrue(); }
@Test public void shouldForwardStartAndStopToDescendants() { ComponentContainer grandParent = new ComponentContainer(); ComponentContainer parent = grandParent.createChild(); ComponentContainer child = parent.createChild(); child.addSingleton(StartableComponent.class); grandParent.startComponents(); StartableComponent component = child.getComponentByType(StartableComponent.class); assertTrue(component.started); parent.stopComponents(); assertTrue(component.stopped); }