summaryrefslogtreecommitdiffstats
path: root/models-provider/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-18 16:14:59 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-18 17:40:33 +0000
commitb477554c29b2d666e7bb0bc860afacc6e935c337 (patch)
tree22c40a3cbc378d042eab7d37df7328f5eb19176f /models-provider/src/test/java
parent88fb2e33c81fa0d69846e8d0d218b0ef4015a4ba (diff)
Add safe entity delete, fix multiple entity get
This review implements checks on whether entities are being used or referenced propr to allowing deletes. The review also fixes bugs on multiple entity get returning 4040 not found Issue-ID: POLICY-1402 Change-Id: I9cebb9a873098740e9ff4be6284d6307e19838bd Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src/test/java')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java76
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java7
2 files changed, 83 insertions, 0 deletions
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
index aa6802a5a..f085605f8 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
@@ -45,6 +45,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.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -536,4 +537,79 @@ public class DatabasePolicyModelsProviderTest {
databaseProvider.close();
}
+
+ @Test
+ public void testDeletePolicyDeployedInSubgroup() throws PfModelException {
+ List<ToscaPolicyIdentifier> policies = new ArrayList<>();
+
+ policies.add(new ToscaPolicyIdentifier("p0", "0.0.1"));
+ policies.add(new ToscaPolicyIdentifier("p1", "0.0.1"));
+
+ List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt2", "0.0.1"));
+
+ PdpSubGroup subGroup = new PdpSubGroup();
+ subGroup.setPdpType("pdpType");
+ subGroup.setSupportedPolicyTypes(supportedPolicyTypes);
+ subGroup.setPolicies(policies);
+
+ List<PdpSubGroup> pdpSubgroups = new ArrayList<>();
+ pdpSubgroups.add(subGroup);
+
+ PdpGroup pdpGroup = new PdpGroup();
+ pdpGroup.setName("pdpGroup");
+ pdpGroup.setPdpGroupState(PdpState.PASSIVE);
+ pdpGroup.setPdpSubgroups(pdpSubgroups);
+
+ List<PdpGroup> pdpGroups = new ArrayList<>();
+ pdpGroups.add(pdpGroup);
+
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ databaseProvider.createPdpGroups(pdpGroups);
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicy("p0", "0.0.1"))
+ .hasMessageContaining("policy is in use, it is deployed in PDP group pdpGroup subgroup pdpType");
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicy("p3", "0.0.1"))
+ .hasMessageContaining("service template not found in database");
+
+ databaseProvider.close();
+ }
+
+ @Test
+ public void testDeletePolicyTypeSupportedInSubgroup() throws PfModelException {
+ List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt1", "0.0.1"));
+ supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt2", "0.0.1"));
+
+ PdpSubGroup subGroup = new PdpSubGroup();
+ subGroup.setPdpType("pdpType");
+ subGroup.setSupportedPolicyTypes(supportedPolicyTypes);
+
+ List<PdpSubGroup> pdpSubgroups = new ArrayList<>();
+ pdpSubgroups.add(subGroup);
+
+ PdpGroup pdpGroup = new PdpGroup();
+ pdpGroup.setName("pdpGroup");
+ pdpGroup.setPdpGroupState(PdpState.PASSIVE);
+ pdpGroup.setPdpSubgroups(pdpSubgroups);
+
+ List<PdpGroup> pdpGroups = new ArrayList<>();
+ pdpGroups.add(pdpGroup);
+
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
+ databaseProvider.createPdpGroups(pdpGroups);
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicyType("pt2", "0.0.1"))
+ .hasMessageContaining("policy type is in use, it is referenced in PDP group pdpGroup subgroup pdpType");
+
+ assertThatThrownBy(() -> databaseProvider.deletePolicyType("pt0", "0.0.1"))
+ .hasMessageContaining("service template not found in database");
+
+ databaseProvider.close();
+ }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
index 500d9d4c0..3212428ae 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+import java.util.Date;
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.Pdp;
@@ -117,6 +118,12 @@ public class DummyPolicyModelsProviderTest {
dummyProvider.updatePdp("name", "type", new Pdp());
dummyProvider.updatePdpStatistics(new ArrayList<>());
assertTrue(dummyProvider.getPdpStatistics("name", null).isEmpty());
+
+ assertTrue(
+ dummyProvider.getFilteredPdpStatistics("name", null, null, new Date(), new Date(), null, 0).isEmpty());
+ assertTrue(dummyProvider.createPdpStatistics(null).isEmpty());
+ assertTrue(dummyProvider.updatePdpStatistics(null).isEmpty());
+ assertTrue(dummyProvider.deletePdpStatistics(null, new Date()).isEmpty());
}
@Test