aboutsummaryrefslogtreecommitdiffstats
path: root/applications/optimization/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-09-30 11:54:21 -0400
committerJim Hahn <jrh3@att.com>2020-09-30 12:23:56 -0400
commit57e705469481f446aeada858c8eb411c5cccebc8 (patch)
treed29c0a51797ee984808b526092a288f3afff80ae /applications/optimization/src/test
parent97be46af1b09c5fa6be63f8ba0c0843c4ce0e94c (diff)
Fix new sonars in xacml-pdp
Addressed the following sonar issues: - extract common test method - too many assertions in a test method Issue-ID: POLICY-2681 Change-Id: I7438be8286d52cd8479c66542fc785b27448972b Signed-off-by: Jim Hahn <jrh3@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.java124
1 files changed, 32 insertions, 92 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 862f75a6..1a1e7566 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
@@ -224,17 +224,8 @@ public class OptimizationPdpApplicationTest {
List<ToscaPolicy> loadedPolicies = TestUtils.loadPolicies("src/test/resources/test-optimization-policies.yaml",
service);
assertThat(loadedPolicies).isNotNull().hasSize(14);
- //
- // Ask for a decision for available default policies
- //
- DecisionResponse response = makeDecision();
- assertThat(response).isNotNull();
- assertThat(response.getPolicies()).hasSize(2);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(2);
}
/**
@@ -279,16 +270,8 @@ public class OptimizationPdpApplicationTest {
// Add US to the geography list
//
((List<String>) baseRequest.getResource().get("geography")).add("US");
- //
- // Ask for a decision for default US Policy
- //
- DecisionResponse response = makeDecision();
- assertThat(response).isNotNull();
- assertThat(response.getPolicies()).hasSize(2);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+
+ validateDecisionCount(2);
}
/**
@@ -301,17 +284,8 @@ public class OptimizationPdpApplicationTest {
// Add vCPE to the service list
//
((List<String>) baseRequest.getResource().get("services")).add("vCPE");
- //
- // Ask for a decision for default US policy for vCPE service
- //
- DecisionResponse response = makeDecision();
- assertThat(response).isNotNull();
- assertThat(response.getPolicies()).hasSize(3);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(3);
}
/**
@@ -324,17 +298,8 @@ public class OptimizationPdpApplicationTest {
// Add vG to the resource list
//
((List<String>) baseRequest.getResource().get("resources")).add("vG");
- //
- // Ask for a decision for default US service vCPE resource vG policy
- //
- DecisionResponse response = makeDecision();
- assertThat(response).isNotNull();
- assertThat(response.getPolicies()).hasSize(6);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(6);
}
/**
@@ -347,18 +312,8 @@ public class OptimizationPdpApplicationTest {
// Add gold as a scope
//
((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()).hasSize(6);
- assertThat(response.getAdvice()).hasSize(2);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(6, 2);
}
/**
@@ -372,18 +327,8 @@ public class OptimizationPdpApplicationTest {
//
((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()).hasSize(8);
- assertThat(response.getAdvice()).hasSize(2);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(8, 2);
}
/**
@@ -398,17 +343,8 @@ public class OptimizationPdpApplicationTest {
((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()).hasSize(7);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(7);
}
/**
@@ -421,17 +357,8 @@ public class OptimizationPdpApplicationTest {
//
List<String> policyTypes = Lists.newArrayList("onap.policies.optimization.resource.AffinityPolicy");
baseRequest.getResource().put("policy-type", policyTypes);
- //
- // Ask for a decision for default
- //
- DecisionResponse response = makeDecision();
- assertThat(response).isNotNull();
- assertThat(response.getPolicies()).hasSize(1);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(1);
}
/**
@@ -445,17 +372,8 @@ public class OptimizationPdpApplicationTest {
//
((List<String>) baseRequest.getResource().get("policy-type"))
.add("onap.policies.optimization.resource.HpaPolicy");
- //
- // Ask for a decision for default
- //
- DecisionResponse response = makeDecision();
- assertThat(response).isNotNull();
- assertThat(response.getPolicies()).hasSize(2);
- //
- // Validate it
- //
- validateDecision(response, baseRequest);
+ validateDecisionCount(2);
}
@Test
@@ -504,6 +422,28 @@ public class OptimizationPdpApplicationTest {
return decision.getKey();
}
+ private DecisionResponse validateDecisionCount(int expectedPolicyCount) {
+ //
+ // Ask for a decision for default
+ //
+ DecisionResponse response = makeDecision();
+
+ assertThat(response).isNotNull();
+ assertThat(response.getPolicies()).hasSize(expectedPolicyCount);
+ //
+ // Validate it
+ //
+ validateDecision(response, baseRequest);
+
+ return response;
+ }
+
+ private void validateDecisionCount(int expectedPolicyCount, int expectedAdviceCount) {
+ DecisionResponse response = validateDecisionCount(expectedPolicyCount);
+
+ assertThat(response.getAdvice()).hasSize(expectedAdviceCount);
+ }
+
@SuppressWarnings("unchecked")
private void validateDecision(DecisionResponse decision, DecisionRequest request) {
for (Entry<String, Object> entrySet : decision.getPolicies().entrySet()) {