Java 17 / Spring 6 / Spring Boot 3 Upgrade
[policy/api.git] / main / src / test / java / org / onap / policy / api / main / rest / utils / CommonTestRestController.java
index 947ed6a..8e9bf70 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy API
  * ================================================================================
- * Copyright (C) 2022 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2022-2023 Nordix Foundation. 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.
 
 package org.onap.policy.api.main.rest.utils;
 
-import static org.junit.Assert.assertTrue;
-
+import jakarta.ws.rs.client.Client;
+import jakarta.ws.rs.client.ClientBuilder;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.Response;
 import java.security.SecureRandom;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
 import org.glassfish.jersey.client.ClientProperties;
 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.junit.jupiter.api.Assertions;
 import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
 import org.onap.policy.common.gson.GsonMessageBodyHandler;
 import org.onap.policy.common.utils.coder.CoderException;
@@ -46,7 +45,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 
 /**
  * Util class to perform REST unit tests.
- *
  */
 public class CommonTestRestController {
 
@@ -60,9 +58,10 @@ public class CommonTestRestController {
     protected static final String CONTEXT_PATH = "/policy/api/v1/";
 
     protected void testSwagger(final int apiPort) throws Exception {
-        final Invocation.Builder invocationBuilder = sendHttpsRequest(CONTEXT_PATH, "v3/api-docs", APP_JSON, apiPort);
+        final Invocation.Builder invocationBuilder = sendHttpsRequest("v3/api-docs", APP_JSON, apiPort);
         final String resp = invocationBuilder.get(String.class);
-        assertTrue((resp).contains("{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Policy Framework Lifecycle API\""));
+        Assertions.assertTrue(
+            (resp).contains("{\"openapi\":\"3.0.1\",\"info\":{\"title\":\"Policy Framework Lifecycle API\""));
     }
 
     protected Response createResource(String endpoint, String resourceName, int apiPort)
@@ -70,10 +69,10 @@ public class CommonTestRestController {
 
         ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName);
         String mediaType = getMediaType(resourceName);
-        mediaType = mediaType == null ?  APP_JSON : mediaType;
+        mediaType = mediaType == null ? APP_JSON : mediaType;
 
         final Invocation.Builder invocationBuilder;
-        invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+        invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
         Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
         return invocationBuilder.post(entity);
     }
@@ -81,14 +80,14 @@ public class CommonTestRestController {
     protected Response readResource(String endpoint, String mediaType, int apiPort) throws Exception {
 
         final Invocation.Builder invocationBuilder;
-        invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+        invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
         return invocationBuilder.get();
     }
 
     protected Response deleteResource(String endpoint, String mediaType, int apiPort) throws Exception {
 
         final Invocation.Builder invocationBuilder;
-        invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+        invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
         return invocationBuilder.delete();
     }
 
@@ -98,7 +97,7 @@ public class CommonTestRestController {
         ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName);
 
         final Invocation.Builder invocationBuilder;
-        invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
+        invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
         Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
         return invocationBuilder.put(entity);
     }
@@ -112,7 +111,7 @@ public class CommonTestRestController {
     }
 
     protected Invocation.Builder sendHttpsRequest(
-            final String context, final String endpoint, String mediaType, int apiPort) throws Exception {
+        final String endpoint, String mediaType, int apiPort) throws Exception {
 
         final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager();
 
@@ -131,7 +130,7 @@ public class CommonTestRestController {
             client.register(YamlMessageBodyHandler.class);
         }
 
-        final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + context + endpoint);
+        final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + CONTEXT_PATH + endpoint);
 
         final Invocation.Builder invocationBuilder = webTarget.request(mediaType);
 
@@ -148,7 +147,7 @@ public class CommonTestRestController {
         } else if (APP_YAML.equals(getMediaType(resourceName))) {
             rawServiceTemplate = decodeYaml(resourceName);
         }
-        return  rawServiceTemplate;
+        return rawServiceTemplate;
     }
 
     private String getMediaType(String resourceName) {