aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-12-02 14:38:05 -0500
committerPamela Dragosh <pdragosh@research.att.com>2019-12-02 15:09:09 -0500
commit3105cfbfb817444ebbfec8a726b8526e7ff38632 (patch)
treecda90d42e538a87d92d6e79de27ff6fe253d5717
parente53be640b3a4c37dbd841c81b5c467082986c05b (diff)
Clear some simple xacml sonar
Missing assertions in JUnit test cases. Use replace vs replaceAll Swapping arguments Issue-ID: POLICY-2079 Change-Id: I5accd462eab3d4f6b3321e375d4ba1084caf4b8c Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
-rw-r--r--applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java5
-rw-r--r--applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java6
-rw-r--r--main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpUpdateListener.java2
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java4
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpHearbeatPublisherTest.java9
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistrationTest.java13
-rw-r--r--main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java11
7 files changed, 34 insertions, 16 deletions
diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
index b01fa708..ac8a0c29 100644
--- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
+++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPipTest.java
@@ -18,6 +18,7 @@
package org.onap.policy.pdp.xacml.application.common.operationshistory;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
@@ -167,7 +168,9 @@ public class CountRecentOperationsPipTest {
@Test
public void testConfigure_DbException() throws Exception {
properties.put("javax.persistence.jdbc.url", "invalid");
- pipEngine.configure("issuer", properties);
+ assertThatCode(() ->
+ pipEngine.configure("issuer", properties)
+ ).doesNotThrowAnyException();
}
@Test
diff --git a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
index eb793f69..eb86486d 100644
--- a/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
+++ b/applications/guard/src/main/java/org/onap/policy/xacml/pdp/application/guard/CoordinationGuardTranslator.java
@@ -151,9 +151,9 @@ public class CoordinationGuardTranslator implements ToscaPolicyTranslator {
* Replace function placeholders with appropriate values
*/
try (Stream<String> stream = Files.lines(Paths.get(xacmlProtoFilename))) {
- return stream.map(s -> s.replaceAll("UNIQUE_ID", uniqueId))
- .map(s -> s.replaceAll("CONTROL_LOOP_ONE", cLOne))
- .map(s -> s.replaceAll("CONTROL_LOOP_TWO", cLTwo))
+ return stream.map(s -> s.replace("UNIQUE_ID", uniqueId))
+ .map(s -> s.replace("CONTROL_LOOP_ONE", cLOne))
+ .map(s -> s.replace("CONTROL_LOOP_TWO", cLTwo))
.collect(Collectors.joining(XacmlPolicyUtils.LINE_SEPARATOR));
} catch (IOException e) {
throw new
diff --git a/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpUpdateListener.java b/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpUpdateListener.java
index 64ffdeda..1e275c15 100644
--- a/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpUpdateListener.java
+++ b/main/src/main/java/org/onap/policy/pdpx/main/comm/listeners/XacmlPdpUpdateListener.java
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
public class XacmlPdpUpdateListener extends ScoListener<PdpUpdate> {
- private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpStateChangeListener.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(XacmlPdpUpdateListener.class);
private final XacmlState state;
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
index 6d7b3c96..b09fe1a1 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/XacmlStateTest.java
@@ -171,8 +171,8 @@ public class XacmlStateTest {
assertEquals(SUBGROUP, status.getPdpSubgroup());
status = state.updateInternalState(req, "Failed to load policy: failLoadPolicy1: null");
- assertEquals(status.getResponse().getResponseMessage(), "Failed to load policy: failLoadPolicy1: null");
- assertEquals(status.getResponse().getResponseStatus(), PdpResponseStatus.FAIL);
+ assertEquals("Failed to load policy: failLoadPolicy1: null", status.getResponse().getResponseMessage());
+ assertEquals(PdpResponseStatus.FAIL, status.getResponse().getResponseStatus());
assertEquals(GROUP, status.getPdpGroup());
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpHearbeatPublisherTest.java b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpHearbeatPublisherTest.java
index a1f50771..3478ef3a 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpHearbeatPublisherTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpHearbeatPublisherTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.pdpx.main.comm;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Matchers.any;
@@ -170,9 +171,11 @@ public class XacmlPdpHearbeatPublisherTest {
// create a plain listener to test the "real" makeTimer() method
publisher = new XacmlPdpHearbeatPublisher(client, state);
- publisher.start();
- publisher.restart(100L);
- publisher.terminate();
+ assertThatCode( () -> {
+ publisher.start();
+ publisher.restart(100L);
+ publisher.terminate();
+ }).doesNotThrowAnyException();
}
private class MyPublisher extends XacmlPdpHearbeatPublisher {
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistrationTest.java b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistrationTest.java
index c05e0999..9f35f530 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistrationTest.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/comm/XacmlPdpPapRegistrationTest.java
@@ -20,6 +20,7 @@
package org.onap.policy.pdpx.main.comm;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.mockito.Mockito.when;
import org.junit.Before;
@@ -54,18 +55,24 @@ public class XacmlPdpPapRegistrationTest {
@Test
public void testPdpRegistration_SendOk() throws TopicSinkClientException {
- reg.pdpRegistration(status);
+ assertThatCode(() ->
+ reg.pdpRegistration(status)
+ ).doesNotThrowAnyException();
}
@Test
public void testPdpRegistration_SendFail() throws TopicSinkClientException {
when(client.send(status)).thenReturn(false);
- reg.pdpRegistration(status);
+ assertThatCode(() ->
+ reg.pdpRegistration(status)
+ ).doesNotThrowAnyException();
}
@Test
public void testPdpRegistration_SendEx() throws TopicSinkClientException {
when(client.send(status)).thenThrow(new IllegalStateException());
- reg.pdpRegistration(status);
+ assertThatCode(() ->
+ reg.pdpRegistration(status)
+ ).doesNotThrowAnyException();
}
}
diff --git a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
index 8b6889d6..5e46b669 100644
--- a/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/pdpx/main/startstop/TestMain.java
@@ -21,6 +21,7 @@
package org.onap.policy.pdpx.main.startstop;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.After;
@@ -51,6 +52,7 @@ public class TestMain extends CommonRest {
CommonRest.stopMain();
}
+ @Override
@Before
public void setUp() {
main = null;
@@ -59,6 +61,7 @@ public class TestMain extends CommonRest {
/**
* Shuts "main" down.
*/
+ @Override
@After
public void tearDown() {
if (main != null) {
@@ -69,9 +72,11 @@ public class TestMain extends CommonRest {
@Test
public void testMain() throws PolicyXacmlPdpException {
final String[] xacmlPdpConfigParameters = {"-c", CONFIG_FILE};
- main = new Main(xacmlPdpConfigParameters);
- main.shutdown();
- main = null;
+ assertThatCode(() -> {
+ main = new Main(xacmlPdpConfigParameters);
+ main.shutdown();
+ main = null;
+ }).doesNotThrowAnyException();
}
@Test