Merge "Add prefix matching for policy version"
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 49dfd6f..4cb0ac5 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 @@
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 0df2d34..a717dc2 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 @@
// 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 @@
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 @@
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 e0fafc1..bd98f18 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.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 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));