diff --git a/src/test/java/info/ebenoit/ebul/cmp/TestComponentState.java b/src/test/java/info/ebenoit/ebul/cmp/TestComponentState.java index 34c4cc2..3f4f30b 100644 --- a/src/test/java/info/ebenoit/ebul/cmp/TestComponentState.java +++ b/src/test/java/info/ebenoit/ebul/cmp/TestComponentState.java @@ -515,6 +515,21 @@ public class TestComponentState } + /** Test: {@link ComponentState#destroy()} on an uninitialised component does nothing */ + @Test + public void testDestroyUninitialised( ) + { + final LCATest lcaTest = new LCATest( ); + final NewComponentInfo< LCATest > ci = new NewComponentInfo< LCATest >( lcaTest ) // + .setLifecycleAction( LifecycleStage.DESTROY , ( o ) -> { + o.stage = LifecycleStage.DESTROY; + } ); + final ComponentState cs = TestComponentState.makeState( ci , this.reg , false , false ); + cs.destroy( ); + Assert.assertNull( lcaTest.stage ); + } + + /** Test: {@link ComponentState#destroy()} re-throws {@link ComponentDestructionException} */ @Test public void testDestroyActionExceptionPassthrough( ) @@ -1101,4 +1116,45 @@ public class TestComponentState Assert.assertFalse( rt.started ); } + + /** Test: {@link ComponentState#restart()} restarts drivers */ + @Test + public void testRestartDrivers( ) + { + final ComponentState cs1 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true ); + final ComponentState cs2 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true ); + cs2.setDriverFor( cs1 ); + + this.reg.active = true; + cs1.restart( ); + + final RestartTest rt = (RestartTest) cs2.getComponent( ); + Assert.assertTrue( rt.stopped ); + Assert.assertTrue( rt.started ); + } + + + /** Test: {@link ComponentState#restart()} stops drivers after normal reverse dependencies and restarts them first */ + @Test + public void testRestartDriversOrder( ) + { + final ComponentState cs1 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true ); + final ComponentState cs2 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true ); + cs2.setDriverFor( cs1 ); + + final RestartTest rt = (RestartTest) cs2.getComponent( ); + NewComponentInfo< Object > ci3 = new NewComponentInfo< Object >( new Object( ) ) // + .setLifecycleAction( LifecycleStage.STOP , ( o ) -> { + Assert.assertFalse( rt.stopped ); + }) // + .setLifecycleAction( LifecycleStage.START , ( o ) -> { + Assert.assertTrue( rt.stopped ); + Assert.assertTrue( rt.started ); + }); // + final ComponentState cs3 = TestComponentState.makeState( ci3 , this.reg , true , true ); + cs3.addDependency( cs1 ); + + this.reg.active = true; + cs1.restart( ); + } }