diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2019-04-09 14:24:34 -0500 |
---|---|---|
committer | jhh <jorge.hernandez-herrero@att.com> | 2019-04-09 14:30:01 -0500 |
commit | 712274e8d332181729c06c31dcf58d49f2a4d8f7 (patch) | |
tree | a684200d82ada2fe062e1f8f1071130f6bec77d5 /feature-lifecycle/src/test/java/org | |
parent | 3f90dba2636b06bcb90b8f1e158b30886af574d5 (diff) |
deploy and undeploy as audits.
Change-Id: Iea1766d5d8075394e1dccc109f4477bd2c270c36
Issue-ID: POLICY-1624
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/test/java/org')
4 files changed, 74 insertions, 15 deletions
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java index 1beee552..d5ac423a 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.nio.file.Paths; import java.util.List; import java.util.Properties; -import java.util.stream.Collectors; import lombok.Getter; import lombok.NonNull; import org.kie.api.builder.ReleaseId; @@ -103,10 +102,6 @@ public class ControllerSupport { public <T> List<T> getFacts(Class<T> clazz) { return PolicyController.factory.get(name) .getDrools() - .facts(SESSION_NAME, clazz.getCanonicalName(), false) - .stream() - .filter(clazz::isInstance) - .map(clazz::cast) - .collect(Collectors.toList()); + .facts(SESSION_NAME, clazz); } } 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 32006425..b8afd200 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 @@ -33,6 +33,7 @@ import java.nio.file.Paths; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.junit.Before; @@ -73,6 +74,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { change.setName(fsm.getName()); fsm.source.offer(new StandardCoder().encode(change)); + controllerSupport.getController().start(); } @Test @@ -197,7 +199,6 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { long interval = 2 * originalInterval; update.setPdpHeartbeatIntervalMs(interval * 1000L); - controllerSupport.getController().start(); fsm.start(controllerSupport.getController()); assertTrue(fsm.update(update)); @@ -207,20 +208,83 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest { assertEquals("Z", fsm.getGroup()); assertEquals("z", fsm.getSubgroup()); - String rawPolicy = - new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy.json"))); - ToscaPolicy toscaPolicy = new StandardCoder().decode(rawPolicy, ToscaPolicy.class); - update.setPolicies(Arrays.asList(toscaPolicy)); + String restartV1 = + new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-operational-restart.json"))); + ToscaPolicy toscaPolicyRestartV1 = new StandardCoder().decode(restartV1, ToscaPolicy.class); + update.setPolicies(Arrays.asList(toscaPolicyRestartV1)); + + // update with an operational.restart policy assertTrue(fsm.update(update)); assertEquals(1, fsm.policyTypesMap.size()); List<ToscaPolicy> factPolicies = controllerSupport.getFacts(ToscaPolicy.class); assertEquals(1, factPolicies.size()); - assertEquals(toscaPolicy, factPolicies.get(0)); + assertEquals(toscaPolicyRestartV1, factPolicies.get(0)); + assertEquals(1, fsm.policiesMap.size()); + + // dup update with the same operational.restart policy - nothing changes + + assertTrue(fsm.update(update)); + assertEquals(1, fsm.policyTypesMap.size()); + + factPolicies = controllerSupport.getFacts(ToscaPolicy.class); + assertEquals(1, factPolicies.size()); + assertEquals(toscaPolicyRestartV1, factPolicies.get(0)); assertEquals(1, fsm.policiesMap.size()); - controllerSupport.getController().stop(); + // undeploy operational.restart policy + + update.setPolicies(Collections.emptyList()); + assertTrue(fsm.update(update)); + assertEquals(1, fsm.policyTypesMap.size()); + + factPolicies = controllerSupport.getFacts(ToscaPolicy.class); + assertEquals(0, factPolicies.size()); + assertEquals(0, fsm.policiesMap.size()); + + // redeploy operational.restart policy + + update.setPolicies(Arrays.asList(toscaPolicyRestartV1)); + assertTrue(fsm.update(update)); + assertEquals(1, fsm.policyTypesMap.size()); + + factPolicies = controllerSupport.getFacts(ToscaPolicy.class); + assertEquals(1, factPolicies.size()); + assertEquals(toscaPolicyRestartV1, factPolicies.get(0)); + assertEquals(1, fsm.policiesMap.size()); + + // deploy a new version of the operational.restart policy + + String restartV2 = + new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-operational-restart.v2.json"))); + ToscaPolicy toscaPolicyRestartV2 = new StandardCoder().decode(restartV2, ToscaPolicy.class); + update.setPolicies(Arrays.asList(toscaPolicyRestartV2)); + assertTrue(fsm.update(update)); + assertEquals(1, fsm.policyTypesMap.size()); + + factPolicies = controllerSupport.getFacts(ToscaPolicy.class); + assertEquals(1, factPolicies.size()); + assertNotEquals(toscaPolicyRestartV1, factPolicies.get(0)); + assertEquals(toscaPolicyRestartV2, factPolicies.get(0)); + assertEquals(1, fsm.policiesMap.size()); + + // deploy another policy : firewall + + String firewall = + new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-operational-firewall.json"))); + ToscaPolicy toscaPolicyFirewall = new StandardCoder().decode(firewall, ToscaPolicy.class); + update.setPolicies(Arrays.asList(toscaPolicyRestartV2, toscaPolicyFirewall)); + assertTrue(fsm.update(update)); + assertEquals(1, fsm.policyTypesMap.size()); + + factPolicies = controllerSupport.getFacts(ToscaPolicy.class); + assertEquals(2, factPolicies.size()); + assertTrue(factPolicies.stream().noneMatch((ff) -> Objects.equals(toscaPolicyRestartV1, ff))); + assertTrue(factPolicies.stream().anyMatch((ff) -> Objects.equals(toscaPolicyRestartV2, ff))); + assertTrue(factPolicies.stream().anyMatch((ff) -> Objects.equals(toscaPolicyFirewall, ff))); + assertEquals(2, fsm.policiesMap.size()); + fsm.shutdown(); } } 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 100bcef5..775dc8b0 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 @@ -187,7 +187,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest { assertBasicPassive(); String rawPolicy = - new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy.json"))); + 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)); diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java index d7bb6d75..6da9dc12 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java @@ -41,7 +41,7 @@ public abstract class LifecycleStateRunningTest { public static void setUp() throws IOException { LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO"); LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN"); - LoggerUtil.setLevel("org.onap.policy.drools", "WARN"); + LoggerUtil.setLevel("org.onap.policy.drools", "INFO"); SystemPersistence.manager.setConfigurationDir("src/test/resources"); controllerSupport.createController(); } |