summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-08 05:27:08 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-08 05:27:08 +0000
commitdd92e0c9ad7049a713c363d1c52e29237c07df62 (patch)
tree4c99624b21f5a66a9fb3901dbaeca8eb8d2dab43 /models-pdp/src/main
parent82699a970d5f06c6dc1391d8beb0efe76bf84089 (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'models-pdp/src/main')
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdp.java10
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java21
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpSubGroup.java48
3 files changed, 44 insertions, 35 deletions
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<Pdp>, 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<Pdp>, 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<Pdp>, 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<Pdp>, 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<PdpGroup> {
*
* @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<PdpGroup> {
*
* @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<PdpGroup> {
}
@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<PdpGroup> {
keyList.addAll(jpaPdpSubgroup.getKeys());
}
-
return keyList;
}
@@ -214,7 +215,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
}
@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<PdpGroup> {
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<String, String> propertyEntry : properties.entrySet()) {
if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) {
@@ -242,7 +248,6 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative<PdpGroup> {
}
}
-
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<PdpSubGro
// @formatter:ofF
@OneToMany
- @CollectionTable(joinColumns = {
- @JoinColumn(name = "pdpSubGroupParentKeyName", referencedColumnName = "parentKeyName"),
+ @CollectionTable(
+ joinColumns = { @JoinColumn(name = "pdpSubGroupParentKeyName", referencedColumnName = "parentKeyName"),
@JoinColumn(name = "pdpSubGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"),
- @JoinColumn(name = "pdpSubGroupParentLocalName", referencedColumnName = "parentLocalName"),
- @JoinColumn(name = "pdpSubGroupLocalName", referencedColumnName = "localName")
- })
+ @JoinColumn(name = "pdpSubGroupParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "pdpSubGroupLocalName", referencedColumnName = "localName") })
// formatter:on
private List<JpaPdp> pdpInstances;
@@ -137,7 +136,7 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
*
* @param copyConcept the concept to copy from
*/
- public JpaPdpSubGroup(final JpaPdpSubGroup copyConcept) {
+ public JpaPdpSubGroup(@NonNull final JpaPdpSubGroup copyConcept) {
super(copyConcept);
}
@@ -146,7 +145,7 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
*
* @param authorativeConcept the authorative concept to copy from
*/
- public JpaPdpSubGroup(final PdpSubGroup authorativeConcept) {
+ public JpaPdpSubGroup(@NonNull final PdpSubGroup authorativeConcept) {
this.fromAuthorative(authorativeConcept);
}
@@ -184,35 +183,40 @@ public class JpaPdpSubGroup extends PfConcept implements PfAuthorative<PdpSubGro
}
@Override
- public void fromAuthorative(final PdpSubGroup pdpSubgroup) {
- if (this.getKey().isNullKey()) {
+ public void fromAuthorative(@NonNull final PdpSubGroup pdpSubgroup) {
+ if (this.key == null || this.getKey().isNullKey()) {
this.setKey(new PfReferenceKey());
getKey().setLocalName(pdpSubgroup.getPdpType());
}
this.supportedPolicyTypes = new ArrayList<>();
- 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<PdpSubGro
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
PfValidationResult result = resultIn;
if (key.isNullKey()) {