summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-18 17:44:18 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-18 17:52:02 +0000
commit19286bf7b66750aba7192af363349db2a4d5323d (patch)
treeaee284056ee18b370a57652698941577ff6f77e2 /main/src/test
parent7575d2d1ecb5ef467032c4418a09283050dfc345 (diff)
Add changes for safe delete in policy-models
Issue-ID: POLICY-1402 Change-Id: I3f97fbb4c11105118857d354970d6a3de1385f2d Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java2
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyGuardPolicyProvider.java37
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java36
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyProvider.java5
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/provider/TestPolicyTypeProvider.java8
-rw-r--r--main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json2
6 files changed, 51 insertions, 39 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 291bddde..d531a0ad 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
@@ -616,7 +616,7 @@ public class TestApiRestServer {
Response rawResponse = deleteResource(POLICYTYPES_TCA_POLICIES_VCPE_VERSION1, mediaType);
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawResponse.getStatus());
ErrorResponse error = rawResponse.readEntity(ErrorResponse.class);
- assertEquals("policies for onap.restart.tca:1.0.0 do not exist", error.getErrorMessage());
+ assertEquals("no policies found", error.getErrorMessage());
}
@Test
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 237da680..342d17b1 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
@@ -58,6 +58,7 @@ import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
@@ -131,7 +132,7 @@ public class TestLegacyGuardPolicyProvider {
assertThatThrownBy(() -> {
guardPolicyProvider.fetchGuardPolicy("dummy", "dummy");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"dummy.0.0\", does not match regular expression");
assertThatCode(() -> {
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
@@ -165,11 +166,11 @@ public class TestLegacyGuardPolicyProvider {
assertThatThrownBy(() -> {
guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "1.0.0");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression");
assertThatThrownBy(() -> {
guardPolicyProvider.fetchGuardPolicy("guard.frequency.scaleout", "latest");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"latest.0.0\", does not match regular expression");
assertThatCode(() -> {
guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
@@ -260,8 +261,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
- + " cannot be deleted as it is deployed in pdp groups");
+ }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
} catch (Exception exc) {
fail("Test should not throw an exception");
}
@@ -290,19 +290,26 @@ public class TestLegacyGuardPolicyProvider {
createdPolicy.get("guard.frequency.scaleout").getType());
assertEquals("1.0.0", createdPolicy.get("guard.frequency.scaleout").getVersion());
- assertThatThrownBy(() -> {
- String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_VERSION);
- LegacyGuardPolicyInput badPolicyToCreate =
- standardCoder.decode(badPolicyString, LegacyGuardPolicyInput.class);
- guardPolicyProvider.createGuardPolicy(badPolicyToCreate);
- }).hasMessage("mandatory field 'policy-version' is missing in the policy: guard.frequency.scaleout");
+ String defaultPolicyVersionString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_VERSION);
+ LegacyGuardPolicyInput defaultVersionPolicy =
+ standardCoder.decode(defaultPolicyVersionString, LegacyGuardPolicyInput.class);
+ createdPolicy = guardPolicyProvider.createGuardPolicy(defaultVersionPolicy);
+ assertEquals("1.0.0", createdPolicy.get("guard.frequency.scaleout.noversion").getVersion());
+
+ assertThatCode(() -> {
+ String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ LegacyGuardPolicyInput duplicatePolicyToCreate =
+ standardCoder.decode(duplicatePolicyString, LegacyGuardPolicyInput.class);
+ guardPolicyProvider.createGuardPolicy(duplicatePolicyToCreate);
+ }).doesNotThrowAnyException();
assertThatThrownBy(() -> {
String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyGuardPolicyInput duplicatePolicyToCreate =
standardCoder.decode(duplicatePolicyString, LegacyGuardPolicyInput.class);
+ duplicatePolicyToCreate.setContent(new LegacyGuardPolicyContent());
guardPolicyProvider.createGuardPolicy(duplicatePolicyToCreate);
- }).hasMessage("guard policy guard.frequency.scaleout:1 already exists; its latest version is 1");
+ }).hasMessageContaining("INVALID:entity in incoming fragment does not equal existing entity");
}
@Test
@@ -374,7 +381,7 @@ public class TestLegacyGuardPolicyProvider {
databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
assertThatThrownBy(() -> {
guardPolicyProvider.deleteGuardPolicy("guard.frequency.scaleout", "1");
- }).hasMessageContaining("cannot be deleted as it is deployed in pdp groups");
+ }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
} catch (Exception exc) {
fail("Test should not throw an exception");
}
@@ -384,11 +391,11 @@ public class TestLegacyGuardPolicyProvider {
public void testDeleteGuardPolicy() {
assertThatThrownBy(() -> {
guardPolicyProvider.deleteGuardPolicy("dummy", null);
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
guardPolicyProvider.deleteGuardPolicy("dummy", "1.0.0");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression");
assertThatCode(() -> {
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
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 f9fc666d..c0084956 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
@@ -128,7 +128,7 @@ public class TestLegacyOperationalPolicyProvider {
assertThatThrownBy(() -> {
operationalPolicyProvider.fetchOperationalPolicy("dummy", "dummy");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"dummy.0.0\", does not match regular expression");
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
.decode(ResourceUtils.getResourceAsString(POLICY_TYPE_RESOURCE), ToscaServiceTemplate.class);
@@ -151,12 +151,12 @@ public class TestLegacyOperationalPolicyProvider {
assertThatThrownBy(() -> {
operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "1.0.0");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"1.0.0.0.0\", does not match regular expression");
assertThatThrownBy(() -> {
operationalPolicyProvider.fetchOperationalPolicy("operational.restart", "latest");
;
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"latest.0.0\", does not match regular expression");
operationalPolicyProvider.deleteOperationalPolicy("operational.restart", "1");
policyTypeProvider.deletePolicyType("onap.policies.controlloop.Operational", "1.0.0");
@@ -246,8 +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
- + " cannot be deleted as it is deployed in pdp groups");
+ }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
} catch (Exception exc) {
fail("Test should not throw an exception");
}
@@ -274,19 +273,26 @@ public class TestLegacyOperationalPolicyProvider {
assertEquals("operational.restart", createdPolicy.getPolicyId());
assertTrue(createdPolicy.getContent().startsWith("controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20"));
- assertThatThrownBy(() -> {
- String badPolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_VERSION);
- LegacyOperationalPolicy badPolicyToCreate =
- standardCoder.decode(badPolicyString, LegacyOperationalPolicy.class);
- operationalPolicyProvider.createOperationalPolicy(badPolicyToCreate);
- }).hasMessage("mandatory field 'policy-version' is missing in the policy: operational.scaleout");
+ String defaultPolicyVersionString = ResourceUtils.getResourceAsString(POLICY_RESOURCE_WITH_NO_VERSION);
+ LegacyOperationalPolicy defaultPolicyVersionPolicy =
+ standardCoder.decode(defaultPolicyVersionString, LegacyOperationalPolicy.class);
+ createdPolicy = operationalPolicyProvider.createOperationalPolicy(defaultPolicyVersionPolicy);
+ assertEquals("1", createdPolicy.getPolicyVersion());
+
+ assertThatCode(() -> {
+ String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
+ LegacyOperationalPolicy duplicatePolicyToCreate =
+ standardCoder.decode(duplicatePolicyString, LegacyOperationalPolicy.class);
+ operationalPolicyProvider.createOperationalPolicy(duplicatePolicyToCreate);
+ }).doesNotThrowAnyException();
assertThatThrownBy(() -> {
String duplicatePolicyString = ResourceUtils.getResourceAsString(POLICY_RESOURCE);
LegacyOperationalPolicy duplicatePolicyToCreate =
standardCoder.decode(duplicatePolicyString, LegacyOperationalPolicy.class);
+ duplicatePolicyToCreate.setContent("some other content");
operationalPolicyProvider.createOperationalPolicy(duplicatePolicyToCreate);
- }).hasMessage("operational policy operational.restart:1 already exists; its latest version is 1");
+ }).hasMessageContaining("INVALID:entity in incoming fragment does not equal existing entity");
}
@Test
@@ -357,7 +363,7 @@ public class TestLegacyOperationalPolicyProvider {
databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getPolicies().size());
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy(policyId, policyVersion);
- }).hasMessageContaining("cannot be deleted as it is deployed in pdp groups");
+ }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
} catch (Exception exc) {
fail("Test should not throw an exception");
}
@@ -368,11 +374,11 @@ public class TestLegacyOperationalPolicyProvider {
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy("dummy", null);
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
operationalPolicyProvider.deleteOperationalPolicy("dummy", "dummy");
- }).hasMessage("legacy policy version is not an integer");
+ }).hasMessageContaining("parameter \"version\": value \"dummy.0.0\", does not match regular expression");
assertThatCode(() -> {
ToscaServiceTemplate policyTypeServiceTemplate = standardYamlCoder
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 31be84a9..d9b01fdb 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
@@ -236,8 +236,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
- + " cannot be deleted as it is deployed in pdp groups");
+ }).hasMessageContaining("policy is in use, it is deployed in PDP group group subgroup type");
} catch (Exception exc) {
fail("Test should not throw an exception");
}
@@ -430,6 +429,6 @@ public class TestPolicyProvider {
assertThatThrownBy(() -> {
policyProvider.deletePolicy("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0", "onap.restart.tca",
"1.0.0");
- }).hasMessageContaining("policies for onap.restart.tca:1.0.0 do not exist");
+ }).hasMessageContaining("no policies found");
}
}
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 3c64e640..82d25245 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
@@ -158,7 +158,7 @@ public class TestPolicyTypeProvider {
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");
+ }).hasMessageContaining("INVALID:key version is a null version");
policyTypeProvider.deletePolicyType(POLICY_TYPE_NAME_MONITORING, POLICY_TYPE_VERSION);
}
@@ -204,8 +204,8 @@ public class TestPolicyTypeProvider {
.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 "
- + "cannot be deleted as it is parameterized by policies onap.restart.tca:1.0.0";
+ String exceptionMessage = "policy type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 is in use, "
+ + "it is referenced in policy onap.restart.tca:1.0.0";
assertThatThrownBy(() -> {
policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
}).hasMessage(exceptionMessage);
@@ -219,6 +219,6 @@ public class TestPolicyTypeProvider {
assertThatThrownBy(() -> {
policyTypeProvider.deletePolicyType("onap.policies.monitoring.cdap.tca.hi.lo.app", "1.0.0");
- }).hasMessage("policy types for onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 do not exist");
+ }).hasMessage("policy type onap.policies.monitoring.cdap.tca.hi.lo.app:1.0.0 not found");
}
}
diff --git a/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json b/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json
index 346765ef..518f09e8 100644
--- a/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json
+++ b/main/src/test/resources/policies/vDNS.policy.guard.frequency.no.policyversion.json
@@ -1,5 +1,5 @@
{
- "policy-id" : "guard.frequency.scaleout",
+ "policy-id" : "guard.frequency.scaleout.noversion",
"content" : {
"actor": "SO",
"recipe": "VF Module Create",