Remove org.glassfish from Actuator test in all ACM participants 75/140275/1
authorFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 19 Feb 2025 15:15:47 +0000 (15:15 +0000)
committerFrancescoFioraEst <francesco.fiora@est.tech>
Wed, 19 Feb 2025 15:25:08 +0000 (15:25 +0000)
Issue-ID: POLICY-5290
Change-Id: I7c4640d6d3fe18c5ed64eaaf3e4ab4be44e7190f
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
15 files changed:
participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java [deleted file]
participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-acelement/src/test/java/org/onap/policy/clamp/acm/element/utils/CommonActuatorController.java [deleted file]
participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java [deleted file]
participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java [deleted file]
participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java [deleted file]
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java [deleted file]
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/rest/ActuatorControllerTest.java
participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java [deleted file]
runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/main/rest/ActuatorControllerTest.java

index b8f1600..89ce8c0 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2023 Nordix Foundation.
+ *  Copyright (C) 2022-2023,2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.participant.a1pms.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
-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.participant.a1pms.utils.CommonActuatorController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 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;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    private static final String HEALTH_ENDPOINT = "health";
-    private static final String METRICS_ENDPOINT = "metrics";
-    private static final String PROMETHEUS_ENDPOINT = "prometheus";
+    @Autowired
+    private WebTestClient webClient;
 
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
-    void testGePrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+    void testGetPrometheus() {
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
-
 }
diff --git a/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-a1pms/src/test/java/org/onap/policy/clamp/acm/participant/a1pms/utils/CommonActuatorController.java
deleted file mode 100644 (file)
index c4a9347..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.a1pms.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-    public static final String CONTEXT_PATH = "onap/policy/clamp/acm/a1pmsparticipant/";
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth            if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final Client client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("participantUser", "zb!XztG34"));
-        }
-
-        final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index 453ccc9..e3c665a 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2024 Nordix Foundation.
+ *  Copyright (C) 2022-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.element.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
-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.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 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;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles({ "test", "default" })
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    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";
+    @Autowired
+    private WebTestClient webClient;
 
-    private static final String WRONG_ENDPOINT = "onap/policy/clamp/acelement/v2/wrong";
-
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
-    }
-
-    @Test
-    void testGetSwagger_Unauthorized() {
-        assertUnauthorizedActGet(SWAGGER_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetPrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetSwagger() {
-        var invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
-    }
-
-    @Test
-    void testWrongEndPoint() {
-        var invocationBuilder = super.sendActRequest(WRONG_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/v3/api-docs").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 }
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
deleted file mode 100644 (file)
index a1d2203..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2022-2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.element.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- *
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final Client client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("acmUser", "zb!XztG34"));
-        }
-
-        final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index 149d8d9..130f656 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.participant.http.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
-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.participant.http.utils.CommonActuatorController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 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;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    private static final String HEALTH_ENDPOINT = "health";
-    private static final String METRICS_ENDPOINT = "metrics";
-    private static final String PROMETHEUS_ENDPOINT = "prometheus";
+    @Autowired
+    private WebTestClient webClient;
 
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
-    void testGePrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+    void testGetPrometheus() {
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
-
 }
diff --git a/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-http/src/test/java/org/onap/policy/clamp/acm/participant/http/utils/CommonActuatorController.java
deleted file mode 100644 (file)
index fa9068a..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.http.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- *
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-    public static final String CONTEXT_PATH = "onap/policy/clamp/acm/httpparticipant/";
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final Client client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("participantUser", "zb!XztG34"));
-        }
-
-        final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index dbdefd2..732dd7b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.participant.kserve.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
 import io.kubernetes.client.openapi.ApiClient;
-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.participant.kserve.utils.CommonActuatorController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
 import org.springframework.boot.test.mock.mockito.MockBean;
-import org.springframework.boot.test.web.server.LocalServerPort;
 import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    private static final String HEALTH_ENDPOINT = "health";
-    private static final String METRICS_ENDPOINT = "metrics";
-    private static final String PROMETHEUS_ENDPOINT = "prometheus";
+    @Autowired
+    private WebTestClient webClient;
 
     @MockBean
-    ApiClient apiClient;
+    private ApiClient apiClient;
 
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
-    void testGePrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+    void testGetPrometheus() {
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
 }
diff --git a/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-kserve/src/test/java/org/onap/policy/clamp/acm/participant/kserve/utils/CommonActuatorController.java
deleted file mode 100644 (file)
index ab2d28a..0000000
+++ /dev/null
@@ -1,107 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.kserve.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-    public static final String CONTEXT_PATH = "onap/policy/clamp/acm/kserveparticipant/";
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth            if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final Client client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("participantUser", "zb!XztG34"));
-        }
-
-        final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index b5b18c5..0dce19e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
+ *  Copyright (C) 2021-2023,2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.participant.kubernetes.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
-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.participant.kubernetes.utils.CommonActuatorController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 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;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    private static final String HEALTH_ENDPOINT = "health";
-    private static final String METRICS_ENDPOINT = "metrics";
-    private static final String PROMETHEUS_ENDPOINT = "prometheus";
-    private static final String SWAGGER_ENDPOINT = "v3/api-docs";
+    @Autowired
+    private WebTestClient webClient;
 
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
-    }
-
-    @Test
-    void testGetSwagger_Unauthorized() {
-        assertUnauthorizedActGet(SWAGGER_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetPrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetSwagger() {
-        var invocationBuilder = super.sendActRequest(SWAGGER_ENDPOINT);
-        var rawresp = invocationBuilder.buildGet().invoke();
-        assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+        webClient.get().uri("/v3/api-docs").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 }
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/utils/CommonActuatorController.java
deleted file mode 100644 (file)
index 4487dbe..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.kubernetes.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import jakarta.ws.rs.client.ClientBuilder;
-import jakarta.ws.rs.client.Invocation;
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- *
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-    public static final String CONTEXT_PATH = "onap/policy/clamp/acm/k8sparticipant/";
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final var client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("participantUser", "zb!XztG34"));
-        }
-
-        final var webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        var rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index 3672e59..91627ed 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.participant.policy.main.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
-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.participant.policy.main.utils.CommonActuatorController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 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;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    private static final String HEALTH_ENDPOINT = "health";
-    private static final String METRICS_ENDPOINT = "metrics";
-    private static final String PROMETHEUS_ENDPOINT = "prometheus";
+    @Autowired
+    private WebTestClient webClient;
 
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
-    void testGePrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+    void testGetPrometheus() {
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
 }
diff --git a/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-policy/src/test/java/org/onap/policy/clamp/acm/participant/policy/main/utils/CommonActuatorController.java
deleted file mode 100644 (file)
index 2b77452..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.policy.main.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- *
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-    public static final String CONTEXT_PATH = "onap/policy/clamp/acm/policyparticipant/";
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final Client client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("participantUser", "zb!XztG34"));
-        }
-
-        final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index ac24dea..a3bf682 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2023-2024 Nordix Foundation.
+ *  Copyright (C) 2023-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.clamp.acm.participant.sim.rest;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.http.MediaType.TEXT_PLAIN;
 
-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.participant.sim.utils.CommonActuatorController;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
 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;
+import org.springframework.test.web.reactive.server.WebTestClient;
+import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 
-@AutoConfigureObservability(tracing = false)
-@ExtendWith(SpringExtension.class)
+@AutoConfigureObservability
+@AutoConfigureWebTestClient
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 @ActiveProfiles("test")
-class ActuatorControllerTest extends CommonActuatorController {
+class ActuatorControllerTest {
 
-    private static final String HEALTH_ENDPOINT = "health";
-    private static final String METRICS_ENDPOINT = "metrics";
-    private static final String PROMETHEUS_ENDPOINT = "prometheus";
+    @Autowired
+    private WebTestClient webClient;
 
-    @LocalServerPort
-    private int randomServerPort;
+    @Value("${spring.security.user.name}")
+    private String username;
+    @Value("${spring.security.user.password}")
+    private String password;
 
     @BeforeEach
-    public void setUpPort() {
-        super.setHttpPrefix(randomServerPort);
-    }
-
-    @Test
-    void testGetHealth_Unauthorized() {
-        assertUnauthorizedActGet(HEALTH_ENDPOINT);
-    }
-
-    @Test
-    void testGetMetrics_Unauthorized() {
-        assertUnauthorizedActGet(METRICS_ENDPOINT);
-    }
-
-    @Test
-    void testGetPrometheus_Unauthorized() {
-        assertUnauthorizedActGet(PROMETHEUS_ENDPOINT);
+    void beforeEach() {
+        var filter = ExchangeFilterFunctions.basicAuthentication(username, password);
+        webClient = webClient.mutate().filter(filter).build();
     }
 
     @Test
     void testGetHealth() {
-        var invocationBuilder = super.sendActRequest(HEALTH_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/health").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
     void testGetMetrics() {
-        var invocationBuilder = super.sendActRequest(METRICS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+        webClient.get().uri("/metrics").accept(APPLICATION_JSON)
+                .exchange().expectStatus().isOk();
     }
 
     @Test
-    void testGePrometheus() {
-        var invocationBuilder = super.sendActRequest(PROMETHEUS_ENDPOINT);
-        try (var rawresp = invocationBuilder.buildGet().invoke()) {
-            assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
-        }
+    void testGetPrometheus() {
+        webClient.get().uri("/prometheus").accept(TEXT_PLAIN)
+                .exchange().expectStatus().isOk();
     }
-
 }
diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/acm/participant/sim/utils/CommonActuatorController.java
deleted file mode 100644 (file)
index 2cb0134..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2023 Nordix Foundation.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.clamp.acm.participant.sim.utils;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-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;
-import org.onap.policy.common.utils.network.NetworkUtil;
-
-/**
- * Class to perform Rest unit tests.
- *
- */
-public class CommonActuatorController {
-
-    public static final String SELF = NetworkUtil.getHostname();
-    public static final String CONTEXT_PATH = "onap/policy/clamp/acm/simparticipant/";
-
-    private static String httpPrefix;
-
-    /**
-     * Sends a request to an actuator endpoint.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, true);
-    }
-
-    /**
-     * Sends a request to an actuator endpoint, without any authorization header.
-     *
-     * @param endpoint the target endpoint
-     * @return a request builder
-     */
-    protected Invocation.Builder sendNoAuthActRequest(final String endpoint) {
-        return sendFqeRequest(httpPrefix + CONTEXT_PATH + endpoint, false);
-    }
-
-    /**
-     * Sends a request to a fully qualified endpoint.
-     *
-     * @param fullyQualifiedEndpoint the fully qualified target endpoint
-     * @param includeAuth if authorization header should be included
-     * @return a request builder
-     */
-    protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth) {
-        final Client client = ClientBuilder.newBuilder().build();
-
-        client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
-        client.register(GsonMessageBodyHandler.class);
-
-        if (includeAuth) {
-            client.register(HttpAuthenticationFeature.basic("participantUser", "zb!XztG34"));
-        }
-
-        final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
-
-        return webTarget.request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN);
-    }
-
-    /**
-     * Assert that GET call to actuator endpoint is Unauthorized.
-     *
-     * @param endPoint the endpoint
-     */
-    protected void assertUnauthorizedActGet(final String endPoint) {
-        Response rawresp = sendNoAuthActRequest(endPoint).buildGet().invoke();
-        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), rawresp.getStatus());
-    }
-
-    /**
-     * Set Up httpPrefix.
-     *
-     * @param port the port
-     */
-    protected void setHttpPrefix(int port) {
-        httpPrefix = "http://" + SELF + ":" + port + "/";
-    }
-
-}
index 18911f4..4b3e8ed 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2024 Nordix Foundation.
+ *  Copyright (C) 2021-2025 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -42,12 +42,12 @@ import org.springframework.web.reactive.function.client.ExchangeFilterFunctions;
 class ActuatorControllerTest {
 
     @Autowired
-    WebTestClient webClient;
+    private WebTestClient webClient;
 
     @Value("${spring.security.user.name}")
-    String username;
+    private String username;
     @Value("${spring.security.user.password}")
-    String password;
+    private String password;
 
     @BeforeEach
     void beforeEach() {