summaryrefslogtreecommitdiffstats
path: root/applications/guard/src/test/java
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2020-03-11 14:06:42 -0400
committerPamela Dragosh <pdragosh@research.att.com>2020-03-12 09:12:22 -0400
commit2924fa7d806435a3bf9f2cb5abcdb01aa7295b00 (patch)
tree094c3b2140e492f8ffc700f0232405dcf83d2d2e /applications/guard/src/test/java
parent2a65ced426b393e9a6fe34c2c64303b1cc83e1a0 (diff)
Better error handling for decisions
Throw exceptions when requests cannot be created and return error information back. Consolidated some code to avoid sonar duplication issues. Companion review to https://gerrit.onap.org/r/c/policy/models/+/103548 Issue-ID: POLICY-2242 Change-Id: Ic873af933dab82e3aeef6335f55939666be20385 Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'applications/guard/src/test/java')
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java4
-rw-r--r--applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java10
2 files changed, 12 insertions, 2 deletions
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
index b5585a7c..5b62f364 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/CoordinationTest.java
@@ -23,6 +23,7 @@
package org.onap.policy.xacml.pdp.application.guard;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import com.att.research.xacml.api.Response;
import java.io.File;
@@ -191,7 +192,8 @@ public class CoordinationTest {
// the application.
//
CoordinationGuardTranslator translator = new CoordinationGuardTranslator();
- assertThat(translator.convertRequest(null)).isNull();
+ assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+ translator.convertRequest(null)).withMessage("this convertRequest shouldn't be used");
assertThat(translator.convertResponse(null)).isNull();
assertThat(CoordinationGuardTranslator.loadCoordinationDirectiveFromFile(
policyFolder.getRoot().getAbsolutePath() + "/nonexist.yaml")).isNull();
diff --git a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java
index b3ef3bdd..41fd4705 100644
--- a/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java
+++ b/applications/guard/src/test/java/org/onap/policy/xacml/pdp/application/guard/GuardPolicyRequestTest.java
@@ -23,16 +23,18 @@
package org.onap.policy.xacml.pdp.application.guard;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
+import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
public class GuardPolicyRequestTest {
@Test
- public void testAnomalies() {
+ public void testAnomalies() throws ToscaPolicyConversionException {
DecisionRequest decisionRequest = new DecisionRequest();
assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
@@ -82,6 +84,12 @@ public class GuardPolicyRequestTest {
resources.put("guard", guard);
decisionRequest.setResource(resources);
assertThat(GuardPolicyRequest.createInstance(decisionRequest)).isNotNull();
+
+ guard.put("vfCount", "I am not valid");
+ resources.put("guard", guard);
+ decisionRequest.setResource(resources);
+ assertThatExceptionOfType(ToscaPolicyConversionException.class).isThrownBy(() ->
+ GuardPolicyRequest.createInstance(decisionRequest));
}
}