aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/test/java/org')
-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
5 files changed, 242 insertions, 294 deletions
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");
}
}