From 6a429b8504cdd38cadb3ce9bb532d08cc5115da9 Mon Sep 17 00:00:00 2001 From: jhh Date: Tue, 17 Nov 2020 14:40:16 -0600 Subject: support for not validated policy types Issue-ID: POLICY-2880 Signed-off-by: jhh Change-Id: Id816bb3edd44c34a342cd7ada95dd8f2f9d1b0a6 Signed-off-by: jhh --- .../server/restful/RestLifecycleManagerTest.java | 60 +++++++++++++--------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'feature-lifecycle/src/test/java/org') diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java index ea485095..0751eb54 100644 --- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java +++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java @@ -76,6 +76,10 @@ public class RestLifecycleManagerTest { private static final String EXAMPLE_NATIVE_ARTIFACT_POLICY_JSON = "src/test/resources/tosca-policy-native-artifact-example.json"; + private static final String EXAMPLE_OTHER_POLICY_NAME = "other"; + private static final String EXAMPLE_OTHER_POLICY_JSON = + "src/test/resources/tosca-policy-other.json"; + private static final String OP_POLICY_NAME_VCPE = "operational.restart"; private static final String VCPE_OPERATIONAL_DROOLS_POLICY_JSON = "policies/vCPE.policy.operational.input.tosca.json"; @@ -231,31 +235,12 @@ public class RestLifecycleManagerTest { if (StringUtils.isBlank(opPolicy.getName())) { opPolicy.setName(opPolicy.getMetadata().get("policy-id")); } - assertTrue( - listPost("policies/operations/validation", toString(opPolicy), Status.OK.getStatusCode()).isEmpty()); + testNotNativePolicy(opPolicy); - booleanPost("policies", toString(opPolicy), Status.OK.getStatusCode(), Boolean.TRUE); - assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").isAlive()); - assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained()); - assertEquals(1, - PolicyControllerConstants - .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size()); + /* add tosca "other" of policy type "other" with no attached type schema */ - resourceLists("policies", 3); - get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.OK.getStatusCode()); - get("policies/example.controller/1.0.0", Status.OK.getStatusCode()); - get("policies/example.artifact/1.0.0", Status.OK.getStatusCode()); - - booleanDelete("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), - Status.OK.getStatusCode(), Boolean.TRUE); - assertEquals(0, - PolicyControllerConstants - .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size()); - - resourceLists("policies", 2); - get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode()); - get("policies/example.controller/1.0.0", Status.OK.getStatusCode()); - get("policies/example.artifact/1.0.0", Status.OK.getStatusCode()); + ToscaPolicy otherPolicy = getPolicyFromFile(EXAMPLE_OTHER_POLICY_JSON, EXAMPLE_OTHER_POLICY_NAME); + testNotNativePolicy(otherPolicy); /* individual deploy/undeploy operations */ @@ -321,6 +306,35 @@ public class RestLifecycleManagerTest { Status.NOT_ACCEPTABLE.getStatusCode()).isEmpty()); } + private void testNotNativePolicy(ToscaPolicy opPolicy) throws CoderException { + assertTrue( + listPost("policies/operations/validation", toString(opPolicy), + Status.OK.getStatusCode()).isEmpty()); + + booleanPost("policies", toString(opPolicy), Status.OK.getStatusCode(), Boolean.TRUE); + assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").isAlive()); + assertTrue(PolicyControllerConstants.getFactory().get("lifecycle").getDrools().isBrained()); + assertEquals(1, + PolicyControllerConstants + .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size()); + + resourceLists("policies", 3); + get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.OK.getStatusCode()); + get("policies/example.controller/1.0.0", Status.OK.getStatusCode()); + get("policies/example.artifact/1.0.0", Status.OK.getStatusCode()); + + booleanDelete("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), + Status.OK.getStatusCode(), Boolean.TRUE); + assertEquals(0, + PolicyControllerConstants + .getFactory().get("lifecycle").getDrools().facts("junits", ToscaPolicy.class).size()); + + resourceLists("policies", 2); + get("policies/" + opPolicy.getName() + "/" + opPolicy.getVersion(), Status.NOT_FOUND.getStatusCode()); + get("policies/example.controller/1.0.0", Status.OK.getStatusCode()); + get("policies/example.artifact/1.0.0", Status.OK.getStatusCode()); + } + private Response get(String contextPath, int statusCode) { Response response = client.get(contextPath); assertEquals(statusCode, response.getStatus()); -- cgit 1.2.3-korg