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