diff options
18 files changed, 1173 insertions, 194 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java index 501d9c353..10ce4ea60 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfObjectFilter.java @@ -49,8 +49,8 @@ public interface PfObjectFilter<T extends Comparable<T>> { * @param pattern the pattern to check against * @return match or not */ - public default boolean filterString(@NonNull final String value, final String pattern) { - return pattern == null || value.equals(pattern); + public default boolean filterString(final String value, final String pattern) { + return value == null || pattern == null || value.equals(pattern); } /** diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java index 3d16f8e3f..c13140726 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java @@ -84,14 +84,6 @@ public class PfObjectFilterTest { assertFalse(dof.filterString("Hello", "Goodbye")); assertTrue(dof.filterString("Hello", "Hello")); - assertThatThrownBy(() -> { - dof.filterString(null, null); - }).hasMessage("value is marked @NonNull but is null"); - - assertThatThrownBy(() -> { - dof.filterString(null, "hello"); - }).hasMessage("value is marked @NonNull but is null"); - assertEquals(false, dof.filterString("Hello", "Goodbye")); assertEquals(true, dof.filterString("Hello", "Hello")); assertEquals(true, dof.filterString("Hello", null)); diff --git a/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml b/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml index 378e8157e..6e32cca28 100644 --- a/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml +++ b/models-examples/src/main/resources/policies/vCPE.policies.optimization.input.tosca.yaml @@ -1,6 +1,6 @@ tosca_definitions_version: tosca_simple_yaml_1_0_0 topology_template: -policies: + policies: - OSDF_CASABLANCA.Affinity_vCPE_1: type: onap.policies.optimization.AffinityPolicy diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java index 20e43f0b5..f0ff4a6c2 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java @@ -290,12 +290,12 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro if (currentInstanceCount < 0) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "the current instance count of a PDP group may not be negative")); + "the current instance count of a PDP sub group may not be negative")); } if (desiredInstanceCount < 0) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "the desired instance count of a PDP group may not be negative")); + "the desired instance count of a PDP sub group may not be negative")); } if (properties != null) { @@ -311,7 +311,6 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro } } - return validateSubConcepts(result); } diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java index bef3f1547..bfdeda984 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/provider/PdpProvider.java @@ -67,35 +67,7 @@ public class PdpProvider { public List<PdpGroup> getPdpGroups(@NonNull final PfDao dao, final String name, final String version) throws PfModelException { - List<JpaPdpGroup> foundPdpGroups = dao.getFiltered(JpaPdpGroup.class, name, version); - - if (foundPdpGroups != null) { - return asPdpGroupList(foundPdpGroups); - } else { - String errorMessage = "no PDP groups found for filter " + name + ":" + version; - LOGGER.warn(errorMessage); - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); - } - } - - /** - * Get latest PDP Groups, returns PDP groups in all states. - * - * @param dao the DAO to use to access the database - * @param name the name of the PDP group to get, null to get all PDP groups - * @return the PDP groups found - * @throws PfModelException on errors getting policies - */ - public List<PdpGroup> getLatestPdpGroups(@NonNull final PfDao dao, final String name) throws PfModelException { - List<JpaPdpGroup> jpaPdpGroupList = new ArrayList<>(); - - if (name == null) { - jpaPdpGroupList.addAll(dao.getAll(JpaPdpGroup.class)); - } else { - jpaPdpGroupList.addAll(dao.getAllVersions(JpaPdpGroup.class, name)); - } - - return asPdpGroupList(jpaPdpGroupList); + return asPdpGroupList(dao.getFiltered(JpaPdpGroup.class, name, version)); } /** @@ -106,8 +78,7 @@ public class PdpProvider { * @return the PDP groups found * @throws PfModelException on errors getting policies */ - public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter) - throws PfModelException { + public List<PdpGroup> getFilteredPdpGroups(@NonNull final PfDao dao, @NonNull final PdpGroupFilter filter) { List<JpaPdpGroup> jpaPdpGroupList = dao.getAll(JpaPdpGroup.class); @@ -211,10 +182,7 @@ public class PdpProvider { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } - if (dao.update(jpaPdpSubgroup) == null) { - String errorMessage = "update of PDP subgroup \"" + jpaPdpSubgroup.getId() + "\" failed"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); - } + dao.update(jpaPdpSubgroup); } /** @@ -228,8 +196,7 @@ public class PdpProvider { * @throws PfModelException on errors updating PDP subgroups */ public void updatePdp(@NonNull final PfDao dao, @NonNull final String pdpGroupName, - @NonNull final String pdpGroupVersion, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp) - throws PfModelException { + @NonNull final String pdpGroupVersion, @NonNull final String pdpSubGroup, @NonNull final Pdp pdp) { final PfReferenceKey pdpKey = new PfReferenceKey(pdpGroupName, pdpGroupVersion, pdpSubGroup, pdp.getInstanceId()); @@ -243,10 +210,7 @@ public class PdpProvider { throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); } - if (dao.update(jpaPdp) == null) { - String errorMessage = "update of PDP \"" + jpaPdp.getId() + "\" failed"; - throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage); - } + dao.update(jpaPdp); } /** @@ -258,8 +222,8 @@ public class PdpProvider { * @return the PDP group deleted * @throws PfModelException on errors deleting PDP groups */ - public PdpGroup deletePdpGroup(@NonNull final PfDao dao, @NonNull final String name, @NonNull final String version) - throws PfModelException { + public PdpGroup deletePdpGroup(@NonNull final PfDao dao, @NonNull final String name, + @NonNull final String version) { PfConceptKey pdpGroupKey = new PfConceptKey(name, version); @@ -298,11 +262,12 @@ public class PdpProvider { * @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 statistics to update * @throws PfModelException on errors updating statistics */ public void updatePdpStatistics(@NonNull final PfDao dao, @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 { // Not implemented yet } diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java index 4012eaa1c..bc77e4bb8 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java @@ -36,14 +36,22 @@ 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.PfModelException; 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.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.PdpGroups; +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.pdp.persistence.provider.PdpProvider; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier; import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; /** @@ -124,6 +132,47 @@ public class PdpProviderTest { } @Test + public void testFilteredPdpGroupGet() throws Exception { + assertThatThrownBy(() -> { + new PdpProvider().getFilteredPdpGroups(null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().getFilteredPdpGroups(null, PdpGroupFilter.builder().build()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().getFilteredPdpGroups(pfDao, null); + }).hasMessage("filter is marked @NonNull but is null"); + + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsForFiltering.json"); + PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); + + assertEquals(5, new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()).size()); + + List<ToscaPolicyTypeIdentifier> policyTypeList = new ArrayList<>(); + policyTypeList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3")); + + List<ToscaPolicyIdentifier> policyList = new ArrayList<>(); + policyList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6")); + + // @formatter:off + final PdpGroupFilter filter = PdpGroupFilter.builder() + .groupState(PdpState.PASSIVE) + .name("PdpGroup0") + .version("1.2.3") + .matchPoliciesExactly(false) + .matchPolicyTypesExactly(false) + .pdpState(PdpState.PASSIVE) + .pdpType("APEX") + .policyTypeList(policyTypeList) + .policyList(policyList) + .build(); + // @formatter:on + assertEquals(1, new PdpProvider().getFilteredPdpGroups(pfDao, filter).size()); + } + + @Test public void testGroupsCreate() throws Exception { assertThatThrownBy(() -> { new PdpProvider().createPdpGroups(null, null); @@ -150,6 +199,11 @@ public class PdpProviderTest { String gotJson = standardCoder.encode(gotPdpGroups0); assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", "")); + + pdpGroups0.getGroups().get(0).setPdpGroupState(null); + assertThatThrownBy(() -> { + new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()); + }).hasMessageContaining("INVALID:pdpGroupState may not be null"); } @Test @@ -210,6 +264,11 @@ public class PdpProviderTest { List<Pdp> beforePdpInstances = updatePdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances(); List<Pdp> afterPdpInstances = updatedPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances(); assertTrue(beforePdpInstances.containsAll(afterPdpInstances)); + + pdpGroups0.getGroups().get(0).setPdpGroupState(null); + assertThatThrownBy(() -> { + new PdpProvider().updatePdpGroups(pfDao, pdpGroups0.getGroups()); + }).hasMessageContaining("INVALID:pdpGroupState may not be null"); } @Test @@ -223,9 +282,25 @@ public class PdpProviderTest { }).hasMessage("dao is marked @NonNull but is null"); assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(null, "name", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { new PdpProvider().deletePdpGroup(null, "name", "version"); }).hasMessage("dao is marked @NonNull but is null"); + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(pfDao, null, "version"); + }).hasMessage("name is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(pfDao, "name", null); + }).hasMessage("version is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().deletePdpGroup(pfDao, "name", "version"); + }).hasMessage("delete of PDP group \"name:version\" failed, PDP group does not exist"); + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); @@ -250,4 +325,539 @@ public class PdpProviderTest { new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3"); }).hasMessage("delete of PDP group \"PdpGroup0:1.2.3\" failed, PDP group does not exist"); } + + @Test + public void testPdpSubgroupUpdate() throws Exception { + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, null, null, new PdpSubGroup()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, null, "version", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, null, "version", new PdpSubGroup()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, "name", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, "name", null, new PdpSubGroup()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, "name", "version", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(null, "name", "version", new PdpSubGroup()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, null, null, new PdpSubGroup()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, null, "version", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, null, "version", new PdpSubGroup()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, "name", null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, "name", null, new PdpSubGroup()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, "name", "version", null); + }).hasMessage("pdpSubGroup is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, "name", "version", new PdpSubGroup()); + }).hasMessage("parameter \"localName\" is null"); + + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); + PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); + + PdpGroups createdPdpGroups0 = new PdpGroups(); + createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups())); + String createdJson = standardCoder.encode(createdPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + + PdpGroups gotPdpGroups0 = new PdpGroups(); + gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3")); + + String gotJson = standardCoder.encode(gotPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", "")); + + PdpSubGroup existingSubGroup = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0); + existingSubGroup.setCurrentInstanceCount(10); + existingSubGroup.setDesiredInstanceCount(10); + new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup); + + List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"); + assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getCurrentInstanceCount()); + assertEquals(10, afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getDesiredInstanceCount()); + + existingSubGroup.setDesiredInstanceCount(-1); + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup); + }).hasMessageContaining("INVALID:the desired instance count of a PDP sub group may not be negative"); + existingSubGroup.setDesiredInstanceCount(10); + + existingSubGroup.setPdpType("Loooooooooooooooooooooooooooooooooooooooo" + + "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongKey"); + assertThatThrownBy(() -> { + new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup); + }).hasMessageContaining("Value too long for column"); + existingSubGroup.setPdpType("APEX"); + } + + @Test + public void testPdpUpdate() throws Exception { + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, null, null, new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, null, "TYPE", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, null, "TYPE", new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, "version", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, "version", null, new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, "version", "TYPE", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, null, "version", "TYPE", new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", null, null, new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", null, "TYPE", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", null, "TYPE", new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", "version", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", "version", null, new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", "version", "TYPE", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(null, "name", "version", "TYPE", new Pdp()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, null, null, new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, null, "TYPE", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, null, "TYPE", new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, "version", null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, "version", null, new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, "version", "TYPE", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, null, "version", "TYPE", new Pdp()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", null, null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", null, null, new Pdp()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", null, "TYPE", null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", null, "TYPE", new Pdp()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", "version", null, null); + }).hasMessage("pdpSubGroup is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", "version", null, new Pdp()); + }).hasMessage("pdpSubGroup is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", "version", "TYPE", null); + }).hasMessage("pdp is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "name", "version", "TYPE", new Pdp()); + }).hasMessage("parameter \"localName\" is null"); + + String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json"); + PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class); + + PdpGroups createdPdpGroups0 = new PdpGroups(); + createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups())); + String createdJson = standardCoder.encode(createdPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", "")); + + PdpGroups gotPdpGroups0 = new PdpGroups(); + gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3")); + + String gotJson = standardCoder.encode(gotPdpGroups0); + assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", "")); + + Pdp existingPdp = gotPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances().get(0); + existingPdp.setPdpState(PdpState.TEST); + existingPdp.setHealthy(PdpHealthStatus.TEST_IN_PROGRESS); + new PdpProvider().updatePdp(pfDao, "PdpGroup0", "1.2.3", "APEX", existingPdp); + + List<PdpGroup> afterUpdatePdpGroups = new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"); + assertEquals(PdpState.TEST, + afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getPdpState()); + assertEquals(PdpHealthStatus.TEST_IN_PROGRESS, + afterUpdatePdpGroups.get(0).getPdpSubgroups().get(0).getPdpInstances().get(0).getHealthy()); + + existingPdp.setMessage(""); + assertThatThrownBy(() -> { + new PdpProvider().updatePdp(pfDao, "PdpGroup0", "1.2.3", "APEX", existingPdp); + }).hasMessageContaining("INVALID:message may not be blank"); + existingPdp.setMessage("A Message"); + } + + @Test + public void testGetPdpStatistics() throws PfModelException { + assertThatThrownBy(() -> { + new PdpProvider().getPdpStatistics(null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().getPdpStatistics(null, null, "version"); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().getPdpStatistics(null, "name", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertEquals(0, new PdpProvider().getPdpStatistics(pfDao, "name", "version").size()); + } + + @Test + public void testUpdatePdpStatistics() throws PfModelException { + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, null, null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, null, "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, null, "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, null, "TYPE", "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", null, null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", null, "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", null, "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, null, "version", "TYPE", "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, null, null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, null, "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, null, "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", null, "TYPE", "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", null, null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", null, null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", null, "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", null, "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", null, null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", null, new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", "inst", null); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(null, "name", "version", "TYPE", "inst", new PdpStatistics()); + }).hasMessage("dao is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, null, null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, null, "inst", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, null, "inst", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", "inst", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, null, "TYPE", "inst", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, "inst", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", null, "inst", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", null, null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", null, new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", "inst", null); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, null, "version", "TYPE", "inst", new PdpStatistics()); + }).hasMessage("pdpGroupName is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, null, new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, "inst", null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, null, "inst", new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", null, null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", null, new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", "inst", null); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", null, "TYPE", "inst", new PdpStatistics()); + }).hasMessage("pdpGroupVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, null, null); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, null, new PdpStatistics()); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, "inst", null); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", null, "inst", new PdpStatistics()); + }).hasMessage("pdpType is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", null, null); + }).hasMessage("pdpInstanceId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", null, new PdpStatistics()); + }).hasMessage("pdpInstanceId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", "inst", null); + }).hasMessage("pdpStatistics is marked @NonNull but is null"); + + new PdpProvider().updatePdpStatistics(pfDao, "name", "version", "TYPE", "inst", new PdpStatistics()); + } } diff --git a/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json b/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json index 623ee4e23..f9c822b06 100644 --- a/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json +++ b/models-pdp/src/test/resources/testdata/PdpGroupsForFiltering.json @@ -1,22 +1,17 @@ { - "groups": - [ + "groups": [ { "name": "PdpGroup0", "version": "1.2.3", "description": "group description", "pdpGroupState": "PASSIVE", - "properties": - { + "properties": { "groupProperty0": "Value of Group Property 0" }, - - "pdpSubgroups": - [ + "pdpSubgroups": [ { "pdpType": "APEX", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.0", "version": "1.2.3" @@ -30,9 +25,7 @@ "version": "7.8.9" } ], - - "policies": - [ + "policies": [ { "name": "Policy0", "version": "4.5.6" @@ -42,16 +35,12 @@ "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "ACTIVE", @@ -59,19 +48,19 @@ "message": "message from PDP" }, { - "instanceId": "apex-0", + "instanceId": "apex-1", "pdpState": "PASSIVE", "healthy": "NOT_HEALTHY", "message": "message from PDP" }, { - "instanceId": "apex-0", + "instanceId": "apex-2", "pdpState": "SAFE", "healthy": "NOT_HEALTHY", "message": "message from PDP" }, { - "instanceId": "apex-0", + "instanceId": "apex-3", "pdpState": "TEST", "healthy": "NOT_HEALTHY", "message": "message from PDP" @@ -80,23 +69,18 @@ } ] }, - { "name": "PdpGroup0", "version": "1.2.4", "description": "group description", "pdpGroupState": "ACTIVE", - "properties": - { + "properties": { "groupProperty0": "Value of Group Property 0" }, - - "pdpSubgroups": - [ + "pdpSubgroups": [ { "pdpType": "APEX", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.0", "version": "1.2.3" @@ -110,24 +94,18 @@ "version": "0.1.2" } ], - - "policies": - [ + "policies": [ { "name": "Policy2", "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "ACTIVE", @@ -138,23 +116,18 @@ } ] }, - { "name": "PdpGroup0", "version": "1.2.1", "description": "group description", "pdpGroupState": "SAFE", - "properties": - { + "properties": { "groupProperty0": "Value of Group Property 0" }, - - "pdpSubgroups": - [ + "pdpSubgroups": [ { "pdpType": "APEX", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.1", "version": "4.5.6" @@ -164,9 +137,7 @@ "version": "0.1.2" } ], - - "policies": - [ + "policies": [ { "name": "Policy2", "version": "4.5.6" @@ -176,16 +147,12 @@ "version": "1.2.3" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "SAFE", @@ -196,31 +163,24 @@ }, { "pdpType": "DROOLS", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.0", "version": "1.2.3" } ], - - "policies": - [ + "policies": [ { "name": "Policy0", "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "SAFE", @@ -236,17 +196,13 @@ "version": "1.2.1", "description": "group description", "pdpGroupState": "PASSIVE", - "properties": - { + "properties": { "groupProperty0": "Value of Group Property 0" }, - - "pdpSubgroups": - [ + "pdpSubgroups": [ { "pdpType": "APEX", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.1", "version": "4.5.6" @@ -256,24 +212,18 @@ "version": "7.8.9" } ], - - "policies": - [ + "policies": [ { "name": "Policy0", "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "PASSIVE", @@ -284,46 +234,35 @@ } ] }, - { "name": "PdpGroup1", "version": "1.2.3", "description": "group description", "pdpGroupState": "TEST", - "properties": - { + "properties": { "groupProperty0": "Value of Group Property 0" }, - - "pdpSubgroups": - [ + "pdpSubgroups": [ { "pdpType": "APEX", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.0", "version": "1.2.3" } ], - - "policies": - [ + "policies": [ { "name": "Policy0", "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "TEST", @@ -334,31 +273,24 @@ }, { "pdpType": "DROOLS", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.0", "version": "1.2.3" } ], - - "policies": - [ + "policies": [ { "name": "Policy0", "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "PASSIVE", @@ -369,31 +301,24 @@ }, { "pdpType": "XACML", - "supportedPolicyTypes": - [ + "supportedPolicyTypes": [ { "name": "policy.type.0", "version": "1.2.3" } ], - - "policies": - [ + "policies": [ { "name": "Policy0", "version": "4.5.6" } ], - "currentInstanceCount": 123, "desiredInstanceCount": 456, - "properties": - { + "properties": { "subgroupProperty0": "Value of sub Group Property 0" }, - - "pdpInstances": - [ + "pdpInstances": [ { "instanceId": "apex-0", "pdpState": "ACTIVE", @@ -405,4 +330,4 @@ ] } ] -}
\ No newline at end of file +} diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java index bf48292fd..8f05244b9 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java @@ -117,7 +117,7 @@ public class PolicyToscaPersistenceTest { } } } catch (Exception exc) { - LOGGER.warn("error processing policies", exc); + LOGGER.warn("error processing policy types", exc); fail("test should not throw an exception"); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java index e89b31635..f5a178a37 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java @@ -54,7 +54,7 @@ public class ToscaEntity implements PfNameVersion { private String description; /** - * Copy COnstructor. + * Copy Constructor. * * @param copyObject object to copy from */ diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java index 75f17ea5b..3a3b1476d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java @@ -23,10 +23,14 @@ package org.onap.policy.models.tosca.authorative.concepts; +import java.util.LinkedHashMap; import java.util.Map; +import java.util.Map.Entry; + import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import lombok.NonNull; /** * Class to represent TOSCA policy type matching input/output from/to client. @@ -39,6 +43,22 @@ import lombok.NoArgsConstructor; public class ToscaPolicyType extends ToscaEntity implements Comparable<ToscaPolicyType> { private Map<String, ToscaProperty> properties; + /** + * Copy Constructor. + * + * @param copyObject object to copy from + */ + public ToscaPolicyType(@NonNull ToscaPolicyType copyObject) { + super(copyObject); + + if (copyObject.properties != null) { + properties = new LinkedHashMap<>(); + for (final Entry<String, ToscaProperty> propertyEntry : copyObject.properties.entrySet()) { + properties.put(propertyEntry.getKey(), propertyEntry.getValue()); + } + } + } + @Override public int compareTo(final ToscaPolicyType other) { return compareNameVersion(this, other); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java index 15240665d..d850052b4 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestPojos.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/PojosTest.java @@ -39,7 +39,7 @@ import org.onap.policy.common.utils.validation.ToStringTester; * @author Chenfei Gao (cgao@research.att.com) * */ -public class TestPojos { +public class PojosTest { private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.authorative.concepts"; diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java new file mode 100644 index 000000000..4653296b7 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java @@ -0,0 +1,214 @@ +/*- + * ============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.authorative.concepts; + +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.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Test of the {@link ToscaPolicyFilter} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyFilterTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyFilterTest.class); + + // @formatter:off + private static final String[] policyResourceNames = { + "policies/vCPE.policies.optimization.input.tosca.yaml", + "policies/vCPE.policy.monitoring.input.tosca.json", + "policies/vCPE.policy.monitoring.input.tosca.yaml", + "policies/vCPE.policy.operational.input.tosca.yaml", + "policies/vDNS.policy.guard.frequency.input.tosca.json", + "policies/vDNS.policy.guard.frequency.input.tosca.yaml", + "policies/vDNS.policy.guard.minmax.input.tosca.yaml", + "policies/vDNS.policy.monitoring.input.tosca.json", + "policies/vDNS.policy.monitoring.input.tosca.yaml", + "policies/vDNS.policy.operational.input.tosca.yaml", + "policies/vFirewall.policy.monitoring.input.tosca.json", + "policies/vFirewall.policy.monitoring.input.tosca.yaml", + "policies/vFirewall.policy.operational.input.tosca.json", + "policies/vFirewall.policy.operational.input.tosca.yaml" + }; + // @formatter:on + + private static List<ToscaPolicy> policyList = new ArrayList<>(); + + /** + * Set up a Tosca Policy type list for filtering. + * + * @throws CoderException on JSON decoding errors + */ + @BeforeClass + public static void setupTypeList() throws CoderException { + for (String policyResourceName : policyResourceNames) { + String policyString = ResourceUtils.getResourceAsString(policyResourceName); + if (policyResourceName.endsWith("yaml")) { + Object yamlObject = new Yaml().load(policyString); + policyString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); + } + + ToscaServiceTemplate serviceTemplate = new StandardCoder().decode(policyString, ToscaServiceTemplate.class); + assertNotNull(serviceTemplate); + + for (Map<String, ToscaPolicy> foundPolicyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) { + for (Entry<String, ToscaPolicy> policyEntry : foundPolicyMap.entrySet()) { + ToscaPolicy policy = policyEntry.getValue(); + if (policy.getName() == null) { + policy.setName(policyEntry.getKey()); + } + if (policy.getVersion() == null) { + policy.setVersion(PfKey.NULL_KEY_VERSION); + } + if (policy.getTypeVersion() == null) { + policy.setTypeVersion(PfKey.NULL_KEY_VERSION); + } + if (!policyList.contains(policy)) { + policyList.add(policy); + } + } + } + } + + for (ToscaPolicy policy : policyList) { + LOGGER.info("using policy-" + policy.getName() + ":" + policy.getVersion() + ", type-" + policy.getType() + + ":" + policy.getTypeVersion()); + } + } + + @Test + public void testNullList() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build(); + + assertThatThrownBy(() -> { + filter.filter(null); + }).hasMessage("originalList is marked @NonNull but is null"); + } + + @Test + public void testFilterNothing() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build(); + + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertTrue(filteredList.containsAll(policyList)); + } + + @Test + public void testFilterLatestVersion() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().version(ToscaPolicyFilter.LATEST_VERSION).build(); + + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertEquals(15, filteredList.size()); + assertEquals("1.0.0", filteredList.get(7).getVersion()); + assertEquals("1.0.0", filteredList.get(12).getVersion()); + + assertEquals(17, policyList.size()); + assertEquals(15, filteredList.size()); + + policyList.get(10).setVersion("2.0.0"); + policyList.get(16).setVersion("3.4.5"); + filteredList = filter.filter(policyList); + assertEquals(15, filteredList.size()); + assertEquals("2.0.0", filteredList.get(7).getVersion()); + assertEquals("3.4.5", filteredList.get(12).getVersion()); + + policyList.get(10).setVersion("1.0.0"); + policyList.get(16).setVersion("1.0.0"); + filteredList = filter.filter(policyList); + assertEquals(15, filteredList.size()); + assertEquals("1.0.0", filteredList.get(7).getVersion()); + assertEquals("1.0.0", filteredList.get(12).getVersion()); + } + + @Test + public void testFilterNameVersion() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").build(); + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("guard.frequency.scaleout").build(); + filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("guard.frequency.scalein").build(); + filteredList = filter.filter(policyList); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyFilter.builder().version("1.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(17, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version("1.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version("1.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + } + + @Test + public void testFilterTypeVersion() { + ToscaPolicyFilter filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").build(); + List<ToscaPolicy> filteredList = filter.filter(policyList); + assertEquals(4, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.monitoring.cdap.tca.hi.lo.app").build(); + filteredList = filter.filter(policyList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.NonOperational").build(); + filteredList = filter.filter(policyList); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyFilter.builder().typeVersion("0.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(17, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.HpaPolicy").typeVersion("0.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion("0.0.0").build(); + filteredList = filter.filter(policyList); + assertEquals(4, filteredList.size()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifierOptVersion.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java index 999dca565..561b4fb21 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifierOptVersion.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java @@ -28,13 +28,13 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; /** - * Test the other constructors, as {@link TestPojos} tests the other methods. + * Test the other constructors, as {@link PojosTest} tests the other methods. */ -public class TestToscaPolicyIdentifierOptVersion extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> { +public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> { private static final String NAME = "my-name"; private static final String VERSION = "1.2.3"; - public TestToscaPolicyIdentifierOptVersion() { + public ToscaPolicyIdentifierOptVersionTest() { super(ToscaPolicyIdentifierOptVersion.class); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifier.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java index 0dc9eb13c..a53af7b1f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyIdentifier.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java @@ -26,13 +26,13 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; /** - * Test the other constructors, as {@link TestPojos} tests the other methods. + * Test the other constructors, as {@link PojosTest} tests the other methods. */ -public class TestToscaPolicyIdentifier extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> { +public class ToscaPolicyIdentifierTest extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> { private static final String NAME = "my-name"; private static final String VERSION = "1.2.3"; - public TestToscaPolicyIdentifier() { + public ToscaPolicyIdentifierTest() { super(ToscaPolicyIdentifier.class); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java index 881a69d07..f5be66c4a 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicy.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java @@ -20,17 +20,25 @@ package org.onap.policy.models.tosca.authorative.concepts; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; +import java.util.LinkedHashMap; + import org.junit.Test; /** - * Tests methods not tested by {@link TestPojos}. + * Tests methods not tested by {@link PojosTest}. */ -public class TestToscaPolicy { +public class ToscaPolicyTest { @Test public void testGetIdentifier_testGetTypeIdentifier() { + assertThatThrownBy(() -> { + new ToscaPolicy(null); + }).hasMessage("copyObject is marked @NonNull but is null"); + + ToscaPolicy policy = new ToscaPolicy(); policy.setName("my_name"); @@ -45,5 +53,13 @@ public class TestToscaPolicy { ToscaPolicyTypeIdentifier type = policy.getTypeIdentifier(); assertEquals("my_type", type.getName()); assertEquals("3.2.1", type.getVersion()); + + ToscaPolicy clonedPolicy0 = new ToscaPolicy(policy); + assertEquals(0, policy.compareTo(clonedPolicy0)); + + policy.setProperties(new LinkedHashMap<String, Object>()); + policy.getProperties().put("PropertyKey", "PropertyValue"); + ToscaPolicy clonedPolicy1 = new ToscaPolicy(policy); + assertEquals(0, policy.compareTo(clonedPolicy1)); } } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java new file mode 100644 index 000000000..12d81ed53 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java @@ -0,0 +1,175 @@ +/*- + * ============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.authorative.concepts; + +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.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; +import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.models.base.PfKey; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Test of the {@link ToscaPolicyTypeFilter} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyTypeFilterTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeFilterTest.class); + + // @formatter:off + private static final String[] policyTypeResourceNames = { + "policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml", + "policytypes/onap.policies.optimization.AffinityPolicy.yaml", + "policytypes/onap.policies.optimization.DistancePolicy.yaml", + "policytypes/onap.policies.optimization.HpaPolicy.yaml", + "policytypes/onap.policies.optimization.OptimizationPolicy.yaml", + "policytypes/onap.policies.optimization.PciPolicy.yaml", + "policytypes/onap.policies.optimization.QueryPolicy.yaml", + "policytypes/onap.policies.optimization.SubscriberPolicy.yaml", + "policytypes/onap.policies.optimization.Vim_fit.yaml", + "policytypes/onap.policies.optimization.VnfPolicy.yaml", + "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml" + }; + // @formatter:on + + private static List<ToscaPolicyType> typeList = new ArrayList<>(); + + /** + * Set up a Tosca Policy type list for filtering. + * + * @throws CoderException on JSON decoding errors + */ + @BeforeClass + public static void setupTypeList() throws CoderException { + for (String policyTypeResourceName : policyTypeResourceNames) { + String policyTypeString = ResourceUtils.getResourceAsString(policyTypeResourceName); + Object yamlObject = new Yaml().load(policyTypeString); + String yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject); + + ToscaServiceTemplate serviceTemplate = + new StandardCoder().decode(yamlAsJsonString, ToscaServiceTemplate.class); + assertNotNull(serviceTemplate); + + for (Map<String, ToscaPolicyType> foundPolicyTypeMap : serviceTemplate.getPolicyTypes()) { + for (Entry<String, ToscaPolicyType> policyTypeEntry : foundPolicyTypeMap.entrySet()) { + ToscaPolicyType policyType = policyTypeEntry.getValue(); + if (policyType.getName() == null) { + policyType.setName(policyTypeEntry.getKey()); + } + if (policyType.getVersion() == null) { + policyType.setVersion(PfKey.NULL_KEY_VERSION); + } + if (!typeList.contains(policyType)) { + typeList.add(policyType); + } + } + } + } + + for (ToscaPolicyType type : typeList) { + LOGGER.info("using policy type-" + type.getName() + ":" + type.getVersion()); + } + } + + @Test + public void testNullList() { + ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build(); + + assertThatThrownBy(() -> { + filter.filter(null); + }).hasMessage("originalList is marked @NonNull but is null"); + } + + @Test + public void testFilterNothing() { + ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build(); + + List<ToscaPolicyType> filteredList = filter.filter(typeList); + assertTrue(filteredList.containsAll(typeList)); + } + + @Test + public void testFilterLatestVersion() { + ToscaPolicyTypeFilter filter = + ToscaPolicyTypeFilter.builder().version(ToscaPolicyTypeFilter.LATEST_VERSION).build(); + + List<ToscaPolicyType> filteredList = filter.filter(typeList); + assertEquals(13, filteredList.size()); + assertEquals("1.0.0", filteredList.get(0).getVersion()); + assertEquals("0.0.0", filteredList.get(4).getVersion()); + + typeList.get(12).setVersion("2.0.0"); + filteredList = filter.filter(typeList); + assertEquals(13, filteredList.size()); + assertEquals("2.0.0", filteredList.get(0).getVersion()); + assertEquals("0.0.0", filteredList.get(4).getVersion()); + + typeList.get(12).setVersion("1.0.0"); + filteredList = filter.filter(typeList); + assertEquals(13, filteredList.size()); + assertEquals("1.0.0", filteredList.get(0).getVersion()); + assertEquals("0.0.0", filteredList.get(4).getVersion()); + } + + @Test + public void testFilterNameVersion() { + ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().name("onap.policies.Monitoring").build(); + List<ToscaPolicyType> filteredList = filter.filter(typeList); + assertEquals(2, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policy.monitoring.cdap.tca.hi.lo.app").build(); + filteredList = filter.filter(typeList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.LpaPolicy").build(); + filteredList = filter.filter(typeList); + assertEquals(0, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().version("0.0.0").build(); + filteredList = filter.filter(typeList); + assertEquals(9, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version("0.0.0").build(); + filteredList = filter.filter(typeList); + assertEquals(1, filteredList.size()); + + filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version("0.0.1").build(); + filteredList = filter.filter(typeList); + assertEquals(0, filteredList.size()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyTypeIdentifier.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java index 778d60c09..8388f1061 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/TestToscaPolicyTypeIdentifier.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java @@ -26,13 +26,13 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; /** - * Test the other constructors, as {@link TestPojos} tests the other methods. + * Test the other constructors, as {@link PojosTest} tests the other methods. */ -public class TestToscaPolicyTypeIdentifier extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> { +public class ToscaPolicyTypeIdentifierTest extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> { private static final String NAME = "my-name"; private static final String VERSION = "1.2.3"; - public TestToscaPolicyTypeIdentifier() { + public ToscaPolicyTypeIdentifierTest() { super(ToscaPolicyTypeIdentifier.class); } diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java new file mode 100644 index 000000000..59a5a3336 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java @@ -0,0 +1,63 @@ +/*- + * ============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.authorative.concepts; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import java.util.LinkedHashMap; + +import org.junit.Test; + +/** + * Test of the {@link ToscaPolicyType} class. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyTypeTest { + + @Test + public void testToscaPolicyType() { + assertThatThrownBy(() -> { + new ToscaPolicyType(null); + }).hasMessage("copyObject is marked @NonNull but is null"); + + ToscaPolicyType tpt = new ToscaPolicyType(); + tpt.setName("AType"); + tpt.setVersion("1.2.3"); + tpt.setDerivedFrom("AParentType"); + tpt.setDescription("Desc"); + + ToscaPolicyType clonedTpt0 = new ToscaPolicyType(tpt); + assertEquals(0, tpt.compareTo(clonedTpt0)); + + tpt.setMetadata(new LinkedHashMap<>()); + tpt.setProperties(new LinkedHashMap<>()); + + tpt.getMetadata().put("MetaKey0", "Metavalue 0"); + + ToscaProperty tp = new ToscaProperty(); + tpt.getProperties().put("Property0", tp); + + ToscaPolicyType clonedTpt1 = new ToscaPolicyType(tpt); + assertEquals(0, tpt.compareTo(clonedTpt1)); + } +} |