aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2020-06-30 12:28:33 +0100
committerwaynedunican <wayne.dunican@est.tech>2020-07-01 16:51:35 +0100
commit99231bc9fdb6feb62b9ba3e50796159ed8743b60 (patch)
tree52c14707d8f3ce5ec53e9c01cc4256d7280e913d
parentfd62fcfdf1bb55a9ece78b356c04359883072ee7 (diff)
Replace try/catch blocks with assertj - xacml-pdp
Replaced try/catch blocks in policy/xacml-pdp with assertj assertions Issue-ID: POLICY-2451 Change-Id: I3e6947a61e0000561c7053a1cdede9ae5825e5ca Signed-off-by: waynedunican <wayne.dunican@est.tech>
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java11
-rw-r--r--applications/optimization/src/test/java/org/onap/policy/xacml/pdp/application/optimization/OptimizationPdpApplicationTest.java13
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java13
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java50
4 files changed, 37 insertions, 50 deletions
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java
index 9b489a67..508b96ea 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/matchable/MatchablePolicyTypeTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +33,6 @@ import com.att.research.xacml.api.XACML3;
import com.att.research.xacml.std.IdentifierImpl;
import com.att.research.xacml.util.XACMLPolicyWriter;
import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -230,12 +230,9 @@ public class MatchablePolicyTypeTest implements MatchableCallback {
//
// Dump it out so we can see what was created
//
- try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
- XACMLPolicyWriter.writePolicyFile(os, policy);
- LOGGER.info("{}", os);
- } catch (IOException e) {
- LOGGER.error("Failed to create byte array stream", e);
- }
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ XACMLPolicyWriter.writePolicyFile(os, policy);
+ LOGGER.info("{}", os);
//
// Sanity check - the example policy should have each possible match type plus
// an extra one for the list and an extra one for the map.
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 631a359c..862f75a6 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
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- Modifications Copyright (C) 2019 Nordix Foundation.
+ Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -468,17 +468,12 @@ public class OptimizationPdpApplicationTest {
//
// Serialize it into a class
//
- ToscaServiceTemplate serviceTemplate;
- try {
- serviceTemplate = yamlCoder.decode(policyYaml, ToscaServiceTemplate.class);
- } catch (CoderException e) {
- throw new XacmlApplicationException("Failed to decode policy from resource file", e);
- }
+ JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
+ ToscaServiceTemplate serviceTemplate = yamlCoder.decode(policyYaml, ToscaServiceTemplate.class);
+ jtst.fromAuthorative(serviceTemplate);
//
// Make sure all the fields are setup properly
//
- JpaToscaServiceTemplate jtst = new JpaToscaServiceTemplate();
- jtst.fromAuthorative(serviceTemplate);
ToscaServiceTemplate completedJtst = jtst.toAuthorative();
//
// Get the policies
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
index a59fee32..52dbff4a 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/parameters/TestXacmlPdpParameterHandler.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
package org.onap.policy.pdpx.main.parameters;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -185,13 +187,12 @@ public class TestXacmlPdpParameterHandler {
}
@Test
- public void testXacmlPdpInvalidOption() throws PolicyXacmlPdpException {
+ public void testXacmlPdpInvalidOption() {
final String[] xacmlPdpConfigParameters = {"-d"};
final XacmlPdpCommandLineArguments arguments = new XacmlPdpCommandLineArguments();
- try {
- arguments.parse(xacmlPdpConfigParameters);
- } catch (final Exception exp) {
- assertTrue(exp.getMessage().startsWith("invalid command line arguments specified"));
- }
+ assertThatThrownBy(() ->
+ arguments.parse(xacmlPdpConfigParameters)
+ ).isInstanceOf(PolicyXacmlPdpException.class)
+ .hasMessageContaining("invalid command line arguments specified");
}
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java
index 6d2a6fa9..c9910349 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/rest/TestAbbreviateDecisionResults.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
@@ -158,39 +158,33 @@ public class TestAbbreviateDecisionResults {
* should have been removed from the response.
*/
@Test
- public void testAbbreviateDecisionResult() {
+ public void testAbbreviateDecisionResult() throws HttpClientConfigException {
LOGGER.info("Running testAbbreviateDecisionResult");
- try {
- // Create DecisionRequest
- DecisionRequest request = new DecisionRequest();
- request.setOnapName("DCAE");
- request.setOnapComponent("PolicyHandler");
- request.setOnapInstance("622431a4-9dea-4eae-b443-3b2164639c64");
- request.setAction("configure");
- Map<String, Object> resource = new HashMap<String, Object>();
- resource.put("policy-id", "onap.scaleout.tca");
- request.setResource(resource);
-
- // Query decision API
- DecisionResponse response = getDecision(request);
- LOGGER.info("Decision Response {}", response);
+ // Create DecisionRequest
+ DecisionRequest request = new DecisionRequest();
+ request.setOnapName("DCAE");
+ request.setOnapComponent("PolicyHandler");
+ request.setOnapInstance("622431a4-9dea-4eae-b443-3b2164639c64");
+ request.setAction("configure");
+ Map<String, Object> resource = new HashMap<String, Object>();
+ resource.put("policy-id", "onap.scaleout.tca");
+ request.setResource(resource);
- assertFalse(response.getPolicies().isEmpty());
+ // Query decision API
+ DecisionResponse response = getDecision(request);
+ LOGGER.info("Decision Response {}", response);
- @SuppressWarnings("unchecked")
- Map<String, Object> policy = (Map<String, Object>) response.getPolicies().get("onap.scaleout.tca");
- assertTrue(policy.containsKey("type"));
- assertFalse(policy.containsKey("properties"));
- assertFalse(policy.containsKey("name"));
- assertFalse(policy.containsKey("version"));
- assertTrue(policy.containsKey("metadata"));
+ assertFalse(response.getPolicies().isEmpty());
- } catch (Exception e) {
- LOGGER.error("Exception {}", e);
- fail("testAbbreviateDecisionResult failed due to: " + e.getLocalizedMessage());
- }
+ @SuppressWarnings("unchecked")
+ Map<String, Object> policy = (Map<String, Object>) response.getPolicies().get("onap.scaleout.tca");
+ assertTrue(policy.containsKey("type"));
+ assertFalse(policy.containsKey("properties"));
+ assertFalse(policy.containsKey("name"));
+ assertFalse(policy.containsKey("version"));
+ assertTrue(policy.containsKey("metadata"));
}
private static Main startXacmlPdpService(File params) throws PolicyXacmlPdpException {