aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/test/java/org/onap/policy
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-02-24 18:14:04 -0600
committerjhh <jorge.hernandez-herrero@att.com>2020-02-24 18:22:33 -0600
commit6d284bc693b5103ad27ff533957ec2a51fa61f42 (patch)
treef0397737c3205f7869c8e1cd75ec344b66b099a5 /controlloop/common/eventmanager/src/test/java/org/onap/policy
parent43c1e8c7c820bc8004725355a4a5eb0ad519e680 (diff)
vDNS tosca compliant policies support
Issue-ID: POLICY-2383 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I5d5d864b2853f6e7e0c7e1096cb17746500f2495 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'controlloop/common/eventmanager/src/test/java/org/onap/policy')
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java62
1 files changed, 50 insertions, 12 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
index a30914781..ae6af6c07 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
@@ -32,14 +32,17 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,32 +58,67 @@ public class ControlLoopProcessorTest {
this.testFailure(yamlString);
}
+ private ToscaPolicy getPolicyFromResource(String resourcePath, String policyName) throws CoderException {
+ String policyJson = ResourceUtils.getResourceAsString(resourcePath);
+ ToscaServiceTemplate serviceTemplate = coder.decode(policyJson, ToscaServiceTemplate.class);
+ ToscaPolicy policy = serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
+ assertNotNull(policy);
+
+ /*
+ * name and version are used within a drl. api component and drools core will ensure that these
+ * are populated.
+ */
+ if (StringUtils.isBlank(policy.getName())) {
+ policy.setName(policyName);
+ }
+
+ if (StringUtils.isBlank(policy.getVersion())) {
+ policy.setVersion(policy.getTypeVersion());
+ }
+
+ return serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
+ }
+
@Test
public void testControlLoopFromToscaLegacy() throws IOException, CoderException, ControlLoopException {
String policy =
new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-legacy-vcpe.json")));
assertNotNull(
new ControlLoopProcessor(coder.decode(policy, ToscaPolicy.class)).getCurrentPolicy());
+
+ policy =
+ new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-legacy-vdns.json")));
+ assertNotNull(
+ new ControlLoopProcessor(coder.decode(policy, ToscaPolicy.class)).getCurrentPolicy());
}
@Test
- public void testControlLoopFromToscaCompliant() throws IOException, CoderException, ControlLoopException {
- String policy =
- new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-compliant-vcpe.json")));
+ public void testControlLoopFromToscaCompliant()
+ throws CoderException, ControlLoopException {
assertNotNull(
- new ControlLoopProcessor(coder.decode(policy, ToscaPolicy.class)).getCurrentPolicy());
+ new ControlLoopProcessor(
+ getPolicyFromResource(
+ "policies/vCPE.policy.operational.input.tosca.json", "operational.restart")
+ ).getCurrentPolicy());
+
- policy =
- new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-compliant-vfw.json")));
assertNotNull(
- new ControlLoopProcessor(coder.decode(policy, ToscaPolicy.class)).getCurrentPolicy());
+ new ControlLoopProcessor(
+ getPolicyFromResource(
+ "policies/vFirewall.policy.operational.input.tosca.json", "operational.modifyconfig")
+ ).getCurrentPolicy());
+
+ assertNotNull(
+ new ControlLoopProcessor(
+ getPolicyFromResource(
+ "policies/vDNS.policy.operational.input.tosca.json", "operational.scaleout")
+ ).getCurrentPolicy());
}
@Test
- public void testControlLoopFromToscaCompliantBad() throws IOException, CoderException, ControlLoopException {
- String policy =
- new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-compliant-vcpe.json")));
- ToscaPolicy toscaPolicy = coder.decode(policy, ToscaPolicy.class);
+ public void testControlLoopFromToscaCompliantBad() throws CoderException {
+ ToscaPolicy toscaPolicy = getPolicyFromResource(
+ "policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
toscaPolicy.setType("onap.policies.controlloop.Operational");
assertThatThrownBy(() -> new ControlLoopProcessor(toscaPolicy)).hasCauseInstanceOf(CoderException.class);
}
@@ -147,7 +185,7 @@ public class ControlLoopProcessorTest {
}
/**
- * Test policies in the given yaml following the successfull path.
+ * Test policies in the given yaml following the successful path.
*
* @param yaml yaml containing the policies to test
* @throws ControlLoopException if an error occurs