Cleanup the sonar issues in PAP 71/101471/3
authora.sreekumar <ajith.sreekumar@est.tech>
Fri, 7 Feb 2020 16:27:26 +0000 (16:27 +0000)
committera.sreekumar <ajith.sreekumar@est.tech>
Mon, 10 Feb 2020 16:57:38 +0000 (16:57 +0000)
Change-Id: I0eccc6064eb0b49d84370104d1219074ec8bde71
Issue-ID: POLICY-2271
Signed-off-by: a.sreekumar <ajith.sreekumar@est.tech>
main/src/main/java/org/onap/policy/pap/main/parameters/PapParameterHandler.java
main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeControllerV1.java
main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java
main/src/test/java/org/onap/policy/pap/main/comm/msgdata/RequestImplTest.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java
main/src/test/java/org/onap/policy/pap/main/startstop/TestMain.java

index 0bcbb5c..e730da2 100644 (file)
@@ -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);
         }
 
index ee6cbe4..4e61621 100644 (file)
@@ -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);
 
index e739b2f..3aa3d93 100644 (file)
@@ -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();
 
index 5665e79..d567b6d 100644 (file)
@@ -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);
             }
 
index 9509d03..4733f91 100644 (file)
@@ -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.
 
 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();
     }
 }
index edc7010..3a35370 100644 (file)
@@ -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
index 4b6c2d9..efd380e 100644 (file)
@@ -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
index ddf2429..fc3bc62 100644 (file)
@@ -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());
     }
 
index ae356e8..250b967 100644 (file)
@@ -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();
     }
 
     /**
index 2658b36..1efa9e1 100644 (file)
@@ -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());
     }
 }