* ============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.
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.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
/**
* Util class to perform REST unit tests.
- *
*/
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\""));
}
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);
}
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();
}
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);
}
}
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();
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);
} else if (APP_YAML.equals(getMediaType(resourceName))) {
rawServiceTemplate = decodeYaml(resourceName);
}
- return rawServiceTemplate;
+ return rawServiceTemplate;
}
private String getMediaType(String resourceName) {