diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2019-04-10 10:25:05 -0500 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2019-04-10 10:59:14 -0500 |
commit | a3188c948acf949984414ca7baf0c32685922d4d (patch) | |
tree | 72e0573a20aa0a162a9258604e0dbe14aca060ec /feature-lifecycle/src/test/java | |
parent | 3a5ac5962d58b850202c4c93f3ad0846366b8ae5 (diff) |
Send policies in status
Change-Id: Ia1f02857922a81c5d94ffc33cee72ce9a822c876
Issue-ID: POLICY-1624
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/test/java')
-rw-r--r-- | feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java index b8afd200..554f2ef0 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java @@ -30,6 +30,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -189,6 +190,9 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { @Test public void update() throws IOException, CoderException { + + // TODO: extract repeated similar assertion blocks into their own helper methods + PdpUpdate update = new PdpUpdate(); update.setName(NetworkUtil.getHostname()); update.setPdpGroup("Z"); @@ -196,7 +200,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { update.setPolicies(Collections.emptyList()); long originalInterval = fsm.getStatusTimerSeconds(); - long interval = 2 * originalInterval; + long interval = 10 * originalInterval; update.setPdpHeartbeatIntervalMs(interval * 1000L); fsm.start(controllerSupport.getController()); @@ -213,10 +217,16 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { ToscaPolicy toscaPolicyRestartV1 = new StandardCoder().decode(restartV1, ToscaPolicy.class); update.setPolicies(Arrays.asList(toscaPolicyRestartV1)); + int qlength = fsm.client.getSink().getRecentEvents().length; + // update with an operational.restart policy assertTrue(fsm.update(update)); + assertEquals(qlength + 1, fsm.client.getSink().getRecentEvents().length); assertEquals(1, fsm.policyTypesMap.size()); + PdpStatus cachedStatus = new StandardCoder() + .decode(fsm.client.getSink().getRecentEvents()[qlength], PdpStatus.class); + assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies()); List<ToscaPolicy> factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(1, factPolicies.size()); @@ -226,7 +236,12 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { // dup update with the same operational.restart policy - nothing changes assertTrue(fsm.update(update)); + assertEquals(qlength + 2, fsm.client.getSink().getRecentEvents().length); assertEquals(1, fsm.policyTypesMap.size()); + cachedStatus = new StandardCoder() + .decode(fsm.client.getSink().getRecentEvents()[qlength + 1], PdpStatus.class); + assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies()); + factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(1, factPolicies.size()); @@ -237,7 +252,11 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { update.setPolicies(Collections.emptyList()); assertTrue(fsm.update(update)); + assertEquals(qlength + 3, fsm.client.getSink().getRecentEvents().length); assertEquals(1, fsm.policyTypesMap.size()); + cachedStatus = new StandardCoder() + .decode(fsm.client.getSink().getRecentEvents()[qlength + 2], PdpStatus.class); + assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies()); factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(0, factPolicies.size()); @@ -247,7 +266,11 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { update.setPolicies(Arrays.asList(toscaPolicyRestartV1)); assertTrue(fsm.update(update)); + assertEquals(qlength + 4, fsm.client.getSink().getRecentEvents().length); assertEquals(1, fsm.policyTypesMap.size()); + cachedStatus = new StandardCoder() + .decode(fsm.client.getSink().getRecentEvents()[qlength + 3], PdpStatus.class); + assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies()); factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(1, factPolicies.size()); @@ -261,7 +284,11 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { ToscaPolicy toscaPolicyRestartV2 = new StandardCoder().decode(restartV2, ToscaPolicy.class); update.setPolicies(Arrays.asList(toscaPolicyRestartV2)); assertTrue(fsm.update(update)); + assertEquals(qlength + 5, fsm.client.getSink().getRecentEvents().length); assertEquals(1, fsm.policyTypesMap.size()); + cachedStatus = new StandardCoder() + .decode(fsm.client.getSink().getRecentEvents()[qlength + 4], PdpStatus.class); + assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies()); factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(1, factPolicies.size()); @@ -276,7 +303,11 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { ToscaPolicy toscaPolicyFirewall = new StandardCoder().decode(firewall, ToscaPolicy.class); update.setPolicies(Arrays.asList(toscaPolicyRestartV2, toscaPolicyFirewall)); assertTrue(fsm.update(update)); + assertEquals(qlength + 6, fsm.client.getSink().getRecentEvents().length); assertEquals(1, fsm.policyTypesMap.size()); + cachedStatus = new StandardCoder() + .decode(fsm.client.getSink().getRecentEvents()[qlength + 5], PdpStatus.class); + assertEquals(new ArrayList<>(fsm.policiesMap.keySet()), cachedStatus.getPolicies()); factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(2, factPolicies.size()); |