Finish unit test on policy-models 79/84779/2
authorliamfallon <liam.fallon@est.tech>
Wed, 10 Apr 2019 11:34:06 +0000 (11:34 +0000)
committerliamfallon <liam.fallon@est.tech>
Wed, 10 Apr 2019 11:34:06 +0000 (11:34 +0000)
Unit test coverage well over 90% in
policy-models-base
policy-models-dao
policy-models-pdp
policy-models-tosca
policy-models-provider

Issue-ID: POLICY-1095
Change-Id: I7703e2ae8a93575ca478c3d809ff8c1fb9f0f334
Signed-off-by: liamfallon <liam.fallon@est.tech>
46 files changed:
models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java
models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
models-pdp/pom.xml
models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java
models-provider/pom.xml
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
models-tosca/pom.xml
models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java
models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/TestPojos.java
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java [moved from models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java with 57% similarity]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java [new file with mode: 0644]
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java [new file with mode: 0644]
pom.xml

index 10ce4ea..35319b4 100644 (file)
@@ -25,8 +25,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import lombok.NonNull;
-
 /**
  * Interface for filtering a list of concepts.
  *
index 1820176..c44d05f 100644 (file)
@@ -173,7 +173,7 @@ public class DefaultPfDao implements PfDao {
             mg.getTransaction().begin();
             mg.createQuery(setQueryTable(DELETE_BY_CONCEPT_KEY, someClass), someClass)
                 .setParameter(NAME,    key.getName())
-                .setParameter("version", key.getVersion())
+                .setParameter(VERSION, key.getVersion())
                 .executeUpdate();
             mg.getTransaction().commit();
             // @formatter:on
@@ -250,7 +250,7 @@ public class DefaultPfDao implements PfDao {
             for (final PfConceptKey key : keys) {
                 deletedCount += mg.createQuery(setQueryTable(DELETE_BY_CONCEPT_KEY, someClass), someClass)
                     .setParameter(NAME,    key.getName())
-                    .setParameter("version", key.getVersion())
+                    .setParameter(VERSION, key.getVersion())
                     .executeUpdate();
             }
             mg.getTransaction().commit();
index 029c76b..8eb7231 100644 (file)
             <artifactId>policy-models-tosca</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.mariadb.jdbc</groupId>
-            <artifactId>mariadb-java-client</artifactId>
-        </dependency>
         <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
index d0fc216..1e77c09 100644 (file)
@@ -238,16 +238,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
         }
 
         if (properties != null) {
-            for (Entry<String, String> propertyEntry : properties.entrySet()) {
-                if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
-                    result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                            "a property key may not be null or blank"));
-                }
-                if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) {
-                    result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
-                            "a property value may not be null or blank"));
-                }
-            }
+            result = validateProperties(result);
         }
 
         if (pdpSubGroups == null) {
@@ -262,6 +253,29 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
         return result;
     }
 
+    /**
+     * Validate the properties.
+     *
+     * @param resultIn the incoming validation results so far
+     * @return the revalidation results including the property validation results
+     */
+    private PfValidationResult validateProperties(PfValidationResult resultIn) {
+        PfValidationResult result = resultIn;
+
+        for (Entry<String, String> propertyEntry : properties.entrySet()) {
+            if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
+                result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+                        "a property key may not be null or blank"));
+            }
+            if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) {
+                result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+                        "a property value may not be null or blank"));
+            }
+        }
+
+        return result;
+    }
+
     @Override
     public int compareTo(final PfConcept otherConcept) {
         if (otherConcept == null) {
index d22642d..541e00b 100644 (file)
@@ -36,11 +36,12 @@ import org.onap.policy.common.utils.validation.ToStringTester;
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
 public class ModelsTest {
+    private static final String POJO_PACKAGE = "org.onap.policy.models.pdp.concepts";
 
     @Test
     public void testPdpModels() {
         final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
                 .with(new GetterTester()).build();
-        validator.validate(ModelsTest.class.getPackage().getName(), new FilterPackageInfo());
+        validator.validate(POJO_PACKAGE, new FilterPackageInfo());
     }
 }
index fb0e302..41a5a2c 100644 (file)
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.mariadb.jdbc</groupId>
-            <artifactId>mariadb-java-client</artifactId>
-            <scope>test</scope>
-        </dependency>
-
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-all</artifactId>
index cf40a57..b186e2b 100644 (file)
@@ -361,9 +361,10 @@ public interface PolicyModelsProvider extends AutoCloseable {
      * @param pdpGroupVersion the version of the PDP group containing the PDP that the statistics are for
      * @param pdpType the PDP type of the subgroup containing the PDP that the statistics are for
      * @param pdpInstanceId the instance ID of the PDP to update statistics for
+     * @param pdpStatistics the PDP statistics
      * @throws PfModelException on errors updating statistics
      */
     public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
             @NonNull final String pdpType, @NonNull final String pdpInstanceId,
-            @NonNull final PdpStatistics pdppStatistics) throws PfModelException;
+            @NonNull final PdpStatistics pdpStatistics) throws PfModelException;
 }
index 2fe52e9..cc70df9 100644 (file)
@@ -348,10 +348,10 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     @Override
     public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
             @NonNull final String pdpType, @NonNull final String pdpInstanceId,
-            @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
+            @NonNull final PdpStatistics pdpStatistics) throws PfModelException {
         assertInitilized();
         new PdpProvider().updatePdpStatistics(pfDao, pdpGroupName, pdpGroupVersion, pdpType, pdpInstanceId,
-                pdppStatistics);
+                pdpStatistics);
     }
 
     /**
index 0bf5297..90545f3 100644 (file)
@@ -27,7 +27,6 @@ import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.core.Response;
-import lombok.NonNull;
 
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
@@ -61,7 +60,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
      *
      * @param parameters the parameters for the provider
      */
-    public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {}
+    public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {}
 
     @Override
     public void init() throws PfModelException {
@@ -84,29 +83,29 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
+        return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
     }
 
     @Override
-    public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) {
+    public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
         return new ArrayList<>();
     }
 
     @Override
-    public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
+    public ToscaServiceTemplate deletePolicyType(final String name, final String version)
             throws PfModelException {
         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
     }
@@ -122,75 +121,75 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException {
-        return null;
+    public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
+        return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
     }
 
     @Override
-    public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
+    public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
         return new ArrayList<>();
     }
 
     @Override
-    public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+    public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate)
             throws PfModelException {
         return serviceTemplate;
     }
 
     @Override
-    public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
+    public ToscaServiceTemplate deletePolicy(final String name, final String version)
             throws PfModelException {
         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
     }
 
     @Override
 
-    public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
+    public LegacyOperationalPolicy getOperationalPolicy(final String policyId) throws PfModelException {
         return new LegacyOperationalPolicy();
     }
 
     @Override
     public LegacyOperationalPolicy createOperationalPolicy(
-            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
+            final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
         return legacyOperationalPolicy;
     }
 
     @Override
     public LegacyOperationalPolicy updateOperationalPolicy(
-            @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
+            final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
         return legacyOperationalPolicy;
     }
 
     @Override
-    public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
+    public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId) throws PfModelException {
         return new LegacyOperationalPolicy();
     }
 
     @Override
-    public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
+    public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId) throws PfModelException {
         return new HashMap<>();
     }
 
     @Override
     public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
-            @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
+            final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
         return new HashMap<>();
     }
 
     @Override
     public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
-            @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
+            final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
         return new HashMap<>();
     }
 
     @Override
-    public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
+    public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId)
             throws PfModelException {
         return new HashMap<>();
     }
@@ -201,34 +200,34 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
+    public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
         return new ArrayList<>();
     }
 
     @Override
-    public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
+    public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
         return new ArrayList<>();
     }
 
     @Override
-    public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
+    public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
         return new ArrayList<>();
     }
 
     @Override
-    public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
-            @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
+    public void updatePdpSubGroup(final String pdpGroupName, final String pdpGroupVersion,
+            final PdpSubGroup pdpSubGroup) throws PfModelException {
         // Not implemented
     }
 
     @Override
-    public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
-            @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException {
+    public void updatePdp(String pdpGroupName, String pdpGroupVersion,
+            String pdpSubGroup, Pdp pdp) throws PfModelException {
         // Not implemented
     }
 
     @Override
-    public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
+    public PdpGroup deletePdpGroup(final String name, final String version) throws PfModelException {
         return null;
     }
 
@@ -238,9 +237,9 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
-            @NonNull final String pdpType, @NonNull final String pdpInstanceId,
-            @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
+    public void updatePdpStatistics(final String pdpGroupName, final String pdpGroupVersion,
+            final String pdpType, final String pdpInstanceId,
+            final PdpStatistics pdppStatistics) throws PfModelException {
         // Not implemented
     }
 
@@ -250,7 +249,7 @@ public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
      * @param fileName the file name containing the dummy response
      * @return the ToscaServiceTemplate with the dummy response
      */
-    protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
+    protected ToscaServiceTemplate getDummyResponse(final String fileName) {
         StandardCoder standardCoder = new StandardCoder();
         ToscaServiceTemplate serviceTemplate;
 
index 38a5ae1..99358c4 100644 (file)
@@ -27,13 +27,23 @@ import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.Base64;
+import java.util.List;
 
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
+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;
@@ -65,6 +75,10 @@ public class DatabasePolicyModelsProviderTest {
 
     @Test
     public void testInitAndClose() throws Exception {
+        assertThatThrownBy(() -> {
+            new DatabasePolicyModelsProviderImpl(null);
+        }).hasMessage("parameters is marked @NonNull but is null");
+
         PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
 
@@ -101,6 +115,17 @@ public class DatabasePolicyModelsProviderTest {
             fail("test shold not throw an exception here");
         }
 
+        assertThatThrownBy(() -> {
+            databaseProvider.init();
+            databaseProvider.init();
+        }).hasMessage("provider is already initialized");
+
+        try {
+            databaseProvider.close();
+        } catch (Exception pfme) {
+            fail("test shold not throw an exception here");
+        }
+
         try {
             databaseProvider.close();
         } catch (Exception pfme) {
@@ -115,23 +140,18 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("could not close connection to database with URL \"jdbc:h2:mem:testdb\"");
     }
 
-    @Ignore
     @Test
     public void testProviderMethodsNull() throws Exception {
         PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+            databaseProvider.getFilteredPolicyTypes(null);
+        }).hasMessage("filter is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes("aaa", null);
-        }).hasMessage("version is marked @NonNull but is null");
-
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicyTypes(null, "aaa");
-        }).hasMessage("name is marked @NonNull but is null");
+            databaseProvider.getFilteredPolicyTypeList(null);
+        }).hasMessage("filter is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             databaseProvider.createPolicyTypes(null);
@@ -154,16 +174,12 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("name is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicies(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+            databaseProvider.getFilteredPolicies(null);
+        }).hasMessage("filter is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            databaseProvider.getPolicies(null, "aaa");
-        }).hasMessage("name is marked @NonNull but is null");
-
-        assertThatThrownBy(() -> {
-            databaseProvider.getPolicies("aaa", null);
-        }).hasMessage("version is marked @NonNull but is null");
+            databaseProvider.getFilteredPolicyList(null);
+        }).hasMessage("filter is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             databaseProvider.createPolicies(null);
@@ -217,6 +233,10 @@ public class DatabasePolicyModelsProviderTest {
             databaseProvider.deleteGuardPolicy(null);
         }).hasMessage("policyId is marked @NonNull but is null");
 
+        assertThatThrownBy(() -> {
+            databaseProvider.getFilteredPdpGroups(null);
+        }).hasMessage("filter is marked @NonNull but is null");
+
         assertThatThrownBy(() -> {
             databaseProvider.createPdpGroups(null);
         }).hasMessage("pdpGroups is marked @NonNull but is null");
@@ -225,12 +245,231 @@ public class DatabasePolicyModelsProviderTest {
             databaseProvider.updatePdpGroups(null);
         }).hasMessage("pdpGroups is marked @NonNull but is null");
 
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup(null, null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup(null, null, new PdpSubGroup());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup(null, "version", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup(null, "version", new PdpSubGroup());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup("name", null, null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup("name", null, new PdpSubGroup());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpSubGroup("name", "version", null);
+        }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, null, null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, null, null, new Pdp());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, null, "sub", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, null, "sub", new Pdp());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, "version", null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, "version", null, new Pdp());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, "version", "sub", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp(null, "version", "sub", new Pdp());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", null, null, null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", null, null, new Pdp());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", null, "sub", null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", null, "sub", new Pdp());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", "version", null, null);
+        }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", "version", null, new Pdp());
+        }).hasMessage("pdpSubGroup is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdp("name", "version", "sub", null);
+        }).hasMessage("pdp is marked @NonNull but is null");
+
         assertThatThrownBy(() -> {
             databaseProvider.deletePdpGroup(null, null);
         }).hasMessage("name is marked @NonNull but is null");
 
-        databaseProvider.close();
+        assertThatThrownBy(() -> {
+            databaseProvider.deletePdpGroup(null, "version");
+        }).hasMessage("name is marked @NonNull but is null");
 
+        assertThatThrownBy(() -> {
+            databaseProvider.deletePdpGroup("name", null);
+        }).hasMessage("version is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, null, null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, null, null, new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, null, "Instance", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, null, "Instance", new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, "type", null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, "type", null, new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, "type", "Instance", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, null, "type", "Instance", new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", null, null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", null, null, new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", null, "Instance", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", null, "Instance", new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", "type", null, null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", "type", null, new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", "type", "Instance", null);
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics(null, "ver", "type", "Instance", new PdpStatistics());
+        }).hasMessage("pdpGroupName is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, null, null, null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, null, null, new PdpStatistics());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, null, "Instance", null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, null, "Instance", new PdpStatistics());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, "type", null, null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, "type", null, new PdpStatistics());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, "type", "Instance", null);
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", null, "type", "Instance", new PdpStatistics());
+        }).hasMessage("pdpGroupVersion is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", null, null, null);
+        }).hasMessage("pdpType is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", null, null, new PdpStatistics());
+        }).hasMessage("pdpType is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", null, "Instance", null);
+        }).hasMessage("pdpType is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", null, "Instance", new PdpStatistics());
+        }).hasMessage("pdpType is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", "type", null, null);
+        }).hasMessage("pdpInstanceId is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", "type", null, new PdpStatistics());
+        }).hasMessage("pdpInstanceId is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            databaseProvider.updatePdpStatistics("name", "ver", "type", "Instance", null);
+        }).hasMessage("pdpStatistics is marked @NonNull but is null");
+
+        databaseProvider.close();
     }
 
     @Test
@@ -245,15 +484,16 @@ public class DatabasePolicyModelsProviderTest {
         }).hasMessage("policy models provider is not initilaized");
     }
 
-    @Ignore
     @Test
     public void testProviderMethods() {
         try (PolicyModelsProvider databaseProvider =
                 new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
 
-            assertThatThrownBy(() -> {
-                databaseProvider.getPolicyTypes("name", "version");
-            }).hasMessage("policy type not found: name:version");
+            assertEquals(0, databaseProvider.getPolicyTypes("name", "version").getPolicyTypes().get(0).size());
+            assertEquals(0, databaseProvider.getPolicyTypeList("name", "version").size());
+            assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build())
+                    .getPolicyTypes().get(0).size());
+            assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size());
 
             assertThatThrownBy(() -> {
                 databaseProvider.createPolicyTypes(new ToscaServiceTemplate());
@@ -263,13 +503,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");
+            assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size());
 
-            assertThatThrownBy(() -> {
-                databaseProvider.getPolicies("name", "version");
-            }).hasMessage("policy not found: name:version");
+            assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size());
+
+            assertEquals(0, databaseProvider.getPolicies("name", "version").getToscaTopologyTemplate().getPolicies()
+                    .get(0).size());
+            assertEquals(0, databaseProvider.getPolicyList("name", "version").size());
+            assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build())
+                    .getToscaTopologyTemplate().getPolicies().get(0).size());
+            assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size());
 
             assertThatThrownBy(() -> {
                 databaseProvider.createPolicies(new ToscaServiceTemplate());
@@ -279,9 +522,8 @@ public class DatabasePolicyModelsProviderTest {
                 databaseProvider.updatePolicies(new ToscaServiceTemplate());
             }).hasMessage("topology template not specified on service template");
 
-            assertThatThrownBy(() -> {
-                databaseProvider.deletePolicy("name", "version");
-            }).hasMessage("policy not found: name:version");
+            assertEquals(0, databaseProvider.deletePolicy("Policy", "0.0.0").getToscaTopologyTemplate().getPolicies()
+                    .get(0).size());
 
             assertThatThrownBy(() -> {
                 databaseProvider.getOperationalPolicy("policy_id");
@@ -316,14 +558,59 @@ public class DatabasePolicyModelsProviderTest {
             }).hasMessage("no policy found for policy ID: policy_id");
 
             assertEquals(0, databaseProvider.getPdpGroups("name", "version").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);
+
+            assertEquals(123, databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0)
+                    .getDesiredInstanceCount());
+            assertEquals(1, databaseProvider.getPdpGroups("group", "1.2.3").size());
+
+            pdpSubGroup.setDesiredInstanceCount(234);
+            databaseProvider.updatePdpSubGroup("group", "1.2.3", pdpSubGroup);
+            assertEquals(234, databaseProvider.getPdpGroups("group", "1.2.3").get(0).getPdpSubgroups()
+                    .get(0).getDesiredInstanceCount());
+
+            assertEquals("Hello", databaseProvider.getPdpGroups("group", "1.2.3").get(0).getPdpSubgroups()
+                    .get(0).getPdpInstances().get(0).getMessage());
+            pdp.setMessage("Howdy");
+            databaseProvider.updatePdp("group", "1.2.3", "type", pdp);
+            assertEquals("Howdy", databaseProvider.getPdpGroups("group", "1.2.3").get(0).getPdpSubgroups()
+                    .get(0).getPdpInstances().get(0).getMessage());
+
             assertThatThrownBy(() -> {
                 databaseProvider.deletePdpGroup("name", "version");
             }).hasMessage("delete of PDP group \"name:version\" failed, PDP group does not exist");
 
+            assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup("group", "1.2.3").getName());
+
+            assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
+
+            databaseProvider.updatePdpStatistics("group", "1.2.3", "type", "type-0", new PdpStatistics());
         } catch (Exception exc) {
             LOGGER.warn("test should not throw an exception", exc);
             fail("test should not throw an exception");
index 01da449..5a0cddb 100644 (file)
@@ -20,7 +20,6 @@
 
 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;
@@ -30,9 +29,15 @@ import static org.junit.Assert.fail;
 import java.util.ArrayList;
 
 import org.junit.Test;
+import org.onap.policy.models.pdp.concepts.Pdp;
+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.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.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
@@ -74,11 +79,17 @@ public class DummyPolicyModelsProviderTest {
         dummyProvider.init();
 
         assertNotNull(dummyProvider.getPolicyTypes("name", "version"));
+        assertNotNull(dummyProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()));
+        assertNotNull(dummyProvider.getPolicyTypeList("name", "version"));
+        assertNotNull(dummyProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()));
         assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate()));
         assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate()));
         assertNotNull(dummyProvider.deletePolicyType("name", "version"));
 
         assertNotNull(dummyProvider.getPolicies("name", "version"));
+        assertNotNull(dummyProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()));
+        assertNotNull(dummyProvider.getPolicyList("name", "version"));
+        assertNotNull(dummyProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()));
         assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate()));
         assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate()));
         assertNotNull(dummyProvider.deletePolicy("name", "version"));
@@ -94,46 +105,15 @@ public class DummyPolicyModelsProviderTest {
         assertNotNull(dummyProvider.deleteGuardPolicy("policy_id"));
 
         assertTrue(dummyProvider.getPdpGroups("name", "version").isEmpty());
+        assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty());
         assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
         assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
         assertNull(dummyProvider.deletePdpGroup("name", "version"));
 
-
-        assertThatThrownBy(() -> {
-            dummyProvider.getOperationalPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.createOperationalPolicy(null);
-        }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.updateOperationalPolicy(null);
-        }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.deleteOperationalPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
-
-        assertThatThrownBy(() -> {
-            dummyProvider.getGuardPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.createGuardPolicy(null);
-        }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.updateGuardPolicy(null);
-        }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.deleteGuardPolicy(null);
-        }).hasMessage("policyId is marked @NonNull but is null");
-
-        assertThatThrownBy(() -> {
-            dummyProvider.createPdpGroups(null);
-        }).hasMessage("pdpGroups is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.updatePdpGroups(null);
-        }).hasMessage("pdpGroups is marked @NonNull but is null");
-        assertThatThrownBy(() -> {
-            dummyProvider.deletePdpGroup(null, null);
-        }).hasMessage("name is marked @NonNull but is null");
+        dummyProvider.updatePdpSubGroup("name", "version", new PdpSubGroup());
+        dummyProvider.updatePdp("name", "version", "type", new Pdp());
+        dummyProvider.updatePdpStatistics("name", "version", "type", "type-0", new PdpStatistics());
+        assertTrue(dummyProvider.getPdpStatistics("name", "version").isEmpty());
 
         dummyProvider.close();
     }
@@ -159,7 +139,7 @@ public class DummyPolicyModelsProviderTest {
             resp.getBadDummyResponse2();
             fail("test should throw an exception");
         } catch (Exception npe) {
-            assertEquals("fileName is marked @NonNull but is null", npe.getMessage());
+            assertEquals("error serializing object", npe.getMessage());
         } finally {
             if (resp != null) {
                 resp.close();
index 47f099a..5ebb448 100644 (file)
@@ -134,6 +134,16 @@ public class PolicyLegacyGuardPersistenceTest {
         assertEquals(gip.getContent(),
                 gotGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
 
+        Map<String, LegacyGuardPolicyOutput> updatedGopm = databaseProvider.updateGuardPolicy(gip);
+        assertEquals(gip.getPolicyId(), updatedGopm.keySet().iterator().next());
+        assertEquals(gip.getContent(),
+                updatedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
+
+        Map<String, LegacyGuardPolicyOutput> deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId());
+        assertEquals(gip.getPolicyId(), deletedGopm.keySet().iterator().next());
+        assertEquals(gip.getContent(),
+                deletedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next());
+
         String actualRetrievedJson = standardCoder.encode(gotGopm);
 
         // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters
index 65e6a2f..af6c4a4 100644 (file)
@@ -130,6 +130,12 @@ public class PolicyLegacyOperationalPersistenceTest {
         LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId());
         assertEquals(gotLop, lop);
 
+        LegacyOperationalPolicy updatedLop = databaseProvider.updateOperationalPolicy(lop);
+        assertEquals(gotLop, updatedLop);
+
+        LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId());
+        assertEquals(gotLop, deletedLop);
+
         String actualRetrievedJson = standardCoder.encode(gotLop);
 
         // All of this dash/underscore stuff is to avoid a checkstyle error around escaping unicode characters
index e8c3441..81795db 100644 (file)
@@ -143,6 +143,7 @@ public class PolicyPersistenceTest {
         assertNotNull(serviceTemplate);
 
         databaseProvider.createPolicies(serviceTemplate);
+        databaseProvider.updatePolicies(serviceTemplate);
 
         for (Map<String, ToscaPolicy> policyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) {
             for (ToscaPolicy policy : policyMap.values()) {
index 96360ec..528395e 100644 (file)
@@ -106,7 +106,7 @@ public class PolicyTypePersistenceTest {
     }
 
     @Test
-    public void testPolicyPersistence() {
+    public void testPolicyTypePersistence() {
         try {
             for (String policyTypeResourceName : policyTypeResourceNames) {
                 String policyTypeString = ResourceUtils.getResourceAsString(policyTypeResourceName);
@@ -118,7 +118,7 @@ public class PolicyTypePersistenceTest {
                 }
             }
         } catch (Exception exc) {
-            LOGGER.warn("error processing policies", exc);
+            LOGGER.warn("error processing policy types", exc);
             fail("test should not throw an exception");
         }
     }
@@ -143,6 +143,7 @@ public class PolicyTypePersistenceTest {
         ToscaPolicyType inPolicyType = serviceTemplate.getPolicyTypes().get(0).values().iterator().next();
 
         databaseProvider.createPolicyTypes(serviceTemplate);
+        databaseProvider.updatePolicyTypes(serviceTemplate);
 
         List<ToscaPolicyType> policyTypeList =
                 databaseProvider.getPolicyTypeList(inPolicyType.getName(), inPolicyType.getVersion());
index 5b857c1..36ee69b 100644 (file)
             <scope>test</scope>
         </dependency>
 
-        <dependency>
-            <groupId>org.mariadb.jdbc</groupId>
-            <artifactId>mariadb-java-client</artifactId>
-            <scope>test</scope>
-        </dependency>
-        
         <dependency>
             <groupId>io.swagger</groupId>
             <artifactId>swagger-jersey2-jaxrs</artifactId>
index 4bf0146..46f920c 100644 (file)
@@ -276,10 +276,6 @@ public class AuthorativeToscaProvider {
      * @return the plain list
      */
     private <T> List<T> asConceptList(final List<Map<String, T>> listOfMaps) {
-        if (listOfMaps == null) {
-            return Collections.emptyList();
-        }
-
         List<T> returnList = new ArrayList<>();
         for (Map<String, T> conceptMap : listOfMaps) {
             for (T concept : conceptMap.values()) {
index cc37338..85b5e6d 100644 (file)
@@ -139,12 +139,6 @@ public class LegacyGuardPolicyMapper
             propertiesMap.put("content", content);
             legacyGuardPolicyOutput.setProperties(propertiesMap);
 
-            if (toscaPolicy.getProperties() == null) {
-                String errorMessage = "property \"Content\" not defined on TOSCA policy";
-                LOGGER.warn(errorMessage);
-                throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-            }
-
             legacyGuardPolicyOutputMap.put(toscaPolicy.getKey().getName(), legacyGuardPolicyOutput);
         }
 
index b6c5d3b..7caba98 100644 (file)
@@ -106,8 +106,8 @@ public class LegacyOperationalPolicyMapper
         }
 
         final String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY);
-        if (toscaPolicy.getProperties() == null) {
-            String errorMessage = "property \"Content\" not defined on TOSCA policy";
+        if (content == null) {
+            String errorMessage = "property \"content\" not defined on TOSCA policy";
             LOGGER.warn(errorMessage);
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
index fad227c..6369f79 100644 (file)
@@ -53,9 +53,7 @@ public abstract class JpaToscaConstraint
     }
 
     @Override
-    public int compareTo(JpaToscaConstraint otherConstraint) {
-        return 0;
-    }
+    public abstract int compareTo(JpaToscaConstraint otherConstraint);
 
     /**
      * Create instances of constraints of various types.
index 9841cbe..632f84a 100644 (file)
@@ -73,30 +73,33 @@ public class JpaToscaConstraintLogical extends JpaToscaConstraint {
     public ToscaConstraint toAuthorative() {
         ToscaConstraint toscaConstraint = new ToscaConstraint();
 
+        if (operation == null) {
+            return null;
+        }
+
         switch (operation) {
-            case EQ: {
+            case EQ:
                 toscaConstraint.setEqual(compareTo);
                 break;
-            }
-            case GT: {
+
+            case GT:
                 toscaConstraint.setGreaterThan(compareTo);
                 break;
-            }
-            case GE: {
+
+            case GE:
                 toscaConstraint.setGreaterOrEqual(compareTo);
                 break;
-            }
-            case LT: {
+
+            case LT:
                 toscaConstraint.setLessThan(compareTo);
                 break;
-            }
-            case LE: {
+
+            case LE:
                 toscaConstraint.setLessOrEqual(compareTo);
                 break;
-            }
-            default: {
+
+            default:
                 // Can't happen
-            }
         }
 
         return toscaConstraint;
index 671b5cc..3bc4722 100644 (file)
@@ -129,6 +129,8 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
      * @param authorativeConcept the authorative concept to copy from
      */
     public JpaToscaPolicy(final ToscaPolicy authorativeConcept) {
+        super(new PfConceptKey());
+        type = new PfConceptKey();
         this.fromAuthorative(authorativeConcept);
     }
 
@@ -215,7 +217,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
         PfValidationResult result = super.validate(resultIn);
 
         if (type == null || type.isNullKey()) {
-            result.addValidationMessage(new PfValidationMessage(type, this.getClass(), ValidationResult.INVALID,
+            result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
                     "type is null or a null key"));
         } else {
             result = type.validate(result);
@@ -238,7 +240,7 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
      * @param result The result of validations up to now
      * @return the validation result
      */
-    private PfValidationResult validateProperties(@NonNull final PfValidationResult resultIn) {
+    private PfValidationResult validateProperties(final PfValidationResult resultIn) {
         PfValidationResult result = resultIn;
 
         for (Entry<String, String> propertyEntry : properties.entrySet()) {
index a207c42..ef8ac05 100644 (file)
@@ -24,14 +24,11 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.ws.rs.core.Response;
-
 import lombok.NonNull;
 
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
-import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.dao.PfDao;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
@@ -40,8 +37,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
 import org.onap.policy.models.tosca.utils.ToscaUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /**
  * This class provides the provision of information on TOSCA concepts in the database to callers.
@@ -49,8 +44,6 @@ import org.slf4j.LoggerFactory;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class SimpleToscaProvider {
-    private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class);
-
     /**
      * Get policy types.
      *
@@ -69,14 +62,9 @@ public class SimpleToscaProvider {
 
         // Add the policy type to the TOSCA service template
         List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getFiltered(JpaToscaPolicyType.class, name, version);
-        if (jpaPolicyTypeList != null) {
-            serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
-            return serviceTemplate;
-        } else {
-            String errorMessage = "policy type not found: " + name + ":" + version;
-            LOGGER.warn(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-        }
+        serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
+
+        return serviceTemplate;
     }
 
     /**
@@ -178,14 +166,8 @@ public class SimpleToscaProvider {
 
         // Add the policy type to the TOSCA service template
         List<JpaToscaPolicy> jpaPolicyList = dao.getFiltered(JpaToscaPolicy.class, name, version);
-        if (jpaPolicyList != null) {
-            serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList));
-            return serviceTemplate;
-        } else {
-            String errorMessage = "policy not found: " + name + ":" + version;
-            LOGGER.warn(errorMessage);
-            throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
-        }
+        serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList));
+        return serviceTemplate;
     }
 
     /**
index 441bbcb..a7d016b 100644 (file)
@@ -143,8 +143,10 @@ public class AuthorativeToscaProviderPolicyTest {
         gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, "1.0.0");
         assertEquals(1, gotPolicyList.size());
         assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
-    }
 
+        gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", "1.0.0");
+        assertEquals(0, gotPolicyList.size());
+    }
 
     @Test
     public void testPoliciesGetFiltered() throws Exception {
index fbb5abf..7dc4a94 100644 (file)
@@ -23,15 +23,18 @@ package org.onap.policy.models.tosca.authorative.provider;
 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 com.google.gson.GsonBuilder;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.commons.lang3.ObjectUtils;
 import org.junit.After;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
@@ -41,10 +44,11 @@ import org.onap.policy.models.dao.DaoParameters;
 import org.onap.policy.models.dao.PfDao;
 import org.onap.policy.models.dao.PfDaoFactory;
 import org.onap.policy.models.dao.impl.DefaultPfDao;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
+import org.yaml.snakeyaml.Yaml;
 
 /**
  * Test of the {@link AuthorativeToscaProvider} class.
@@ -52,10 +56,26 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class AuthorativeToscaProviderPolicyTypeTest {
+    private static String yamlAsJsonString;
     private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
+
+    /**
+     * Read the policy type definition.
+     *
+     * @throws Exception on errors
+     */
+    @BeforeClass
+    public static void readPolicyDefinition() {
+        String yamlString =
+                ResourceUtils.getResourceAsString("policytypes/onap.policies.optimization.AffinityPolicy.yaml");
+
+        Object yamlObject = new Yaml().load(yamlString);
+        yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject);
+    }
+
     /**
      * Set up the DAO towards the database.
      *
@@ -93,281 +113,272 @@ public class AuthorativeToscaProviderPolicyTypeTest {
     }
 
     @Test
-    public void testPoliciesGet() throws Exception {
+    public void testPolicyTypesGet() throws Exception {
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getPolicies(null, null, null);
+            new AuthorativeToscaProvider().getPolicyTypes(null, null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
             new AuthorativeToscaProvider().getPolicyList(null, null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
-        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
-                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                ToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
         assertNotNull(toscaServiceTemplate);
         ToscaServiceTemplate createdServiceTemplate =
-                new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
+                new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
 
-        PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+        PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
 
-        ToscaPolicy beforePolicy =
-                toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        ToscaPolicy createdPolicy =
-                createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
-        assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
+        ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
+        ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
 
-        ToscaServiceTemplate gotServiceTemplate =
-                new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
+        ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao,
+                policyTypeKey.getName(), policyTypeKey.getVersion());
 
-        ToscaPolicy gotPolicy =
-                gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
-        assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
+        ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
 
-        List<ToscaPolicy> gotPolicyList =
-                new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", "1.0.0");
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
+        List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
+                "onap.policies.optimization.AffinityPolicy", "0.0.0");
+        assertEquals(1, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
 
-        gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", null);
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
+        gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
+                "onap.policies.optimization.AffinityPolicy", null);
+        assertEquals(1, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
 
-        gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, null);
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
+        gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, null);
+        assertEquals(2, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
 
-        gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, "1.0.0");
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
+        gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, "0.0.0");
+        assertEquals(2, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
     }
 
 
     @Test
-    public void testPoliciesGetFiltered() throws Exception {
+    public void testPolicyTypesGetFiltered() throws Exception {
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getFilteredPolicies(null, null);
+            new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build());
+            new AuthorativeToscaProvider().getFilteredPolicyTypes(null, ToscaPolicyTypeFilter.builder().build());
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null);
+            new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null);
         }).hasMessage("filter is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getFilteredPolicyList(null, null);
+            new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build());
+            new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, ToscaPolicyTypeFilter.builder().build());
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
+            new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null);
         }).hasMessage("filter is marked @NonNull but is null");
 
-        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
-                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                ToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
         assertNotNull(toscaServiceTemplate);
         ToscaServiceTemplate createdServiceTemplate =
-                new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
+                new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
 
-        PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+        PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
 
-        ToscaPolicy beforePolicy =
-                toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        ToscaPolicy createdPolicy =
-                createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
-        assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
+        ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
+        ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
 
         ToscaServiceTemplate gotServiceTemplate =
-                new AuthorativeToscaProvider().getFilteredPolicies(pfDao, ToscaPolicyFilter.builder().build());
-
-        ToscaPolicy gotPolicy =
-                gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
-        assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
-
-        gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
-                ToscaPolicyFilter.builder().name(policyKey.getName()).build());
-
-        gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
-        assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
-
-        gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
-                ToscaPolicyFilter.builder().name(policyKey.getName()).version("1.0.0").build());
-
-        gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
-        assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
-
-        List<ToscaPolicy> gotPolicyList =
-                new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", "1.0.0");
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
-
-        gotPolicyList =
-                new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, ToscaPolicyFilter.builder().build());
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
-
-        gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
-                ToscaPolicyFilter.builder().name(policyKey.getName()).build());
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
-
-        gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
-                ToscaPolicyFilter.builder().name(policyKey.getName()).version("1.0.0").build());
-        assertEquals(1, gotPolicyList.size());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
+                new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, ToscaPolicyTypeFilter.builder().build());
+
+        ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+
+        gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao,
+                ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).build());
+
+        gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+
+        gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao,
+                ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version("0.0.0").build());
+
+        gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+
+        List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
+                "onap.policies.optimization.AffinityPolicy", "0.0.0");
+        assertEquals(1, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+
+        gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
+                ToscaPolicyTypeFilter.builder().build());
+        assertEquals(2, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+
+        gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
+                ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).build());
+        assertEquals(1, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+
+        gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
+                ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version("0.0.0").build());
+        assertEquals(1, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
+
+        gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
+                ToscaPolicyTypeFilter.builder().version("1.0.0").build());
+        assertEquals(1, gotPolicyTypeList.size());
+        assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
     }
 
     @Test
-    public void testPolicyCreate() throws Exception {
+    public void testPolicyTypesCreate() throws Exception {
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(null, null);
+            new AuthorativeToscaProvider().createPolicyTypes(null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate());
+            new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate());
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(pfDao, null);
+            new AuthorativeToscaProvider().createPolicyTypes(pfDao, null);
         }).hasMessage("serviceTemplate is marked @NonNull but is null");
 
-        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
-                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                ToscaServiceTemplate.class);
+        ToscaServiceTemplate testToscaServiceTemplate = new ToscaServiceTemplate();
+        assertThatThrownBy(() -> {
+            new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate);
+        }).hasMessage("no policy types specified on service template");
+
+        testToscaServiceTemplate.setPolicyTypes(new ArrayList<>());
+        assertThatThrownBy(() -> {
+            new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate);
+        }).hasMessage("An incoming list of concepts must have at least one entry");
+
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
         assertNotNull(toscaServiceTemplate);
         ToscaServiceTemplate createdServiceTemplate =
-                new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
+                new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
 
-        PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+        PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
 
-        ToscaPolicy beforePolicy =
-                toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        ToscaPolicy createdPolicy =
-                createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
-        assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
+        ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
+        ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
     }
 
-
     @Test
-    public void testPolicyUpdate() throws Exception {
+    public void testPolicyTypesUpdate() throws Exception {
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(null, null);
+            new AuthorativeToscaProvider().createPolicyTypes(null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().updatePolicies(null, null);
+            new AuthorativeToscaProvider().updatePolicyTypes(null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate());
+            new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate());
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().updatePolicies(pfDao, null);
+            new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null);
         }).hasMessage("serviceTemplate is marked @NonNull but is null");
 
-        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
-                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                ToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
         assertNotNull(toscaServiceTemplate);
         ToscaServiceTemplate createdServiceTemplate =
-                new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
+                new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
 
-        PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+        PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
 
-        ToscaPolicy beforePolicy =
-                toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        ToscaPolicy createdPolicy =
-                createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
-        assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
+        ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
+        ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
 
         ToscaServiceTemplate updatedServiceTemplate =
-                new AuthorativeToscaProvider().updatePolicies(pfDao, toscaServiceTemplate);
+                new AuthorativeToscaProvider().updatePolicyTypes(pfDao, toscaServiceTemplate);
 
-        ToscaPolicy updatedPolicy =
-                updatedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, updatedPolicy));
-        assertTrue(beforePolicy.getType().equals(updatedPolicy.getType()));
+        ToscaPolicyType updatedPolicy = updatedServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(updatedPolicy.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), updatedPolicy.getDescription()));
     }
 
     @Test
-    public void testPoliciesDelete() throws Exception {
+    public void testPolicyTypesDelete() throws Exception {
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(null, null, null);
+            new AuthorativeToscaProvider().deletePolicyType(null, null, null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(null, null, "version");
+            new AuthorativeToscaProvider().deletePolicyType(null, null, "version");
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(null, "name", null);
+            new AuthorativeToscaProvider().deletePolicyType(null, "name", null);
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(null, "name", "version");
+            new AuthorativeToscaProvider().deletePolicyType(null, "name", "version");
         }).hasMessage("dao is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(pfDao, null, null);
+            new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null);
         }).hasMessage("name is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(pfDao, null, "version");
+            new AuthorativeToscaProvider().deletePolicyType(pfDao, null, "version");
         }).hasMessage("name is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
+            new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null);
         }).hasMessage("version is marked @NonNull but is null");
 
-        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
-                ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
-                ToscaServiceTemplate.class);
+        ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
         assertNotNull(toscaServiceTemplate);
         ToscaServiceTemplate createdServiceTemplate =
-                new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
+                new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
 
-        PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+        PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
 
-        ToscaPolicy beforePolicy =
-                toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        ToscaPolicy createdPolicy =
-                createdServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
-        assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
+        ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
+        ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
 
-        ToscaServiceTemplate deletedServiceTemplate =
-                new AuthorativeToscaProvider().deletePolicy(pfDao, policyKey.getName(), policyKey.getVersion());
+        ToscaServiceTemplate deletedServiceTemplate = new AuthorativeToscaProvider().deletePolicyType(pfDao,
+                policyTypeKey.getName(), policyTypeKey.getVersion());
 
-        ToscaPolicy deletedPolicy =
-                deletedServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
-        assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, createdPolicy));
-        assertTrue(beforePolicy.getType().equals(deletedPolicy.getType()));
+        ToscaPolicyType deletedPolicy = deletedServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
+        assertEquals(true, beforePolicyType.getName().equals(deletedPolicy.getName()));
+        assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), deletedPolicy.getDescription()));
 
-        ToscaServiceTemplate gotServiceTemplate =
-                new AuthorativeToscaProvider().getPolicies(pfDao, policyKey.getName(), policyKey.getVersion());
+        ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getPolicyTypes(pfDao,
+                policyTypeKey.getName(), policyTypeKey.getVersion());
 
-        assertEquals(0, gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).size());
+        assertEquals(0, gotServiceTemplate.getPolicyTypes().get(0).size());
     }
 
     @Test
@@ -375,21 +386,21 @@ public class AuthorativeToscaProviderPolicyTypeTest {
         ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate();
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
+            new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null);
         }).hasMessage("version is marked @NonNull but is null");
 
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
-        }).hasMessage("topology template not specified on service template");
+            new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate);
+        }).hasMessage("no policy types specified on service template");
 
         testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
-        }).hasMessage("no policies specified on topology template of service template");
+            new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate);
+        }).hasMessage("no policy types specified on service template");
 
-        testServiceTemplate.getToscaTopologyTemplate().setPolicies(new ArrayList<>());
+        testServiceTemplate.setPolicyTypes(new ArrayList<>());
         assertThatThrownBy(() -> {
-            new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
+            new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate);
         }).hasMessage("An incoming list of concepts must have at least one entry");
     }
 }
index 5720b55..9c23440 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.legacy.concepts;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
@@ -28,6 +29,7 @@ import java.util.Map;
 
 import org.junit.Test;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
+import org.onap.policy.models.tosca.legacy.concepts.testconcepts.DummyBadLegacyGuardPolicyContent;
 
 public class LegacyGuardPolicyTest {
 
@@ -45,6 +47,10 @@ public class LegacyGuardPolicyTest {
         content.setActor("SO");
         guard.setContent(content);
         assertEquals("SO", guard.getContent().getActor());
-    }
 
+        DummyBadLegacyGuardPolicyContent dblgpc = new DummyBadLegacyGuardPolicyContent();
+        assertThatThrownBy(() -> {
+            dblgpc.getAsPropertyMap();
+        }).hasMessage("could not convert content to a property map");
+    }
 }
index f35a4e6..2607718 100644 (file)
@@ -44,9 +44,19 @@ public class TestPojos {
 
     @Test
     public void testPojos() {
-        final Validator validator = ValidatorBuilder.create().with(new ToStringTester())
-                .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester())
-                .with(new GetterTester()).build();
-        validator.validate(POJO_PACKAGE, new FilterPackageInfo());
+        // @formatter:off
+        final Validator validator = ValidatorBuilder
+                .create()
+                .with(new ToStringTester())
+                .with(new SetterMustExistRule())
+                .with(new GetterMustExistRule())
+                .with(new SetterTester())
+                .with(new GetterTester())
+                .build();
+        validator.validate(POJO_PACKAGE,
+                new FilterPackageInfo()
+        );
+
+        // @formatter:on
     }
 }
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/testconcepts/DummyBadLegacyGuardPolicyContent.java
new file mode 100644 (file)
index 0000000..1b14941
--- /dev/null
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.legacy.concepts.testconcepts;
+
+import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent;
+
+/**
+ * Dummy {@link LegacyGuardPolicyContent} class to force exception for testing.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyBadLegacyGuardPolicyContent extends LegacyGuardPolicyContent {
+    public static final String TO_TRIGGER_EXCEPTION = "Dummy";
+    @SuppressWarnings("unused")
+    private final transient String aaa = "aaa";
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapperTest.java
new file mode 100644 (file)
index 0000000..b1dac8f
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.legacy.mapping;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
+
+/**
+ * Test the {@link LegacyGuardPolicyMapper} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class LegacyGuardPolicyMapperTest {
+
+    @Test
+    public void testLegacyGuardPolicyMapper() {
+        JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+        serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+        serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+
+        JpaToscaPolicy policy = new JpaToscaPolicy(new PfConceptKey("PolicyName", "0.0.1"));
+        serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy.getKey(), policy);
+
+        assertThatThrownBy(() -> {
+            new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+        }).hasMessageContaining("no properties defined on TOSCA policy");
+    }
+}
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.policy.models.tosca.legacy.serialization;
+package org.onap.policy.models.tosca.legacy.mapping;
 
+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.LinkedHashMap;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
 import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,9 +47,9 @@ import org.slf4j.LoggerFactory;
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
-public class LegacyOperationalPolicySerializationTest {
+public class LegacyOperationalPolicyMapperTest {
     // Logger for this class
-    private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicySerializationTest.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapperTest.class);
 
     private StandardCoder standardCoder;
 
@@ -68,4 +75,31 @@ public class LegacyOperationalPolicySerializationTest {
         assertEquals("operational.restart:1.0.0",
                 serviceTemplate.getTopologyTemplate().getPolicies().get("operational.restart").getId());
     }
+
+    @Test
+    public void testOperationalPolicyMapper() throws Exception {
+        JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+        serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+        serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+
+        JpaToscaPolicy policy0 = new JpaToscaPolicy(new PfConceptKey("PolicyName0", "0.0.1"));
+        serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy0.getKey(), policy0);
+        JpaToscaPolicy policy1 = new JpaToscaPolicy(new PfConceptKey("PolicyName1", "0.0.1"));
+        serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policy1.getKey(), policy1);
+
+        assertThatThrownBy(() -> {
+            new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+        }).hasMessage("more than one policy found in service template");
+
+        serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().remove(policy1.getKey());
+
+        assertThatThrownBy(() -> {
+            new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+        }).hasMessage("no properties defined on TOSCA policy");
+
+        policy0.setProperties(new LinkedHashMap<>());
+        assertThatThrownBy(() -> {
+            new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate);
+        }).hasMessage("property \"content\" not defined on TOSCA policy");
+    }
 }
index de0c813..d3239da 100644 (file)
 package org.onap.policy.models.tosca.simple.concepts;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
 
 import org.junit.Test;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
 
 /**
- * DAO test for ToscaConstraintLogicalString.
+ * Test the {@link JpaToscaConstraintLogical} class.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class JpaToscaConstraintLogicalTest {
 
     @Test
-    public void testConstraintLogicalStringPojo() {
-        assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
+    public void testLogicalConstraint() {
+        ToscaConstraint c0 = new ToscaConstraint();
+        c0.setEqual("Hello");
+        JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
+        assertEquals(c0, jc0.toAuthorative());
+
+        ToscaConstraint c1 = new ToscaConstraint();
+        c1.setGreaterOrEqual("Hello");
+        JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
+        assertEquals(c1, jc1.toAuthorative());
+
+        ToscaConstraint c2 = new ToscaConstraint();
+        c2.setGreaterThan("Hello");
+        JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
+        assertEquals(c2, jc2.toAuthorative());
 
-        try {
-            new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("operation is marked @NonNull but is null", exc.getMessage());
-        }
+        ToscaConstraint c3 = new ToscaConstraint();
+        c3.setLessOrEqual("Hello");
+        JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
+        assertEquals(c3, jc3.toAuthorative());
 
-        try {
-            new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello");
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("operation is marked @NonNull but is null", exc.getMessage());
-        }
+        ToscaConstraint c4 = new ToscaConstraint();
+        c4.setLessThan("Hello");
+        JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
+        assertEquals(c4, jc4.toAuthorative());
 
-        try {
-            new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("compareTo is marked @NonNull but is null", exc.getMessage());
-        }
+        ToscaConstraint c5 = new ToscaConstraint();
+        JpaToscaConstraintLogical jc5 = new JpaToscaConstraintLogical(c5);
+        assertNull(jc5.toAuthorative());
 
-        assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
+        assertEquals(-1, jc0.compareTo(null));
+        assertEquals(0, jc0.compareTo(jc0));
+        assertNotEquals(0, jc0.compareTo(new JpaToscaConstraintValidValues(new ArrayList<>())));
+        assertEquals(-2, jc0.compareTo(jc1));
     }
 }
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java
new file mode 100644 (file)
index 0000000..ff4187a
--- /dev/null
@@ -0,0 +1,88 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
+
+/**
+ * DAO test for ToscaConstraintLogicalString.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class JpaToscaConstraintTest {
+
+    @Test
+    public void testConstraintLogicalStringPojo() {
+        assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
+
+        try {
+            new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null);
+            fail("test should throw an exception");
+        } catch (Exception exc) {
+            assertEquals("operation is marked @NonNull but is null", exc.getMessage());
+        }
+
+        try {
+            new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello");
+            fail("test should throw an exception");
+        } catch (Exception exc) {
+            assertEquals("operation is marked @NonNull but is null", exc.getMessage());
+        }
+
+        try {
+            new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null);
+            fail("test should throw an exception");
+        } catch (Exception exc) {
+            assertEquals("compareTo is marked @NonNull but is null", exc.getMessage());
+        }
+
+        assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
+
+        assertEquals(0, new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")
+                .compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")));
+
+        JpaToscaConstraintOperation op = JpaToscaConstraintOperation.EQ;
+        assertEquals("equal_to", op.getToscaToken());
+
+        List<String> validValues = new ArrayList<>();
+        validValues.add("hello");
+        validValues.add("goodbye");
+        JpaToscaConstraintValidValues cvv0 = new JpaToscaConstraintValidValues(validValues);
+        assertEquals(-1, cvv0.compareTo(null));
+        assertEquals(0, cvv0.compareTo(cvv0));
+        assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")));
+        JpaToscaConstraintValidValues cvv1 = new JpaToscaConstraintValidValues(validValues);
+        assertEquals(0, cvv0.compareTo(cvv1));
+
+        cvv1.fromAuthorative(new ToscaConstraint());
+        assertNotNull(cvv1.getValidValues());
+    }
+}
index efdddcc..66cde51 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 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.LinkedHashMap;
@@ -35,6 +35,8 @@ import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
@@ -51,20 +53,15 @@ public class JpaToscaDataTypeTest {
         assertNotNull(new JpaToscaDataType());
         assertNotNull(new JpaToscaDataType(new PfConceptKey()));
         assertNotNull(new JpaToscaDataType(new JpaToscaDataType()));
+        assertNotNull(new JpaToscaDataType(new ToscaDataType()));
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaDataType((PfConceptKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaDataType((JpaToscaDataType) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("copyConcept is marked @NonNull but is null");
 
         PfConceptKey dtKey = new PfConceptKey("tdt", "0.0.1");
         JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
@@ -105,12 +102,9 @@ public class JpaToscaDataTypeTest {
         otherDt.setProperties(properties);
         assertEquals(0, tdt.compareTo(otherDt));
 
-        try {
+        assertThatThrownBy(() -> {
             tdt.copyTo(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("target is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("target is marked @NonNull but is null");
 
         assertEquals(3, tdt.getKeys().size());
         assertEquals(1, new JpaToscaDataType().getKeys().size());
@@ -132,12 +126,23 @@ public class JpaToscaDataTypeTest {
         tdt.getProperties().remove(null);
         assertTrue(tdt.validate(new PfValidationResult()).isValid());
 
-        try {
+        assertThatThrownBy(() -> {
             tdt.validate(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
-        }
-
+        }).hasMessage("resultIn is marked @NonNull but is null");
+
+        ToscaDataType dat = new ToscaDataType();
+        dat.setName("name");
+        dat.setVersion("1.2.3");
+        dat.setConstraints(new ArrayList<>());
+        ToscaConstraint constraint = new ToscaConstraint();
+        constraint.setEqual("EqualTo");
+        dat.getConstraints().add(constraint);
+
+        JpaToscaDataType tdta = new JpaToscaDataType();
+        tdta.fromAuthorative(dat);
+        assertEquals("name", tdta.getKey().getName());
+
+        ToscaDataType datOut = tdta.toAuthorative();
+        assertNotNull(datOut);
     }
 }
index ce90e37..c732fa6 100644 (file)
@@ -24,10 +24,15 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
 
@@ -74,5 +79,10 @@ public class JpaToscaDataTypesTest {
         } catch (Exception exc) {
             assertEquals("key is marked @NonNull but is null", exc.getMessage());
         }
+
+        List<Map<String, ToscaDataType>> dtMapList = new ArrayList<>();
+        dtMapList.add(new LinkedHashMap<>());
+        dtMapList.get(0).put("policyType", new ToscaDataType());
+        assertNotNull(new JpaToscaDataTypes(dtMapList));
     }
 }
index 6f6141c..db3635e 100644 (file)
@@ -24,10 +24,15 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 
@@ -74,5 +79,10 @@ public class JpaToscaPoliciesTest {
         } catch (Exception exc) {
             assertEquals("key is marked @NonNull but is null", exc.getMessage());
         }
+
+        List<Map<String, ToscaPolicy>> polMapList = new ArrayList<>();
+        polMapList.add(new LinkedHashMap<>());
+        polMapList.get(0).put("policyType", new ToscaPolicy());
+        assertNotNull(new JpaToscaPolicies(polMapList));
     }
 }
index ec8e6da..571cde4 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 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.HashMap;
@@ -33,7 +33,9 @@ import java.util.Map;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 
 /**
@@ -50,40 +52,29 @@ public class JpaToscaPolicyTest {
         assertNotNull(new JpaToscaPolicy(new PfConceptKey(), new PfConceptKey()));
         assertNotNull(new JpaToscaPolicy(new JpaToscaPolicy()));
 
-        try {
+        ToscaPolicy pol = new ToscaPolicy();
+        pol.setType("type");
+        assertNotNull(new JpaToscaPolicy(pol));
+
+        assertThatThrownBy(() -> {
             new JpaToscaPolicy((PfConceptKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaPolicy(null, null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaPolicy(new PfConceptKey(), null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("type is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("type is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaPolicy(null, new PfConceptKey());
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaPolicy((JpaToscaPolicy) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("copyConcept is marked @NonNull but is null");
 
         PfConceptKey tpKey = new PfConceptKey("tdt", "0.0.1");
         PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
@@ -126,12 +117,9 @@ public class JpaToscaPolicyTest {
         otherDt.setTargets(targets);
         assertEquals(0, tp.compareTo(otherDt));
 
-        try {
+        assertThatThrownBy(() -> {
             tp.copyTo(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("target is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("target is marked @NonNull but is null");
 
         assertEquals(3, tp.getKeys().size());
         assertEquals(2, new JpaToscaPolicy().getKeys().size());
@@ -164,11 +152,35 @@ public class JpaToscaPolicyTest {
         tp.getTargets().remove(null);
         assertTrue(tp.validate(new PfValidationResult()).isValid());
 
-        try {
+        PfConceptKey tpTypeKey = tp.getKey();
+        assertNotNull(tpTypeKey);
+        tp.setType(null);
+        assertFalse(tp.validate(new PfValidationResult()).isValid());
+        tp.setType(PfConceptKey.getNullKey());
+        assertFalse(tp.validate(new PfValidationResult()).isValid());
+        tp.setType(tpTypeKey);
+        assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+        assertThatThrownBy(() -> {
             tp.validate(null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("resultIn is marked @NonNull but is null");
+
+        assertNotNull(tp.toAuthorative());
+        tp.getType().setVersion(PfKey.NULL_KEY_VERSION);
+        assertNotNull(tp.toAuthorative());
+        tp.setProperties(null);
+        assertNotNull(tp.toAuthorative());
+
+        assertThatThrownBy(() -> {
+            tp.fromAuthorative(null);
+        }).hasMessage("toscaPolicy is marked @NonNull but is null");
+
+        pol = new ToscaPolicy();
+        pol.setName("policy");
+        pol.setVersion("1.2.3");
+        pol.setType("poltype");
+        pol.setTypeVersion("2.2.3");
+        tp.fromAuthorative(pol);
+        assertEquals("2.2.3", tp.getType().getVersion());
     }
-}
\ No newline at end of file
+}
index 870640e..3cdcd95 100644 (file)
@@ -37,6 +37,7 @@ import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
@@ -209,5 +210,9 @@ public class JpaToscaPolicyTypeTest {
         assertEquals(-1, tet.compareTo(null));
         assertEquals(0, tet.compareTo(tet));
         assertFalse(tet.compareTo(tet.getKey()) == 0);
+
+        assertNotNull(new JpaToscaPolicyType(new ToscaPolicyType()));
+
+        assertNotNull(new JpaToscaEntityType<ToscaPolicyType>(new ToscaPolicyType()));
     }
 }
index d0ea178..e02df23 100644 (file)
@@ -24,10 +24,15 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
 
@@ -74,5 +79,10 @@ public class JpaToscaPolicyTypesTest {
         } catch (Exception exc) {
             assertEquals("key is marked @NonNull but is null", exc.getMessage());
         }
+
+        List<Map<String, ToscaPolicyType>> ptMapList = new ArrayList<>();
+        ptMapList.add(new LinkedHashMap<>());
+        ptMapList.get(0).put("policyType", new ToscaPolicyType());
+        assertNotNull(new JpaToscaPolicyTypes(ptMapList));
     }
 }
index b876660..706011b 100644 (file)
@@ -191,6 +191,8 @@ public class JpaToscaPropertyTest {
 
         tp.setDefaultValue(null);
         assertTrue(tp.validate(new PfValidationResult()).isValid());
+        tp.setDefaultValue("");
+        assertFalse(tp.validate(new PfValidationResult()).isValid());
         tp.setDefaultValue("defaultKey");
         assertTrue(tp.validate(new PfValidationResult()).isValid());
 
index 91d6d0b..354fe8b 100644 (file)
 
 package org.onap.policy.models.tosca.simple.concepts;
 
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
 
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 import java.util.TreeMap;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates;
 
@@ -41,39 +45,29 @@ public class JpaToscaServiceTemplatesTest {
                 new JpaToscaServiceTemplates(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaServiceTemplate>()));
         assertNotNull(new JpaToscaServiceTemplates(new JpaToscaServiceTemplates()));
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaServiceTemplates((PfConceptKey) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaServiceTemplates((JpaToscaServiceTemplates) null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("copyConcept is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaServiceTemplates(null, null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaServiceTemplates(new PfConceptKey(), null);
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("conceptMap is marked @NonNull but is null");
 
-        try {
+        assertThatThrownBy(() -> {
             new JpaToscaServiceTemplates(null, new TreeMap<PfConceptKey, JpaToscaServiceTemplate>());
-            fail("test should throw an exception");
-        } catch (Exception exc) {
-            assertEquals("key is marked @NonNull but is null", exc.getMessage());
-        }
+        }).hasMessage("key is marked @NonNull but is null");
+
+        List<Map<String, ToscaServiceTemplate>> tsMapList = new ArrayList<>();
+        tsMapList.add(new LinkedHashMap<>());
+        tsMapList.get(0).put("serviceTemplate", new ToscaServiceTemplate());
+        assertNotNull(new JpaToscaServiceTemplates(tsMapList));
     }
 }
index 417f202..61ce3d0 100644 (file)
@@ -33,6 +33,7 @@ import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
 import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
 import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
@@ -49,6 +50,7 @@ public class JpaToscaTopologyTemplateTest {
         assertNotNull(new JpaToscaTopologyTemplate());
         assertNotNull(new JpaToscaTopologyTemplate(new PfReferenceKey()));
         assertNotNull(new JpaToscaTopologyTemplate(new JpaToscaTopologyTemplate()));
+        assertNotNull(new JpaToscaTopologyTemplate(new ToscaTopologyTemplate()));
 
         try {
             new JpaToscaTopologyTemplate((PfReferenceKey) null);
@@ -121,6 +123,11 @@ public class JpaToscaTopologyTemplateTest {
         assertTrue(new JpaToscaTopologyTemplate().validate(new PfValidationResult()).isValid());
         assertTrue(ttt.validate(new PfValidationResult()).isValid());
 
+        ttt.setKey(PfReferenceKey.getNullKey());
+        assertFalse(ttt.validate(new PfValidationResult()).isValid());
+        ttt.setKey(tttKey);
+        assertTrue(ttt.validate(new PfValidationResult()).isValid());
+
         ttt.setDescription(null);
         assertTrue(ttt.validate(new PfValidationResult()).isValid());
         ttt.setDescription("");
index e5be498..edb6e2e 100644 (file)
@@ -40,7 +40,6 @@ import org.onap.policy.common.utils.validation.ToStringTester;
  *
  */
 public class TestPojos {
-
     private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.simple.concepts";
 
     @Test
index b13cb4b..f8e4221 100644 (file)
@@ -45,4 +45,9 @@ public class DummyToscaConstraint extends JpaToscaConstraint {
     @Override
     public void fromAuthorative(ToscaConstraint authorativeConcept) {
     }
+
+    @Override
+    public int compareTo(JpaToscaConstraint otherConstraint) {
+        return 0;
+    }
 }
index d94c399..ddfb567 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.models.tosca.simple.provider;
 
+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;
@@ -92,13 +93,6 @@ public class SimpleToscaProviderTest {
 
     @Test
     public void testPoliciesGet() throws Exception {
-        try {
-            new SimpleToscaProvider().getPolicies(null, null, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
                 ToscaServiceTemplate.class);
@@ -124,27 +118,6 @@ public class SimpleToscaProviderTest {
 
     @Test
     public void testPolicyCreate() throws Exception {
-        try {
-            new SimpleToscaProvider().createPolicies(null, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate());
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().createPolicies(pfDao, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage());
-        }
-
         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
                 ToscaServiceTemplate.class);
@@ -161,27 +134,6 @@ public class SimpleToscaProviderTest {
 
     @Test
     public void testPolicyUpdate() throws Exception {
-        try {
-            new SimpleToscaProvider().updatePolicies(null, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate());
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().updatePolicies(pfDao, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage());
-        }
-
         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
                 ToscaServiceTemplate.class);
@@ -198,27 +150,6 @@ public class SimpleToscaProviderTest {
 
     @Test
     public void testPoliciesDelete() throws Exception {
-        try {
-            new SimpleToscaProvider().deletePolicy(null, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("dao is marked @NonNull but is null", exc.getMessage());
-        }
-
-        try {
-            new SimpleToscaProvider().deletePolicy(pfDao, null);
-            fail("test should throw an exception here");
-        } catch (Exception exc) {
-            assertEquals("policyKey is marked @NonNull but is null", exc.getMessage());
-        }
-
         ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
                 ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
                 ToscaServiceTemplate.class);
@@ -271,6 +202,88 @@ public class SimpleToscaProviderTest {
             assertEquals("list of policies specified on topology template of service template is empty",
                     exc.getMessage());
         }
+    }
+
+    @Test
+    public void testNonNulls() {
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().getPolicyTypes(null, null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().createPolicyTypes(null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate());
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().createPolicyTypes(pfDao, null);
+        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().updatePolicyTypes(null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate());
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().updatePolicyTypes(pfDao, null);
+        }).hasMessage("serviceTemplate is marked @NonNull but is null");
 
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().deletePolicyType(null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey());
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().deletePolicyType(pfDao, null);
+        }).hasMessage("policyTypeKey is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().getPolicies(null, null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().createPolicies(null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate());
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().createPolicies(pfDao, null);
+        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().updatePolicies(null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate());
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().updatePolicies(pfDao, null);
+        }).hasMessage("serviceTemplate is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().deletePolicy(null, null);
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
+        }).hasMessage("dao is marked @NonNull but is null");
+
+        assertThatThrownBy(() -> {
+            new SimpleToscaProvider().deletePolicy(pfDao, null);
+        }).hasMessage("policyKey is marked @NonNull but is null");
     }
 }
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
new file mode 100644 (file)
index 0000000..40a2fd2
--- /dev/null
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.utils;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.Test;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+
+/**
+ * Import the {@link ToscaUtils} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaUtilsTest {
+
+    @Test
+    public void test() {
+        JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+        jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
+
+        assertThatThrownBy(() -> {
+            ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
+        }).hasMessage("list of policy types specified on service template is empty");
+    }
+}
diff --git a/pom.xml b/pom.xml
index 13743ae..9b10713 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <version>${javax.ws.rs-api.version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.mariadb.jdbc</groupId>
+            <artifactId>mariadb-java-client</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>