aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-13 13:42:27 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-13 13:42:32 +0000
commit86571f2d2b289edad0210d16ff7815578a118190 (patch)
treec95b5701a332e0a2d7e422bdf19ae9af3428316e
parentc7bd8dbbfc3427485bbc6a69262de3b46079467e (diff)
Update API for changes in TOSCA provider
Knock on changes and some simplification of the code because the TOSCA provider now does some of the checks that were in API, so those checks are not needed in API any more. Various JUnit fixes. Issue-ID: POLICY-1402 Change-Id: Ic3a08e415c8cce4f2aad4b5da2623e41280c4e66 Signed-off-by: liamfallon <liam.fallon@est.tech>
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java225
-rw-r--r--main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java71
-rw-r--r--main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java13
-rw-r--r--main/src/main/resources/META-INF/persistence.xml32
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java254
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java35
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java34
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java155
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java58
-rw-r--r--main/src/test/resources/META-INF/persistence.xml8
-rw-r--r--main/src/test/resources/policies/vCPE.policy.different.policy.fields.json (renamed from main/src/test/resources/policies/vCPE.policy.duplicate.policyversion.json)45
-rw-r--r--main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml1
-rw-r--r--main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml63
-rw-r--r--main/src/test/resources/policytypes/onap.policies.Test.yaml31
14 files changed, 385 insertions, 640 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
index e45674cc..15e409c6 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyProvider.java
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +24,9 @@
package org.onap.policy.api.main.rest.provider;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
+
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.Pair;
@@ -66,11 +66,11 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- public ToscaServiceTemplate fetchPolicies(String policyTypeId, String policyTypeVersion,
- String policyId, String policyVersion) throws PfModelException {
+ public ToscaServiceTemplate fetchPolicies(String policyTypeId, String policyTypeVersion, String policyId,
+ String policyVersion) throws PfModelException {
- ToscaServiceTemplate serviceTemplate = getFilteredPolicies(
- policyTypeId, policyTypeVersion, policyId, policyVersion);
+ ToscaServiceTemplate serviceTemplate =
+ getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
if (!hasPolicy(serviceTemplate)) {
throw new PfModelException(Response.Status.NOT_FOUND,
@@ -91,11 +91,11 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- public ToscaServiceTemplate fetchLatestPolicies(String policyTypeId, String policyTypeVersion,
- String policyId) throws PfModelException {
+ public ToscaServiceTemplate fetchLatestPolicies(String policyTypeId, String policyTypeVersion, String policyId)
+ throws PfModelException {
- ToscaServiceTemplate serviceTemplate = getFilteredPolicies(
- policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION);
+ ToscaServiceTemplate serviceTemplate =
+ getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION);
if (!hasPolicy(serviceTemplate)) {
throw new PfModelException(Response.Status.NOT_FOUND,
@@ -116,8 +116,8 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- public Map<Pair<String, String>, List<ToscaPolicy>> fetchDeployedPolicies(
- String policyTypeId, String policyTypeVersion, String policyId) throws PfModelException {
+ public Map<Pair<String, String>, List<ToscaPolicy>> fetchDeployedPolicies(String policyTypeId,
+ String policyTypeVersion, String policyId) throws PfModelException {
return collectDeployedPolicies(policyId, new PfConceptKey(policyTypeId, policyTypeVersion),
modelsProvider::getPolicyList, List::addAll, new ArrayList<>(5));
@@ -134,12 +134,9 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- public ToscaServiceTemplate createPolicy(String policyTypeId, String policyTypeVersion,
- ToscaServiceTemplate body) throws PfModelException {
+ public ToscaServiceTemplate createPolicy(String policyTypeId, String policyTypeVersion, ToscaServiceTemplate body)
+ throws PfModelException {
- validatePolicyTypeExist(policyTypeId, policyTypeVersion);
- validatePolicyTypeMatch(policyTypeId, policyTypeVersion, body);
- validatePolicyVersion(body);
return modelsProvider.createPolicies(body);
}
@@ -153,8 +150,6 @@ public class PolicyProvider extends CommonModelProvider {
* @throws PfModelException the PfModel parsing exception
*/
public ToscaServiceTemplate createPolicies(ToscaServiceTemplate body) throws PfModelException {
-
- validatePolicyVersion(body);
return modelsProvider.createPolicies(body);
}
@@ -170,8 +165,8 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion,
- String policyId, String policyVersion) throws PfModelException {
+ public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion, String policyId,
+ String policyVersion) throws PfModelException {
validateDeleteEligibility(policyTypeId, policyTypeVersion, policyId, policyVersion);
@@ -186,52 +181,6 @@ public class PolicyProvider extends CommonModelProvider {
}
/**
- * Validates whether policy type exists.
- *
- * @param policyTypeId the ID of policy type
- * @param policyTypeVersion the version of policy type
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validatePolicyTypeExist(String policyTypeId, String policyTypeVersion) throws PfModelException {
-
- ToscaServiceTemplate serviceTemplate = modelsProvider.getPolicyTypes(policyTypeId, policyTypeVersion);
- if (!hasPolicyType(serviceTemplate)) {
- throw new PfModelException(Response.Status.NOT_FOUND,
- "policy type with ID " + policyTypeId + ":" + policyTypeVersion + " does not exist");
- }
- }
-
- /**
- * Validates the match between policy type specified in path and the one specified in type of policy.
- *
- * @param policyTypeId the ID of policy type
- * @param policyTypeVersion the version of policy type
- * @param serviceTemplate the ToscaServiceTemplate to validate
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validatePolicyTypeMatch(String policyTypeId, String policyTypeVersion,
- ToscaServiceTemplate serviceTemplate) throws PfModelException {
-
- List<Map<String, ToscaPolicy>> policies = serviceTemplate.getToscaTopologyTemplate().getPolicies();
- for (Map<String, ToscaPolicy> policy : policies) {
- if (policy.size() > 1) {
- throw new PfModelException(Response.Status.BAD_REQUEST,
- "one policy block contains more than one policies");
- }
- ToscaPolicy policyContent = policy.values().iterator().next();
- if (!policyTypeId.equalsIgnoreCase(policyContent.getType())) {
- throw new PfModelException(Response.Status.BAD_REQUEST, "policy type id does not match");
- }
- if (policyContent.getTypeVersion() != null
- && !policyTypeVersion.equalsIgnoreCase(policyContent.getTypeVersion())) {
- throw new PfModelException(Response.Status.BAD_REQUEST, "policy type version does not match");
- }
- }
- }
-
- /**
* Validates whether specified policy can be deleted based on the rule that deployed policy cannot be deleted.
*
* @param policyTypeId the ID of policy type
@@ -241,15 +190,16 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion,
- String policyId, String policyVersion) throws PfModelException {
+ private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion, String policyId,
+ String policyVersion) throws PfModelException {
+ // TODO: Remove this method when delete validation is implemented in the tosca provider
List<ToscaPolicyTypeIdentifier> policyTypes = new ArrayList<>(1);
policyTypes.add(new ToscaPolicyTypeIdentifier(policyTypeId, policyTypeVersion));
List<ToscaPolicyIdentifier> policies = new ArrayList<>(1);
policies.add(new ToscaPolicyIdentifier(policyId, policyVersion));
- PdpGroupFilter pdpGroupFilter = PdpGroupFilter.builder()
- .policyTypeList(policyTypes).policyList(policies).build();
+ PdpGroupFilter pdpGroupFilter =
+ PdpGroupFilter.builder().policyTypeList(policyTypes).policyList(policies).build();
List<PdpGroup> pdpGroups = modelsProvider.getFilteredPdpGroups(pdpGroupFilter);
@@ -260,124 +210,6 @@ public class PolicyProvider extends CommonModelProvider {
}
/**
- * Validates the provided policy version in the payload.
- *
- * @param body the provided TOSCA service template which contains the policies
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validatePolicyVersion(ToscaServiceTemplate body) throws PfModelException {
-
- validatePolicyVersionExist(body);
- validateNoDuplicateVersionInDb(body);
- validateNoDuplicateVersionInPl(body);
- }
-
- /**
- * Validates the existence of at least one policies in the provided payload.
- *
- * @param body the TOSCA service template payload to check against
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validatePolicyVersionExist(ToscaServiceTemplate body) throws PfModelException {
-
- List<String> invalidPolicyNames = new ArrayList<>(body.getToscaTopologyTemplate().getPolicies().size());
- for (Map<String, ToscaPolicy> policy : body.getToscaTopologyTemplate().getPolicies()) {
- ToscaPolicy policyContent = policy.values().iterator().next();
- if (policyContent.getVersion() == null) {
- invalidPolicyNames.add(policy.keySet().iterator().next());
- }
- }
-
- if (!invalidPolicyNames.isEmpty()) {
- String errMsg = "mandatory 'version' field is missing in policies: "
- + String.join(", ", invalidPolicyNames);
- throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errMsg);
- }
- }
-
- /**
- * Validates there is no duplicate policy version stored in the database.
- *
- * @param body the TOSCA service template payload to check against
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validateNoDuplicateVersionInDb(ToscaServiceTemplate body) throws PfModelException {
-
- Map<String, String> invalidPolicies = new HashMap<>();
- for (Map<String, ToscaPolicy> policy: body.getToscaTopologyTemplate().getPolicies()) {
- ToscaPolicy policyContent = policy.values().iterator().next();
- String policyName = policy.keySet().iterator().next();
- String policyVersion = policyContent.getVersion();
- String policyTypeName = policyContent.getType();
- String policyTypeVersion = policyContent.getTypeVersion();
- ToscaServiceTemplate serviceTemplate =
- getFilteredPolicies(policyTypeName, policyTypeVersion, policyName, policyVersion);
- if (hasPolicy(serviceTemplate)) {
- String latestVersion = getFilteredPolicies(policyTypeName, policyTypeVersion,
- policyName, ToscaPolicyFilter.LATEST_VERSION).getToscaTopologyTemplate().getPoliciesAsMap()
- .values().iterator().next().getVersion();
- invalidPolicies.put(String.join(":", policyName, policyVersion), latestVersion);
- }
- }
-
- if (!invalidPolicies.isEmpty()) {
- List<String> duplicateVersions = new ArrayList<>(5);
- for (Entry<String, String> invalidPolicy : invalidPolicies.entrySet()) {
- String eachDuplicateVersion = "policy " + invalidPolicy.getKey()
- + " already exists; its latest version is " + invalidPolicy.getValue();
- duplicateVersions.add(eachDuplicateVersion);
- }
- throw new PfModelException(Response.Status.NOT_ACCEPTABLE, String.join("\n", duplicateVersions));
- }
- }
-
- /**
- * Validates there is no duplicate policy version in the provided payload if multiple policies are present.
- *
- * @param body the TOSCA service template payload to check against
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validateNoDuplicateVersionInPl(ToscaServiceTemplate body) throws PfModelException {
-
- List<Map<String, ToscaPolicy>> policies = body.getToscaTopologyTemplate().getPolicies();
- List<String> duplicateVersions = new ArrayList<>();
- for (int i = 0; i < policies.size() - 1; i++) {
- for (int j = i + 1; j < policies.size(); j++) {
- if (hasSameNameVersion(policies.get(i), policies.get(j))) {
- String nameVersion = policies.get(i).keySet().iterator().next() + ":"
- + policies.get(i).values().iterator().next().getVersion();
- duplicateVersions.add(nameVersion);
- }
- }
- }
-
- if (!duplicateVersions.isEmpty()) {
- String errMsg = "the same version of policies '" + String.join(", ", duplicateVersions)
- + "' appear multiple times in the payload";
- throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errMsg);
- }
- }
-
- /**
- * Checks if two policies have the same name and version.
- *
- * @param policy1 the first policy
- * @param policy2 the second policy
- *
- * @return the boolean flag to indicate the result
- */
- private boolean hasSameNameVersion(Map<String, ToscaPolicy> policy1, Map<String, ToscaPolicy> policy2) {
-
- return (policy1.keySet().iterator().next().equals(policy2.keySet().iterator().next())
- && policy1.values().iterator().next().getVersion().equals(
- policy2.values().iterator().next().getVersion()));
- }
-
- /**
* Retrieves the specified version of the policy.
*
* @param policyTypeName the name of the policy type
@@ -389,11 +221,10 @@ public class PolicyProvider extends CommonModelProvider {
*
* @throws PfModelException the PfModel parsing exception
*/
- private ToscaServiceTemplate getFilteredPolicies(String policyTypeName, String policyTypeVersion,
- String policyName, String policyVersion) throws PfModelException {
+ private ToscaServiceTemplate getFilteredPolicies(String policyTypeName, String policyTypeVersion, String policyName,
+ String policyVersion) throws PfModelException {
- ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder()
- .name(policyName).version(policyVersion)
+ ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder().name(policyName).version(policyVersion)
.type(policyTypeName).typeVersion(policyTypeVersion).build();
return modelsProvider.getFilteredPolicies(policyFilter);
}
@@ -408,10 +239,10 @@ public class PolicyProvider extends CommonModelProvider {
*
* @return constructed message
*/
- private String constructResourceNotFoundMessage(String policyTypeId, String policyTypeVersion,
- String policyId, String policyVersion) {
+ private String constructResourceNotFoundMessage(String policyTypeId, String policyTypeVersion, String policyId,
+ String policyVersion) {
- return "policy with ID " + policyId + ":" + policyVersion
- + " and type " + policyTypeId + ":" + policyTypeVersion + " does not exist";
+ return "policy with ID " + policyId + ":" + policyVersion + " and type " + policyTypeId + ":"
+ + policyTypeVersion + " does not exist";
}
}
diff --git a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
index d23615c0..d325f2c0 100644
--- a/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
+++ b/main/src/main/java/org/onap/policy/api/main/rest/provider/PolicyTypeProvider.java
@@ -3,6 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +24,9 @@
package org.onap.policy.api.main.rest.provider;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Map.Entry;
+
import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfModelException;
@@ -87,8 +87,7 @@ public class PolicyTypeProvider extends CommonModelProvider {
ToscaServiceTemplate serviceTemplate =
getFilteredPolicyTypes(policyTypeId, ToscaPolicyTypeFilter.LATEST_VERSION);
if (!hasPolicyType(serviceTemplate)) {
- throw new PfModelException(Response.Status.NOT_FOUND,
- constructResourceNotFoundMessage(policyTypeId, null));
+ throw new PfModelException(Response.Status.NOT_FOUND, constructResourceNotFoundMessage(policyTypeId, null));
}
return serviceTemplate;
@@ -108,7 +107,7 @@ public class PolicyTypeProvider extends CommonModelProvider {
throw new PfModelException(Response.Status.BAD_REQUEST,
"no policy types specified in the service template");
}
- validatePolicyTypeVersion(body);
+ validatePolicyTypeVersionExist(body);
return modelsProvider.createPolicyTypes(body);
}
@@ -138,8 +137,8 @@ public class PolicyTypeProvider extends CommonModelProvider {
}
/**
- * Validates whether specified policy type can be deleted based on the rule that
- * policy type parameterized by at least one policies cannot be deleted.
+ * Validates whether specified policy type can be deleted based on the rule that policy type parameterized by at
+ * least one policies cannot be deleted.
*
* @param policyTypeId the ID of policy type
* @param policyTypeVersion the version of policy type
@@ -148,8 +147,8 @@ public class PolicyTypeProvider extends CommonModelProvider {
*/
private void validateDeleteEligibility(String policyTypeId, String policyTypeVersion) throws PfModelException {
- ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder()
- .type(policyTypeId).typeVersion(policyTypeVersion).build();
+ ToscaPolicyFilter policyFilter =
+ ToscaPolicyFilter.builder().type(policyTypeId).typeVersion(policyTypeVersion).build();
List<ToscaPolicy> policies = modelsProvider.getFilteredPolicyList(policyFilter);
if (!policies.isEmpty()) {
throw new PfModelException(Response.Status.CONFLICT,
@@ -158,19 +157,6 @@ public class PolicyTypeProvider extends CommonModelProvider {
}
/**
- * Validates the provided policy type version in the payload.
- *
- * @param body the provided TOSCA service template which contains the policy types
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validatePolicyTypeVersion(ToscaServiceTemplate body) throws PfModelException {
-
- validatePolicyTypeVersionExist(body);
- validateNoDuplicateVersionInDb(body);
- }
-
- /**
* Validates that each policy type has a version specified in the payload.
*
* @param body the TOSCA service template payload to check against
@@ -180,7 +166,7 @@ public class PolicyTypeProvider extends CommonModelProvider {
private void validatePolicyTypeVersionExist(ToscaServiceTemplate body) throws PfModelException {
List<String> invalidPolicyTypeNames = new ArrayList<>();
- for (Entry<String, ToscaPolicyType> policyType: body.getPolicyTypes().entrySet()) {
+ for (Entry<String, ToscaPolicyType> policyType : body.getPolicyTypes().entrySet()) {
if (!"tosca.policies.Root".equals(policyType.getValue().getDerivedFrom())
&& policyType.getValue().getVersion() == null) {
invalidPolicyTypeNames.add(policyType.getKey());
@@ -195,41 +181,6 @@ public class PolicyTypeProvider extends CommonModelProvider {
}
/**
- * Validates that there is no duplicate version of the policy type stored in the database.
- *
- * @param body the TOSCA service template payload
- *
- * @throws PfModelException the PfModel parsing exception
- */
- private void validateNoDuplicateVersionInDb(ToscaServiceTemplate body) throws PfModelException {
-
- Map<String, String> invalidPolicyTypes = new HashMap<>();
- for (Entry<String, ToscaPolicyType> policyType: body.getPolicyTypes().entrySet()) {
- if ("tosca.policies.Root".equals(policyType.getValue().getDerivedFrom())) {
- continue;
- }
- String policyTypeName = policyType.getKey();
- String policyTypeVersion = policyType.getValue().getVersion();
- ToscaServiceTemplate serviceTemplate = getFilteredPolicyTypes(policyTypeName, policyTypeVersion);
- if (hasPolicyType(serviceTemplate)) {
- String latestVersion = getFilteredPolicyTypes(policyTypeName, ToscaPolicyTypeFilter.LATEST_VERSION)
- .getPolicyTypesAsMap().entrySet().iterator().next().getKey().getVersion();
- invalidPolicyTypes.put(String.join(":", policyTypeName, policyTypeVersion), latestVersion);
- }
- }
-
- if (!invalidPolicyTypes.isEmpty()) {
- List<String> duplicateVersions = new ArrayList<>(invalidPolicyTypes.size());
- for (Entry<String, String> invalidPolicyType : invalidPolicyTypes.entrySet()) {
- String eachDuplicateVersion = "policy type " + invalidPolicyType.getKey()
- + " already exists; its latest version is " + invalidPolicyType.getValue();
- duplicateVersions.add(eachDuplicateVersion);
- }
- throw new PfModelException(Response.Status.NOT_ACCEPTABLE, String.join("\n", duplicateVersions));
- }
- }
-
- /**
* Retrieves the specified version of the policy type.
*
* @param policyTypeName the name of the policy type
@@ -242,8 +193,8 @@ public class PolicyTypeProvider extends CommonModelProvider {
private ToscaServiceTemplate getFilteredPolicyTypes(String policyTypeName, String policyTypeVersion)
throws PfModelException {
- ToscaPolicyTypeFilter policyTypeFilter = ToscaPolicyTypeFilter.builder()
- .name(policyTypeName).version(policyTypeVersion).build();
+ ToscaPolicyTypeFilter policyTypeFilter =
+ ToscaPolicyTypeFilter.builder().name(policyTypeName).version(policyTypeVersion).build();
return modelsProvider.getFilteredPolicyTypes(policyTypeFilter);
}
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
index 6ac2f0fc..aee28303 100644
--- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
+++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
package org.onap.policy.api.main.startstop;
import java.util.LinkedHashMap;
+
import org.onap.policy.api.main.exception.PolicyApiException;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
import org.onap.policy.common.utils.coder.CoderException;
@@ -32,6 +33,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
@@ -64,12 +66,12 @@ public class ApiDatabaseInitializer {
* @param apiParameterGroup the apiParameterGroup parameters
* @throws PolicyApiException in case of errors.
*/
- public void initializeApiDatabase(final ApiParameterGroup apiParameterGroup)
- throws PolicyApiException {
+ public void initializeApiDatabase(final ApiParameterGroup apiParameterGroup) throws PolicyApiException {
try (PolicyModelsProvider databaseProvider =
factory.createPolicyModelsProvider(apiParameterGroup.getDatabaseProviderParameters())) {
ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
+ serviceTemplate.setDataTypes(new LinkedHashMap<String, ToscaDataType>());
serviceTemplate.setPolicyTypes(new LinkedHashMap<String, ToscaPolicyType>());
serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0_0");
for (String pt : apiParameterGroup.getPreloadPolicyTypes()) {
@@ -86,7 +88,10 @@ public class ApiDatabaseInitializer {
if (singlePolicyType == null) {
throw new PolicyApiException("Error deserializing policy type from file: " + pt);
}
- // Consolidate policy types
+ // Consolidate data types and policy types
+ if (singlePolicyType.getDataTypes() != null) {
+ serviceTemplate.getDataTypes().putAll(singlePolicyType.getDataTypes());
+ }
serviceTemplate.getPolicyTypes().putAll(singlePolicyType.getPolicyTypes());
}
ToscaServiceTemplate createdPolicyTypes = databaseProvider.createPolicyTypes(serviceTemplate);
diff --git a/main/src/main/resources/META-INF/persistence.xml b/main/src/main/resources/META-INF/persistence.xml
index 18c57549..c6f4fc51 100644
--- a/main/src/main/resources/META-INF/persistence.xml
+++ b/main/src/main/resources/META-INF/persistence.xml
@@ -19,25 +19,43 @@
============LICENSE_END=========================================================
-->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
- <persistence-unit name="PolicyMariaDb" transaction-type="RESOURCE_LOCAL">
+<persistence
+ xmlns="http://java.sun.com/xml/ns/persistence"
+ version="2.0">
+ <persistence-unit
+ name="PolicyMariaDb"
+ transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>org.onap.policy.models.dao.converters.CDataConditioner</class>
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
+ <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class>
<properties>
- <property name="javax.persistence.schema-generation.database.action" value="create" />
- <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
- <property name="eclipselink.ddl-generation.output-mode" value="database" />
- <property name="eclipselink.logging.level" value="INFO" />
+ <property
+ name="javax.persistence.schema-generation.database.action"
+ value="create" />
+ <property
+ name="eclipselink.ddl-generation"
+ value="create-or-extend-tables" />
+ <property
+ name="eclipselink.ddl-generation.output-mode"
+ value="database" />
+ <property
+ name="eclipselink.logging.level"
+ value="INFO" />
</properties>
</persistence-unit>
</persistence>
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index 80c99636..1a9b6535 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,12 +22,14 @@
package org.onap.policy.api.main.rest;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.security.SecureRandom;
@@ -49,7 +51,6 @@ import javax.ws.rs.core.Response;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.junit.AfterClass;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.api.main.parameters.ApiParameterGroup;
@@ -69,7 +70,6 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.errors.concepts.ErrorResponse;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
@@ -126,7 +126,6 @@ public class TestApiRestServer {
private static final String POLICYTYPES_DROOLS_POLICIES_VCPE_VERSION =
POLICYTYPES_DROOLS_VERSION + "/policies/" + OP_POLICY_NAME_VCPE + "/versions/1.0.0";
- private static final String GUARD_POLICYTYPE = "onap.policies.controlloop.Guard";
private static final String GUARD_POLICIES = "policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies";
private static final String GUARD_POLICIES_VDNS_FL_LATEST =
"policytypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.frequency.scaleout"
@@ -142,7 +141,6 @@ public class TestApiRestServer {
private static final String GUARD_POLICIES_VDNS_MINMAX_VERSION =
"policytypes/" + "onap.policies.controlloop.Guard/versions/1.0.0/policies/guard.minmax.scaleout/versions/1";
- private static final String OPS_POLICYTYPE = "onap.policies.controlloop.Operational";
private static final String OPS_POLICIES =
"policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies";
private static final String OPS_POLICIES_VCPE_LATEST =
@@ -218,23 +216,12 @@ public class TestApiRestServer {
"policies/vDNS.policy.guard.minmax.input.json"
};
- private static final String[] LEGACY_GUARD_POLICY_NAMES = {
- "guard.frequency.scaleout",
- "guard.minmax.scaleout"
- };
-
private static final String[] LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES = {
"policies/vCPE.policy.operational.input.json",
"policies/vDNS.policy.operational.input.json",
"policies/vFirewall.policy.operational.input.json"
};
- private static final String[] LEGACY_OPERATIONAL_POLICY_NAMES = {
- OP_POLICY_NAME_VCPE,
- OP_POLICY_NAME_VDNS,
- OP_POLICY_NAME_VFW
- };
-
private static PolicyModelsProviderParameters providerParams;
private static ApiParameterGroup apiParamGroup;
private static PolicyProvider policyProvider;
@@ -250,12 +237,13 @@ public class TestApiRestServer {
private static StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
/**
- * Initializes parameters.
+ * Initializes parameters and set up test environment.
*
* @throws PfModelException the PfModel parsing exception
+ * @throws IOException on I/O exceptions
*/
@BeforeClass
- public static void setupParameters() throws PfModelException {
+ public static void setupParameters() throws PfModelException, IOException {
providerParams = new PolicyModelsProviderParameters();
providerParams.setDatabaseDriver("org.h2.Driver");
providerParams.setDatabaseUrl("jdbc:h2:mem:testdb");
@@ -267,15 +255,7 @@ public class TestApiRestServer {
policyTypeProvider = new PolicyTypeProvider();
policyProvider = new PolicyProvider();
- }
- /**
- * Set up test environemnt.
- *
- * @throws Exception on test setup exceptions
- */
- @BeforeClass
- public static void beforeStartApiService() throws Exception {
apiPort = NetworkUtil.allocPort();
final String[] apiConfigParameters = new String[2];
@@ -287,6 +267,7 @@ public class TestApiRestServer {
"src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json", apiPort);
apiConfigParameters[0] = "-c";
apiConfigParameters[1] = "src/test/resources/parameters/ApiConfigParameters_HttpsXXX.json";
+
apiMain = new Main(apiConfigParameters);
}
@@ -303,32 +284,6 @@ public class TestApiRestServer {
}
}
- /**
- * Clear the database before each test.
- *
- * @throws Exception on clearing exceptions
- */
- @Before
- public void beforeClearDatabase() throws Exception {
-
- Response rawResponse = readResource(POLICYTYPES, APP_JSON);
- ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
-
- for (ToscaEntityKey policyTypeKey : response.getPolicyTypesAsMap().keySet()) {
- if (GUARD_POLICYTYPE.equals(policyTypeKey.getName())
- || OPS_POLICYTYPE.equals(policyTypeKey.getName())) {
- deleteLegacyPolicies(LEGACY_GUARD_POLICY_NAMES, GUARD_POLICYTYPE);
- deleteLegacyPolicies(LEGACY_OPERATIONAL_POLICY_NAMES, OPS_POLICYTYPE);
- } else {
- deleteToscaPolicies(policyTypeKey);
- }
-
- String deletePolicyTypePath =
- "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion();
- deleteResource(deletePolicyTypePath, APP_JSON);
- }
- }
-
@Test
public void testApiStatisticsConstructorIsPrivate() {
@@ -367,8 +322,6 @@ public class TestApiRestServer {
@Test
public void testCreatePolicies() throws Exception {
- createPolicyTypes();
-
for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -387,7 +340,8 @@ public class TestApiRestServer {
createResource(POLICYTYPES_TCA_POLICIES, "src/test/resources/policies/BadTestPolicy.yaml");
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
- assertEquals("policy type id does not match", errorResponse.getErrorMessage());
+ assertThat(errorResponse.getErrorMessage())
+ .contains("entity in incoming fragment does not equal existing entity");
}
@Test
@@ -411,34 +365,44 @@ public class TestApiRestServer {
Response rawResponse2 = createResource(POLICIES, "src/test/resources/policies/BadTestPolicy.yaml");
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse2.getStatus());
ErrorResponse errorResponse = rawResponse2.readEntity(ErrorResponse.class);
- assertEquals("policy type NULL:0.0.0 for policy onap.restart.tca:2.0.0 does not exist",
- errorResponse.getErrorMessage());
+ assertThat(errorResponse.getErrorMessage()).contains("policy type NULL:1.0.0 referenced in policy not found");
}
@Test
public void testCreateGuardPolicies() throws Exception {
- createPolicyTypes();
-
for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
+
+ Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
public void testCreateOperationalPolicies() throws Exception {
- createPolicyTypes();
-
for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
+
+ Response rawResponse = deleteResource(OPS_POLICIES + "/operational.restart/versions/1", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(OPS_POLICIES + "/operational.scaleout/versions/1", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(OPS_POLICIES + "/operational.modifyconfig/versions/1", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
+ @SuppressWarnings("unchecked")
@Test
public void testToscaCompliantOpDroolsPolicies() throws Exception {
- Response rawResponse =
- createResource(POLICYTYPES, TOSCA_POLICYTYPE_OP_RESOURCE);
+ Response rawResponse = createResource(POLICYTYPES, TOSCA_POLICYTYPE_OP_RESOURCE);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
rawResponse = readResource(POLICYTYPES_DROOLS_VERSION, APP_JSON);
@@ -448,7 +412,7 @@ public class TestApiRestServer {
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
rawResponse = createResource(POLICIES, TOSCA_POLICY_OP_DROOLS_VCPE_RESOURSE_YAML);
- assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), rawResponse.getStatus());
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
rawResponse = readResource(POLICYTYPES_DROOLS_POLICIES_VCPE_VERSION, APP_JSON);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -468,7 +432,7 @@ public class TestApiRestServer {
ToscaServiceTemplate toscaVcpeSt = rawResponse.readEntity(ToscaServiceTemplate.class);
assertEquals(1, toscaVcpeSt.getToscaTopologyTemplate().getPolicies().size());
assertEquals(OP_POLICY_NAME_VCPE,
- toscaVcpeSt.getToscaTopologyTemplate().getPolicies().get(0).get(OP_POLICY_NAME_VCPE).getName());
+ toscaVcpeSt.getToscaTopologyTemplate().getPolicies().get(0).get(OP_POLICY_NAME_VCPE).getName());
Map<String, Object> props =
toscaVcpeSt.getToscaTopologyTemplate().getPolicies().get(0).get(OP_POLICY_NAME_VCPE).getProperties();
@@ -482,6 +446,9 @@ public class TestApiRestServer {
(Map<String, Object>) ((Map<String, Object>) operations.get(0)).get("operation");
assertEquals("APPC", operation.get("actor"));
assertEquals("Restart", operation.get("operation"));
+
+ rawResponse = deleteResource(POLICYTYPES_DROOLS_POLICIES_VCPE_VERSION, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
@@ -532,8 +499,6 @@ public class TestApiRestServer {
}
private void testReadPolicyTypes(String mediaType) throws Exception {
- createPolicyTypes();
-
Response rawResponse = readResource(POLICYTYPES, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
ToscaServiceTemplate response = rawResponse.readEntity(ToscaServiceTemplate.class);
@@ -578,29 +543,20 @@ public class TestApiRestServer {
}
private void testDeletePolicyType(String mediaType) throws Exception {
- createPolicyTypes();
-
- Response rawResponse = deleteResource(POLICYTYPES_TCA_VERSION, mediaType);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = readResource(POLICYTYPES_TCA_VERSION, mediaType);
+ Response rawResponse = deleteResource("policytypes/onap.policies.IDoNotExist/versions/1.0.0", mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- rawResponse = deleteResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
+ rawResponse = createResource(POLICYTYPES, "policytypes/onap.policies.Test.yaml");
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_VERSION, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ rawResponse = readResource("policytypes/onap.policies.Test/versions/1.0.0", mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR, mediaType);
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
+ rawResponse = deleteResource("policytypes/onap.policies.Test/versions/1.0.0", mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- rawResponse = readResource(POLICYTYPES_COLLECTOR_LATEST, mediaType);
+ rawResponse = readResource("policytypes/onap.policies.Test/versions/1.0.0", mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
- ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policy type with ID "
- + "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server:null does not exist",
- errorResponse.getErrorMessage());
}
@Test
@@ -614,7 +570,10 @@ public class TestApiRestServer {
}
private void testReadPolicies(String mediaType) throws Exception {
- testCreatePolicies();
+ for (String resrcName : TOSCA_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createResource(POLICYTYPES_TCA_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
Response rawResponse = readResource(POLICYTYPES_TCA_POLICIES, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -630,6 +589,12 @@ public class TestApiRestServer {
rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION1, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
@@ -643,15 +608,10 @@ public class TestApiRestServer {
}
private void testDeletePolicies(String mediaType) throws Exception {
- createPolicyTypes();
-
Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION1, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:1.0.0 and "
- + "type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- error.getErrorMessage());
+ assertEquals("policies for onap.restart.tca:1.0.0 do not exist", error.getErrorMessage());
}
@Test
@@ -693,26 +653,17 @@ public class TestApiRestServer {
rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION2, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
errorResponse = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:2.0.0 and type "
- + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- errorResponse.getErrorMessage());
+ assertEquals("policies for onap.restart.tca:2.0.0 do not exist", errorResponse.getErrorMessage());
rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
errorResponse = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:null and type "
- + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- errorResponse.getErrorMessage());
+ assertEquals("policies for onap.restart.tca:null do not exist", errorResponse.getErrorMessage());
rawResponse = readResource(POLICYTYPES_TCA_POLICIES_VCPE_LATEST, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
errorResponse = rawResponse.readEntity(ErrorResponse.class);
- assertEquals(
- "policy with ID onap.restart.tca:null and type "
- + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist",
- errorResponse.getErrorMessage());
+ assertEquals("policies for onap.restart.tca:null do not exist", errorResponse.getErrorMessage());
}
@Test
@@ -752,7 +703,10 @@ public class TestApiRestServer {
}
private void testReadGuardPolicies(String mediaType) throws Exception {
- createGuardPolicies();
+ for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
Response rawResponse = readResource(GUARD_POLICIES_VDNS_FL_LATEST, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -765,6 +719,12 @@ public class TestApiRestServer {
rawResponse = readResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
@@ -778,7 +738,10 @@ public class TestApiRestServer {
}
private void testReadOperationalPolicies(String mediaType) throws Exception {
- createOperationalPolicies();
+ for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
Response rawResponse = readResource(OPS_POLICIES_VCPE_LATEST, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
@@ -797,6 +760,16 @@ public class TestApiRestServer {
rawResponse = readResource(OPS_POLICIES_VFIREWALL_VERSION, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(OPS_POLICIES + "/operational.restart/versions/1", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(OPS_POLICIES + "/operational.scaleout/versions/1", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(OPS_POLICIES + "/operational.modifyconfig/versions/1", APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
}
@Test
@@ -810,10 +783,16 @@ public class TestApiRestServer {
}
private void testDeleteGuardPolicy(String mediaType) throws Exception {
- createGuardPolicies();
+ for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
+ Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+ }
Response rawResponse = deleteResource(GUARD_POLICIES_VDNS_FL_VERSION, mediaType);
assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
+
+ rawResponse = deleteResource(GUARD_POLICIES_VDNS_MINMAX_VERSION, APP_JSON);
+ assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
}
@Test
@@ -847,12 +826,10 @@ public class TestApiRestServer {
}
private void testDeleteOperationalPolicy(String mediaType) throws Exception {
- createPolicyTypes();
-
Response rawResponse = deleteResource(OPS_POLICIES_VCPE_VERSION, mediaType);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("no policy found for policy: " + OP_POLICY_NAME_VCPE + ":1", error.getErrorMessage());
+ assertEquals("no policy found for policy: operational.restart:1", error.getErrorMessage());
}
@Test
@@ -931,12 +908,7 @@ public class TestApiRestServer {
@Test
public void testDeleteSpecificVersionOfOperationalPolicy() throws Exception {
- createOperationalPolicies();
-
- Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_JSON);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
-
- rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_YAML);
+ Response rawResponse = deleteResource(OPS_POLICIES_VDNS_VERSION, APP_YAML);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawResponse.getStatus());
ErrorResponse errorResponse = rawResponse.readEntity(ErrorResponse.class);
assertEquals("no policy found for policy: " + OP_POLICY_NAME_VDNS + ":1", errorResponse.getErrorMessage());
@@ -1024,31 +996,6 @@ public class TestApiRestServer {
return invocationBuilder.delete();
}
- private void createPolicyTypes() throws Exception {
- for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
- Response rawResponse = createResource(POLICYTYPES, resrcName);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- }
-
- private void createGuardPolicies() throws Exception {
- createPolicyTypes();
-
- for (String resrcName : LEGACY_GUARD_POLICY_RESOURCE_NAMES) {
- Response rawResponse = createGuardPolicy(GUARD_POLICIES, resrcName);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- }
-
- private void createOperationalPolicies() throws Exception {
- createPolicyTypes();
-
- for (String resrcName : LEGACY_OPERATIONAL_POLICY_RESOURCE_NAMES) {
- Response rawResponse = createOperationalPolicy(OPS_POLICIES, resrcName);
- assertEquals(Response.Status.OK.getStatusCode(), rawResponse.getStatus());
- }
- }
-
private Invocation.Builder sendHttpsRequest(final String endpoint, String mediaType) throws Exception {
final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager();
@@ -1111,33 +1058,4 @@ public class TestApiRestServer {
assertEquals(code, report.getCode());
assertEquals(message, report.getMessage());
}
-
- private void deleteToscaPolicies(ToscaEntityKey policyTypeKey) throws Exception {
-
- String getPoliciesPath =
- "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion() + "/policies";
-
- Response rawPolicyResponse = readResource(getPoliciesPath, APP_JSON);
- if (Response.Status.OK.getStatusCode() == rawPolicyResponse.getStatus()) {
- ToscaServiceTemplate policyResponse = rawPolicyResponse.readEntity(ToscaServiceTemplate.class);
-
- for (ToscaEntityKey policyKey : policyResponse.getToscaTopologyTemplate().getPoliciesAsMap().keySet()) {
- String deletePolicyPath =
- "policytypes/" + policyTypeKey.getName() + "/versions/" + policyTypeKey.getVersion()
- + "/policies/" + policyKey.getName() + "/versions/" + policyKey.getVersion();
- deleteResource(deletePolicyPath, APP_JSON);
- }
- }
- }
-
- private void deleteLegacyPolicies(String[] legacyPolicyNames, String legacyPolicyType) throws Exception {
-
- for (String policyName : legacyPolicyNames) {
- String policyPath =
- "policytypes/" + legacyPolicyType + "/versions/1.0.0/policies/" + policyName + "/versions/1";
- if (Response.Status.OK.getStatusCode() == readResource(policyPath, APP_JSON).getStatus()) {
- deleteResource(policyPath, APP_JSON);
- }
- }
- }
} \ No newline at end of file
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
index 71ce44b1..237da680 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,7 +85,6 @@ public class TestLegacyGuardPolicyProvider {
private static final String POLICY_TYPE_ID = "onap.policies.controlloop.guard.FrequencyLimiter:1.0.0";
private static final String POLICY_TYPE_NAME = "onap.policies.controlloop.guard.FrequencyLimiter";
private static final String POLICY_TYPE_VERSION = "1.0.0";
- private static final String POLICY_ID = "guard.frequency.scaleout:1.0.0";
private static final String POLICY_NAME = "guard.frequency.scaleout";
private static final String POLICY_VERSION = "1";
private static final String LEGACY_MINOR_PATCH_SUFFIX = ".0.0";
@@ -97,7 +96,6 @@ public class TestLegacyGuardPolicyProvider {
*/
@Before
public void setupParameters() throws PfModelException {
-
standardCoder = new StandardCoder();
standardYamlCoder = new StandardYamlCoder();
providerParams = new PolicyModelsProviderParameters();
@@ -119,13 +117,11 @@ public class TestLegacyGuardPolicyProvider {
*/
@After
public void tearDown() throws PfModelException {
-
guardPolicyProvider.close();
policyTypeProvider.close();
ParameterService.deregister(apiParamGroup);
}
-
@Test
public void testFetchGuardPolicy() {
@@ -138,8 +134,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_VER1);
@@ -228,8 +224,8 @@ public class TestLegacyGuardPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -246,10 +242,9 @@ public class TestLegacyGuardPolicyProvider {
// Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
assertThatThrownBy(() -> {
guardPolicyProvider.fetchDeployedGuardPolicies(POLICY_NAME);
- }) .hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID
+ }).hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID
+ " deployed in any pdp group");
-
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies()
@@ -265,7 +260,7 @@ public class TestLegacyGuardPolicyProvider {
// Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
assertThatThrownBy(() -> {
guardPolicyProvider.deleteGuardPolicy(POLICY_NAME, POLICY_VERSION);
- }) .hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ }).hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ " cannot be deleted as it is deployed in pdp groups");
} catch (Exception exc) {
fail("Test should not throw an exception");
@@ -274,15 +269,15 @@ public class TestLegacyGuardPolicyProvider {
@Test
public void testCreateGuardPolicy() throws Exception {
-
assertThatThrownBy(() -> {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyGuardPolicyInput policyToCreate = standardCoder.decode(policyString, LegacyGuardPolicyInput.class);
guardPolicyProvider.createGuardPolicy(policyToCreate);
- }).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
+ }).hasMessageContaining(
+ "no policy types are defined on the service template for the policies in the topology template");
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
@@ -356,8 +351,8 @@ public class TestLegacyGuardPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -396,8 +391,8 @@ public class TestLegacyGuardPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
index 72e57a98..d812d4e1 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,7 +78,6 @@ public class TestLegacyOperationalPolicyProvider {
"policies/vDNS.policy.operational.no.policyversion.json";
private static final String POLICY_TYPE_RESOURCE = "policytypes/onap.policies.controlloop.Operational.yaml";
private static final String POLICY_TYPE_ID = "onap.policies.controlloop.Operational:1.0.0";
- private static final String POLICY_ID = "operational.restart:1.0.0";
private static final String POLICY_NAME = "operational.restart";
private static final String POLICY_VERSION = "1";
private static final String POLICY_TYPE_NAME = "onap.policies.controlloop.Operational";
@@ -131,8 +130,8 @@ public class TestLegacyOperationalPolicyProvider {
operationalPolicyProvider.fetchOperationalPolicy("dummy", "dummy");
}).hasMessage("legacy policy version is not an integer");
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
@@ -155,7 +154,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatThrownBy(() -> {
- operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "latest");;
+ operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "latest");
+ ;
}).hasMessage("legacy policy version is not an integer");
operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1");
@@ -208,8 +208,8 @@ public class TestLegacyOperationalPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -228,10 +228,9 @@ public class TestLegacyOperationalPolicyProvider {
// Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
assertThatThrownBy(() -> {
operationalPolicyProvider.fetchDeployedOperationalPolicies(POLICY_NAME);
- }) .hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID
+ }).hasMessage("could not find policy with ID " + POLICY_NAME + " and type " + POLICY_TYPE_ID
+ " deployed in any pdp group");
-
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies()
@@ -247,7 +246,7 @@ public class TestLegacyOperationalPolicyProvider {
// Test validateDeleteEligibility exception path(!pdpGroups.isEmpty())
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy(POLICY_NAME, POLICY_VERSION);
- }) .hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ }).hasMessageContaining("policy with ID " + POLICY_NAME + ":" + POLICY_VERSION
+ " cannot be deleted as it is deployed in pdp groups");
} catch (Exception exc) {
fail("Test should not throw an exception");
@@ -261,10 +260,11 @@ public class TestLegacyOperationalPolicyProvider {
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyOperationalPolicy policyToCreate = standardCoder.decode(policyString, LegacyOperationalPolicy.class);
operationalPolicyProvider.createOperationalPolicy(policyToCreate);
- }).hasMessage("policy type " + POLICY_TYPE_ID + " for policy " + POLICY_ID + " does not exist");
+ }).hasMessageContaining(
+ "no policy types are defined on the service template for the policies in the topology template");
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
@@ -335,8 +335,8 @@ public class TestLegacyOperationalPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -375,8 +375,8 @@ public class TestLegacyOperationalPolicyProvider {
}).hasMessage("legacy policy version is not an integer");
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
index 4b7c3133..51cd4d3c 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java
@@ -3,7 +3,7 @@
* ONAP Policy API
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,8 +78,8 @@ public class TestPolicyProvider {
private static final String POLICY_RESOURCE_WITH_BAD_POLICYTYPE_VERSION =
"policies/vCPE.policy.bad.policytypeversion.json";
private static final String POLICY_RESOURCE_WITH_NO_POLICY_VERSION = "policies/vCPE.policy.no.policyversion.json";
- private static final String POLICY_RESOURCE_WITH_DUPLICATE_POLICY_VERSION =
- "policies/vCPE.policy.duplicate.policyversion.json";
+ private static final String POLICY_RESOURCE_WITH_DIFFERENT_FIELDS =
+ "policies/vCPE.policy.different.policy.fields.json";
private static final String MULTIPLE_POLICIES_RESOURCE = "policies/vCPE.policies.optimization.input.tosca.json";
public static final String POLICY_TYPE_RESOURCE_OPERATIONAL =
@@ -87,20 +87,6 @@ public class TestPolicyProvider {
private static final String POLICY_RESOURCE_OPERATIONAL = "policies/vCPE.policy.operational.input.tosca.json";
public static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
-
- // @formatter:off
- private String[] toscaPolicyTypeResourceNames = {
- "policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml",
- "policytypes/onap.policies.optimization.resource.DistancePolicy.yaml",
- "policytypes/onap.policies.optimization.resource.HpaPolicy.yaml",
- "policytypes/onap.policies.optimization.service.QueryPolicy.yaml",
- "policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml",
- "policytypes/onap.policies.optimization.resource.Vim_fit.yaml",
- "policytypes/onap.policies.optimization.resource.VnfPolicy.yaml",
- "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"
- };
- // @formatter:on
-
/**
* Initializes parameters.
*
@@ -141,15 +127,15 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
policyProvider.fetchPolicies("dummy", "1.0.0", null, null);
- }).hasMessage("policy with ID null:null and type dummy:1.0.0 does not exist");
+ }).hasMessage("service template not found in database");
assertThatThrownBy(() -> {
policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", null);
- }).hasMessage("policy with ID dummy:null and type dummy:1.0.0 does not exist");
+ }).hasMessage("service template not found in database");
assertThatThrownBy(() -> {
policyProvider.fetchPolicies("dummy", "1.0.0", "dummy", "1.0.0");
- }).hasMessage("policy with ID dummy:1.0.0 and type dummy:1.0.0 does not exist");
+ }).hasMessage("service template not found in database");
}
@Test
@@ -157,10 +143,9 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
policyProvider.fetchLatestPolicies("dummy", "dummy", "dummy");
- }).hasMessage("policy with ID dummy:null and type dummy:dummy does not exist");
+ }).hasMessage("service template not found in database");
}
-
@Test
public void testFetchDeployedPolicies() {
String policyId = "onap.restart.tca";
@@ -211,8 +196,8 @@ public class TestPolicyProvider {
// Create Policy Type
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -229,10 +214,9 @@ public class TestPolicyProvider {
// Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
assertThatThrownBy(() -> {
policyProvider.fetchDeployedPolicies(policyTypeId, policyTypeVersion, policyId);
- }) .hasMessage("could not find policy with ID " + policyId + " and type " + policyTypeId + ":"
+ }).hasMessage("could not find policy with ID " + policyId + " and type " + policyTypeId + ":"
+ policyTypeVersion + " deployed in any pdp group");
-
// Update pdpSubGroup
pdpSubGroup.setPolicies(new ArrayList<>());
pdpSubGroup.getPolicies().add(new ToscaPolicyIdentifier(policyId, policyVersion));
@@ -248,7 +232,7 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
"1.0.0");
- }) .hasMessageContaining("policy with ID " + policyId + ":" + policyVersion
+ }).hasMessageContaining("policy with ID " + policyId + ":" + policyVersion
+ " cannot be deleted as it is deployed in pdp groups");
} catch (Exception exc) {
fail("Test should not throw an exception");
@@ -260,19 +244,22 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
policyProvider.createPolicy("dummy", "1.0.0", new ToscaServiceTemplate());
- }).hasMessage("policy type with ID dummy:1.0.0 does not exist");
+ }).hasMessage("topology template not specified on service template");
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ assertThatCode(() -> policyTypeProvider.createPolicyType(policyTypeServiceTemplate)).doesNotThrowAnyException();
+
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_BAD_POLICYTYPE_ID);
ToscaServiceTemplate badPolicyServiceTemplate =
standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
badPolicyServiceTemplate);
- }).hasMessage("policy type id does not match");
+ }).hasMessageContaining(
+ "policy type onap.policies.monitoring.cdap.tca.hi.lo.appxxx:0.0.0 referenced in policy not found");
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_BAD_POLICYTYPE_VERSION);
@@ -280,7 +267,8 @@ public class TestPolicyProvider {
standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
badPolicyServiceTemplate);
- }).hasMessage("policy type version does not match");
+ }).hasMessageContaining(
+ "policy type onap.policies.monitoring.cdap.tca.hi.lo.app:2.0.0 referenced in policy not found");
assertThatThrownBy(() -> {
String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_POLICY_VERSION);
@@ -288,15 +276,7 @@ public class TestPolicyProvider {
standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
badPolicyServiceTemplate);
- }).hasMessage("mandatory 'version' field is missing in policies: onap.restart.tca");
-
- assertThatThrownBy(() -> {
- String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_DUPLICATE_POLICY_VERSION);
- ToscaServiceTemplate badPolicyServiceTemplate =
- standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
- policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
- badPolicyServiceTemplate);
- }).hasMessage("the same version of policies 'onap.restart.tca:1.0.0' appear multiple times in the payload");
+ }).hasMessageContaining("key version is a null version");
String policyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
ToscaServiceTemplate policyServiceTemplate = standardCoder.decode(policyString, ToscaServiceTemplate.class);
@@ -305,12 +285,12 @@ public class TestPolicyProvider {
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
assertThatThrownBy(() -> {
- String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_DIFFERENT_FIELDS);
ToscaServiceTemplate badPolicyServiceTemplate =
standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
badPolicyServiceTemplate);
- }).hasMessage("policy onap.restart.tca:1.0.0 already exists; its latest version is 1.0.0");
+ }).hasMessageContaining("entity in incoming fragment does not equal existing entity");
}
@Test
@@ -329,34 +309,82 @@ public class TestPolicyProvider {
@Test
public void testSimpleCreatePolicy() throws Exception {
- String errorMessage = "policy type onap.policies.optimization.resource.AffinityPolicy:1.0.0 for "
- + "policy OSDF_CASABLANCA.Affinity_Default:1.0.0 does not exist";
assertThatThrownBy(() -> {
String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
ToscaServiceTemplate multiPoliciesServiceTemplate =
standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
policyProvider.createPolicies(multiPoliciesServiceTemplate);
- }).hasMessage(errorMessage);
+ }).hasMessageContaining(
+ "no policy types are defined on the service template for the policies in the topology template");
// Create required policy types
- for (String policyTypeName : toscaPolicyTypeResourceNames) {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(policyTypeName), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
- }
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.Optimization.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.Resource.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils
+ .getResourceAsString("policytypes/onap.policies.optimization.resource.AffinityPolicy.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils
+ .getResourceAsString("policytypes/onap.policies.optimization.resource.DistancePolicy.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.Vim_fit.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.HpaPolicy.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.resource.VnfPolicy.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.Service.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils
+ .getResourceAsString("policytypes/onap.policies.optimization.service.SubscriberPolicy.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.service.QueryPolicy.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"),
+ ToscaServiceTemplate.class);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
// Create multiple policies in one call
String multiPoliciesString = ResourceUtils.getResourceAsString(MULTIPLE_POLICIES_RESOURCE);
ToscaServiceTemplate multiPoliciesServiceTemplate =
standardCoder.decode(multiPoliciesString, ToscaServiceTemplate.class);
- policyProvider.createPolicies(multiPoliciesServiceTemplate);
- assertThatThrownBy(() -> {
- String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_DUPLICATE_POLICY_VERSION);
- ToscaServiceTemplate badPolicyServiceTemplate =
- standardCoder.decode(badPolicyString, ToscaServiceTemplate.class);
- policyProvider.createPolicies(badPolicyServiceTemplate);
- }).hasMessage("the same version of policies 'onap.restart.tca:1.0.0' appear multiple times in the payload");
+ assertThatCode(() -> {
+ policyProvider.createPolicies(multiPoliciesServiceTemplate);
+ policyProvider.createPolicies(multiPoliciesServiceTemplate);
+ }).doesNotThrowAnyException();
}
@Test
@@ -364,11 +392,11 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
policyProvider.deletePolicy("dummy", "1.0.0", "dummy", "1.0.0");
- }).hasMessage("policy with ID dummy:1.0.0 and type dummy:1.0.0 does not exist");
+ }).hasMessage("service template not found in database");
assertThatCode(() -> {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
}).doesNotThrowAnyException();
@@ -386,12 +414,9 @@ public class TestPolicyProvider {
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
}).doesNotThrowAnyException();
- String exceptionMessage = "policy with ID onap.restart.tca:1.0.0 and type "
- + "onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist";
assertThatThrownBy(() -> {
policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
"1.0.0");
- }).hasMessage(exceptionMessage);
+ }).hasMessageContaining("policies for onap.restart.tca:1.0.0 do not exist");
}
-
}
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
index 177ff535..8f5657b3 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java
@@ -23,12 +23,14 @@
package org.onap.policy.api.main.rest.provider;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import java.util.Base64;
import java.util.Collections;
+
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -39,6 +41,7 @@ import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
@@ -66,7 +69,7 @@ public class TestPolicyTypeProvider {
public static final String POLICY_TYPE_RESOURCE_OPERATIONAL =
"policytypes/onap.policies.controlloop.operational.Common.yaml";
public static final String POLICY_TYPE_RESOURCE_OPERATIONAL_APEX =
- "policytypes/onap.policies.controlloop.operational.common.Apex.yaml";
+ "policytypes/onap.policies.controlloop.operational.common.Apex.yaml";
public static final String POLICY_TYPE_OPERATIONAL_COMMON = "onap.policies.controlloop.operational.Common";
public static final String POLICY_TYPE_OPERATIONAL_APEX = "onap.policies.controlloop.operational.common.Apex";
public static final String POLICY_TYPE_OPERATIONAL_DROOLS = "onap.policies.controlloop.operational.common.Drools";
@@ -131,22 +134,27 @@ public class TestPolicyTypeProvider {
@Test
public void testCreatePolicyType() throws Exception {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
- String errorMessage = "policy type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 already exists; "
- + "its latest version is 1.0.0";
+ assertThatCode(() -> {
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).doesNotThrowAnyException();
+
+ ToscaPolicyType policyType =
+ policyTypeServiceTemplate.getPolicyTypes().get("onap.policies.monitoring.cdap.tca.hi.lo.app");
+ policyType.setDescription("Some other description");
+
assertThatThrownBy(() -> {
- ToscaServiceTemplate duplicatePolicyType = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
- policyTypeProvider.createPolicyType(duplicatePolicyType);
- }).hasMessage(errorMessage);
+ policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ }).hasMessageContaining("entity in incoming fragment does not equal existing entity");
assertThatThrownBy(() -> {
- ToscaServiceTemplate badPolicyType = standardYamlCoder.decode(ResourceUtils.getResourceAsString(
- POLICY_TYPE_RESOURCE_WITH_NO_VERSION), ToscaServiceTemplate.class);
+ ToscaServiceTemplate badPolicyType =
+ standardYamlCoder.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_WITH_NO_VERSION),
+ ToscaServiceTemplate.class);
policyTypeProvider.createPolicyType(badPolicyType);
}).hasMessage("mandatory 'version' field is missing in policy types: onap.policies.optimization.Resource");
@@ -155,22 +163,25 @@ public class TestPolicyTypeProvider {
@Test
public void testCreateOperationalPolicyTypes() throws CoderException, PfModelException {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
- .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertNotNull(serviceTemplate.getPolicyTypes().get(POLICY_TYPE_OPERATIONAL_COMMON));
assertNotNull(serviceTemplate.getPolicyTypes().get(POLICY_TYPE_OPERATIONAL_DROOLS));
- policyTypeProvider.deletePolicyType(POLICY_TYPE_OPERATIONAL_COMMON, POLICY_TYPE_VERSION);
policyTypeProvider.deletePolicyType(POLICY_TYPE_OPERATIONAL_DROOLS, POLICY_TYPE_VERSION);
+ policyTypeProvider.deletePolicyType(POLICY_TYPE_OPERATIONAL_COMMON, POLICY_TYPE_VERSION);
}
@Test
public void testCreateApexOperationalPolicyTypes() throws CoderException, PfModelException {
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_APEX), ToscaServiceTemplate.class);
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
+ policyTypeServiceTemplate = standardYamlCoder.decode(
+ ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_OPERATIONAL_APEX), ToscaServiceTemplate.class);
+ serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertNotNull(serviceTemplate.getPolicyTypes().get(POLICY_TYPE_OPERATIONAL_APEX));
policyTypeProvider.deletePolicyType(POLICY_TYPE_OPERATIONAL_APEX, POLICY_TYPE_VERSION);
}
@@ -178,13 +189,13 @@ public class TestPolicyTypeProvider {
@Test
public void testDeletePolicyType() throws Exception {
- ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE_MONITORING), ToscaServiceTemplate.class);
ToscaServiceTemplate serviceTemplate = policyTypeProvider.createPolicyType(policyTypeServiceTemplate);
assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
- ToscaServiceTemplate policyServiceTemplate = standardYamlCoder.decode(
- ResourceUtils.getResourceAsString(POLICY_RESOURCE_MONITORING), ToscaServiceTemplate.class);
+ ToscaServiceTemplate policyServiceTemplate = standardYamlCoder
+ .decode(ResourceUtils.getResourceAsString(POLICY_RESOURCE_MONITORING), ToscaServiceTemplate.class);
policyProvider.createPolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", policyServiceTemplate);
String exceptionMessage = "policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 "
@@ -193,16 +204,15 @@ public class TestPolicyTypeProvider {
policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
}).hasMessage(exceptionMessage);
- serviceTemplate = policyProvider
- .deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca", "1.0.0");
+ serviceTemplate = policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0",
+ "onap.restart.tca", "1.0.0");
assertFalse(serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).isEmpty());
- serviceTemplate =
- policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
+ serviceTemplate = policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
assertFalse(serviceTemplate.getPolicyTypes().isEmpty());
assertThatThrownBy(() -> {
policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
- }).hasMessage("policy type with ID onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 does not exist");
+ }).hasMessage("policy types for onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 do not exist");
}
}
diff --git a/main/src/test/resources/META-INF/persistence.xml b/main/src/test/resources/META-INF/persistence.xml
index 2fa25a5d..7fbcca6b 100644
--- a/main/src/test/resources/META-INF/persistence.xml
+++ b/main/src/test/resources/META-INF/persistence.xml
@@ -27,11 +27,17 @@
<class>org.onap.policy.models.dao.converters.Uuid2String</class>
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
- <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
<class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
+ <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpStatistics</class>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="create" />
diff --git a/main/src/test/resources/policies/vCPE.policy.duplicate.policyversion.json b/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json
index 6caeb503..cc7e4ee4 100644
--- a/main/src/test/resources/policies/vCPE.policy.duplicate.policyversion.json
+++ b/main/src/test/resources/policies/vCPE.policy.different.policy.fields.json
@@ -5,52 +5,9 @@
{
"onap.restart.tca": {
"type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
- "version": "1.0.0",
"type_version": "1.0.0",
- "metadata": {
- "policy-id": "onap.restart.tca"
- },
- "properties": {
- "tca_policy" : {
- "domain": "measurementsForVfScaling",
- "metricsPerEventName": [
- {
- "eventName": "Measurement_vGMUX",
- "controlLoopSchemaType": "VNF",
- "policyScope": "DCAE",
- "policyName": "DCAE.Config_tca-hi-lo",
- "policyVersion": "v0.0.1",
- "thresholds": [
- {
- "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
- "thresholdValue": 0,
- "direction": "EQUAL",
- "severity": "MAJOR",
- "closedLoopEventStatus": "ABATED"
- },
- {
- "closedLoopControlName": "ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e",
- "version": "1.0.2",
- "fieldPath": "$.event.measurementsForVfScalingFields.additionalMeasurements[*].arrayOfFields[0].value",
- "thresholdValue": 0,
- "direction": "GREATER",
- "severity": "CRITICAL",
- "closedLoopEventStatus": "ONSET"
- }
- ]
- }
- ]
- }
- }
- }
- },
- {
- "onap.restart.tca": {
- "type": "onap.policies.monitoring.cdap.tca.hi.lo.app",
"version": "1.0.0",
- "type_version": "1.0.0",
+ "description": "description field added to policy",
"metadata": {
"policy-id": "onap.restart.tca"
},
diff --git a/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml
index 523e9bb5..459dcf7d 100644
--- a/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml
+++ b/main/src/test/resources/policies/vCPE.policy.monitoring.input.tosca.v2.yaml
@@ -4,6 +4,7 @@ topology_template:
-
onap.restart.tca:
type: onap.policies.monitoring.cdap.tca.hi.lo.app
+ type_version: 1.0.0
version: 2.0.0
metadata:
policy-id: onap.restart.tca
diff --git a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml
index 9893af1d..208c656f 100644
--- a/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml
+++ b/main/src/test/resources/policies/vDNS.policy.monitoring.input.tosca.v2.yaml
@@ -1,36 +1,33 @@
tosca_definitions_version: tosca_simple_yaml_1_0_0
topology_template:
policies:
- -
- onap.scaleout.tca:
- type: onap.policies.monitoring.cdap.tca.hi.lo.app
- version: 2.0.0
- metadata:
- policy-id: onap.scaleout.tca
- properties:
- tca_policy:
- domain: measurementsForVfScaling
- metricsPerEventName:
- -
- eventName: vLoadBalancer
- controlLoopSchemaType: VNF
- policyScope: "type=configuration"
- policyName: "onap.scaleout.tca"
- policyVersion: "v0.0.1"
- thresholds:
- -
- closedLoopControlName: "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3"
- closedLoopEventStatus: ONSET
- version: "1.0.2"
- fieldPath: "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated"
- thresholdValue: 500
- direction: LESS_OR_EQUAL
- severity: MAJOR
- -
- closedLoopControlName: "ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3"
- closedLoopEventStatus: ONSET
- version: "1.0.2"
- fieldPath: "$.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated"
- thresholdValue: 5000
- direction: GREATER_OR_EQUAL
- severity: CRITICAL
+ - onap.scaleout.tca:
+ type: onap.policies.monitoring.cdap.tca.hi.lo.app
+ type_version: 1.0.0
+ version: 2.0.0
+ metadata:
+ policy-id: onap.scaleout.tca
+ properties:
+ tca_policy:
+ domain: measurementsForVfScaling
+ metricsPerEventName:
+ - eventName: vLoadBalancer
+ controlLoopSchemaType: VNF
+ policyScope: type=configuration
+ policyName: onap.scaleout.tca
+ policyVersion: v0.0.1
+ thresholds:
+ - closedLoopControlName: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+ closedLoopEventStatus: ONSET
+ version: 1.0.2
+ fieldPath: $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated
+ thresholdValue: 500
+ direction: LESS_OR_EQUAL
+ severity: MAJOR
+ - closedLoopControlName: ControlLoop-vDNS-6f37f56d-a87d-4b85-b6a9-cc953cf779b3
+ closedLoopEventStatus: ONSET
+ version: 1.0.2
+ fieldPath: $.event.measurementsForVfScalingFields.vNicPerformanceArray[*].receivedBroadcastPacketsAccumulated
+ thresholdValue: 5000
+ direction: GREATER_OR_EQUAL
+ severity: CRITICAL \ No newline at end of file
diff --git a/main/src/test/resources/policytypes/onap.policies.Test.yaml b/main/src/test/resources/policytypes/onap.policies.Test.yaml
new file mode 100644
index 00000000..c8850a13
--- /dev/null
+++ b/main/src/test/resources/policytypes/onap.policies.Test.yaml
@@ -0,0 +1,31 @@
+tosca_definitions_version: tosca_simple_yaml_1_0_0
+policy_types:
+ onap.policies.Test:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ description: The base policy type for all policies that govern optimization
+ properties:
+ scope:
+ description: Scope for the policy - could be for a specific release.
+ type: list
+ metadata:
+ matchable: true
+ required: true
+ entry_schema:
+ type: string
+ geography:
+ description: One or more geographic regions
+ type: list
+ metadata:
+ matchable: true
+ required: true
+ entry_schema:
+ type: string
+ constraints:
+ - valid_values:
+ - US
+ - International
+ identity:
+ description: Used internally for identification
+ type: string
+ required: true \ No newline at end of file