From: adheli.tavares Date: Mon, 21 Jul 2025 09:50:06 +0000 (+0100) Subject: Fix sonar issues X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F141555%2F1;p=policy%2Fapi.git Fix sonar issues Issue-ID: POLICY-5421 Change-Id: I767787d7c0129aecc778292c5e8ae08eea256d14 Signed-off-by: adheli.tavares --- diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestController.java index a9a7cb8a..1c9dd2cf 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2024 Nordix Foundation. All rights reserved. + * Copyright (C) 2024-2025 OpenInfra Foundation Europe. 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. @@ -43,10 +43,10 @@ import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -59,10 +59,10 @@ class TestApiRestController { @Autowired private MockMvc mvc; - @MockBean + @MockitoBean private HealthCheckProvider healthCheckProvider; - @MockBean + @MockitoBean private ToscaServiceTemplateService toscaServiceTemplateService; AutoCloseable autoCloseable; diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java b/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java index 22c4346d..06ff1f59 100644 --- a/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java +++ b/main/src/test/java/org/onap/policy/api/main/rest/TestNodeTemplateController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2022-2024 Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2025 OpenInfra Foundation Europe. 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. @@ -43,10 +43,10 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -59,7 +59,7 @@ class TestNodeTemplateController { @Autowired private MockMvc mvc; - @MockBean + @MockitoBean private ToscaServiceTemplateService toscaServiceTemplateService; AutoCloseable autoCloseable; diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java index fcdb9287..924ed1e1 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestCommonToscaServiceTemplateService.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2023-2024 Nordix Foundation. + * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe. 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. @@ -35,7 +35,7 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * This class offers common mock utility methods for uni testing {@link ToscaServiceTemplateService}. */ -public class TestCommonToscaServiceTemplateService { +class TestCommonToscaServiceTemplateService { protected enum Operation { CREATE_POLICY_TYPE, @@ -93,14 +93,14 @@ public class TestCommonToscaServiceTemplateService { * Setup to return empty DB service template. */ @BeforeEach - public void setUp() { + void setUp() { autoCloseable = MockitoAnnotations.openMocks(this); Mockito.when(toscaServiceTemplateRepository.findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME, JpaToscaServiceTemplate.DEFAULT_VERSION))).thenReturn(Optional.of(new JpaToscaServiceTemplate())); } @AfterEach - public void tearDown() throws Exception { + void tearDown() throws Exception { autoCloseable.close(); } } \ No newline at end of file diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java index b48306ff..a1fea219 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestNodeTemplateService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy API * ================================================================================ - * Copyright (C) 2022-2024 Nordix Foundation. All rights reserved. + * Copyright (C) 2022-2025 OpenInfra Foundation Europe. 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. @@ -74,7 +74,7 @@ class TestNodeTemplateService { * @throws CoderException if error in json parsing */ @BeforeEach - public void setUp() throws CoderException { + void setUp() throws CoderException { closeable = MockitoAnnotations.openMocks(this); StandardCoder standardCoder = new StandardCoder(); policyServiceTemplate = diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java index d46592fc..da37ff03 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestPdpGroupService.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023, 2025 OpenInfra Foundation Europe. 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. @@ -56,7 +56,7 @@ class TestPdpGroupService { * @throws CoderException decode errors */ @BeforeEach - public void setUp() throws CoderException { + void setUp() throws CoderException { closeable = MockitoAnnotations.openMocks(this); var pdpGroups = new StandardCoder().decode(ResourceUtils.getResourceAsString("pdpgroups/PdpGroups.json"), PdpGroups.class).getGroups(); diff --git a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java index 278d5971..cc311491 100644 --- a/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java +++ b/main/src/test/java/org/onap/policy/api/main/service/TestPolicyTypeService.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2022 Bell Canada. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications Copyright (C) 2023, 2025 OpenInfra Foundation Europe. 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. @@ -44,7 +44,7 @@ class TestPolicyTypeService { AutoCloseable closeable; @BeforeEach - public void setUp() { + void setUp() { closeable = MockitoAnnotations.openMocks(this); } diff --git a/packages/policy-api-docker/src/main/docker/policy-api.sh b/packages/policy-api-docker/src/main/docker/policy-api.sh index e638ceb9..b4c0fefc 100644 --- a/packages/policy-api-docker/src/main/docker/policy-api.sh +++ b/packages/policy-api-docker/src/main/docker/policy-api.sh @@ -2,7 +2,7 @@ # # ============LICENSE_START======================================================= # Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. -# Modifications Copyright (C) 2019-2022 Nordix Foundation. +# Modifications Copyright (C) 2019-2022, 2025 OpenInfra Foundation Europe. All rights reserved. # Modifications Copyright (C) 2022 Bell Canada. All rights reserved. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,14 +21,10 @@ # ============LICENSE_END========================================================= # -KEYSTORE="${KEYSTORE:-$POLICY_HOME/etc/ssl/policy-keystore}" -TRUSTSTORE="${TRUSTSTORE:-$POLICY_HOME/etc/ssl/policy-truststore}" -KEYSTORE_PASSWD="${KEYSTORE_PASSWD:-Pol1cy_0nap}" -TRUSTSTORE_PASSWD="${TRUSTSTORE_PASSWD:-Pol1cy_0nap}" - if [ "$#" -eq 1 ]; then CONFIG_FILE=$1 else + # shellcheck disable=SC2269 CONFIG_FILE=${CONFIG_FILE} fi @@ -38,26 +34,12 @@ fi echo "Policy api config file: $CONFIG_FILE" -if [ -f "${POLICY_HOME}/etc/mounted/policy-truststore" ]; then - echo "overriding policy-truststore" - cp -f "${POLICY_HOME}"/etc/mounted/policy-truststore "${TRUSTSTORE}" -fi - -if [ -f "${POLICY_HOME}/etc/mounted/policy-keystore" ]; then - echo "overriding policy-keystore" - cp -f "${POLICY_HOME}"/etc/mounted/policy-keystore "${KEYSTORE}" -fi - if [ -f "${POLICY_HOME}/etc/mounted/logback.xml" ]; then echo "overriding logback.xml" cp -f "${POLICY_HOME}"/etc/mounted/logback.xml "${POLICY_HOME}"/etc/ fi -$JAVA_HOME/bin/java \ +"$JAVA_HOME"/bin/java \ -Dlogging.config="${POLICY_HOME}/etc/logback.xml" \ - -Dserver.ssl.key-store="${KEYSTORE}" \ - -Dserver.ssl.key-store-password="${KEYSTORE_PASSWD}" \ - -Djavax.net.ssl.trustStore="${TRUSTSTORE}" \ - -Djavax.net.ssl.trustStorePassword="${TRUSTSTORE_PASSWD}" \ -jar /app/api.jar \ --spring.config.location="${CONFIG_FILE}" diff --git a/packages/policy-api-tarball/src/main/resources/etc/ssl/policy-truststore b/packages/policy-api-tarball/src/main/resources/etc/ssl/policy-truststore deleted file mode 100644 index 8834ac25..00000000 Binary files a/packages/policy-api-tarball/src/main/resources/etc/ssl/policy-truststore and /dev/null differ