summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-05-05 13:05:11 +0100
committerliamfallon <liam.fallon@est.tech>2020-05-05 13:05:15 +0100
commit83a1bbff60a642043260bfc61e238203a3bba769 (patch)
tree1179e0f61b652a68e3408b947f0f0edc89bdca94 /models-provider/src/test
parent275a3c5707c721d6fb020c9632f7a545cbc33b81 (diff)
Policy delete should only return deleted policy
The policy type delete and policy delete now only return what is deleted in the service template. Issue-ID: POLICY-2534 Change-Id: I1b8d10c22d4392b0bbb655aa6876ac900ebc81df Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src/test')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java9
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java30
2 files changed, 36 insertions, 3 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
index cbc57fe75..210c900c2 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
@@ -179,8 +179,11 @@ public class PolicyToscaPersistenceTest {
assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size());
long deleteStartTime = System.currentTimeMillis();
- databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", "1.0.0");
+ ToscaServiceTemplate deletedServiceTemplate =
+ databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", "1.0.0");
LOGGER.trace("Naming policy delete time (ms): {}", System.currentTimeMillis() - deleteStartTime);
+
+ assertEquals(1, deletedServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
}
@Test
@@ -228,7 +231,9 @@ public class PolicyToscaPersistenceTest {
.next().getVersion());
for (int i = 1; i < 22; i++) {
- databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", i + ".0.0");
+ ToscaServiceTemplate deletedServiceTemplate =
+ databaseProvider.deletePolicy("SDNC_Policy.ONAP_NF_NAMING_TIMESTAMP", i + ".0.0");
+ assertEquals(1, deletedServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size());
}
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
index 6cda57b60..8001d536c 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
@@ -21,7 +21,7 @@
package org.onap.policy.models.provider.impl;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.awaitility.Awaitility.await;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -40,6 +40,7 @@ import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.provider.PolicyModelsProviderParameters;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
@@ -140,5 +141,32 @@ public class PolicyTypePersistenceTest {
assertTrue(resOptPolicyTypeSt.getPolicyTypesAsMap().containsKey(optimizationPtKey));
assertEquals(2, resOptPolicyTypeSt.getDataTypesAsMap().size());
+
+ deleteUnreferencedPolicyTypes();
+
+ assertThatThrownBy(() -> {
+ databaseProvider.getPolicyTypes(null, null);
+ }).hasMessageContaining("policy types for null:null do not exist");
+ }
+
+ private void deleteUnreferencedPolicyTypes() throws PfModelException {
+ ToscaServiceTemplate allPolicyTypes = databaseProvider.getPolicyTypes(null, null);
+
+ boolean deleteFailedDueToReference = false;
+
+ for (ToscaPolicyType policyType : allPolicyTypes.getPolicyTypes().values()) {
+ try {
+ ToscaServiceTemplate deletedServiceTemplate =
+ databaseProvider.deletePolicyType(policyType.getName(), policyType.getVersion());
+ assertEquals(1, deletedServiceTemplate.getPolicyTypesAsMap().size());
+ } catch (Exception pfModelRuntimeException) {
+ assertTrue(pfModelRuntimeException.getMessage().contains("is in use, it is referenced in policy type"));
+ deleteFailedDueToReference = true;
+ }
+ }
+
+ if (deleteFailedDueToReference) {
+ deleteUnreferencedPolicyTypes();
+ }
}
}