summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2021-03-25 18:19:29 +0100
committersebdet <sebastien.determe@intl.att.com>2021-04-07 10:14:00 +0200
commit7f685aa342813c611b6e43d7b4a869c7454baddc (patch)
treeb1668e028b2b68fa928f4819ab52b0f2849f31f9 /src/test/java/org/onap
parentdf451dc64de36d571efb4f0457a83bc94e8f3969 (diff)
Rework the backend to support PDP updates
Rework Pdp payloads builder so that we can integrate different actions in the same batch + Add a new endpoint to support pdp payload&query to PEF from UI Issue-ID: POLICY-2930 Issue-ID: POLICY-2931 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Change-Id: I3c933272419770595b706f6950f821220a76f778
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/policy/clamp/loop/PolicyComponentTest.java11
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java16
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadExceptionTest.java33
-rw-r--r--src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadTest.java75
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);
+ }
+}