Remove Sonar warnings 46/3846/1
authorelinuxhenrik <henrik.b.andersson@est.tech>
Tue, 26 May 2020 11:08:26 +0000 (13:08 +0200)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Tue, 26 May 2020 11:08:31 +0000 (13:08 +0200)
Change-Id: I068216c0301b573e30fc94a759a231bf566b6f09
Issue-ID: NONRTRIC-116
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/ControlPanelTestServer.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/ControlPanelUserManagerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/AbstractControllerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/DefaultContextTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/PortalRestCentralServiceTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/policyagentapi/PolicyAgentApiImplTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/portalapi/PortalAuthManagerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/util/AsyncRestClientTest.java

index ea832ee..432823c 100644 (file)
@@ -46,7 +46,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
  */
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
-public class ControlPanelTestServer {
+class ControlPanelTestServer {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
@@ -57,7 +57,7 @@ public class ControlPanelTestServer {
     @SuppressWarnings("squid:S2699") // To avoid warning about missing assertion.
     @EnabledIfSystemProperty(named = "org.oransc.portal.nonrtric.controlpanel", matches = "mock")
     @Test
-    public void keepServerAlive() {
+    void keepServerAlive() {
         logger.warn("Keeping server alive!");
         try {
             synchronized (this) {
index 8f9d913..f6e72d6 100644 (file)
@@ -34,7 +34,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ActiveProfiles;
 
 @ActiveProfiles("test")
-public class ControlPanelUserManagerTest {
+class ControlPanelUserManagerTest {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
@@ -54,7 +54,7 @@ public class ControlPanelUserManagerTest {
     }
 
     @Test
-    public void testUserMgr() throws Exception {
+    void testUserMgr() throws Exception {
         final String loginId = "demo";
         ControlPanelUserManager dum = new ControlPanelUserManager(true);
         EcompUser user = createEcompUser(loginId);
index f462096..f7f6336 100644 (file)
@@ -41,7 +41,7 @@ import org.springframework.web.util.UriComponentsBuilder;
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 // Need the fake answers from the backend
 @ActiveProfiles("test")
-public class AbstractControllerTest {
+class AbstractControllerTest {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
@@ -89,7 +89,7 @@ public class AbstractControllerTest {
     // Because I put the annotations on this parent class,
     // must define at least one test here.
     @Test
-    public void contextLoads() {
+    void contextLoads() {
         // Silence Sonar warning about missing assertion.
         Assertions.assertTrue(logger.isWarnEnabled());
         logger.info("Context loads on mock profile");
index 4c2687b..8f7e793 100644 (file)
@@ -35,12 +35,12 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
  */
 @ExtendWith(SpringExtension.class)
 @SpringBootTest
-public class DefaultContextTest {
+class DefaultContextTest {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
     @Test
-    public void contextLoads() {
+    void contextLoads() {
         // Silence Sonar warning about missing assertion.
         Assertions.assertTrue(logger.isWarnEnabled());
         logger.info("Context loads on default profile");
index 94e7eeb..d9919a5 100644 (file)
@@ -30,32 +30,36 @@ import org.junit.jupiter.api.Test;
 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.http.ResponseEntity;
 import org.springframework.web.reactive.function.client.WebClientResponseException;
+import reactor.core.publisher.Mono;
 
-public class PortalRestCentralServiceTest extends AbstractControllerTest {
+class PortalRestCentralServiceTest extends AbstractControllerTest {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
     @Test
-    public void getAnalyticsTest() {
+    void getAnalyticsTest() {
         // paths are hardcoded here exactly like the EPSDK-FW library :(
         URI uri = buildUri(null, PortalApiConstants.API_PREFIX, "/analytics");
         logger.info("Invoking {}", uri);
+        Mono<ResponseEntity<String>> forEntity = webClient.getForEntity(uri.toString());
         WebClientResponseException e = assertThrows(WebClientResponseException.class, () -> {
-            webClient.getForEntity(uri.toString()).block();
+            forEntity.block();
         });
         // No Portal is available so this always fails
         Assertions.assertTrue(e.getStatusCode().is4xxClientError());
     }
 
     @Test
-    public void getErrorPageTest() {
+    void getErrorPageTest() {
         // Send unauthorized request
 
         URI uri = buildUri(null, "/favicon.ico");
         logger.info("Invoking {}", uri);
+        Mono<ResponseEntity<String>> forEntity = webClient.getForEntity(uri.toString());
         WebClientResponseException e = assertThrows(WebClientResponseException.class, () -> {
-            webClient.getForEntity(uri.toString()).block();
+            forEntity.block();
         });
         Assertions.assertTrue(e.getStatusCode().is4xxClientError());
         Assertions.assertTrue(e.getResponseBodyAsString().contains("Static error page"));
index 37fdd8d..87a831f 100644 (file)
@@ -46,7 +46,7 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.HttpServerErrorException;
 import reactor.core.publisher.Mono;
 
-public class PolicyAgentApiImplTest {
+class PolicyAgentApiImplTest {
     private static final String URL_POLICY_SCHEMAS = "/policy_schemas";
     private static final String POLICY_TYPE_1_ID = "type1";
     private static final String POLICY_TYPE_1_VALID = "{\"title\":\"type1\"}";
@@ -69,7 +69,7 @@ public class PolicyAgentApiImplTest {
     AsyncRestClient restClient;
 
     @BeforeEach
-    public void init() {
+    void init() {
         restClient = mock(AsyncRestClient.class);
         apiUnderTest = new PolicyAgentApiImpl(restClient);
     }
@@ -85,14 +85,14 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetAllPolicyTypesFailure() {
+    void testGetAllPolicyTypesFailure() {
         whenGetReturnFailure(URL_POLICY_SCHEMAS, HttpStatus.NOT_FOUND, "");
         ResponseEntity<String> returnedResp = apiUnderTest.getAllPolicyTypes();
         assertEquals(HttpStatus.NOT_FOUND, returnedResp.getStatusCode());
     }
 
     @Test
-    public void testGetAllPolicyTypesSuccessValidJson() {
+    void testGetAllPolicyTypesSuccessValidJson() {
         String policyTypes = Arrays.asList(POLICY_TYPE_1_VALID, POLICY_TYPE_2_VALID).toString();
 
         whenGetReturnOK(URL_POLICY_SCHEMAS, HttpStatus.OK, policyTypes);
@@ -103,7 +103,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetAllPolicyTypesSuccessInvalidJson() {
+    void testGetAllPolicyTypesSuccessInvalidJson() {
         String policyTypes = Arrays.asList(POLICY_TYPE_1_INVALID, POLICY_TYPE_2_VALID).toString();
         whenGetReturnOK(URL_POLICY_SCHEMAS, HttpStatus.OK, policyTypes);
 
@@ -118,7 +118,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetPolicyInstancesForTypeFailure() {
+    void testGetPolicyInstancesForTypeFailure() {
         whenGetReturnFailure(urlPolicyInstances(POLICY_TYPE_1_ID), HttpStatus.NOT_FOUND, "");
 
         ResponseEntity<String> returnedResp = apiUnderTest.getPolicyInstancesForType(POLICY_TYPE_1_ID);
@@ -127,7 +127,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetPolicyInstancesForTypeSuccessValidJson() {
+    void testGetPolicyInstancesForTypeSuccessValidJson() {
         String policyInstances = Arrays.asList(POLICY_1_VALID).toString();
         String policyInstancesJson = parsePolicyInstancesJson(policyInstances);
 
@@ -140,7 +140,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetPolicyInstancesForTypeSuccessInvalidJson() {
+    void testGetPolicyInstancesForTypeSuccessInvalidJson() {
         String policyInstances = Arrays.asList(POLICY_1_INVALID).toString();
 
         whenGetReturnOK(urlPolicyInstances(POLICY_TYPE_1_ID), HttpStatus.OK, policyInstances);
@@ -156,7 +156,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetPolicyInstance() {
+    void testGetPolicyInstance() {
         whenGetReturnOK(urlPolicyInstance(POLICY_1_ID), HttpStatus.OK, POLICY_1_VALID);
 
         ResponseEntity<Object> returnedResp = apiUnderTest.getPolicyInstance(POLICY_1_ID);
@@ -182,7 +182,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testPutPolicyFailure() {
+    void testPutPolicyFailure() {
         String url = urlPutPolicy(POLICY_TYPE_1_ID, POLICY_1_ID, RIC_1_ID);
         whenPutReturnFailure(url, POLICY_1_VALID, HttpStatus.NOT_FOUND, CLIENT_ERROR_MESSAGE);
 
@@ -194,7 +194,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testPutPolicySuccess() {
+    void testPutPolicySuccess() {
         String url = urlPutPolicy(POLICY_TYPE_1_ID, POLICY_1_ID, RIC_1_ID);
         whenPutReturnOK(url, POLICY_1_VALID, HttpStatus.OK, POLICY_1_VALID);
 
@@ -221,7 +221,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testDeletePolicyFailure() {
+    void testDeletePolicyFailure() {
         whenDeleteReturnFailure(deletePolicyUrl(POLICY_1_ID), HttpStatus.NOT_FOUND, CLIENT_ERROR_MESSAGE);
 
         ResponseEntity<String> returnedResp = apiUnderTest.deletePolicy(POLICY_1_ID);
@@ -231,7 +231,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testDeletePolicySuccess() {
+    void testDeletePolicySuccess() {
         whenDeleteReturnOK(deletePolicyUrl(POLICY_1_ID), HttpStatus.OK);
         ResponseEntity<String> returnedResp = apiUnderTest.deletePolicy(POLICY_1_ID);
 
@@ -243,7 +243,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetRicsSupportingTypeValidJson() {
+    void testGetRicsSupportingTypeValidJson() {
         String rics = Arrays.asList(RIC_1_INFO_VALID).toString();
 
         this.whenGetReturnOK(urlRicInfo(POLICY_TYPE_1_ID), HttpStatus.OK, rics);
@@ -255,7 +255,7 @@ public class PolicyAgentApiImplTest {
     }
 
     @Test
-    public void testGetRicsSupportingTypeInvalidJson() {
+    void testGetRicsSupportingTypeInvalidJson() {
         String rics = Arrays.asList(RIC_1_INFO_INVALID).toString();
 
         this.whenGetReturnOK(urlRicInfo(POLICY_TYPE_1_ID), HttpStatus.OK, rics);
index 38daac6..fa8c86b 100644 (file)
@@ -45,7 +45,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-public class PortalAuthManagerTest {
+class PortalAuthManagerTest {
 
     @Value("${portalapi.decryptor}")
     private String decryptor;
@@ -53,7 +53,7 @@ public class PortalAuthManagerTest {
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
     @Test
-    public void testPortalStuff() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
+    void testPortalStuff() throws ClassNotFoundException, InstantiationException, IllegalAccessException,
         InvocationTargetException, NoSuchMethodException, IOException, ServletException {
 
         PortalAuthManager m = new PortalAuthManager("app", "user", "secret", decryptor, "cookie");
index 8135ad3..33527a4 100644 (file)
@@ -39,7 +39,7 @@ import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
 import reactor.util.Loggers;
 
-public class AsyncRestClientTest {
+class AsyncRestClientTest {
     private static final String BASE_URL = "BaseUrl";
     private static final String REQUEST_URL = "/test";
     private static final String TEST_JSON = "{\"type\":\"type1\"}";
@@ -65,7 +65,7 @@ public class AsyncRestClientTest {
     }
 
     @Test
-    public void testGetNoError() {
+    void testGetNoError() {
         mockWebServer.enqueue(new MockResponse().setResponseCode(SUCCESS_CODE) //
             .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) //
             .setBody(TEST_JSON));
@@ -75,7 +75,7 @@ public class AsyncRestClientTest {
     }
 
     @Test
-    public void testGetError() {
+    void testGetError() {
         mockWebServer.enqueue(new MockResponse().setResponseCode(ERROR_CODE));
 
         Mono<String> returnedMono = clientUnderTest.get(REQUEST_URL);
@@ -84,7 +84,7 @@ public class AsyncRestClientTest {
     }
 
     @Test
-    public void testPutNoError() {
+    void testPutNoError() {
         mockWebServer.enqueue(new MockResponse().setResponseCode(SUCCESS_CODE) //
             .setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) //
             .setBody(TEST_JSON));
@@ -94,7 +94,7 @@ public class AsyncRestClientTest {
     }
 
     @Test
-    public void testPutError() {
+    void testPutError() {
         mockWebServer.enqueue(new MockResponse().setResponseCode(ERROR_CODE));
 
         Mono<String> returnedMono = clientUnderTest.put(REQUEST_URL, TEST_JSON);
@@ -103,7 +103,7 @@ public class AsyncRestClientTest {
     }
 
     @Test
-    public void testDeleteNoError() {
+    void testDeleteNoError() {
         mockWebServer.enqueue(new MockResponse().setResponseCode(SUCCESS_CODE));
 
         Mono<String> returnedMono = clientUnderTest.delete(REQUEST_URL);
@@ -111,7 +111,7 @@ public class AsyncRestClientTest {
     }
 
     @Test
-    public void testDeleteError() {
+    void testDeleteError() {
         mockWebServer.enqueue(new MockResponse().setResponseCode(ERROR_CODE));
 
         Mono<String> returnedMono = clientUnderTest.delete(REQUEST_URL);