summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java7
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateData.java19
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/internal/PdpDeployPolicies.java40
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/mapper/Mapper.java284
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java5
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java3
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryProvider.java2
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java18
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateDataTest.java26
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/mapper/MapperTest.java418
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java4
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java2
13 files changed, 71 insertions, 759 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
index f873ab3c..45452356 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java
@@ -33,7 +33,7 @@ import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
-import org.onap.policy.models.pdp.concepts.PolicyTypeIdent;
+import org.onap.policy.models.pdp.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.pap.main.PapConstants;
@@ -109,7 +109,7 @@ public class PdpStatusMessageHandler {
private List<Pair<String, String>> createSupportedPolictTypesPair(final PdpStatus message) {
final List<Pair<String, String>> supportedPolicyTypesPair = new ArrayList<>();
- for (final PolicyTypeIdent policyTypeIdent : message.getSupportedPolicyTypes()) {
+ for (final ToscaPolicyTypeIdentifier policyTypeIdent : message.getSupportedPolicyTypes()) {
supportedPolicyTypesPair.add(Pair.of(policyTypeIdent.getName(), policyTypeIdent.getVersion()));
}
return supportedPolicyTypesPair;
@@ -219,7 +219,8 @@ public class PdpStatusMessageHandler {
update.setName(pdpInstanceId);
update.setPdpGroup(pdpGroupName);
update.setPdpSubgroup(subGroup.getPdpType());
- update.setPolicies(subGroup.getPolicies());
+ // TODO: create code for fetching ToscaPolicy from DB and setting here.
+ // update.setPolicies(subGroup.getPolicies());
LOGGER.debug("Created PdpUpdate message - {}", update);
return update;
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateData.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateData.java
index 4be057b7..f439d254 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateData.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateData.java
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
+import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams;
@@ -61,18 +62,32 @@ public abstract class UpdateData extends MessageData {
}
// see if the other has any policies that this does not have
- ArrayList<ToscaPolicy> lst = new ArrayList<>(response.getPolicies());
+ ArrayList<ToscaPolicyIdentifier> lst = new ArrayList<>(response.getPolicies());
List<ToscaPolicy> mypolicies = update.getPolicies();
if (mypolicies.size() != lst.size()) {
return "policies do not match";
}
- lst.removeAll(update.getPolicies());
+ lst.removeAll(convertToscaPolicyToToscaPolicyIndentifier(update.getPolicies()));
if (!lst.isEmpty()) {
return "policies do not match";
}
return null;
}
+
+ /**
+ * Converts a ToscaPolicy list to ToscaPolicyIdentifier list.
+ *
+ * @param toscaPolicies the list of ToscaPolicy
+ * @return the ToscaPolicyIdentifier list
+ */
+ private List<ToscaPolicyIdentifier> convertToscaPolicyToToscaPolicyIndentifier(List<ToscaPolicy> toscaPolicies) {
+ final List<ToscaPolicyIdentifier> toscaPolicyIdentifiers = new ArrayList<>();
+ for (final ToscaPolicy toscaPolicy : toscaPolicies) {
+ toscaPolicyIdentifiers.add(new ToscaPolicyIdentifier(toscaPolicy.getName(), toscaPolicy.getVersion()));
+ }
+ return toscaPolicyIdentifiers;
+ }
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/internal/PdpDeployPolicies.java b/main/src/main/java/org/onap/policy/pap/main/internal/PdpDeployPolicies.java
deleted file mode 100644
index bd3f7a6a..00000000
--- a/main/src/main/java/org/onap/policy/pap/main/internal/PdpDeployPolicies.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP Policy Models
- * ================================================================================
- * Copyright (C) 2019 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.pap.main.internal;
-
-import java.util.List;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-import org.onap.policy.models.pdp.concepts.PolicyIdentOptVersion;
-
-/**
- * Request deploy or update a set of policies using the <i>simple</i> PDP Group deployment
- * REST API. Only the "name" and "version" fields of a Policy are used, and only the
- * "name" field is actually required.
- */
-@Getter
-@Setter
-@ToString
-public class PdpDeployPolicies {
- private List<PolicyIdentOptVersion> policies;
-}
diff --git a/main/src/main/java/org/onap/policy/pap/main/mapper/Mapper.java b/main/src/main/java/org/onap/policy/pap/main/mapper/Mapper.java
deleted file mode 100644
index 0ae179b4..00000000
--- a/main/src/main/java/org/onap/policy/pap/main/mapper/Mapper.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP PAP
- * ================================================================================
- * Copyright (C) 2019 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.pap.main.mapper;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import org.onap.policy.models.pdp.concepts.Pdp;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.PolicyIdent;
-import org.onap.policy.models.pdp.concepts.PolicyIdentOptVersion;
-import org.onap.policy.models.pdp.concepts.PolicyTypeIdent;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.pap.main.internal.PdpDeployPolicies;
-
-/**
- * Classes used to map internal PAP/PDP classes to/from external classes used by the PAP
- * REST API.
- */
-public class Mapper {
-
- private Mapper() {
- super();
- }
-
-
- // these methods map from internal to external
-
- /**
- * Converts an internal PdpGroups to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PdpGroups toExternal(PdpGroups source) {
-
- org.onap.policy.models.pap.concepts.PdpGroups target = new org.onap.policy.models.pap.concepts.PdpGroups();
-
- target.setGroups(mapIt(source.getGroups(), Mapper::toExternal));
-
- return target;
- }
-
- /**
- * Converts an internal PdpGroup to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PdpGroup toExternal(PdpGroup source) {
-
- org.onap.policy.models.pap.concepts.PdpGroup target = new org.onap.policy.models.pap.concepts.PdpGroup();
-
- target.setDescription(source.getDescription());
- target.setName(source.getName());
- target.setPdpGroupState(source.getPdpGroupState());
- target.setPdpSubgroups(mapIt(source.getPdpSubgroups(), Mapper::toExternal));
- target.setProperties(mapIt(source.getProperties()));
- target.setVersion(source.getVersion());
-
- return target;
- }
-
- /**
- * Converts an internal PdpSubGroup to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PdpSubGroup toExternal(PdpSubGroup source) {
-
- org.onap.policy.models.pap.concepts.PdpSubGroup target = new org.onap.policy.models.pap.concepts.PdpSubGroup();
-
- target.setCurrentInstanceCount(source.getCurrentInstanceCount());
- target.setDesiredInstanceCount(source.getDesiredInstanceCount());
- target.setPdpInstances(mapIt(source.getPdpInstances(), Mapper::toExternal));
- target.setPdpType(source.getPdpType());
- target.setPolicies(mapIt(source.getPolicies(), Mapper::toExternal));
- target.setProperties(mapIt(source.getProperties()));
- target.setSupportedPolicyTypes(mapIt(source.getSupportedPolicyTypes(), Mapper::toExternal));
-
- return target;
- }
-
- /**
- * Converts an internal policy to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.Policy toExternal(ToscaPolicy source) {
-
- org.onap.policy.models.pap.concepts.Policy target = new org.onap.policy.models.pap.concepts.Policy();
-
- target.setName(source.getName());
- target.setPolicyVersion(source.getVersion());
- target.setPolicyType(source.getType());
- target.setPolicyTypeVersion(source.getTypeVersion());
-
- // TODO setPolicyTypeImpl
-
- return target;
- }
-
- /**
- * Converts an internal PDP instance details to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PdpInstanceDetails toExternal(Pdp source) {
-
- org.onap.policy.models.pap.concepts.PdpInstanceDetails target =
- new org.onap.policy.models.pap.concepts.PdpInstanceDetails();
-
- target.setHealthy(source.getHealthy());
- target.setInstanceId(source.getInstanceId());
- target.setMessage(source.getMessage());
- target.setPdpState(source.getPdpState());
-
- return target;
- }
-
- /**
- * Converts an internal policy identifier to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PolicyIdent toExternal(PolicyIdent source) {
-
- org.onap.policy.models.pap.concepts.PolicyIdent target = new org.onap.policy.models.pap.concepts.PolicyIdent();
-
- target.setName(source.getName());
- target.setVersion(source.getVersion());
-
- return target;
- }
-
- /**
- * Converts an internal policy type identifier to the corresponding external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PolicyTypeIdent toExternal(PolicyTypeIdent source) {
-
- org.onap.policy.models.pap.concepts.PolicyTypeIdent target =
- new org.onap.policy.models.pap.concepts.PolicyTypeIdent();
-
- target.setName(source.getName());
- target.setVersion(source.getVersion());
-
- return target;
- }
-
- /**
- * Converts an internal policy identifier, with optional version, to the corresponding
- * external class.
- *
- * @return an external object, populated with data from this object
- */
- public static org.onap.policy.models.pap.concepts.PolicyIdentOptVersion toExternal(PolicyIdentOptVersion source) {
-
- org.onap.policy.models.pap.concepts.PolicyIdentOptVersion target =
- new org.onap.policy.models.pap.concepts.PolicyIdentOptVersion();
-
- target.setName(source.getName());
- target.setVersion(source.getVersion());
-
- return target;
- }
-
-
- // these methods map from external to internal
-
- /**
- * Converts an external PdpDeployPolicies to the corresponding internal class.
- *
- * @return an internal object, populated with data from this object
- */
- public static PdpDeployPolicies toInternal(org.onap.policy.models.pap.concepts.PdpDeployPolicies source) {
- PdpDeployPolicies target = new PdpDeployPolicies();
-
- target.setPolicies(mapIt(source.getPolicies(), Mapper::toInternal));
-
- return target;
- }
-
- /**
- * Converts an external PDP instance details to the corresponding internal class.
- *
- * @return an internal object, populated with data from this object
- */
- public static Pdp toInternal(org.onap.policy.models.pap.concepts.PdpInstanceDetails source) {
- Pdp target = new Pdp();
-
- target.setHealthy(source.getHealthy());
- target.setInstanceId(source.getInstanceId());
- target.setMessage(source.getMessage());
- target.setPdpState(source.getPdpState());
-
- return target;
- }
-
- /**
- * Converts an external policy identifier to the corresponding internal class.
- *
- * @return an internal object, populated with data from this object
- */
- public static PolicyIdent toInternal(org.onap.policy.models.pap.concepts.PolicyIdent source) {
- PolicyIdent target = new PolicyIdent();
-
- target.setName(source.getName());
- target.setVersion(source.getVersion());
-
- return target;
- }
-
- /**
- * Converts an external policy type identifier to the corresponding internal class.
- *
- * @return an internal object, populated with data from this object
- */
- public static PolicyTypeIdent toInternal(org.onap.policy.models.pap.concepts.PolicyTypeIdent source) {
- PolicyTypeIdent target = new PolicyTypeIdent();
-
- target.setName(source.getName());
- target.setVersion(source.getVersion());
-
- return target;
- }
-
- /**
- * Converts an external policy identifier, with optional version, to the corresponding
- * internal class.
- *
- * @return an internal object, populated with data from this object
- */
- public static PolicyIdentOptVersion toInternal(org.onap.policy.models.pap.concepts.PolicyIdentOptVersion source) {
- PolicyIdentOptVersion target = new PolicyIdentOptVersion();
-
- target.setName(source.getName());
- target.setVersion(source.getVersion());
-
- return target;
- }
-
- /**
- * Maps a list of one type of object to a list of another type of object.
- *
- * @param source list of items to be mapped
- * @param mapper function to map an item to an object of the target type
- * @return a list of objects of the new type
- */
- private static <T, R> List<R> mapIt(List<T> source, Function<T, R> mapper) {
- return source.stream().map(mapper).collect(Collectors.toList());
- }
-
- /**
- * Creates a copy of a map.
- *
- * @param map map to be copied
- * @return a copy of the map
- */
- private static Map<String, String> mapIt(Map<String, String> map) {
- return new LinkedHashMap<>(map);
- }
-}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
index 3de39465..b60f6d11 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployControllerV1.java
@@ -28,16 +28,19 @@ import io.swagger.annotations.Authorization;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
+
import java.util.UUID;
+
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
-import org.onap.policy.models.pap.concepts.PdpGroups;
import org.onap.policy.models.pap.concepts.PdpPolicies;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
/**
* Class to provide REST end points for PAP component to deploy a PDP group.
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
index a6424fce..dc38e01b 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
@@ -21,10 +21,11 @@
package org.onap.policy.pap.main.rest;
import javax.ws.rs.core.Response;
+
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
-import org.onap.policy.models.pap.concepts.PdpGroups;
import org.onap.policy.models.pap.concepts.PdpPolicies;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
/**
* Provider for PAP component to deploy PDP groups.
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java
index ae4ef1d9..fb0c2f12 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java
@@ -38,7 +38,7 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.apache.commons.lang3.tuple.Pair;
-import org.onap.policy.models.pap.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
/**
* Class to provide REST end points for PAP component to query details of all PDP groups.
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryProvider.java
index d37409bf..4dd42af4 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryProvider.java
@@ -23,7 +23,7 @@ package org.onap.policy.pap.main.rest;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.Pair;
-import org.onap.policy.models.pap.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
/**
* Provider for PAP component to query details of all PDP groups.
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
index c2993528..91d7d435 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
@@ -42,6 +42,7 @@ import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.function.Consumer;
+
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -54,6 +55,7 @@ import org.onap.policy.models.pdp.concepts.PdpMessage;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
+import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.PapConstants;
@@ -132,7 +134,7 @@ public class PdpModifyRequestMapTest {
response.setState(PdpState.SAFE);
response.setPdpGroup(update.getPdpGroup());
response.setPdpSubgroup(update.getPdpSubgroup());
- response.setPolicies(update.getPolicies());
+ response.setPolicies(convertToscaPolicyToToscaPolicyIndentifier());
map = new PdpModifyRequestMap(makeParameters()) {
@@ -583,4 +585,18 @@ public class PdpModifyRequestMapTest {
return cng;
}
+
+ /**
+ * Converts a ToscaPolicy list to ToscaPolicyIdentifier list.
+ *
+ * @return the ToscaPolicyIdentifier list
+ */
+ private List<ToscaPolicyIdentifier> convertToscaPolicyToToscaPolicyIndentifier() {
+ final List<ToscaPolicy> toscaPolicies = update.getPolicies();
+ final List<ToscaPolicyIdentifier> toscaPolicyIdentifiers = new ArrayList<>();
+ for (final ToscaPolicy toscaPolicy : toscaPolicies) {
+ toscaPolicyIdentifiers.add(new ToscaPolicyIdentifier(toscaPolicy.getName(), toscaPolicy.getVersion()));
+ }
+ return toscaPolicyIdentifiers;
+ }
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateDataTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateDataTest.java
index 06a3bf01..127843a0 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateDataTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateDataTest.java
@@ -28,10 +28,13 @@ import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
+import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.pap.main.comm.TimerManager;
import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams;
@@ -69,7 +72,7 @@ public class UpdateDataTest {
response.setName(MY_NAME);
response.setPdpGroup(update.getPdpGroup());
response.setPdpSubgroup(update.getPdpSubgroup());
- response.setPolicies(update.getPolicies());
+ response.setPolicies(convertToscaPolicyToToscaPolicyIndentifier(update.getPolicies()));
data = new MyData(update);
}
@@ -112,15 +115,16 @@ public class UpdateDataTest {
@Test
public void testUpdateDataCheckResponse_MismatchedPoliciesLength() {
- response.setPolicies(Arrays.asList(update.getPolicies().get(0)));
+ response.setPolicies(convertToscaPolicyToToscaPolicyIndentifier(Arrays.asList(update.getPolicies().get(0))));
assertEquals("policies do not match", data.checkResponse(response));
}
@Test
public void testUpdateDataCheckResponse_MismatchedPolicies() {
- ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies());
- policies.set(0, makePolicy(DIFFERENT, "10.0.0"));
+ ArrayList<ToscaPolicyIdentifier> policies =
+ new ArrayList<>(convertToscaPolicyToToscaPolicyIndentifier(update.getPolicies()));
+ policies.set(0, new ToscaPolicyIdentifier(DIFFERENT, "10.0.0"));
response.setPolicies(policies);
@@ -180,4 +184,18 @@ public class UpdateDataTest {
// do nothing
}
}
+
+ /**
+ * Converts a ToscaPolicy list to ToscaPolicyIdentifier list.
+ *
+ * @param toscaPolicies the list of ToscaPolicy
+ * @return the ToscaPolicyIdentifier list
+ */
+ private List<ToscaPolicyIdentifier> convertToscaPolicyToToscaPolicyIndentifier(List<ToscaPolicy> toscaPolicies) {
+ final List<ToscaPolicyIdentifier> toscaPolicyIdentifiers = new ArrayList<>();
+ for (final ToscaPolicy toscaPolicy : toscaPolicies) {
+ toscaPolicyIdentifiers.add(new ToscaPolicyIdentifier(toscaPolicy.getName(), toscaPolicy.getVersion()));
+ }
+ return toscaPolicyIdentifiers;
+ }
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/mapper/MapperTest.java b/main/src/test/java/org/onap/policy/pap/main/mapper/MapperTest.java
deleted file mode 100644
index 350bd509..00000000
--- a/main/src/test/java/org/onap/policy/pap/main/mapper/MapperTest.java
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * ONAP PAP
- * ================================================================================
- * Copyright (C) 2019 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.pap.main.mapper;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.function.BiConsumer;
-import org.junit.Test;
-import org.onap.policy.models.pdp.concepts.Pdp;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.PolicyIdent;
-import org.onap.policy.models.pdp.concepts.PolicyIdentOptVersion;
-import org.onap.policy.models.pdp.concepts.PolicyTypeIdent;
-import org.onap.policy.models.pdp.enums.PdpHealthStatus;
-import org.onap.policy.models.pdp.enums.PdpState;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.pap.main.internal.PdpDeployPolicies;
-import org.powermock.reflect.Whitebox;
-
-public class MapperTest {
- private static final String MY_NAME = "my-name";
- private static final String MY_VERSION = "10.11.12";
- private static final PdpHealthStatus MY_HEALTH = PdpHealthStatus.TEST_IN_PROGRESS;
- private static final String MY_INSTANCE = "my_1";
- private static final String MY_MESSAGE = "my message";
- private static final PdpState MY_STATE = PdpState.SAFE;
- private static final int CURRENT_COUNT = 1;
- private static final int DESIRED_COUNT = 2;
- private static final String PDP_TYPE1 = "drools";
- private static final String PROPKEY1 = "prop-a";
- private static final String PROPVAL1 = "value-a";
- private static final String PROPKEY2 = "prop-b";
- private static final String PROPVAL2 = "value-b";
- private static final String MY_DESCRIPTION = "my description";
-
- @Test
- public void testConstructor() throws Exception {
- Whitebox.invokeConstructor(Mapper.class);
- }
-
- @Test
- public void testPdpDeployPolicies() {
-
- // TO-INTERNAL
-
- // test populated object
- org.onap.policy.models.pap.concepts.PdpDeployPolicies external =
- new org.onap.policy.models.pap.concepts.PdpDeployPolicies();
-
- external.setPolicies(Arrays.asList(makePolicyIdentOptVersion(1), makePolicyIdentOptVersion(2)));
- compareWithExternal(external, Mapper.toInternal(external));
- }
-
- private org.onap.policy.models.pap.concepts.PolicyIdentOptVersion makePolicyIdentOptVersion(int count) {
-
- org.onap.policy.models.pap.concepts.PolicyIdentOptVersion type =
- new org.onap.policy.models.pap.concepts.PolicyIdentOptVersion();
-
-
- type.setName(MY_NAME + "-id-" + count);
- type.setVersion(count + ".1.2");
-
- return type;
- }
-
- @Test
- public void testPdpGroups() {
-
- // TO-EXTERNAL
-
- // test populated object
- PdpGroups internal = new PdpGroups();
- internal.setGroups(Arrays.asList(makeGroup(1), makeGroup(2)));
-
- compareWithInternal(internal, Mapper.toExternal(internal));
- }
-
- private PdpGroup makeGroup(int count) {
- PdpGroup group = new PdpGroup();
-
- group.setDescription(MY_DESCRIPTION + "-" + count);
- group.setName(MY_NAME);
- group.setVersion(MY_VERSION);
- group.setPdpGroupState(MY_STATE);
-
- int inc = count + 1;
- group.setPdpSubgroups(Arrays.asList(makeSubGroup(count * 10), makeSubGroup(inc * 10)));
- group.setProperties(makeProperties());
-
- return group;
- }
-
- private PdpSubGroup makeSubGroup(int count) {
- PdpSubGroup subgroup = new PdpSubGroup();
-
- subgroup.setCurrentInstanceCount(CURRENT_COUNT);
- subgroup.setDesiredInstanceCount(DESIRED_COUNT);
-
- int inc = count + 1;
- subgroup.setPdpInstances(Arrays.asList(makePdp(count), makePdp(inc)));
- subgroup.setPdpType(PDP_TYPE1);
- subgroup.setPolicies(Arrays.asList(makePolicy(count, count), makePolicy(inc, inc)));
- subgroup.setProperties(makeProperties());
- subgroup.setSupportedPolicyTypes(Arrays.asList(makePolicyType(count), makePolicyType(inc)));
-
- return subgroup;
- }
-
- private Pdp makePdp(int count) {
- Pdp object = new Pdp();
-
- object.setHealthy(MY_HEALTH);
- object.setInstanceId(MY_INSTANCE + count);
- object.setMessage(MY_MESSAGE);
- object.setPdpState(MY_STATE);
-
- return object;
- }
-
- private PolicyTypeIdent makePolicyType(int count) {
- PolicyTypeIdent type = new PolicyTypeIdent();
-
- type.setName(MY_NAME + "-type-" + count);
- type.setVersion(count + ".1.2");
-
- return type;
- }
-
- private Map<String, String> makeProperties() {
- Map<String, String> map = new TreeMap<>();
-
- map.put(PROPKEY1, PROPVAL1);
- map.put(PROPKEY2, PROPVAL2);
-
- return map;
- }
-
- @Test
- public void testPdpGroup() {
-
- // TO-EXTERNAL
-
- // test populated object
- PdpGroup internal = makeGroup(1);
- compareWithInternal(internal, Mapper.toExternal(internal));
- }
-
- @Test
- public void testPdpSubGroup() {
-
- // TO-EXTERNAL
-
- // test populated object
- PdpSubGroup internal = makeSubGroup(1);
- compareWithInternal(internal, Mapper.toExternal(internal));
- }
-
- @Test
- public void testPolicy() {
-
- // TO-EXTERNAL
-
- // test populated object
- ToscaPolicy internal = makePolicy(1, 1);
- compareWithInternal(internal, Mapper.toExternal(internal));
- }
-
- private ToscaPolicy makePolicy(int count, int typeCount) {
- ToscaPolicy policy = new ToscaPolicy();
-
- policy.setName(MY_NAME + "-policy-" + count);
- policy.setVersion("1.2." + count);
- policy.setType(MY_NAME + "-type-" + typeCount);
- policy.setTypeVersion("1.2." + typeCount);
-
- return policy;
- }
-
- @Test
- public void testPdpInstanceDetails() {
-
- // TO-EXTERNAL
-
- // test populated object
- Pdp internal = makePdp(1);
- compareWithInternal(internal, Mapper.toExternal(internal));
-
-
- // TO-INTERNAL
-
- // test populated object
- org.onap.policy.models.pap.concepts.PdpInstanceDetails external =
- new org.onap.policy.models.pap.concepts.PdpInstanceDetails();
- external.setHealthy(MY_HEALTH);
- external.setInstanceId(MY_INSTANCE);
- external.setMessage(MY_MESSAGE);
- external.setPdpState(MY_STATE);
- compareWithExternal(external, Mapper.toInternal(external));
- }
-
- @Test
- public void testPolicyIdent() {
-
- // TO-EXTERNAL
-
- // first test default object
- PolicyIdent internal = new PolicyIdent();
- org.onap.policy.models.pap.concepts.PolicyIdent external = Mapper.toExternal(internal);
- compareWithInternal(internal, external);
-
- // now test populated object
- internal.setName(MY_NAME);
- internal.setVersion(MY_VERSION);
- external = Mapper.toExternal(internal);
- compareWithInternal(internal, external);
-
-
- // TO-INTERNAL
-
- external = new org.onap.policy.models.pap.concepts.PolicyIdent();
- external.setName(MY_NAME);
- external.setVersion(MY_VERSION);
- compareWithExternal(external, Mapper.toInternal(external));
- }
-
- @Test
- public void testPolicyTypeIdent() {
-
- // TO-EXTERNAL
-
- // first test default object
- PolicyTypeIdent internal = new PolicyTypeIdent();
- org.onap.policy.models.pap.concepts.PolicyTypeIdent external = Mapper.toExternal(internal);
- compareWithInternal(internal, external);
-
- // now test populated object
- internal.setName(MY_NAME);
- internal.setVersion(MY_VERSION);
- external = Mapper.toExternal(internal);
- compareWithInternal(internal, external);
-
-
- // TO-INTERNAL
-
- external = new org.onap.policy.models.pap.concepts.PolicyTypeIdent();
- external.setName(MY_NAME);
- external.setVersion(MY_VERSION);
- compareWithExternal(external, Mapper.toInternal(external));
- }
-
- @Test
- public void testPolicyIdentOptVersion() {
-
- // TO-EXTERNAL
-
- PolicyIdentOptVersion internal = new PolicyIdentOptVersion();
- internal.setName(MY_NAME);
- internal.setVersion(MY_VERSION);
- org.onap.policy.models.pap.concepts.PolicyIdentOptVersion external = Mapper.toExternal(internal);
- compareWithInternal(internal, external);
-
-
- // TO-INTERNAL
-
- external = new org.onap.policy.models.pap.concepts.PolicyIdentOptVersion();
- external.setName(MY_NAME);
- external.setVersion(MY_VERSION);
- compareWithExternal(external, Mapper.toInternal(external));
- }
-
-
- /**
- * Compares the items in two lists.
- *
- * @param expected the expected items
- * @param actual the actual items
- * @param compareItem function to compare an expected item with an actual item
- */
- private static <L, R> void compareList(List<L> expected, List<R> actual, BiConsumer<L, R> compareItem) {
-
- assertEquals(expected.size(), actual.size());
-
- Iterator<L> expIterator = expected.iterator();
- for (R actualItem : actual) {
- L expectedItem = expIterator.next();
- compareItem.accept(expectedItem, actualItem);
- }
- }
-
-
- // compares actual internal objects with expected external objects
-
- private static void compareWithExternal(org.onap.policy.models.pap.concepts.PolicyIdent expected,
- PolicyIdent actual) {
-
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- }
-
- private static void compareWithExternal(org.onap.policy.models.pap.concepts.PolicyTypeIdent expected,
- PolicyTypeIdent actual) {
-
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- }
-
- private static void compareWithExternal(org.onap.policy.models.pap.concepts.PolicyIdentOptVersion expected,
- PolicyIdentOptVersion actual) {
-
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- }
-
- private static void compareWithExternal(org.onap.policy.models.pap.concepts.PdpDeployPolicies expected,
- PdpDeployPolicies actual) {
-
- compareList(expected.getPolicies(), actual.getPolicies(), MapperTest::compareWithExternal);
- }
-
- private static void compareWithExternal(org.onap.policy.models.pap.concepts.PdpInstanceDetails expected,
- Pdp actual) {
-
- assertEquals(expected.getHealthy(), actual.getHealthy());
- assertEquals(expected.getInstanceId(), actual.getInstanceId());
- assertEquals(expected.getMessage(), actual.getMessage());
- assertEquals(expected.getPdpState(), actual.getPdpState());
- }
-
- // compares actual external objects with expected internal objects
-
- private static void compareWithInternal(PolicyIdent expected,
- org.onap.policy.models.pap.concepts.PolicyIdent actual) {
-
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- }
-
- private static void compareWithInternal(PolicyTypeIdent expected,
- org.onap.policy.models.pap.concepts.PolicyTypeIdent actual) {
-
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- }
-
- private static void compareWithInternal(PolicyIdentOptVersion expected,
- org.onap.policy.models.pap.concepts.PolicyIdentOptVersion actual) {
-
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- }
-
- private static void compareWithInternal(PdpGroups expected, org.onap.policy.models.pap.concepts.PdpGroups actual) {
- compareList(expected.getGroups(), actual.getGroups(), MapperTest::compareWithInternal);
- }
-
- private static void compareWithInternal(PdpGroup expected, org.onap.policy.models.pap.concepts.PdpGroup actual) {
- assertEquals(expected.getDescription(), actual.getDescription());
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getVersion());
- assertEquals(expected.getPdpGroupState(), actual.getPdpGroupState());
- compareList(expected.getPdpSubgroups(), actual.getPdpSubgroups(), MapperTest::compareWithInternal);
- assertEquals(expected.getProperties(), actual.getProperties());
- }
-
- private static void compareWithInternal(PdpSubGroup expected,
- org.onap.policy.models.pap.concepts.PdpSubGroup actual) {
-
- assertEquals(expected.getCurrentInstanceCount(), actual.getCurrentInstanceCount());
- assertEquals(expected.getDesiredInstanceCount(), actual.getDesiredInstanceCount());
- compareList(expected.getPdpInstances(), actual.getPdpInstances(), MapperTest::compareWithInternal);
- assertEquals(expected.getPdpType(), actual.getPdpType());
- compareList(expected.getPolicies(), actual.getPolicies(), MapperTest::compareWithInternal);
- assertEquals(expected.getProperties(), actual.getProperties());
- compareList(expected.getSupportedPolicyTypes(), actual.getSupportedPolicyTypes(),
- MapperTest::compareWithInternal);
- }
-
- private static void compareWithInternal(ToscaPolicy expected, org.onap.policy.models.pap.concepts.Policy actual) {
- assertEquals(expected.getName(), actual.getName());
- assertEquals(expected.getVersion(), actual.getPolicyVersion());
- assertEquals(expected.getType(), actual.getPolicyType());
- assertEquals(expected.getTypeVersion(), actual.getPolicyTypeVersion());
- }
-
- private static void compareWithInternal(Pdp expected,
- org.onap.policy.models.pap.concepts.PdpInstanceDetails actual) {
-
- assertEquals(expected.getHealthy(), actual.getHealthy());
- assertEquals(expected.getInstanceId(), actual.getInstanceId());
- assertEquals(expected.getMessage(), actual.getMessage());
- assertEquals(expected.getPdpState(), actual.getPdpState());
- }
-}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
index b6d0f1d7..e02e85c1 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
@@ -32,11 +32,11 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Test;
-import org.onap.policy.models.pap.concepts.PdpGroup;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
import org.onap.policy.models.pap.concepts.PdpPolicies;
-import org.onap.policy.models.pap.concepts.PdpSubGroup;
import org.onap.policy.models.pap.concepts.Policy;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java
index f0bc12bd..869bc198 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java
@@ -27,7 +27,7 @@ import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Response;
import org.junit.Test;
-import org.onap.policy.models.pap.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.PdpGroups;
/**
* Class to perform unit test of {@link PdpGroupQueryControllerV1}.