diff options
Diffstat (limited to 'models-pdp/src')
4 files changed, 668 insertions, 169 deletions
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 +} |