aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java5
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java17
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupsTest.java12
3 files changed, 26 insertions, 8 deletions
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
index 49dfd6fbb..4cb0ac54e 100644
--- a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
+++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpGroup.java
@@ -89,6 +89,11 @@ public class PdpGroup implements PfNameVersion, Comparable<PdpGroup> {
result.validateNotNull("name", name);
result.validateNotNullList("pdpSubgroups", pdpSubgroups, PdpSubGroup::validatePapRest);
+ if (pdpSubgroups != null && pdpSubgroups.isEmpty()) {
+ result.addResult(new ObjectValidationResult("pdpSubgroups", pdpSubgroups, ValidationStatus.INVALID,
+ "is empty"));
+ }
+
checkDuplicateSubgroups(result);
return result;
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java
index 0df2d34d9..a717dc2d8 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java
@@ -56,7 +56,7 @@ public class PdpGroupTest {
// verify with null values
assertEquals("PdpGroup(name=null, description=null, pdpGroupState=null, " + "properties=null, pdpSubgroups=[])",
- new PdpGroup(orig).toString());
+ new PdpGroup(orig).toString());
// verify with all values
orig.setDescription("my-descript");
@@ -77,11 +77,11 @@ public class PdpGroupTest {
orig.setProperties(props);
assertEquals("PdpGroup(name=my-name, description=my-description, "
- + "pdpGroupState=SAFE, properties={key-A=value-A, key-B=value-B}, "
- + "pdpSubgroups=[PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], "
- + "currentInstanceCount=10, desiredInstanceCount=0, properties=null, pdpInstances=[]), "
- + "PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], currentInstanceCount=11, "
- + "desiredInstanceCount=0, properties=null, pdpInstances=[])])", new PdpGroup(orig).toString());
+ + "pdpGroupState=SAFE, properties={key-A=value-A, key-B=value-B}, "
+ + "pdpSubgroups=[PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], "
+ + "currentInstanceCount=10, desiredInstanceCount=0, properties=null, pdpInstances=[]), "
+ + "PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], currentInstanceCount=11, "
+ + "desiredInstanceCount=0, properties=null, pdpInstances=[])])", new PdpGroup(orig).toString());
}
@Test
@@ -154,6 +154,11 @@ public class PdpGroupTest {
group2.setPdpSubgroups(null);
assertInvalid(group2);
+ // empty subgroup list
+ group2 = new PdpGroup(group);
+ group2.setPdpSubgroups(Collections.emptyList());
+ assertInvalid(group2);
+
// null subgroup
group2 = new PdpGroup(group);
group2.setPdpSubgroups(Arrays.asList(subgroup1, null));
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupsTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupsTest.java
index e0fafc18d..bd98f18c3 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupsTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupsTest.java
@@ -34,6 +34,7 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
public class PdpGroupsTest {
@@ -41,11 +42,18 @@ public class PdpGroupsTest {
public void testValidatePapRest_toMapList() {
PdpGroup group1 = new PdpGroup();
group1.setName("group-1");
- group1.setPdpSubgroups(Collections.emptyList());
+
+ PdpSubGroup subgrp = new PdpSubGroup();
+ subgrp.setDesiredInstanceCount(1);
+ subgrp.setPdpType("pdp-type");
+ subgrp.setSupportedPolicyTypes(Arrays.asList(new ToscaPolicyTypeIdentifier("policy-type", "9.8.7")));
+ subgrp.setPolicies(Collections.emptyList());
+
+ group1.setPdpSubgroups(Arrays.asList(subgrp));
PdpGroup group2 = new PdpGroup();
group2.setName("group-2");
- group2.setPdpSubgroups(Collections.emptyList());
+ group2.setPdpSubgroups(Arrays.asList(subgrp));
PdpGroups groups = new PdpGroups();
groups.setGroups(Arrays.asList(group1, group2));