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 e4ecb9d..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.assertNull;
+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.base.PfConceptKey;
-import org.onap.policy.models.pap.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.legacy.concepts.LegacyGuardPolicy;
+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;
-import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -46,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;
@@ -56,301 +92,444 @@ 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");
-        try {
-            databaseProvider.init();
-            fail("test should throw an exception");
-        } catch (Exception pfme) {
-            assertEquals("could not connect to database with URL \"jdbc://www.acmecorp.nonexist\"", pfme.getMessage());
-        }
-        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
 
-        try {
-            databaseProvider.init();
-            databaseProvider.close();
-        } catch (Exception pfme) {
-            fail("test shold not throw an exception here");
-        }
+        databaseProvider.close();
+        databaseProvider.init();
+
+        databaseProvider.close();
+
+        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
 
         parameters.setPersistenceUnit("WileECoyote");
-        try {
-            databaseProvider.init();
-            fail("test should throw an exception");
-        } catch (Exception pfme) {
-            assertEquals("could not create Data Access Object (DAO) using url "
-                    + "\"jdbc:h2:mem:testdb\" and persistence unit \"WileECoyote\"", pfme.getMessage());
-        }
+
+        assertThatThrownBy(databaseProvider::init).hasMessageContaining("could not create Data Access Object (DAO)");
+
         parameters.setPersistenceUnit("ToscaConceptTest");
 
-        try {
+        databaseProvider.init();
+        databaseProvider.close();
+
+        assertThatThrownBy(() -> {
             databaseProvider.init();
-            databaseProvider.close();
-        } catch (Exception pfme) {
-            fail("test shold not throw an exception here");
-        }
+            databaseProvider.init();
+        }).hasMessage("provider is already initialized");
 
-        try {
-            databaseProvider.close();
-        } catch (Exception pfme) {
-            fail("test shold not throw an exception here");
-        }
+        databaseProvider.close();
 
-        try {
-            DatabasePolicyModelsProviderImpl databaseProviderImpl = (DatabasePolicyModelsProviderImpl) databaseProvider;
-            databaseProvider.init();
-            databaseProviderImpl.setConnection(new DummyConnection());
-            databaseProvider.close();
-            fail("test should throw an exception");
-        } catch (Exception pfme) {
-            assertEquals("could not close connection to database with URL \"jdbc:h2:mem:testdb\"", pfme.getMessage());
-        }
+        databaseProvider.close();
     }
 
     @Test
     public void testProviderMethodsNull() throws Exception {
-        PolicyModelsProvider databaseProvider =
-                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-        databaseProvider.init();
 
-        try {
-            databaseProvider.getPolicyTypes(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyTypeKey is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.createPolicyTypes(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.updatePolicyTypes(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.deletePolicyTypes(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyTypeKey is marked @NonNull but is null", npe.getMessage());
-        }
+        try (PolicyModelsProvider databaseProvider =
+                new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
 
-        try {
-            databaseProvider.getPolicies(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyKey is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.createPolicies(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.updatePolicies(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("serviceTemplate is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.deletePolicies(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyKey is marked @NonNull but is null", npe.getMessage());
-        }
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicyTypes(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
 
-        try {
-            databaseProvider.getOperationalPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.createOperationalPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("legacyOperationalPolicy is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.updateOperationalPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("legacyOperationalPolicy is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.deleteOperationalPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
-        }
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicyTypeList(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
 
-        try {
-            databaseProvider.getGuardPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.createGuardPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("legacyGuardPolicy is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.updateGuardPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("legacyGuardPolicy is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.deleteGuardPolicy(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policyId is marked @NonNull but is null", npe.getMessage());
-        }
+            assertThatThrownBy(() -> {
+                databaseProvider.createPolicyTypes(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
 
-        try {
-            databaseProvider.getPdpGroups(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("pdpGroupFilter is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.createPdpGroups(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("pdpGroups is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.updatePdpGroups(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("pdpGroups is marked @NonNull but is null", npe.getMessage());
-        }
-        try {
-            databaseProvider.deletePdpGroups(null);
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("pdpGroupFilter is marked @NonNull but is null", npe.getMessage());
-        }
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePolicyTypes(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
 
-        databaseProvider.close();
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicyType(null, null);
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicyType("aaa", null);
+            }).hasMessageMatching("^version is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicyType(null, "aaa");
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicies(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getFilteredPolicyList(null);
+            }).hasMessageMatching(FILTER_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.createPolicies(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updatePolicies(null);
+            }).hasMessageMatching(TEMPLATE_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicy(null, null);
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicy(null, "aaa");
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deletePolicy("aaa", null);
+            }).hasMessageMatching("^version is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy("", null);
+            }).hasMessage("no policy found for policy: :null");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.createOperationalPolicy(null);
+            }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updateOperationalPolicy(null);
+            }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy("", null);
+            }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy(null, null);
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy(null, "");
+            }).hasMessageMatching(POLICY_ID_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getGuardPolicy("", null);
+            }).hasMessage("no policy found for policy: :null");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.createGuardPolicy(null);
+            }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
+
+            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
     public void testProviderMethodsNotInit() throws Exception {
         PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
-        try {
-            databaseProvider.getPolicyTypes(new PfConceptKey());
-            fail("test should throw an exception");
-        } catch (Exception npe) {
-            assertEquals("policy models provider is not initilaized", npe.getMessage());
-        }
+
+        databaseProvider.close();
+
+        assertThatThrownBy(() -> {
+            databaseProvider.getPolicyTypes(NAME, "version");
+        }).hasMessage("policy models provider is not initilaized");
     }
 
     @Test
     public void testProviderMethods() {
         try (PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
-            databaseProvider.init();
 
-            try {
-                databaseProvider.getPolicyTypes(new PfConceptKey());
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("policy type not found: NULL:0.0.0", npe.getMessage());
-            }
-            try {
+            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());
-            } catch (Exception npe) {
-                assertEquals("no policy types specified on service template", npe.getMessage());
-            }
-            try {
+            }).hasMessage("no policy types specified on service template");
+
+            assertThatThrownBy(() -> {
                 databaseProvider.updatePolicyTypes(new ToscaServiceTemplate());
-            } catch (Exception npe) {
-                assertEquals("no policy types specified on service template", npe.getMessage());
-            }
-            try {
-                databaseProvider.deletePolicyTypes(new PfConceptKey());
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("policy type not found: NULL:0.0.0", npe.getMessage());
-            }
-
-            try {
-                databaseProvider.getPolicies(new PfConceptKey());
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("policy not found: NULL:0.0.0", npe.getMessage());
-            }
-            try {
+            }).hasMessage("no policy types specified on service template");
+
+            assertTrue(databaseProvider.deletePolicyType(NAME, VERSION_100).getPolicyTypes().isEmpty());
+
+            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());
-            } catch (Exception npe) {
-                assertEquals("topology template not specified on service template", npe.getMessage());
-            }
-            try {
+            }).hasMessage("topology template not specified on service template");
+
+            assertThatThrownBy(() -> {
                 databaseProvider.updatePolicies(new ToscaServiceTemplate());
-            } catch (Exception npe) {
-                assertEquals("topology template not specified on service template", npe.getMessage());
-            }
-            try {
-                databaseProvider.deletePolicies(new PfConceptKey());
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("policy not found: NULL:0.0.0", npe.getMessage());
-            }
-
-            try {
-                assertNull(databaseProvider.getOperationalPolicy("policy_id"));
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("no policy found for policy ID: policy_id", npe.getMessage());
-            }
-            try {
-                assertNull(databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy()));
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("name is marked @NonNull but is null", npe.getMessage());
-            }
-            try {
-                assertNull(databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy()));
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("no policy found for policy ID: null", npe.getMessage());
-            }
-            try {
-                assertNull(databaseProvider.deleteOperationalPolicy("policy_id"));
-                fail("test should throw an exception");
-            } catch (Exception npe) {
-                assertEquals("no policy found for policy ID: policy_id", npe.getMessage());
-            }
-
-            assertNull(databaseProvider.getGuardPolicy("policy_id"));
-            assertNull(databaseProvider.createGuardPolicy(new LegacyGuardPolicy()));
-            assertNull(databaseProvider.updateGuardPolicy(new LegacyGuardPolicy()));
-            assertNull(databaseProvider.deleteGuardPolicy("policy_id"));
-
-            assertNotNull(databaseProvider.getPdpGroups("filter"));
-            assertNotNull(databaseProvider.createPdpGroups(new PdpGroups()));
-            assertNotNull(databaseProvider.updatePdpGroups(new PdpGroups()));
-            assertNotNull(databaseProvider.deletePdpGroups("filter"));
+            }).hasMessage("topology template not specified on service template");
+
+            assertTrue(databaseProvider.deletePolicy("Policy", "0.0.0").getToscaTopologyTemplate().getPolicies()
+                    .isEmpty());
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy(POLICY_ID, null);
+            }).hasMessage("no policy found for policy: policy_id:null");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.getOperationalPolicy(POLICY_ID, "10");
+            }).hasMessage("no policy found for policy: policy_id:10");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
+            }).hasMessageMatching(NAME_IS_NULL);
+
+            assertThatThrownBy(() -> {
+                databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
+            }).hasMessage("no policy found for policy: policy_id:55");
+
+            assertThatThrownBy(() -> {
+                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());
+            }).hasMessage("policy type for guard policy \"null\" unknown");
+
+            assertThatThrownBy(() -> {
+                databaseProvider.updateGuardPolicy(new LegacyGuardPolicyInput());
+            }).hasMessage("policy type for guard policy \"null\" unknown");
+
+            assertThatThrownBy(() -> {
+                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");