diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-29 12:14:07 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-29 12:43:12 -0400 |
commit | 57c87591cde427a672dcbeb17f17eb06fbdeca1c (patch) | |
tree | d6a9fa1c0958372dd269589924585730ae5795a5 | |
parent | 2521a4a50b3496d9356f318c67cacb511e485de4 (diff) |
Fix issues in api for new sonar rules
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>
4 files changed, 12 insertions, 14 deletions
diff --git a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java index 4cbfd06d..dbcc42cc 100644 --- a/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java +++ b/main/src/main/java/org/onap/policy/api/main/startstop/ApiDatabaseInitializer.java @@ -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; } diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java index 68377003..dc921488 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestCommonRestController.java @@ -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)); } /* diff --git a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java index bb4eca95..c91d8adc 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/provider/TestLegacyOperationalPolicyProvider.java @@ -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 diff --git a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java index 60222f6d..90397755 100644 --- a/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java +++ b/main/src/test/java/org/onap/policy/api/main/startstop/TestMain.java @@ -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()); } } |