aboutsummaryrefslogtreecommitdiffstats
path: root/applications/optimization/src/test
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-12-11 10:00:21 -0500
committerPamela Dragosh <pdragosh@research.att.com>2019-12-23 13:33:19 +0000
commit85744c81b27a833db4a8089c90a4faeb98d8f349 (patch)
tree290b6c6f6dfcc7c108182c6af44116e7bcfae581 /applications/optimization/src/test
parent4ff3b261231274ec9f3cd957ba50108fef3e0eb5 (diff)
Add optimization subscriber request
Adding support for a preliminary request to pull subscriber details. The returned decision adds scope attributes for the original request. Fixed some checkstyle issues due to new checkstyle requirements. Issue-ID: POLICY-2066 Change-Id: Ief02d896ce33e4864bb20e9185b0d0f5eb254bfd Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/optimization/src/test')
-rw-r--r--applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java82
-rw-r--r--applications/optimization/src/test/resources/decision.optimization.input.json3
-rw-r--r--applications/optimization/src/test/resources/vCPE.policies.optimization.input.tosca.yaml4
3 files changed, 66 insertions, 23 deletions
diff --git a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
index 1cb8f32a..e457e2f2 100644
--- a/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
+++ b/applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java
@@ -30,8 +30,6 @@ import static org.mockito.Mockito.when;
import com.att.research.xacml.api.Response;
import com.google.common.collect.Lists;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Collection;
@@ -162,6 +160,9 @@ public class OptimizationPdpApplicationTest {
service.initialize(propertiesFile.toPath().getParent(), clientParams);
}
+ /**
+ * Simply test some of the simple methods for the application.
+ */
@Test
public void test01Basics() {
//
@@ -169,7 +170,7 @@ public class OptimizationPdpApplicationTest {
//
assertThat(service.applicationName()).isNotEmpty();
//
- // Decisions
+ // Does it return the correct decisions
//
assertThat(service.actionDecisionsSupported().size()).isEqualTo(1);
assertThat(service.actionDecisionsSupported()).contains("optimize");
@@ -185,6 +186,11 @@ public class OptimizationPdpApplicationTest {
"onap.foobar", "1.0.0"))).isFalse();
}
+ /**
+ * With no policies loaded, there should be 0 policies returned.
+ *
+ * @throws CoderException CoderException
+ */
@Test
public void test02NoPolicies() throws CoderException {
//
@@ -198,9 +204,13 @@ public class OptimizationPdpApplicationTest {
assertThat(decision.getKey().getPolicies().size()).isEqualTo(0);
}
+ /**
+ * Should return ONLY default policies.
+ *
+ * @throws XacmlApplicationException could not load policies
+ */
@Test
- public void test03OptimizationDefault() throws CoderException, FileNotFoundException, IOException,
- XacmlApplicationException {
+ public void test03OptimizationDefault() throws XacmlApplicationException {
//
// Now load all the optimization policies
//
@@ -218,10 +228,12 @@ public class OptimizationPdpApplicationTest {
validateDecision(response, baseRequest);
}
+ /**
+ * Should only return default HPA policy type.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test04OptimizationDefaultHpa() throws CoderException, FileNotFoundException, IOException,
- XacmlApplicationException {
+ public void test04OptimizationDefaultHpa() {
//
// Add in policy type
//
@@ -244,6 +256,9 @@ public class OptimizationPdpApplicationTest {
validateDecision(response, baseRequest);
}
+ /**
+ * Refine for US only policies.
+ */
@SuppressWarnings("unchecked")
@Test
public void test05OptimizationDefaultGeography() throws CoderException {
@@ -267,9 +282,12 @@ public class OptimizationPdpApplicationTest {
validateDecision(response, baseRequest);
}
+ /**
+ * Add more refinement for service.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test06OptimizationDefaultGeographyAndService() throws CoderException {
+ public void test06OptimizationDefaultGeographyAndService() {
//
// Add vCPE to the service list
//
@@ -280,16 +298,19 @@ public class OptimizationPdpApplicationTest {
DecisionResponse response = makeDecision();
assertThat(response).isNotNull();
- assertThat(response.getPolicies().size()).isEqualTo(5);
+ assertThat(response.getPolicies().size()).isEqualTo(3);
//
// Validate it
//
validateDecision(response, baseRequest);
}
+ /**
+ * Add more refinement for specific resource.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test07OptimizationDefaultGeographyAndServiceAndResource() throws CoderException {
+ public void test07OptimizationDefaultGeographyAndServiceAndResource() {
//
// Add vG to the resource list
//
@@ -300,75 +321,91 @@ public class OptimizationPdpApplicationTest {
DecisionResponse response = makeDecision();
assertThat(response).isNotNull();
- assertThat(response.getPolicies().size()).isEqualTo(8);
+ assertThat(response.getPolicies().size()).isEqualTo(6);
//
// Validate it
//
validateDecision(response, baseRequest);
}
+ /**
+ * Now we need to add in subscriberName in order to get scope for gold.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test08OptimizationGeographyAndServiceAndResourceAndScope() throws CoderException {
+ public void test08OptimizationGeographyAndServiceAndResourceAndScopeIsGoldSubscriber() {
//
// Add gold as a scope
//
- ((List<String>)baseRequest.getResource().get("scope")).add("gold");
+ //((List<String>)baseRequest.getResource().get("scope")).add("gold");
+ ((List<String>)baseRequest.getContext().get("subscriberName")).add("subscriber_a");
//
// Ask for a decision for specific US vCPE vG gold
//
DecisionResponse response = makeDecision();
assertThat(response).isNotNull();
- assertThat(response.getPolicies().size()).isEqualTo(8);
+ assertThat(response.getPolicies().size()).isEqualTo(6);
//
// Validate it
//
validateDecision(response, baseRequest);
}
+ /**
+ * Add a subscriber that should be platinum.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test09OptimizationGeographyAndServiceAndResourceAndScopeIsGoldOrPlatinum() throws CoderException {
+ public void test09OptimizationGeographyAndServiceAndResourceAndScopeGoldOrPlatinumSubscriber() {
//
// Add platinum to the scope list: this is now gold OR platinum
//
- ((List<String>)baseRequest.getResource().get("scope")).add("platinum");
+ ((List<String>)baseRequest.getResource().get("scope")).remove("gold");
+ ((List<String>)baseRequest.getContext().get("subscriberName")).add("subscriber_x");
//
// Ask for a decision for specific US vCPE vG (gold or platinum)
//
DecisionResponse response = makeDecision();
assertThat(response).isNotNull();
- assertThat(response.getPolicies().size()).isEqualTo(10);
+ assertThat(response.getPolicies().size()).isEqualTo(8);
//
// Validate it
//
validateDecision(response, baseRequest);
}
+ /**
+ * Remove gold subscriber, keep the platinum one.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test10OptimizationGeographyAndServiceAndResourceAndScopeNotGold() throws CoderException {
+ public void test10OptimizationGeographyAndServiceAndResourceAndScopeNotGoldStillPlatinum() {
//
// Add gold as a scope
//
((List<String>)baseRequest.getResource().get("scope")).remove("gold");
+ ((List<String>)baseRequest.getResource().get("scope")).remove("platinum");
+ ((List<String>)baseRequest.getContext().get("subscriberName")).remove("subscriber_a");
//
// Ask for a decision for specific US vCPE vG gold
//
DecisionResponse response = makeDecision();
assertThat(response).isNotNull();
- assertThat(response.getPolicies().size()).isEqualTo(9);
+ assertThat(response.getPolicies().size()).isEqualTo(7);
//
// Validate it
//
validateDecision(response, baseRequest);
}
+ /**
+ * Filter by Affinity policy.
+ */
@Test
- public void test11OptimizationPolicyTypeDefault() throws CoderException {
+ public void test11OptimizationPolicyTypeDefault() {
//
// Add in policy type
//
@@ -387,9 +424,12 @@ public class OptimizationPdpApplicationTest {
validateDecision(response, baseRequest);
}
+ /**
+ * Now filter by HPA policy type.
+ */
@SuppressWarnings("unchecked")
@Test
- public void test12OptimizationPolicyTypeDefault() throws CoderException {
+ public void test12OptimizationPolicyTypeDefault() {
//
// Add in another policy type
//
diff --git a/applications/optimization/src/test/resources/decision.optimization.input.json b/applications/optimization/src/test/resources/decision.optimization.input.json
index 3872ca90..523b9d5d 100644
--- a/applications/optimization/src/test/resources/decision.optimization.input.json
+++ b/applications/optimization/src/test/resources/decision.optimization.input.json
@@ -2,6 +2,9 @@
"ONAPName": "OOF",
"ONAPComponent": "OOF-component",
"ONAPInstance": "OOF-component-instance",
+ "context" : {
+ "subscriberName": []
+ },
"action": "optimize",
"resource": {
"scope": [],
diff --git a/applications/optimization/src/test/resources/vCPE.policies.optimization.input.tosca.yaml b/applications/optimization/src/test/resources/vCPE.policies.optimization.input.tosca.yaml
index 3eedac95..fb848637 100644
--- a/applications/optimization/src/test/resources/vCPE.policies.optimization.input.tosca.yaml
+++ b/applications/optimization/src/test/resources/vCPE.policies.optimization.input.tosca.yaml
@@ -291,7 +291,7 @@ topology_template:
scope: []
services: [vCPE]
identity: subscriber_vCPE
- properties:
+ subscriberProperties:
subscriberName: [subscriber_x, subscriber_y]
subscriberRole: [platinum]
provStatus: [CAPPED]
@@ -307,7 +307,7 @@ topology_template:
scope: []
services: [vCPE]
identity: subscriber_vCPE
- properties:
+ subscriberProperties:
subscriberName: [subscriber_a, subscriber_b]
subscriberRole: [gold]
provStatus: [CAPPED]