From 4407ea6948a060734a4f2836b11bd2d5c6ea6194 Mon Sep 17 00:00:00 2001 From: "adheli.tavares" Date: Fri, 11 Aug 2023 15:10:44 +0100 Subject: Upgrade Java 17 Issue-ID: POLICY-4673 Change-Id: I01fd3677687b5d2e065d0cc131b338ed841d7e99 Signed-off-by: adheli.tavares --- .../participant-impl-acelement/pom.xml | 6 ++- .../clamp/acm/element/config/SecurityConfig.java | 10 ++--- .../acm/element/handler/MessageActivator.java | 6 +-- .../clamp/acm/element/handler/MessageHandler.java | 10 ++--- .../acm/element/handler/MessagePublisher.java | 2 +- .../acm/element/main/parameters/AcElement.java | 4 +- .../main/rest/AcElementErrorController.java | 4 +- .../clamp/acm/element/service/ConfigService.java | 2 +- .../clamp/acm/element/service/SinkService.java | 2 +- .../clamp/acm/element/service/StarterService.java | 2 +- .../acm/element/rest/AcElementControllerTest.java | 2 +- .../acm/element/rest/ActuatorControllerTest.java | 49 +++++++++++----------- .../element/utils/CommonActuatorController.java | 12 +++--- 13 files changed, 55 insertions(+), 56 deletions(-) mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/pom.xml mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/StarterService.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java mode change 100644 => 100755 participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java (limited to 'participant/participant-impl/participant-impl-acelement') diff --git a/participant/participant-impl/participant-impl-acelement/pom.xml b/participant/participant-impl/participant-impl-acelement/pom.xml old mode 100644 new mode 100755 index b4a63406a..b82f9b501 --- a/participant/participant-impl/participant-impl-acelement/pom.xml +++ b/participant/participant-impl/participant-impl-acelement/pom.xml @@ -26,7 +26,7 @@ org.onap.policy.clamp.participant policy-clamp-participant-impl - 7.0.0-SNAPSHOT + 7.0.1-SNAPSHOT policy-clamp-acm-element-impl @@ -56,9 +56,10 @@ src/gen/java - java11 + java17 true true + true @@ -67,6 +68,7 @@ org.springframework.boot spring-boot-maven-plugin + ${version.springboot} diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SecurityConfig.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SecurityConfig.java index ecb127580..71b01dbdf 100644 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SecurityConfig.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/config/SecurityConfig.java @@ -22,7 +22,9 @@ package org.onap.policy.clamp.acm.element.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.web.SecurityFilterChain; /** @@ -39,11 +41,9 @@ public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { http - .httpBasic() - .and() - .authorizeHttpRequests().anyRequest().authenticated() - .and() - .csrf().disable(); + .httpBasic(Customizer.withDefaults()) + .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated()) + .csrf(AbstractHttpConfigurer::disable); return http.build(); } } diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageActivator.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageActivator.java index ac3c72e52..ef8ceb00f 100644 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageActivator.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageActivator.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.util.List; import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementMessageType; import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager; -import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher; import org.onap.policy.common.endpoints.parameters.TopicParameterGroup; @@ -46,13 +45,12 @@ public class MessageActivator extends ServiceManagerContainer implements AutoClo private static final String[] MSG_TYPE_NAMES = { "messageType" }; // Topics from which the AC element receives and sends messages - private List topicSinks; private List topicSources; private final MessageListener listener; private final MessagePublisher publisher; - private MessageTypeDispatcher msgDispatcher; + private final MessageTypeDispatcher msgDispatcher; /** * Constructor. @@ -73,7 +71,7 @@ public class MessageActivator extends ServiceManagerContainer implements AutoClo * @param parameters TopicParameterGroup */ public void activate(final TopicParameterGroup parameters) { - topicSinks = TopicEndpointManager.getManager().addTopicSinks(parameters.getTopicSinks()); + var topicSinks = TopicEndpointManager.getManager().addTopicSinks(parameters.getTopicSinks()); topicSources = TopicEndpointManager.getManager().addTopicSources(parameters.getTopicSources()); // @formatter:off diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java old mode 100644 new mode 100755 index 906fc321c..c0ac329e0 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessageHandler.java @@ -21,10 +21,10 @@ package org.onap.policy.clamp.acm.element.handler; import io.micrometer.core.annotation.Timed; -import java.util.HashMap; +import jakarta.ws.rs.core.Response; +import java.util.EnumMap; import java.util.List; import java.util.Map; -import javax.ws.rs.core.Response; import lombok.NonNull; import org.onap.policy.clamp.acm.element.main.parameters.AcElement; import org.onap.policy.clamp.acm.element.service.ElementService; @@ -39,9 +39,9 @@ import org.springframework.stereotype.Component; public class MessageHandler { private ElementType elementType; - private ToscaConceptIdentifier elementId; + private final ToscaConceptIdentifier elementId; - private Map map = new HashMap<>(); + private final Map map = new EnumMap<>(ElementType.class); /** * Constructor. @@ -51,7 +51,7 @@ public class MessageHandler { */ public MessageHandler(AcElement acElement, List elementServices) { elementId = acElement.getElementId(); - elementServices.stream().forEach(elementService -> map.put(elementService.getType(), elementService)); + elementServices.forEach(elementService -> map.put(elementService.getType(), elementService)); } /** diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java old mode 100644 new mode 100755 index 1b0c2234a..09c681d93 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/handler/MessagePublisher.java @@ -21,8 +21,8 @@ package org.onap.policy.clamp.acm.element.handler; import io.micrometer.core.annotation.Timed; +import jakarta.ws.rs.core.Response; import java.util.List; -import javax.ws.rs.core.Response; import org.onap.policy.clamp.common.acm.exception.AutomationCompositionRuntimeException; import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementMessage; import org.onap.policy.common.endpoints.event.comm.TopicSink; diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java old mode 100644 new mode 100755 index bb80cc638..a0df74c50 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/parameters/AcElement.java @@ -21,8 +21,8 @@ package org.onap.policy.clamp.acm.element.main.parameters; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java old mode 100644 new mode 100755 index 717390088..3442eedf6 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/main/rest/AcElementErrorController.java @@ -22,9 +22,9 @@ package org.onap.policy.clamp.acm.element.main.rest; +import jakarta.servlet.RequestDispatcher; +import jakarta.servlet.http.HttpServletRequest; import java.util.Map; -import javax.servlet.RequestDispatcher; -import javax.servlet.http.HttpServletRequest; import org.onap.policy.clamp.models.acm.messages.rest.SimpleResponse; import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse; import org.springframework.beans.factory.annotation.Value; diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java old mode 100644 new mode 100755 index ff07cef53..b3f662c86 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/ConfigService.java @@ -20,8 +20,8 @@ package org.onap.policy.clamp.acm.element.service; +import jakarta.ws.rs.core.Response; import java.util.List; -import javax.ws.rs.core.Response; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.onap.policy.clamp.acm.element.handler.MessageActivator; diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/SinkService.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/SinkService.java index 6de8255ba..c90643f39 100644 --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/SinkService.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/SinkService.java @@ -36,7 +36,7 @@ public class SinkService extends AbstractElementService { @Override public void handleMessage(ElementMessage message) { - LOGGER.info("Cycle completed in sink service with the full message: " + message); + LOGGER.info("Cycle completed in sink service with the full message: {}", message); } @Override diff --git a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/StarterService.java b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/StarterService.java old mode 100644 new mode 100755 index 479fa44b6..236ba502b --- a/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/StarterService.java +++ b/participant/participant-impl/participant-impl-acelement/src/main/java/org/onap/policy/clamp/acm/element/service/StarterService.java @@ -20,10 +20,10 @@ package org.onap.policy.clamp.acm.element.service; +import jakarta.ws.rs.core.Response; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import javax.ws.rs.core.Response; import org.onap.policy.clamp.acm.element.handler.MessagePublisher; import org.onap.policy.clamp.acm.element.main.parameters.AcElement; import org.onap.policy.clamp.models.acm.messages.dmaap.element.ElementStatus; diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java old mode 100644 new mode 100755 index 1d19b1a17..1ffe7d11d --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/AcElementControllerTest.java @@ -30,10 +30,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import jakarta.ws.rs.core.Response; import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; -import javax.ws.rs.core.Response; import org.apache.commons.io.FileUtils; import org.json.JSONObject; import org.junit.jupiter.api.BeforeAll; diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java old mode 100644 new mode 100755 index c37bca3aa..5ccee7b31 --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java @@ -22,29 +22,28 @@ package org.onap.policy.clamp.acm.element.rest; import static org.junit.jupiter.api.Assertions.assertEquals; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.core.Response; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.onap.policy.clamp.acm.element.utils.CommonActuatorController; -import org.springframework.boot.test.autoconfigure.actuate.metrics.AutoConfigureMetrics; +import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.server.LocalServerPort; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; -@AutoConfigureMetrics +@AutoConfigureObservability(tracing = false) @ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") +@ActiveProfiles({ "test", "default" }) class ActuatorControllerTest extends CommonActuatorController { - private static final String HEALTH_ENDPOINT = "onap/policy/clamp/acelement/v2/health/"; - private static final String METRICS_ENDPOINT = "onap/policy/clamp/acelement/v2/metrics/"; - private static final String PROMETHEUS_ENDPOINT = "onap/policy/clamp/acelement/v2/prometheus/"; - private static final String SWAGGER_ENDPOINT = "onap/policy/clamp/acelement/v2/v3/api-docs/"; + private static final String HEALTH_ENDPOINT = "onap/policy/clamp/acelement/v2/health"; + private static final String METRICS_ENDPOINT = "onap/policy/clamp/acelement/v2/metrics"; + private static final String PROMETHEUS_ENDPOINT = "onap/policy/clamp/acelement/v2/prometheus"; + private static final String SWAGGER_ENDPOINT = "onap/policy/clamp/acelement/v2/v3/api-docs"; @LocalServerPort private int randomServerPort; @@ -55,50 +54,50 @@ class ActuatorControllerTest extends CommonActuatorController { } @Test - void testGetHealth_Unauthorized() throws Exception { + void testGetHealth_Unauthorized() { assertUnauthorizedActGet(HEALTH_ENDPOINT); } @Test - void testGetMetrics_Unauthorized() throws Exception { + void testGetMetrics_Unauthorized() { assertUnauthorizedActGet(METRICS_ENDPOINT); } @Test - void testGetPrometheus_Unauthorized() throws Exception { + void testGetPrometheus_Unauthorized() { assertUnauthorizedActGet(PROMETHEUS_ENDPOINT); } @Test - void testGetSwagger_Unauthorized() throws Exception { + void testGetSwagger_Unauthorized() { assertUnauthorizedActGet(SWAGGER_ENDPOINT); } @Test - void testGetHealth() throws Exception { - Invocation.Builder invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); - Response rawresp = invocationBuilder.buildGet().invoke(); + void testGetHealth() { + var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT); + var rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); } @Test - void testGetMetrics() throws Exception { - Invocation.Builder invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); - Response rawresp = invocationBuilder.buildGet().invoke(); + void testGetMetrics() { + var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT); + var rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); } @Test - void testGetPrometheus() throws Exception { - Invocation.Builder invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); - Response rawresp = invocationBuilder.buildGet().invoke(); + void testGetPrometheus() { + var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT); + var rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); } @Test - void testGetSwagger() throws Exception { - Invocation.Builder invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT); - Response rawresp = invocationBuilder.buildGet().invoke(); + void testGetSwagger() { + var invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT); + var rawresp = invocationBuilder.buildGet().invoke(); assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); } } diff --git a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java old mode 100644 new mode 100755 index 022925dab..1b43e607f --- a/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java +++ b/participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java @@ -22,12 +22,12 @@ package org.onap.policy.clamp.acm.element.utils; import static org.junit.Assert.assertEquals; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Invocation; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; +import jakarta.ws.rs.client.Client; +import jakarta.ws.rs.client.ClientBuilder; +import jakarta.ws.rs.client.Invocation; +import jakarta.ws.rs.client.WebTarget; +import jakarta.ws.rs.core.MediaType; +import jakarta.ws.rs.core.Response; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.onap.policy.common.gson.GsonMessageBodyHandler; -- cgit 1.2.3-korg