diff options
Diffstat (limited to 'src/test/java/org/onap')
4 files changed, 121 insertions, 14 deletions
diff --git a/src/test/java/org/onap/policy/clamp/loop/PolicyComponentTest.java b/src/test/java/org/onap/policy/clamp/loop/PolicyComponentTest.java index ea8785855..5b4e405bb 100644 --- a/src/test/java/org/onap/policy/clamp/loop/PolicyComponentTest.java +++ b/src/test/java/org/onap/policy/clamp/loop/PolicyComponentTest.java @@ -1,8 +1,8 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,6 +39,7 @@ import org.onap.policy.clamp.loop.template.LoopTemplate; import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.clamp.policy.microservice.MicroServicePolicy; import org.onap.policy.clamp.policy.operational.OperationalPolicy; +import org.skyscreamer.jsonassert.JSONAssert; public class PolicyComponentTest { @@ -289,9 +290,7 @@ public class PolicyComponentTest { loopTemplate.setDcaeBlueprintId("UUID-blueprint"); loopTest.setLoopTemplate(loopTemplate); - String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest, "POST"); - String expectedRes = ResourceFileUtils.getResourceAsString("tosca/pdp-group-policy-payload.json"); - - assertThat(payload).isEqualTo(expectedRes); + JSONAssert.assertEquals(ResourceFileUtils.getResourceAsString("example/policy/pdp-group-policy-payload.json"), + PolicyComponent.createPoliciesPayloadPdpGroup(loopTest, "POST"), false); } } diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java index c7ada58cf..30d4ebe28 100644 --- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java @@ -158,8 +158,8 @@ public class PdpGroupAnalyzerTest { assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0"))).hasSize(1); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() - .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups().size()) - .isEqualTo(1); + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups()) + .hasSize(1); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups()) .contains(pdpSubgroup2); @@ -167,20 +167,20 @@ public class PdpGroupAnalyzerTest { assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1"))).hasSize(3); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() - .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups().size()) - .isEqualTo(1); + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups()) + .hasSize(1); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups()) .contains(pdpSubgroupBad); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() - .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups().size()) - .isEqualTo(1); + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups()) + .hasSize(1); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups()) .contains(pdpSubgroupBad); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() - .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups().size()) - .isEqualTo(1); + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups()) + .hasSize(1); assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups()) .contains(pdpSubgroupBad); diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadExceptionTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadExceptionTest.java new file mode 100644 index 000000000..f3c3fc6cd --- /dev/null +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadExceptionTest.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.clamp.policy.pdpgroup; + +import org.junit.Test; +import org.onap.policy.clamp.policy.pdpgroup.PdpGroupPayloadException; +import org.onap.policy.common.utils.test.ExceptionsTester; + +public class PdpGroupPayloadExceptionTest extends ExceptionsTester { + + @Test + public void testPdpGroupPayloadException() { + test(PdpGroupPayloadException.class); + } +} diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadTest.java new file mode 100644 index 000000000..34674e3ec --- /dev/null +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadTest.java @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.policy.clamp.policy.pdpgroup; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.io.IOException; +import org.junit.Test; +import org.onap.policy.clamp.clds.util.ResourceFileUtils; +import org.skyscreamer.jsonassert.JSONAssert; + +/** + * This class tests the PdpGroupPayload features. + */ +public class PdpGroupPayloadTest { + + @Test + public void testGeneratePdpGroupPayload() throws IOException, PdpGroupPayloadException { + JsonArray operations = new JsonArray(); + operations.add("POST/pdpgroup1/pdpsubgroup1/policyname1/1.0.0"); + operations.add("POST/pdpgroup1/pdpsubgroup1/policyname2/1.0.0"); + operations.add("POST/pdpgroup1/pdpsubgroup1/policyname1/2.0.0"); + operations.add("DELETE/pdpgroup2/pdpsubgroup2/policyname1/1.0.0"); + operations.add("POST/pdpgroup2/pdpsubgroup2/policyname1/2.0.0"); + operations.add("DELETE/pdpgroup2/pdpsubgroup2/policyname2/1.0.0"); + JsonObject listOfOperations = new JsonObject(); + listOfOperations.add(PdpGroupPayload.PDP_ACTIONS, operations); + + PdpGroupPayload pdpGroupPayload = new PdpGroupPayload(listOfOperations); + JSONAssert.assertEquals( + ResourceFileUtils.getResourceAsString("example/policy/pdp-group-multi-policies-payload.json"), + pdpGroupPayload.generatePdpGroupPayload(), false); + } + + @Test + public void testGeneratePdpGroupPayload_WithEmptyList() throws PdpGroupPayloadException { + JsonArray operations = new JsonArray(); + JsonObject listOfOperations = new JsonObject(); + listOfOperations.add(PdpGroupPayload.PDP_ACTIONS, operations); + + PdpGroupPayload pdpGroupPayload = new PdpGroupPayload(listOfOperations); + JSONAssert.assertEquals("{}", pdpGroupPayload.generatePdpGroupPayload(), false); + } + + @Test(expected = PdpGroupPayloadException.class) + public void testUpdatePdpGroupMap_WithEmptyEntry() throws PdpGroupPayloadException { + JsonArray operations = new JsonArray(); + operations.add(""); + JsonObject listOfOperations = new JsonObject(); + listOfOperations.add(PdpGroupPayload.PDP_ACTIONS, operations); + + PdpGroupPayload pdpGroupPayload = new PdpGroupPayload(listOfOperations); + } +} |