aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--pom.xml7
-rw-r--r--src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java22
-rw-r--r--src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java149
-rw-r--r--src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadException.java54
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml38
-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
-rw-r--r--src/test/resources/example/policy/pdp-group-multi-policies-payload.json94
-rw-r--r--src/test/resources/example/policy/pdp-group-policy-payload.json (renamed from src/test/resources/tosca/pdp-group-policy-payload.json)32
11 files changed, 434 insertions, 97 deletions
diff --git a/pom.xml b/pom.xml
index 0ac401da4..5fe58301a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -111,6 +111,7 @@
<npm.publish.url>https://nexus3.onap.org/repository/npm.snapshot/</npm.publish.url>
<policy.models.version>2.4.0</policy.models.version>
+ <policy.common.version>1.8.1</policy.common.version>
</properties>
<profiles>
@@ -557,6 +558,12 @@
<version>3.2.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils-test</artifactId>
+ <version>${policy.common.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java
index ff4e2643c..27e8e1a13 100644
--- a/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java
+++ b/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java
@@ -27,10 +27,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import javax.persistence.Transient;
import org.apache.camel.Exchange;
-import org.onap.policy.clamp.clds.util.JsonUtils;
import org.onap.policy.clamp.loop.Loop;
-import org.onap.policy.clamp.policy.microservice.MicroServicePolicy;
-import org.onap.policy.clamp.policy.operational.OperationalPolicy;
import org.onap.policy.clamp.policy.pdpgroup.PdpGroupPayload;
/**
@@ -81,19 +78,14 @@ public class PolicyComponent extends ExternalComponent {
*/
public static String createPoliciesPayloadPdpGroup(Loop loop, String action) {
PdpGroupPayload pdpGroupPayload = new PdpGroupPayload();
- for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) {
- pdpGroupPayload
- .updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), opPolicy.getName(), "1.0.0");
- }
-
- for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) {
- pdpGroupPayload
- .updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(), msPolicy.getName(), "1.0.0");
- }
+ loop.getOperationalPolicies().stream().forEach(opPolicy -> pdpGroupPayload
+ .updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), opPolicy.getName(), "1.0.0",
+ action));
- String payload = JsonUtils.GSON.toJson(pdpGroupPayload.generateActivatePdpGroupPayload(action));
- logger.info("PdpGroup policy payload: " + payload);
- return payload;
+ loop.getMicroServicePolicies().stream().forEach(msPolicy -> pdpGroupPayload
+ .updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(), msPolicy.getName(), "1.0.0",
+ action));
+ return pdpGroupPayload.generatePdpGroupPayload();
}
private static ExternalComponentState findNewState(boolean found, boolean deployed) {
diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java
index c89395044..a10f6df7d 100644
--- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java
+++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java
@@ -23,86 +23,115 @@
package org.onap.policy.clamp.policy.pdpgroup;
-import com.google.gson.JsonArray;
-import com.google.gson.JsonObject;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.gson.JsonElement;
+import java.util.ArrayList;
+import java.util.Arrays;
+import org.onap.policy.clamp.clds.util.JsonUtils;
+import org.onap.policy.models.pdp.concepts.DeploymentGroup;
+import org.onap.policy.models.pdp.concepts.DeploymentGroups;
+import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
* This is an utility class that build the PDP group policy payload.
* This is used when policies have to be deployed to PDP group/subgroups on the Policy Engine.
+ * Currently it does not group the queries per pdpgroup/subgroups/action.
+ * This is currently NOT thread safe, do not use parallel streams to update the structure.
*/
public class PdpGroupPayload {
- private Map<String, Map<String, List<JsonObject>>> pdpGroupMap = new HashMap<>();
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(PdpGroupPayload.class);
/**
- * This method updates the pdpGroupMap structure for a specific policy/version/pdpdGroup/PdpSubGroup.
+ * The default node that will contain the actions array.
+ */
+ public static final String PDP_ACTIONS = "PdpActions";
+
+ private final DeploymentGroups deploymentGroups = new DeploymentGroups();
+
+ /**
+ * Default constructor.
+ */
+ public PdpGroupPayload() {
+ deploymentGroups.setGroups(new ArrayList<>());
+ }
+
+ /**
+ * Constructor that takes a list of actions in input.
*
- * @param pdpGroup The pdp Group in String
- * @param pdpSubGroup The pdp Sub Group in String
- * @param policyName The policy name
- * @param policyVersion The policy Version
+ * @param listOfPdpActions The list of actions that needs to be done.
+ * e.g: {"Pdpactions":["DELETE/PdpGroup1/PdpSubGroup1/PolicyName1/1.0.0",....]}
+ * @throws PdpGroupPayloadException in case of issues to read the listOfActions
*/
- public void updatePdpGroupMap(String pdpGroup,
- String pdpSubGroup,
- String policyName,
- String policyVersion) {
- JsonObject policyJson = new JsonObject();
- policyJson.addProperty("name", policyName);
- policyJson.addProperty("version", policyVersion);
- Map<String, List<JsonObject>> pdpSubGroupMap;
- List<JsonObject> policyList;
- if (pdpGroupMap.get(pdpGroup) == null) {
- pdpSubGroupMap = new HashMap<>();
- policyList = new LinkedList<>();
- } else {
- pdpSubGroupMap = pdpGroupMap.get(pdpGroup);
- if (pdpSubGroupMap.get(pdpSubGroup) == null) {
- policyList = new LinkedList<>();
+ public PdpGroupPayload(final JsonElement listOfPdpActions) throws PdpGroupPayloadException {
+ this();
+ this.readListOfActions(listOfPdpActions);
+ }
+
+ /**
+ * This method converts the list of actions directly to the pdp payload query as String.
+ *
+ * @param listOfPdpActions The list of actions that needs to be done.
+ * e.g: {"Pdpactions":["DELETE/PdpGroup1/PdpSubGroup1/PolicyName1/1.0.0",....]}
+ * @return The string containing the PDP payload that can be sent directly
+ * @throws PdpGroupPayloadException in case of issues to read the listOfActions
+ */
+ public static String generatePdpGroupPayloadFromList(final JsonElement listOfPdpActions)
+ throws PdpGroupPayloadException {
+ return new PdpGroupPayload(listOfPdpActions).generatePdpGroupPayload();
+ }
+
+
+ private void readListOfActions(final JsonElement listOfPdpActions) throws PdpGroupPayloadException {
+ for (JsonElement action : listOfPdpActions.getAsJsonObject().getAsJsonArray(PDP_ACTIONS)) {
+ String[] opParams = action.getAsString().split("/");
+ if (opParams.length == 5) {
+ this.updatePdpGroupMap(opParams[1], opParams[2], opParams[3], opParams[4], opParams[0]);
} else {
- policyList = pdpSubGroupMap.get(pdpSubGroup);
+ logger.error("One PDP push command does not contain the right number of arguments: " + action);
+ throw new PdpGroupPayloadException(
+ "One PDP push command does not contain the right number of arguments: " + action);
}
}
- policyList.add(policyJson);
- pdpSubGroupMap.put(pdpSubGroup, policyList);
- pdpGroupMap.put(pdpGroup, pdpSubGroupMap);
+ }
+
+ /**
+ * This method updates the pdpGroupMap structure for a specific policy/version/pdpdGroup/PdpSubGroup.
+ *
+ * @param pdpGroup The pdp Group in String
+ * @param pdpSubGroup The pdp Sub Group in String
+ * @param policyName The policy name
+ * @param policyVersion The policy Version
+ * @param action DELETE or POST
+ */
+ public void updatePdpGroupMap(String pdpGroup,
+ String pdpSubGroup,
+ String policyName,
+ String policyVersion, String action) {
+ // create subgroup
+ DeploymentSubGroup newSubGroup = new DeploymentSubGroup();
+ newSubGroup.setPdpType(pdpSubGroup);
+ newSubGroup.setAction(DeploymentSubGroup.Action.valueOf(action));
+ newSubGroup.setPolicies(Arrays.asList(new ToscaConceptIdentifier(policyName, policyVersion)));
+ // Then the group
+ DeploymentGroup newGroup = new DeploymentGroup();
+ newGroup.setName(pdpGroup);
+ newGroup.setDeploymentSubgroups(Arrays.asList(newSubGroup));
+ // Add to deployment Groups structure
+ this.deploymentGroups.getGroups().add(newGroup);
}
/**
* This method generates the Payload in Json from the pdp Group structure containing the policies/versions
* that must be sent to the policy framework.
*
- * @param action The action to do, either a POST or a DELETE
- * @return The Json that can be sent to policy framework as JsonObject
+ * @return The Json that can be sent to policy framework as String
*/
- public JsonObject generateActivatePdpGroupPayload(String action) {
- JsonArray payloadArray = new JsonArray();
- for (Map.Entry<String, Map<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) {
- JsonObject pdpGroupNode = new JsonObject();
- JsonArray subPdpArray = new JsonArray();
- pdpGroupNode.addProperty("name", pdpGroupInfo.getKey());
- pdpGroupNode.add("deploymentSubgroups", subPdpArray);
-
- for (Map.Entry<String, List<JsonObject>> pdpSubGroupInfo : pdpGroupInfo.getValue().entrySet()) {
- JsonObject pdpSubGroupNode = new JsonObject();
- subPdpArray.add(pdpSubGroupNode);
- pdpSubGroupNode.addProperty("pdpType", pdpSubGroupInfo.getKey());
- pdpSubGroupNode.addProperty("action", action);
-
- JsonArray policyArray = new JsonArray();
- pdpSubGroupNode.add("policies", policyArray);
-
- for (JsonObject policy : pdpSubGroupInfo.getValue()) {
- policyArray.add(policy);
- }
- }
- payloadArray.add(pdpGroupNode);
- }
- JsonObject jsonObject = new JsonObject();
- jsonObject.add("groups", payloadArray);
- return jsonObject;
+ public String generatePdpGroupPayload() {
+ String payload = JsonUtils.GSON.toJson(this.deploymentGroups);
+ logger.info("PdpGroup policy payload: " + payload);
+ return payload;
}
}
diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadException.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadException.java
new file mode 100644
index 000000000..4ce0721b2
--- /dev/null
+++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayloadException.java
@@ -0,0 +1,54 @@
+/*-
+ * ============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;
+
+/**
+ * Exception during Pdp Group payload construction.
+ */
+public class PdpGroupPayloadException extends Exception {
+
+ /**
+ * serialization id.
+ */
+ private static final long serialVersionUID = -5676848693241134101L;
+
+ /**
+ * This constructor can be used to create a new PdpGroupPayloadException.
+ *
+ * @param message The message to dump
+ */
+ public PdpGroupPayloadException(final String message) {
+ super(message);
+ }
+
+ /**
+ * This constructor can be used to create a new PdpGroupPayloadException.
+ *
+ * @param message The message to dump
+ * @param cause The Throwable cause object
+ */
+ public PdpGroupPayloadException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index de0bb1ab0..7129c2828 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1463,6 +1463,44 @@
</route>
</delete>
+ <put uri="/v2/policies/pdpDeployment/"
+ type="com.google.gson.JsonElement"
+ consumes="application/json" >
+ <route>
+ <doTry>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'Pdp group deployment update')"/>
+ <to
+ uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'policies','','update')"/>
+ <setBody>
+ <method ref="org.onap.policy.clamp.policy.pdpgroup.PdpGroupPayload"
+ method="generatePdpGroupPayloadFromList(${body})"/>
+ </setBody>
+ <log loggingLevel="INFO"
+ message="PDP Group DEPLOY request payload: ${body}"/>
+ <to uri="direct:add-multiple-policies-to-pdp-group"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/>
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
+ <log loggingLevel="ERROR"
+ message="PDP Group deployment request failed: ${exception.stacktrace}"/>
+ <setHeader headerName="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>PDP Group deployment request FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </put>
+
<get uri="/v2/clampInformation" outType="org.onap.policy.clamp.clds.model.ClampInformation"
produces="application/json">
<to
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);
+ }
+}
diff --git a/src/test/resources/example/policy/pdp-group-multi-policies-payload.json b/src/test/resources/example/policy/pdp-group-multi-policies-payload.json
new file mode 100644
index 000000000..f8625ebbb
--- /dev/null
+++ b/src/test/resources/example/policy/pdp-group-multi-policies-payload.json
@@ -0,0 +1,94 @@
+{
+ "groups": [
+ {
+ "name": "pdpgroup1",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpsubgroup1",
+ "action": "POST",
+ "policies": [
+ {
+ "name": "policyname1",
+ "version": "1.0.0"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "pdpgroup1",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpsubgroup1",
+ "action": "POST",
+ "policies": [
+ {
+ "name": "policyname2",
+ "version": "1.0.0"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "pdpgroup1",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpsubgroup1",
+ "action": "POST",
+ "policies": [
+ {
+ "name": "policyname1",
+ "version": "2.0.0"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "pdpgroup2",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpsubgroup2",
+ "action": "DELETE",
+ "policies": [
+ {
+ "name": "policyname1",
+ "version": "1.0.0"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "pdpgroup2",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpsubgroup2",
+ "action": "POST",
+ "policies": [
+ {
+ "name": "policyname1",
+ "version": "2.0.0"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "pdpgroup2",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpsubgroup2",
+ "action": "DELETE",
+ "policies": [
+ {
+ "name": "policyname2",
+ "version": "1.0.0"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/src/test/resources/tosca/pdp-group-policy-payload.json b/src/test/resources/example/policy/pdp-group-policy-payload.json
index 17535ecbb..44a48dacb 100644
--- a/src/test/resources/tosca/pdp-group-policy-payload.json
+++ b/src/test/resources/example/policy/pdp-group-policy-payload.json
@@ -1,14 +1,14 @@
{
"groups": [
{
- "name": "pdpGroup1",
+ "name": "pdpGroup2",
"deploymentSubgroups": [
{
- "pdpType": "pdpSubgroup1",
+ "pdpType": "pdpSubgroup2",
"action": "POST",
"policies": [
{
- "name": "configPolicyTest",
+ "name": "opLegacyPolicy",
"version": "1.0.0"
}
]
@@ -23,15 +23,16 @@
"action": "POST",
"policies": [
{
- "name": "opLegacyPolicy",
- "version": "1.0.0"
- },
- {
"name": "opPolicy",
"version": "1.0.0"
}
]
- },
+ }
+ ]
+ },
+ {
+ "name": "pdpGroup2",
+ "deploymentSubgroups": [
{
"pdpType": "pdpSubgroup1",
"action": "POST",
@@ -43,6 +44,21 @@
]
}
]
+ },
+ {
+ "name": "pdpGroup1",
+ "deploymentSubgroups": [
+ {
+ "pdpType": "pdpSubgroup1",
+ "action": "POST",
+ "policies": [
+ {
+ "name": "configPolicyTest",
+ "version": "1.0.0"
+ }
+ ]
+ }
+ ]
}
]
} \ No newline at end of file