Fix issues in api for new sonar rules 58/109658/1
authorJim Hahn <jrh3@att.com>
Mon, 29 Jun 2020 16:14:07 +0000 (12:14 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 29 Jun 2020 16:43:12 +0000 (12:43 -0400)
Addressed issues reported due to updates to the sonar rules:
- use assertEquals, assertNull, etc.
- use "<>"
- use "{}" place-holder

Issue-ID: POLICY-2680
Change-Id: I42d5e635e09bac6e520fc7aa386814ad617fc1f6
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java
main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java
main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java
main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java

index 4cbfd06..dbcc42c 100644 (file)
@@ -35,8 +35,6 @@ import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.provider.PolicyModelsProvider;
 import org.onap.policy.models.provider.PolicyModelsProviderFactory;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
@@ -79,8 +77,8 @@ public class ApiDatabaseInitializer {
             }
 
             ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
-            serviceTemplate.setDataTypes(new LinkedHashMap<String, ToscaDataType>());
-            serviceTemplate.setPolicyTypes(new LinkedHashMap<String, ToscaPolicyType>());
+            serviceTemplate.setDataTypes(new LinkedHashMap<>());
+            serviceTemplate.setPolicyTypes(new LinkedHashMap<>());
             serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_1_0");
 
             ToscaServiceTemplate createdPolicyTypes = preloadServiceTemplate(serviceTemplate,
@@ -114,7 +112,7 @@ public class ApiDatabaseInitializer {
         for (String entity : entities) {
             String entityAsStringYaml = ResourceUtils.getResourceAsString(entity);
             if (entityAsStringYaml == null) {
-                LOGGER.warn("Preloading entity cannot be found: " + entity);
+                LOGGER.warn("Preloading entity cannot be found: {}", entity);
                 continue;
             }
 
index 6837700..dc92148 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy API
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@
 package org.onap.policy.api.main.rest;
 
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertSame;
 
 import java.util.UUID;
 import javax.ws.rs.core.Response;
@@ -42,7 +42,7 @@ public class TestCommonRestController {
         UUID requestId = UUID.randomUUID();
         ResponseBuilder rb =
                 crc.addLoggingHeaders(crc.addVersionControlHeaders(Response.status(Response.Status.OK)), requestId);
-        assertTrue(rb.equals(rb.header("X-ONAP-RequestID", requestId)));
+        assertSame(rb, rb.header("X-ONAP-RequestID", requestId));
     }
 
     /*
index bb4eca9..c91d8ad 100644 (file)
@@ -26,7 +26,6 @@ package org.onap.policy.api.main.rest.provider;
 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.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
@@ -222,7 +221,7 @@ public class TestLegacyOperationalPolicyProvider {
                     operationalPolicyProvider.createOperationalPolicy(policyToCreate);
                 assertEquals("operational.restart", policyCreated.getPolicyId());
                 assertEquals("1", policyCreated.getPolicyVersion());
-                assertFalse(policyCreated.getContent() == null);
+                assertNotNull(policyCreated.getContent());
             }).doesNotThrowAnyException();
 
             // Test fetchDeployedPolicies (deployedPolicyMap.isEmpty())==true
index 60222f6..9039775 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- *  Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ package org.onap.policy.api.main.startstop;
 
 import static org.assertj.core.api.Assertions.assertThatCode;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
@@ -51,14 +52,14 @@ public class TestMain {
     public void testMain_NoArguments() {
         final String[] apiConfigParameters = {};
         final Main main = new Main(apiConfigParameters);
-        assertTrue(main.getParameters() == null);
+        assertNull(main.getParameters());
     }
 
     @Test
     public void testMain_InvalidArguments() {
         final String[] apiConfigParameters = {"parameters/ApiConfigParameters.json"};
         final Main main = new Main(apiConfigParameters);
-        assertTrue(main.getParameters() == null);
+        assertNull(main.getParameters());
     }
 
     @Test
@@ -71,6 +72,6 @@ public class TestMain {
     public void testMain_InvalidParameters() {
         final String[] apiConfigParameters = {"-c", "parameters/ApiConfigParameters_InvalidName.json"};
         final Main main = new Main(apiConfigParameters);
-        assertTrue(main.getParameters() == null);
+        assertNull(main.getParameters());
     }
 }