Merge "Update tosca utils to remove code duplication"
[policy/models.git] / models-provider / src / test / java / org / onap / policy / models / provider / impl / DatabasePolicyModelsProviderTest.java
index d925333..fd566a5 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.models.provider.impl;
 
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
 import java.util.Base64;
-
+import java.util.Date;
+import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
-import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.onap.policy.models.pdp.concepts.Pdp;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
+import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
+import org.onap.policy.models.pdp.concepts.PdpStatistics;
+import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.onap.policy.models.pdp.enums.PdpHealthStatus;
+import org.onap.policy.models.pdp.enums.PdpState;
 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.ToscaPolicyTypeFilter;
+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.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
@@ -44,6 +58,30 @@ import org.slf4j.LoggerFactory;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class DatabasePolicyModelsProviderTest {
+    private static final String NAME = "name";
+
+    private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$";
+
+    private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$";
+
+    private static final String SUBGROUP_IS_NULL = "^pdpSubGroup is marked .*on.*ull but is null$";
+
+    private static final String GROUP_IS_NULL = "^pdpGroupName is marked .*on.*ull but is null$";
+
+    private static final String NAME_IS_NULL = "^name is marked .*on.*ull but is null$";
+
+    private static final String FILTER_IS_NULL = "^filter is marked .*on.*ull but is null$";
+
+    private static final String POLICY_ID = "policy_id";
+
+    private static final String GROUP = "group";
+
+    private static final String VERSION_100 = "1.0.0";
+
+    private static final Date TIMESTAMP = new Date();
+
+    private static final String ORDER = "DESC";
+
     private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderTest.class);
 
     PolicyModelsProviderParameters parameters;
@@ -54,180 +92,257 @@ public class DatabasePolicyModelsProviderTest {
     @Before
     public void setupParameters() {
         parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
         parameters.setPersistenceUnit("ToscaConceptTest");
-
     }
 
     @Test
     public void testInitAndClose() throws Exception {
+        assertThatThrownBy(() -> {
+            new DatabasePolicyModelsProviderImpl(null);
+        }).hasMessageMatching("^parameters is marked .*on.*ull but is null$");
+
         PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
 
         parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.init();
-        }).hasMessage("could not connect to database with URL \"jdbc://www.acmecorp.nonexist\"");
+        databaseProvider.close();
+        databaseProvider.init();
 
-        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
+        databaseProvider.close();
 
-        try {
-            databaseProvider.init();
-            databaseProvider.close();
-        } catch (Exception pfme) {
-            fail("test shold not throw an exception here");
-        }
+        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
 
         parameters.setPersistenceUnit("WileECoyote");
 
-        String errorMessage = "could not create Data Access Object (DAO) using url "
-                + "\"jdbc:h2:mem:testdb\" and persistence unit \"WileECoyote\"";
-        assertThatThrownBy(() -> {
-            databaseProvider.init();
-        }).hasMessage(errorMessage);
+        assertThatThrownBy(databaseProvider::init).hasMessageContaining("could not create Data Access Object (DAO)");
 
         parameters.setPersistenceUnit("ToscaConceptTest");
 
-        try {
-            databaseProvider.init();
-            databaseProvider.close();
-        } catch (Exception pfme) {
-            fail("test shold not throw an exception here");
-        }
-
-        try {
-            databaseProvider.close();
-        } catch (Exception pfme) {
-            fail("test shold not throw an exception here");
-        }
+        databaseProvider.init();
+        databaseProvider.close();
 
         assertThatThrownBy(() -> {
-            DatabasePolicyModelsProviderImpl databaseProviderImpl = (DatabasePolicyModelsProviderImpl) databaseProvider;
             databaseProvider.init();
-            databaseProviderImpl.setConnection(new DummyConnection());
-            databaseProvider.close();
-        }).hasMessage("could not close connection to database with URL \"jdbc:h2:mem:testdb\"");
+            databaseProvider.init();
+        }).hasMessage("provider is already initialized");
+
+        databaseProvider.close();
+
+        databaseProvider.close();
     }
 
     @Test
     public void testProviderMethodsNull() throws Exception {
-        PolicyModelsProvider databaseProvider =
-                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-        databaseProvider.init();
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+        try (PolicyModelsProvider databaseProvider =
+                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes("aaa", null);
-        }).hasMessage("version is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicyTypes(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes(null, "aaa");
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicyTypeList(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.createPolicyTypes(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.createPolicyTypes(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.updatePolicyTypes(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePolicyTypes(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePolicyType(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicyType(null, null);
+            }).hasMessageMatching(NAME_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePolicyType("aaa", null);
-        }).hasMessage("version is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicyType("aaa", null);
+            }).hasMessageMatching("^version is marked .*on.*ull but is null$");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePolicyType(null, "aaa");
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicyType(null, "aaa");
+            }).hasMessageMatching(NAME_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicies(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicies(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicies(null, "aaa");
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicyList(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicies("aaa", null);
-        }).hasMessage("version is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.createPolicies(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.createPolicies(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePolicies(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.updatePolicies(null);
-        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicy(null, null);
+            }).hasMessageMatching(NAME_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePolicy(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicy(null, "aaa");
+            }).hasMessageMatching(NAME_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePolicy(null, "aaa");
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicy("aaa", null);
+            }).hasMessageMatching("^version is marked .*on.*ull but is null$");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePolicy("aaa", null);
-        }).hasMessage("version is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getOperationalPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.createOperationalPolicy(null);
-        }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy("", null);
+            }).hasMessage("no policy found for policy: :null");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.updateOperationalPolicy(null);
-        }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.createOperationalPolicy(null);
+            }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deleteOperationalPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.updateOperationalPolicy(null);
+            }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.getGuardPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.createGuardPolicy(null);
-        }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.updateGuardPolicy(null);
-        }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy("", null);
+            }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deleteGuardPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.createPdpGroups(null);
-        }).hasMessage("pdpGroups is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            databaseProvider.updatePdpGroups(null);
-        }).hasMessage("pdpGroups is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy("", null);
+            }).hasMessage("no policy found for policy: :null");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.deletePdpGroup(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+            assertThatThrownBy(() -> {
+                databaseProvider.createGuardPolicy(null);
+            }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
 
-        databaseProvider.close();
+            assertThatThrownBy(() -> {
+                databaseProvider.updateGuardPolicy(null);
+            }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteGuardPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteGuardPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteGuardPolicy("", null);
+            }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPdpGroups(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.createPdpGroups(null);
+            }).hasMessageMatching("^pdpGroups is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdpGroups(null);
+            }).hasMessageMatching("^pdpGroups is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdpSubGroup(null, null);
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdpSubGroup(null, new PdpSubGroup());
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdpSubGroup(NAME, null);
+            }).hasMessageMatching(SUBGROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdpSubGroup(NAME, new PdpSubGroup());
+            }).hasMessage("parameter \"localName\" is null");
 
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(null, null, null);
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(null, null, new Pdp());
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(null, "sub", null);
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(null, "sub", new Pdp());
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(NAME, null, null);
+            }).hasMessageMatching(SUBGROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(NAME, null, new Pdp());
+            }).hasMessageMatching(SUBGROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(NAME, "sub", null);
+            }).hasMessageMatching("^pdp is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdp(NAME, "sub", new Pdp());
+            }).hasMessage("parameter \"localName\" is null");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePdpGroup(null);
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP, ORDER, 0);
+            }).hasMessageMatching(GROUP_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.createPdpStatistics(null);
+            }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePdpStatistics(null);
+            }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePdpStatistics(null, TIMESTAMP);
+            }).hasMessageMatching(NAME_IS_NULL);
+
+        }
     }
 
     @Test
@@ -235,8 +350,10 @@ public class DatabasePolicyModelsProviderTest {
         PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
 
+        databaseProvider.close();
+
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes("name", "version");
+            databaseProvider.getPolicyTypes(NAME, "version");
         }).hasMessage("policy models provider is not initilaized");
     }
 
@@ -244,11 +361,12 @@ public class DatabasePolicyModelsProviderTest {
     public void testProviderMethods() {
         try (PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
-            databaseProvider.init();
 
-            assertThatThrownBy(() -> {
-                databaseProvider.getPolicyTypes("name", "version");
-            }).hasMessage("policy type not found: name:version");
+            assertTrue(databaseProvider.getPolicyTypes(NAME, VERSION_100).getPolicyTypes().isEmpty());
+            assertTrue(databaseProvider.getPolicyTypeList(NAME, VERSION_100).isEmpty());
+            assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())
+                    .getPolicyTypes().size());
+            assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size());
 
             assertThatThrownBy(() -> {
                 databaseProvider.createPolicyTypes(new ToscaServiceTemplate());
@@ -258,13 +376,16 @@ public class DatabasePolicyModelsProviderTest {
                 databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
             }).hasMessage("no policy types specified on service template");
 
-            assertThatThrownBy(() -> {
-                databaseProvider.deletePolicyType("name", "version");
-            }).hasMessage("policy type not found: name:version");
+            assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
 
-            assertThatThrownBy(() -> {
-                databaseProvider.getPolicies("name", "version");
-            }).hasMessage("policy not found: name:version");
+            assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
+
+            assertTrue(
+                    databaseProvider.getPolicies(NAME, VERSION_100).getToscaTopologyTemplate().getPolicies().isEmpty());
+            assertTrue(databaseProvider.getPolicyList(NAME, VERSION_100).isEmpty());
+            assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())
+                    .getToscaTopologyTemplate().getPolicies().size());
+            assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size());
 
             assertThatThrownBy(() -> {
                 databaseProvider.createPolicies(new ToscaServiceTemplate());
@@ -274,29 +395,36 @@ public class DatabasePolicyModelsProviderTest {
                 databaseProvider.updatePolicies(new ToscaServiceTemplate());
             }).hasMessage("topology template not specified on service template");
 
+            assertTrue(databaseProvider.deletePolicy("Policy", "0.0.0").getToscaTopologyTemplate().getPolicies()
+                    .isEmpty());
+
             assertThatThrownBy(() -> {
-                databaseProvider.deletePolicy("name", "version");
-            }).hasMessage("policy not found: name:version");
+                databaseProvider.getOperationalPolicy(POLICY_ID, null);
+            }).hasMessage("no policy found for policy: policy_id:null");
 
             assertThatThrownBy(() -> {
-                databaseProvider.getOperationalPolicy("policy_id");
-            }).hasMessage("no policy found for policy ID: policy_id");
+                databaseProvider.getOperationalPolicy(POLICY_ID, "10");
+            }).hasMessage("no policy found for policy: policy_id:10");
 
             assertThatThrownBy(() -> {
                 databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
-            }).hasMessage("name is marked @NonNull but is null");
+            }).hasMessageMatching(NAME_IS_NULL);
 
             assertThatThrownBy(() -> {
                 databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
-            }).hasMessage("no policy found for policy ID: null");
+            }).hasMessageMatching(NAME_IS_NULL);
 
             assertThatThrownBy(() -> {
-                databaseProvider.deleteOperationalPolicy("policy_id");
-            }).hasMessage("no policy found for policy ID: policy_id");
+                databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
+            }).hasMessage("no policy found for policy: policy_id:55");
 
             assertThatThrownBy(() -> {
-                databaseProvider.getGuardPolicy("policy_id");
-            }).hasMessage("no policy found for policy ID: policy_id");
+                databaseProvider.getGuardPolicy(POLICY_ID, null);
+            }).hasMessage("no policy found for policy: policy_id:null");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy(POLICY_ID, "6");
+            }).hasMessage("no policy found for policy: policy_id:6");
 
             assertThatThrownBy(() -> {
                 databaseProvider.createGuardPolicy(new LegacyGuardPolicyInput());
@@ -307,14 +435,101 @@ public class DatabasePolicyModelsProviderTest {
             }).hasMessage("policy type for guard policy \"null\" unknown");
 
             assertThatThrownBy(() -> {
-                databaseProvider.deleteGuardPolicy("policy_id");
-            }).hasMessage("no policy found for policy ID: policy_id");
-
-            assertNotNull(databaseProvider.getPdpGroups("name", "version"));
-            assertNotNull(databaseProvider.createPdpGroups(new PdpGroups()));
-            assertNotNull(databaseProvider.updatePdpGroups(new PdpGroups()));
-            assertNotNull(databaseProvider.deletePdpGroup("name", "version"));
+                databaseProvider.deleteGuardPolicy(POLICY_ID, "33");
+            }).hasMessage("no policy found for policy: policy_id:33");
+
+            assertEquals(0, databaseProvider.getPdpGroups(NAME).size());
+            assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size());
+
+            assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>()));
+            assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>()));
+
+            PdpGroup pdpGroup = new PdpGroup();
+            pdpGroup.setName(GROUP);
+            pdpGroup.setVersion("1.2.3");
+            pdpGroup.setPdpGroupState(PdpState.ACTIVE);
+            pdpGroup.setPdpSubgroups(new ArrayList<>());
+            List<PdpGroup> groupList = new ArrayList<>();
+            groupList.add(pdpGroup);
+
+            PdpSubGroup pdpSubGroup = new PdpSubGroup();
+            pdpSubGroup.setPdpType("type");
+            pdpSubGroup.setDesiredInstanceCount(123);
+            pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
+            pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("type", "7.8.9"));
+            pdpGroup.getPdpSubgroups().add(pdpSubGroup);
+
+            Pdp pdp = new Pdp();
+            pdp.setInstanceId("type-0");
+            pdp.setMessage("Hello");
+            pdp.setPdpState(PdpState.ACTIVE);
+            pdp.setHealthy(PdpHealthStatus.UNKNOWN);
+            pdpSubGroup.setPdpInstances(new ArrayList<>());
+            pdpSubGroup.getPdpInstances().add(pdp);
+
+            PdpStatistics pdpStatistics = new PdpStatistics();
+            pdpStatistics.setPdpInstanceId(NAME);
+            pdpStatistics.setTimeStamp(new Date());
+            pdpStatistics.setPdpGroupName(GROUP);
+            pdpStatistics.setPdpSubGroupName("type");
+            ArrayList<PdpStatistics> statisticsArrayList = new ArrayList<>();
+            statisticsArrayList.add(pdpStatistics);
+
+            assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
+                    .getDesiredInstanceCount());
+            assertEquals(1, databaseProvider.getPdpGroups(GROUP).size());
+
+            pdpSubGroup.setDesiredInstanceCount(234);
+            databaseProvider.updatePdpSubGroup(GROUP, pdpSubGroup);
+            assertEquals(234,
+                    databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
+
+            assertEquals("Hello", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups().get(0).getPdpInstances()
+                    .get(0).getMessage());
+            pdp.setMessage("Howdy");
+            databaseProvider.updatePdp(GROUP, "type", pdp);
+            assertEquals("Howdy", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups().get(0).getPdpInstances()
+                    .get(0).getMessage());
 
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePdpGroup(NAME);
+            }).hasMessage("delete of PDP group \"name:0.0.0\" failed, PDP group does not exist");
+
+            assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName());
+
+            assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
+            assertEquals(1, databaseProvider.createPdpStatistics(statisticsArrayList).size());
+            assertEquals(1, databaseProvider.updatePdpStatistics(statisticsArrayList).size());
+
+            assertEquals(NAME, databaseProvider.getPdpStatistics(null, null).get(0).getPdpInstanceId());
+            assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, null, ORDER, 0).get(0)
+                    .getPdpInstanceId());
+            assertEquals(0,
+                    databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), null, ORDER, 0).size());
+            assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, new Date(), ORDER, 0)
+                    .get(0).getPdpInstanceId());
+            assertEquals(0, databaseProvider
+                    .getFilteredPdpStatistics(null, GROUP, null, new Date(), new Date(), ORDER, 0).size());
+
+            assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, null, ORDER, 0).get(0)
+                    .getPdpInstanceId());
+            assertEquals(0, databaseProvider
+                    .getFilteredPdpStatistics(NAME, GROUP, null, new Date(), new Date(), ORDER, 0).size());
+
+            assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 0)
+                    .get(0).getPdpInstanceId());
+            assertEquals(0, databaseProvider
+                    .getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date(), ORDER, 0).size());
+
+            assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 1)
+                    .get(0).getPdpInstanceId());
+            assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null, ORDER, 5)
+                    .get(0).getPdpInstanceId());
+            assertEquals(0, databaseProvider
+                    .getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date(), ORDER, 5).size());
+
+            assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId());
+            assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
         } catch (Exception exc) {
             LOGGER.warn("test should not throw an exception", exc);
             fail("test should not throw an exception");