summaryrefslogtreecommitdiffstats
path: root/models-pdp/src/test/java
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-04-08 17:30:54 +0000
committerliamfallon <liam.fallon@est.tech>2019-04-08 17:30:54 +0000
commit0b15f3bf60162a62505593186737bca98bd4349c (patch)
tree0935b5d9321c9a988256741309d9dfdb688f4521 /models-pdp/src/test/java
parenta32b49c3ec54e5f3bf23634a5fb538909905f8e6 (diff)
Add lists and tests for PDP filters
The policy type and policy filters for PDP groups are added in this review. Also filter tests for PDP group filter is completed. Issue-ID: POLICY-1095 Change-Id: Ia28776c809f2ab879af4007b3480621637a83f69 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-pdp/src/test/java')
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java)4
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java222
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java)4
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpInstanceDetailsTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java)4
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java)2
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStateChangeTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java)4
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java)4
-rw-r--r--models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpUpdateTest.java (renamed from models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java)4
8 files changed, 235 insertions, 13 deletions
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java
index 1813dde7d..d22642d98 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestModels.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/ModelsTest.java
@@ -35,12 +35,12 @@ import org.onap.policy.common.utils.validation.ToStringTester;
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-public class TestModels {
+public class ModelsTest {
@Test
public void testPdpModels() {
final Validator validator = ValidatorBuilder.create().with(new ToStringTester()).with(new SetterTester())
.with(new GetterTester()).build();
- validator.validate(TestModels.class.getPackage().getName(), new FilterPackageInfo());
+ validator.validate(ModelsTest.class.getPackage().getName(), new FilterPackageInfo());
}
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java
index 61974dc89..75ec4d169 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupFilterTest.java
@@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
@@ -31,6 +32,9 @@ import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.pdp.enums.PdpState;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* Test of the {@link PdpGroupFilter} class.
@@ -105,4 +109,222 @@ public class PdpGroupFilterTest {
filteredList = filter.filter(pdpGroupList);
assertEquals(0, filteredList.size());
}
+
+ @Test
+ public void testFilterPdpGroupState() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().groupState(PdpState.ACTIVE).build();
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ filter = PdpGroupFilter.builder().groupState(PdpState.PASSIVE).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+
+ filter = PdpGroupFilter.builder().groupState(PdpState.TEST).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ filter = PdpGroupFilter.builder().groupState(PdpState.SAFE).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ filter = PdpGroupFilter.builder().groupState(PdpState.TERMINATED).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+ }
+
+ @Test
+ public void testFilterPdpType() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().pdpType("APEX").build();
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(5, filteredList.size());
+
+ filter = PdpGroupFilter.builder().pdpType("DROOLS").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+
+ filter = PdpGroupFilter.builder().pdpType("XACML").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+ }
+
+ @Test
+ public void testFilterPdpState() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().pdpState(PdpState.ACTIVE).build();
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(3, filteredList.size());
+
+ filter = PdpGroupFilter.builder().pdpState(PdpState.PASSIVE).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(3, filteredList.size());
+
+ filter = PdpGroupFilter.builder().pdpState(PdpState.SAFE).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+
+ filter = PdpGroupFilter.builder().pdpState(PdpState.TEST).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+ }
+
+ @Test
+ public void testFilterPolicyType() {
+ List<ToscaPolicyTypeIdentifier> identifierList = new ArrayList<>();
+
+ identifierList.add(new ToscaPolicyTypeIdentifier("Nonexistant", "1.2.3"));
+ PdpGroupFilter filter =
+ PdpGroupFilter.builder().policyTypeList(identifierList).build();
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(4, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(4, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.2", "7.8.9"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyTypeIdentifier("Nonexistant", "1.2.3"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "9.9.9"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.2", "7.8.9"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(5, filteredList.size());
+
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.2", "7.8.9"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.0", "1.2.3"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.1", "4.5.6"));
+ identifierList.add(new ToscaPolicyTypeIdentifier("policy.type.3", "0.1.2"));
+ filter = PdpGroupFilter.builder().policyTypeList(identifierList).matchPolicyTypesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+ }
+
+ @Test
+ public void testFilterPolicy() {
+ List<ToscaPolicyIdentifier> identifierList = new ArrayList<>();
+
+ identifierList.add(new ToscaPolicyIdentifier("Nonexistant", "1.2.3"));
+ PdpGroupFilter filter =
+ PdpGroupFilter.builder().policyList(identifierList).build();
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyIdentifier("Policy0", "9.9.9"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(4, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyIdentifier("Policy1", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyIdentifier("Policy3", "1.2.3"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+ identifierList.clear();
+
+ identifierList.add(new ToscaPolicyIdentifier("Nonexistant", "1.2.3"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy0", "9.9.9"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy1", "4.5.6"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy3", "1.2.3"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(5, filteredList.size());
+
+ filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(3, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyIdentifier("Policy0", "4.5.6"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy1", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ identifierList.clear();
+ identifierList.add(new ToscaPolicyIdentifier("Policy2", "4.5.6"));
+ identifierList.add(new ToscaPolicyIdentifier("Policy3", "1.2.3"));
+ filter = PdpGroupFilter.builder().policyList(identifierList).matchPoliciesExactly(true).build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+ }
}
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java
index 4698ece7b..77666b228 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpGroup.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpGroupTest.java
@@ -34,9 +34,9 @@ import org.junit.Test;
import org.onap.policy.models.pdp.enums.PdpState;
/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Test the copy constructor, as {@link ModelsTest} tests the other methods.
*/
-public class TestPdpGroup {
+public class PdpGroupTest {
@Test
public void testCopyConstructor() {
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpInstanceDetailsTest.java
index 79bb52ee8..e1c76671a 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpInstanceDetails.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpInstanceDetailsTest.java
@@ -28,9 +28,9 @@ import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Test the copy constructor, as {@link ModelsTest} tests the other methods.
*/
-public class TestPdpInstanceDetails {
+public class PdpInstanceDetailsTest {
@Test
public void testCopyConstructor() {
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java
index 0d3f591c7..bc90f649b 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java
@@ -32,7 +32,7 @@ import org.onap.policy.models.pdp.enums.PdpMessageType;
/**
* Tests methods not already tested by {@link TestModels}.
*/
-public class TestPdpMessage {
+public class PdpMessageTest {
private static final String PDP_NAME = "pdpA";
private static final String PDP_GROUP = "groupA";
private static final String PDP_SUBGROUP = "subgroupA";
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStateChangeTest.java
index 55eaedc26..f50d2a7b7 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpStateChange.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpStateChangeTest.java
@@ -29,9 +29,9 @@ import org.junit.Test;
import org.onap.policy.models.pdp.enums.PdpState;
/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Test the copy constructor, as {@link ModelsTest} tests the other methods.
*/
-public class TestPdpStateChange {
+public class PdpStateChangeTest {
@Test
public void testCopyConstructor() {
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java
index c80745d76..4284f71c4 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpSubGroup.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpSubGroupTest.java
@@ -33,9 +33,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Test the copy constructor, as {@link ModelsTest} tests the other methods.
*/
-public class TestPdpSubGroup {
+public class PdpSubGroupTest {
@Test
public void testCopyConstructor() {
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpUpdateTest.java
index b366088d1..8889e483f 100644
--- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpUpdate.java
+++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpUpdateTest.java
@@ -32,9 +32,9 @@ import org.junit.Test;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
- * Test the copy constructor, as {@link TestModels} tests the other methods.
+ * Test the copy constructor, as {@link ModelsTest} tests the other methods.
*/
-public class TestPdpUpdate {
+public class PdpUpdateTest {
@Test
public void testCopyConstructor() {