summaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@est.tech>2020-02-07 16:27:26 +0000
committera.sreekumar <ajith.sreekumar@est.tech>2020-02-10 16:57:38 +0000
commit93a3e76cef9e3c39ce90b6c68f3d551ee489149b (patch)
tree524391e903a3b4a860d472de43560049c56e2e2b /main/src
parentce9d064bf511926f0f187d5b28ff018a492556cf (diff)
Cleanup the sonar issues in PAP
Change-Id: I0eccc6064eb0b49d84370104d1219074ec8bde71 Issue-ID: POLICY-2271 Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
Diffstat (limited to 'main/src')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java5
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java14
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java7
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java8
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java6
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java9
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java9
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java17
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java11
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java12
10 files changed, 48 insertions, 50 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
index 0bcbb5cb..e730da2e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
+++ b/main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -59,8 +59,7 @@ public class PapParameterHandler {
papParameterGroup = CODER.decode(file, PapParameterGroup.class);
} catch (final CoderException e) {
final String errorMessage = "error reading parameters from \"" + arguments.getConfigurationFilePath()
- + "\"\n" + "(" + e.getClass().getSimpleName() + "):" + e.getMessage();
- LOGGER.error(errorMessage, e);
+ + "\"\n" + "(" + e.getClass().getSimpleName() + ")";
throw new PolicyPapException(errorMessage, e);
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
index ee6cbe4c..4e61621b 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
@@ -272,7 +272,7 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase {
dbgroup.getPdpSubgroups().add(subgrp);
} else {
- updated = updateSubGroup(data, dbsub, subgrp, subResult) || updated;
+ updated = updateSubGroup(dbsub, subgrp, subResult) || updated;
}
result.addResult(subResult);
@@ -371,20 +371,17 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase {
/**
* Updates an existing subgroup.
*
- * @param data session data
* @param dbsub the subgroup, from the DB
* @param subgrp the subgroup to be updated, updated to fully qualified versions upon
* return
* @param container container for additional validation results
* @return {@code true} if the subgroup content was changed, {@code false} if there
* were no changes
- * @throws PfModelException if an error occurred
*/
- private boolean updateSubGroup(SessionData data, PdpSubGroup dbsub, PdpSubGroup subgrp,
- BeanValidationResult container) throws PfModelException {
+ private boolean updateSubGroup(PdpSubGroup dbsub, PdpSubGroup subgrp, BeanValidationResult container) {
// perform additional validations first
- if (!validateSubGroup(data, dbsub, subgrp, container)) {
+ if (!validateSubGroup(dbsub, subgrp, container)) {
return false;
}
@@ -405,16 +402,13 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase {
/**
* Performs additional validations of a subgroup.
*
- * @param data session data
* @param dbsub the subgroup, from the DB
* @param subgrp the subgroup to be validated, updated to fully qualified versions
* upon return
* @param container container for additional validation results
* @return {@code true} if the subgroup is valid, {@code false} otherwise
- * @throws PfModelException if an error occurred
*/
- private boolean validateSubGroup(SessionData data, PdpSubGroup dbsub, PdpSubGroup subgrp,
- BeanValidationResult container) throws PfModelException {
+ private boolean validateSubGroup(PdpSubGroup dbsub, PdpSubGroup subgrp, BeanValidationResult container) {
BeanValidationResult result = new BeanValidationResult(subgrp.getPdpType(), subgrp);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java
index e739b2fc..3aa3d93f 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,9 +29,7 @@ import io.swagger.annotations.Authorization;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.ResponseHeader;
-
import java.util.UUID;
-
import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
@@ -39,7 +37,6 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse;
@@ -54,7 +51,7 @@ import org.slf4j.LoggerFactory;
*/
public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 {
- private static final Logger LOGGER = LoggerFactory.getLogger(PdpGroupQueryControllerV1.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(PdpGroupStateChangeControllerV1.class);
private final PdpGroupStateChangeProvider provider = new PdpGroupStateChangeProvider();
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
index 5665e795..d567b6d3 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* 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.
@@ -38,8 +39,6 @@ import org.onap.policy.pap.main.PapConstants;
import org.onap.policy.pap.main.PolicyModelsProviderFactoryWrapper;
import org.onap.policy.pap.main.comm.PdpModifyRequestMap;
import org.onap.policy.pap.main.notification.PolicyNotifier;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Super class of providers that deploy and undeploy PDP groups. The following items must
@@ -51,11 +50,8 @@ import org.slf4j.LoggerFactory;
* </ul>
*/
public abstract class ProviderBase {
- private static final String DEPLOY_FAILED = "failed to deploy/undeploy policies";
public static final String DB_ERROR_MSG = "DB error";
- private static final Logger logger = LoggerFactory.getLogger(ProviderBase.class);
-
/**
* Lock used when updating PDPs.
*/
@@ -108,11 +104,9 @@ public abstract class ProviderBase {
data.updateDb();
} catch (PfModelException | PfModelRuntimeException e) {
- logger.warn(DEPLOY_FAILED, e);
throw e;
} catch (RuntimeException e) {
- logger.warn(DEPLOY_FAILED, e);
throw new PfModelException(Status.INTERNAL_SERVER_ERROR, "request failed", e);
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java b/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
index 9509d03b..4733f91e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* 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,14 +21,15 @@
package org.onap.policy.pap.main;
+import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.powermock.reflect.Whitebox;
public class PapConstantsTest {
@Test
- public void test() throws Exception {
+ public void test() {
// verify that constructor does not throw an exception
- Whitebox.invokeConstructor(PapConstants.class);
+ Assertions.assertThatCode(() -> Whitebox.invokeConstructor(PapConstants.class)).doesNotThrowAnyException();
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
index edc70103..3a35370b 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* 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.
@@ -26,8 +27,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -42,6 +43,7 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
+import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -103,6 +105,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
* @throws Exception if an error occurs
*/
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
@@ -164,7 +167,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase {
@Test
public void testAddRequestPdpUpdatePdpStateChange_BothNull() {
// nulls should be ok
- map.addRequest(null, null);
+ Assertions.assertThatCode(() -> map.addRequest(null, null)).doesNotThrowAnyException();
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java
index 4b6c2d9a..efd380ec 100644
--- a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* 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.
@@ -29,12 +30,13 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
+import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.PdpMessage;
@@ -56,6 +58,7 @@ public class RequestImplTest extends CommonRequestBase {
* @throws Exception if an error occurs
*/
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
@@ -192,7 +195,7 @@ public class RequestImplTest extends CommonRequestBase {
@Test
public void testStopPublishingBoolean_NotPublishing() {
// should not throw an exception
- req.stopPublishing();
+ Assertions.assertThatCode(() -> req.stopPublishing()).doesNotThrowAnyException();
}
@Test
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
index ddf24293..fc3bc626 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
@@ -36,6 +36,7 @@ import java.util.Collections;
import java.util.List;
import java.util.TreeMap;
import javax.ws.rs.core.Response.Status;
+import org.assertj.core.api.Assertions;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
@@ -67,8 +68,8 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
*
* @throws Exception if an error occurs
*/
- @Override
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
@@ -143,24 +144,24 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
}
@Test
- public void testValidateGroupOnly_NullState() throws PfModelException {
+ public void testValidateGroupOnly_NullState() {
PdpGroups groups = loadPdpGroups("createGroups.json");
groups.getGroups().get(0).setPdpGroupState(null);
- prov.createOrUpdateGroups(groups);
+ Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException();
}
@Test
- public void testValidateGroupOnly_Active() throws PfModelException {
+ public void testValidateGroupOnly_Active() {
PdpGroups groups = loadPdpGroups("createGroups.json");
groups.getGroups().get(0).setPdpGroupState(PdpState.ACTIVE);
- prov.createOrUpdateGroups(groups);
+ Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException();
}
@Test
- public void testValidateGroupOnly_Passive() throws PfModelException {
+ public void testValidateGroupOnly_Passive() {
PdpGroups groups = loadPdpGroups("createGroups.json");
groups.getGroups().get(0).setPdpGroupState(PdpState.PASSIVE);
- prov.createOrUpdateGroups(groups);
+ Assertions.assertThatCode(() -> prov.createOrUpdateGroups(groups)).doesNotThrowAnyException();
}
@Test
@@ -212,7 +213,7 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
assertGroupUpdateOnly(group);
- assertEquals(group.getDescription(), "my description");
+ assertEquals("my description", group.getDescription());
assertEquals(newgrp.toString(), group.toString());
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java
index ae356e83..250b9678 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* 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.
@@ -25,8 +26,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -37,6 +38,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Set;
import javax.ws.rs.core.Response.Status;
+import org.assertj.core.api.Assertions;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
@@ -81,6 +83,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
* @throws Exception if an error occurs
*/
@Before
+ @Override
public void setUp() throws Exception {
super.setUp();
@@ -155,8 +158,8 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper {
}
@Test
- public void testUndeploy_testUndeployPolicy() throws Exception {
- prov.undeploy(optIdent);
+ public void testUndeploy_testUndeployPolicy() {
+ Assertions.assertThatCode(() -> prov.undeploy(optIdent)).doesNotThrowAnyException();
}
/**
diff --git a/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java
index 2658b36c..1efa9e14 100644
--- a/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java
+++ b/main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,6 +23,7 @@ package org.onap.policy.pap.main.startstop;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.After;
@@ -81,26 +82,27 @@ public class TestMain {
public void testMain_NoArguments() {
final String[] papConfigParameters = {};
main = new Main(papConfigParameters);
- assertTrue(main.getParameters() == null);
+ assertNull(main.getParameters());
}
@Test
public void testMain_InvalidArguments() {
final String[] papConfigParameters = {"parameters/PapConfigParameters.json"};
main = new Main(papConfigParameters);
- assertTrue(main.getParameters() == null);
+ assertNull(main.getParameters());
}
@Test
public void testMain_Help() {
final String[] papConfigParameters = {"-h"};
- Main.main(papConfigParameters);
+ main = new Main(papConfigParameters);
+ assertNull(main.getParameters());
}
@Test
public void testMain_InvalidParameters() {
final String[] papConfigParameters = {"-c", "parameters/PapConfigParameters_InvalidName.json"};
main = new Main(papConfigParameters);
- assertTrue(main.getParameters() == null);
+ assertNull(main.getParameters());
}
}