diff options
author | jhh <jorge.hernandez-herrero@att.com> | 2020-02-12 18:20:06 -0600 |
---|---|---|
committer | Jorge Hernandez <jorge.hernandez-herrero@att.com> | 2020-02-17 20:25:22 +0000 |
commit | 6dfab64262ea5816c761042192c84e498a3177ab (patch) | |
tree | 665dd3e68a9fc4303898fc9d7fe34d4c404ef7a4 /controlloop/common/controller-usecases/src/test | |
parent | 43b12b12c0c427bc89ab88f4d4034821d4c9835d (diff) |
tosca compliant op policy support + vcpe test
Tosca Compliant and Toscal Legacy Operational policies are
both supported for backwards compatibility.
vCPE usecase junits to support 2 equivalent policies,
one tosca compliant and the other one legacy.
Issue-ID: POLICY-2360
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Iafbfc92bbec42e6a3fe4ceb4a9a17c85e636ea14
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'controlloop/common/controller-usecases/src/test')
-rw-r--r-- | controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java | 10 | ||||
-rw-r--r-- | controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java | 44 | ||||
-rw-r--r-- | controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json | 37 | ||||
-rw-r--r-- | controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json (renamed from controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json) | 0 |
4 files changed, 73 insertions, 18 deletions
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java index 1fe6ace44..618963a70 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesBase.java @@ -146,7 +146,7 @@ public abstract class UsecasesBase { return usecases .getDrools() .facts(USECASES, ControlLoopParams.class).stream() - .filter((params) -> params.getControlLoopYaml() == policy.getProperties().get("content")) + .filter((params) -> params.getToscaPolicy() == policy) .findFirst() .get(); } @@ -178,7 +178,7 @@ public abstract class UsecasesBase { usecases .getDrools() .facts(USECASES, ControlLoopParams.class).stream() - .filter((params) -> params.getControlLoopYaml() == policy.getProperties().get("content")) + .filter((params) -> params.getToscaPolicy() == policy) .count()); return policy; @@ -209,18 +209,18 @@ public abstract class UsecasesBase { usecases .getDrools() .facts(USECASES, ControlLoopParams.class).stream() - .filter((params) -> params.getControlLoopYaml() == policy.getProperties().get("content")) + .filter((params) -> params.getPolicyName() == policy.getName()) .count()); } /** * Prepare a PDP-D to test the Use Cases. */ - protected static void preparePdpD() throws IOException, InterruptedException, CoderException { + protected static void preparePdpD() throws IOException { KieUtils.installArtifact( Paths.get("src/main/resources/META-INF/kmodule.xml").toFile(), Paths.get("src/test/resources/usecases.pom").toFile(), - "src/main/resources/onap.policies.controlloop.Operational/org/onap/policy/controlloop/", + "src/main/resources/org/onap/policy/controlloop/", Collections.singletonList(Paths.get("src/main/resources/usecases.drl").toFile())); repo.setConfigurationDir("src/test/resources/config"); diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java index 8690f1a0a..1d9d0dd26 100644 --- a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java +++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/VcpeTest.java @@ -42,7 +42,8 @@ public class VcpeTest extends UsecasesBase { /** * VCPE Tosca Policy File. */ - private static final String TOSCA_POLICY_VCPE = "src/test/resources/vcpe/tosca-vcpe.json"; + private static final String TOSCA_LEGACY_POLICY_VCPE = "src/test/resources/vcpe/tosca-legacy-vcpe.json"; + private static final String TOSCA_COMPLIANT_POLICY_VCPE = "src/test/resources/vcpe/tosca-compliant-vcpe.json"; /* * VCPE Use case Messages. @@ -86,7 +87,6 @@ public class VcpeTest extends UsecasesBase { /** * Sunny day scenario for the VCPE use case. */ - @Test public void sunnyDay() throws IOException { /* Inject an ONSET event over the DCAE topic */ @@ -122,12 +122,40 @@ public class VcpeTest extends UsecasesBase { } /** + * Sunny Day with Legacy Tosca Policy. + */ + @Test + public void sunnyDayLegacy() throws InterruptedException, CoderException, IOException { + assertEquals(0, usecases.getDrools().factCount(USECASES)); + policy = setupPolicy(TOSCA_LEGACY_POLICY_VCPE); + assertEquals(2, usecases.getDrools().factCount(USECASES)); + + sunnyDay(); + } + + /** + * Sunny Day with Tosca Compliant Policy. + */ + @Test + public void sunnyDayCompliant() throws InterruptedException, CoderException, IOException { + assertEquals(0, usecases.getDrools().factCount(USECASES)); + policy = setupPolicy(TOSCA_COMPLIANT_POLICY_VCPE); + assertEquals(2, usecases.getDrools().factCount(USECASES)); + + sunnyDay(); + } + + /** * An ONSET flood prevention test that injects a few ONSETs at once. * It attempts to simulate the flooding behavior of the DCAE TCA microservice. * TCA could blast tenths or hundreds of ONSETs within sub-second intervals. */ @Test - public void onsetFloodPrevention() throws IOException { + public void onsetFloodPrevention() throws IOException, InterruptedException, CoderException { + assertEquals(0, usecases.getDrools().factCount(USECASES)); + policy = setupPolicy(TOSCA_LEGACY_POLICY_VCPE); + assertEquals(2, usecases.getDrools().factCount(USECASES)); + injectOnTopic(DCAE_TOPIC, Paths.get(ONSET_1)); injectOnTopic(DCAE_TOPIC, Paths.get(ONSET_2)); injectOnTopic(DCAE_TOPIC, Paths.get(ONSET_3)); @@ -169,16 +197,6 @@ public class VcpeTest extends UsecasesBase { } /** - * Install Policy. - */ - @Before - public void installPolicy() throws IOException, CoderException, InterruptedException { - assertEquals(0, usecases.getDrools().factCount(USECASES)); - policy = setupPolicy(TOSCA_POLICY_VCPE); - assertEquals(2, usecases.getDrools().factCount(USECASES)); - } - - /** * Uninstall Policy. */ @After diff --git a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json new file mode 100644 index 000000000..c01f6898c --- /dev/null +++ b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-compliant-vcpe.json @@ -0,0 +1,37 @@ +{ + "type": "onap.policies.controlloop.operational.common.Drools", + "type_version": "1.0.0", + "version": "1.0.0", + "name": "operational.restart", + "metadata": { + "policy-id": "operational.restart" + }, + "properties": { + "id": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", + "timeout": 3600, + "abatement": false, + "trigger": "unique-policy-id-1-restart", + "operations": [ + { + "id": "unique-policy-id-1-restart", + "description": "Restart the VM", + "operation": { + "actor": "APPC", + "operation": "Restart", + "target": { + "type": "VM" + } + }, + "timeout": 1200, + "retries": 3, + "success": "final_success", + "failure": "final_failure", + "failure_timeout": "final_failure_timeout", + "failure_retries": "final_failure_retries", + "failure_exception": "final_failure_exception", + "failure_guard": "final_failure_guard" + } + ], + "controllerName": "usecases" + } +}
\ No newline at end of file diff --git a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json index f42c07da9..f42c07da9 100644 --- a/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-vcpe.json +++ b/controlloop/common/controller-usecases/src/test/resources/vcpe/tosca-legacy-vcpe.json |