From dd92e0c9ad7049a713c363d1c52e29237c07df62 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 8 Apr 2019 05:27:08 +0000 Subject: Add unit test for PDP groups Unit test for the JPA concepts in models-pdp. Issue-ID: POLICY-1095 Change-Id: Id33626f3789da45e36935edf564003651e9ce7c4 Signed-off-by: liamfallon --- .../models/pdp/persistence/concepts/JpaPdp.java | 10 ++--- .../pdp/persistence/concepts/JpaPdpGroup.java | 21 ++++++---- .../pdp/persistence/concepts/JpaPdpSubGroup.java | 48 ++++++++++++---------- 3 files changed, 44 insertions(+), 35 deletions(-) (limited to 'models-pdp/src/main') diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java index 0a9aa5874..627641825 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java @@ -111,7 +111,7 @@ public class JpaPdp extends PfConcept implements PfAuthorative, Serializabl * * @param copyConcept the concept to copy from */ - public JpaPdp(final JpaPdp copyConcept) { + public JpaPdp(@NonNull final JpaPdp copyConcept) { super(copyConcept); } @@ -120,7 +120,7 @@ public class JpaPdp extends PfConcept implements PfAuthorative, Serializabl * * @param authorativeConcept the authorative concept to copy from */ - public JpaPdp(final Pdp authorativeConcept) { + public JpaPdp(@NonNull final Pdp authorativeConcept) { this.fromAuthorative(authorativeConcept); } @@ -137,8 +137,8 @@ public class JpaPdp extends PfConcept implements PfAuthorative, Serializabl } @Override - public void fromAuthorative(final Pdp pdp) { - if (this.getKey().isNullKey()) { + public void fromAuthorative(@NonNull final Pdp pdp) { + if (this.key == null || this.getKey().isNullKey()) { this.setKey(new PfReferenceKey()); getKey().setLocalName(pdp.getInstanceId()); } @@ -163,7 +163,7 @@ public class JpaPdp extends PfConcept implements PfAuthorative, Serializabl } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { + public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { PfValidationResult result = resultIn; if (key.isNullKey()) { diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java index 9c896a31b..71f27c48b 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java @@ -131,7 +131,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { * * @param copyConcept the concept to copy from */ - public JpaPdpGroup(final JpaPdpGroup copyConcept) { + public JpaPdpGroup(@NonNull final JpaPdpGroup copyConcept) { super(copyConcept); } @@ -140,7 +140,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { * * @param authorativeConcept the authorative concept to copy from */ - public JpaPdpGroup(final PdpGroup authorativeConcept) { + public JpaPdpGroup(@NonNull final PdpGroup authorativeConcept) { this.fromAuthorative(authorativeConcept); } @@ -164,8 +164,10 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { } @Override - public void fromAuthorative(final PdpGroup pdpGroup) { - this.setKey(new PfConceptKey(pdpGroup.getName(), pdpGroup.getVersion())); + public void fromAuthorative(@NonNull final PdpGroup pdpGroup) { + if (this.key == null || this.getKey().isNullKey()) { + this.setKey(new PfConceptKey(pdpGroup.getName(), pdpGroup.getVersion())); + } this.description = pdpGroup.getDescription(); this.pdpGroupState = pdpGroup.getPdpGroupState(); @@ -190,7 +192,6 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { keyList.addAll(jpaPdpSubgroup.getKeys()); } - return keyList; } @@ -214,7 +215,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { } @Override - public PfValidationResult validate(final PfValidationResult resultIn) { + public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { PfValidationResult result = resultIn; if (key.isNullKey()) { @@ -224,11 +225,16 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { result = key.validate(result); - if (StringUtils.isBlank(description)) { + if (description != null && StringUtils.isBlank(description)) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "description may not be blank")); } + if (pdpGroupState == null) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "pdpGroupState may not be null")); + } + if (properties != null) { for (Entry propertyEntry : properties.entrySet()) { if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { @@ -242,7 +248,6 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { } } - if (pdpSubGroups == null) { result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "a PDP group must have a list of PDP subgroups")); 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 1937cbfbb..d51cfc67e 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 @@ -91,12 +91,11 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative pdpInstances; @@ -137,7 +136,7 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative(); - for (ToscaPolicyTypeIdentifier supportedPolicyType : pdpSubgroup.getSupportedPolicyTypes()) { - this.supportedPolicyTypes - .add(new PfConceptKey(supportedPolicyType.getName(), supportedPolicyType.getVersion())); + if (pdpSubgroup.getSupportedPolicyTypes() != null) { + for (ToscaPolicyTypeIdentifier supportedPolicyType : pdpSubgroup.getSupportedPolicyTypes()) { + this.supportedPolicyTypes + .add(new PfConceptKey(supportedPolicyType.getName(), supportedPolicyType.getVersion())); + } } - this.policies = new ArrayList<>(); - for (ToscaPolicyIdentifier toscaPolicyIdentifier : pdpSubgroup.getPolicies()) { - this.policies.add(new PfConceptKey(toscaPolicyIdentifier.getName(), toscaPolicyIdentifier.getVersion())); + if (pdpSubgroup.getPolicies() != null) { + for (ToscaPolicyIdentifier toscaPolicyIdentifier : pdpSubgroup.getPolicies()) { + this.policies + .add(new PfConceptKey(toscaPolicyIdentifier.getName(), toscaPolicyIdentifier.getVersion())); + } } - this.currentInstanceCount = pdpSubgroup.getCurrentInstanceCount(); this.desiredInstanceCount = pdpSubgroup.getDesiredInstanceCount(); this.properties = (pdpSubgroup.getProperties() == null ? null : new LinkedHashMap<>(pdpSubgroup.getProperties())); this.pdpInstances = new ArrayList<>(); - for (Pdp pdp : pdpSubgroup.getPdpInstances()) { - JpaPdp jpaPdp = new JpaPdp(); - jpaPdp.setKey(new PfReferenceKey(getKey(), pdp.getInstanceId())); - jpaPdp.fromAuthorative(pdp); - this.pdpInstances.add(jpaPdp); + if (pdpSubgroup.getPdpInstances() != null) { + for (Pdp pdp : pdpSubgroup.getPdpInstances()) { + JpaPdp jpaPdp = new JpaPdp(); + jpaPdp.setKey(new PfReferenceKey(getKey(), pdp.getInstanceId())); + jpaPdp.fromAuthorative(pdp); + this.pdpInstances.add(jpaPdp); + } } } @@ -262,7 +266,7 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative