summaryrefslogtreecommitdiffstats
path: root/models-provider
diff options
context:
space:
mode:
Diffstat (limited to 'models-provider')
-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();
+ }
}
}