Merge "Add copy constructor to ToscaNodeTemplate"
[policy/models.git] / models-provider / src / test / java / org / onap / policy / models / provider / impl / DatabasePolicyModelsProviderTest.java
index f085605..fb5af1e 100644 (file)
@@ -1,7 +1,8 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Copyright (C) 2019-2021 Nordix Foundation.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2020 Bell Canada. 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.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
 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 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.PfModelException;
@@ -44,13 +45,11 @@ 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.ToscaConceptIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 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;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
-import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 
 /**
  * Test the database models provider implementation.
@@ -62,8 +61,6 @@ public class DatabasePolicyModelsProviderTest {
 
     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$";
@@ -72,8 +69,6 @@ public class DatabasePolicyModelsProviderTest {
 
     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";
@@ -93,7 +88,7 @@ public class DatabasePolicyModelsProviderTest {
         parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
-        parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
+        parameters.setDatabasePassword("P01icY");
         parameters.setPersistenceUnit("ToscaConceptTest");
     }
 
@@ -196,70 +191,6 @@ public class DatabasePolicyModelsProviderTest {
             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);
@@ -402,46 +333,6 @@ public class DatabasePolicyModelsProviderTest {
         assertThatThrownBy(() -> databaseProvider.deletePolicy("Policy", "0.0.0").getToscaTopologyTemplate())
                 .hasMessage("service template not found in database");
 
-        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());
 
@@ -460,7 +351,7 @@ public class DatabasePolicyModelsProviderTest {
         pdpSubGroup.setPdpType("type");
         pdpSubGroup.setDesiredInstanceCount(123);
         pdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
-        pdpSubGroup.getSupportedPolicyTypes().add(new ToscaPolicyTypeIdentifier("type", "7.8.9"));
+        pdpSubGroup.getSupportedPolicyTypes().add(new ToscaConceptIdentifier("type", "7.8.9"));
         pdpGroup.getPdpSubgroups().add(pdpSubGroup);
 
         Pdp pdp = new Pdp();
@@ -535,18 +426,24 @@ public class DatabasePolicyModelsProviderTest {
         assertEquals(NAME, databaseProvider.deletePdpStatistics(NAME, null).get(0).getPdpInstanceId());
         assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
 
+        assertThat(databaseProvider.getAllPolicyStatus()).isEmpty();
+        assertThat(databaseProvider.getAllPolicyStatus(new ToscaConceptIdentifierOptVersion("MyPolicy", null)))
+                        .isEmpty();
+        assertThat(databaseProvider.getGroupPolicyStatus(GROUP)).isEmpty();
+        assertThatCode(() -> databaseProvider.cudPolicyStatus(null, null, null)).doesNotThrowAnyException();
+
         databaseProvider.close();
     }
 
     @Test
     public void testDeletePolicyDeployedInSubgroup() throws PfModelException {
-        List<ToscaPolicyIdentifier> policies = new ArrayList<>();
+        List<ToscaConceptIdentifier> policies = new ArrayList<>();
 
-        policies.add(new ToscaPolicyIdentifier("p0", "0.0.1"));
-        policies.add(new ToscaPolicyIdentifier("p1", "0.0.1"));
+        policies.add(new ToscaConceptIdentifier("p0", "0.0.1"));
+        policies.add(new ToscaConceptIdentifier("p1", "0.0.1"));
 
-        List<ToscaPolicyTypeIdentifier> supportedPolicyTypes = new ArrayList<>();
-        supportedPolicyTypes.add(new ToscaPolicyTypeIdentifier("pt2", "0.0.1"));
+        List<ToscaConceptIdentifier> supportedPolicyTypes = new ArrayList<>();
+        supportedPolicyTypes.add(new ToscaConceptIdentifier("pt2", "0.0.1"));
 
         PdpSubGroup subGroup = new PdpSubGroup();
         subGroup.setPdpType("pdpType");
@@ -580,9 +477,9 @@ public class DatabasePolicyModelsProviderTest {
 
     @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"));
+        List<ToscaConceptIdentifier> supportedPolicyTypes = new ArrayList<>();
+        supportedPolicyTypes.add(new ToscaConceptIdentifier("pt1", "0.0.1"));
+        supportedPolicyTypes.add(new ToscaConceptIdentifier("pt2", "0.0.1"));
 
         PdpSubGroup subGroup = new PdpSubGroup();
         subGroup.setPdpType("pdpType");