From 9d93b8b4c3577a381e9b5181965d2ceb31e446ed Mon Sep 17 00:00:00 2001 From: jhh Date: Mon, 13 May 2019 23:31:44 -0500 Subject: Ensure passive policies are injected when active Add vim package for testing support Change-Id: Icefcf8a57eea80b4fed97d4c63080f6159d8167a Issue-ID: POLICY-1748 Signed-off-by: jhh --- .../lifecycle/LifecycleStatePassiveTest.java | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'feature-lifecycle/src/test') diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java index 71147e2a..711db028 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java @@ -267,7 +267,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest { } @Test - public void stateChange() throws CoderException { + public void stateChange() throws CoderException, IOException { /* no name */ PdpStateChange change = new PdpStateChange(); change.setPdpGroup("A"); @@ -282,13 +282,45 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest { assertNull(fsm.getGroup()); assertNull(fsm.getSubgroup()); + PdpUpdate update = new PdpUpdate(); + update.setName(NetworkUtil.getHostname()); + update.setPdpGroup("A"); + update.setPdpSubgroup("a"); + + String rawPolicy = + new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-operational-restart.json"))); + ToscaPolicy toscaPolicy = new StandardCoder().decode(rawPolicy, ToscaPolicy.class); + update.setPolicies(Arrays.asList(toscaPolicy)); + + controllerSupport.getController().start(); + fsm.start(controllerSupport.getController()); + assertEquals(1, fsm.policyTypesMap.size()); + assertTrue(fsm.policiesMap.isEmpty()); + + assertTrue(fsm.update(update)); + assertEquals(1, fsm.policyTypesMap.size()); + assertEquals(1, fsm.policiesMap.size()); + assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy); + assertEquals(PdpState.PASSIVE, fsm.state()); + assertEquals("A", fsm.getGroup()); + assertEquals("a", fsm.getSubgroup()); + assertBasicPassive(); + assertEquals(0, controllerSupport.getController().getDrools().factCount("junits")); + /* correct name */ change.setName(fsm.getName()); fsm.source.offer(new StandardCoder().encode(change)); assertEquals(PdpState.ACTIVE, fsm.state()); - assertNull(fsm.getGroup()); - assertNull(fsm.getSubgroup()); + assertEquals("A", fsm.getGroup()); + assertEquals("a", fsm.getSubgroup()); + + await() + .atMost(5, TimeUnit.SECONDS) + .until(() -> controllerSupport.getController().getDrools().factCount("junits") == 1); + + assertTrue(controllerSupport.getController().getDrools().delete(ToscaPolicy.class)); + assertEquals(0, controllerSupport.getController().getDrools().factCount("junits")); fsm.shutdown(); } -- cgit 1.2.3-korg