From 7ccae60ba9695dc6a3f9abf0ca52717309f66b0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 17 Sep 2015 23:51:31 +0200 Subject: [PATCH] Component state - A few more missing tests --- .../ebenoit/ebul/cmp/TestComponentState.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) 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( ); + } }