summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2022-12-20 12:03:46 +0000
committerlapentafd <francesco.lapenta@est.tech>2022-12-21 10:41:25 +0000
commit80aa9814fe7d52b1c893ae36db8c4be103e53484 (patch)
treecfe632bfd702e22965c4077a46e6ba0b63cb055d /main/src/test
parent2e012cd81b39424ab691f5bacbd80eb56f20add6 (diff)
Use generated API interface for Swagger(2)
This commit removes the Swagger V2 annotations on the ApiRestController in policy-api. The OpeApi annotations (Swagger v3 annotations) are on a generated Java Interface. The code is changed so that the controller implements that interface. There are no code changes tot he controller except that the order of the parameters is switched in some cases. Adds unit test for SpingDoc swagger document generator endpoint. Issue-ID: POLICY-4404 Change-Id: Ic8976362481a0b49ad05cebb2f4f9ce4147f3965 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java12
-rw-r--r--main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java24
2 files changed, 26 insertions, 10 deletions
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
index 4f4dd6b8..eab9fe72 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/TestApiRestServer.java
@@ -184,6 +184,11 @@ public class TestApiRestServer extends CommonTestRestController {
}
@Test
+ public void testSwagger() throws Exception {
+ super.testSwagger(apiPort);
+ }
+
+ @Test
public void testCreatePolicyTypes() throws Exception {
for (String resrcName : TOSCA_POLICYTYPE_RESOURCE_NAMES) {
Response rawResponse = createResource(POLICYTYPES, resrcName, apiPort);
@@ -318,7 +323,8 @@ public class TestApiRestServer extends CommonTestRestController {
}
private void testHealthCheckSuccess(String mediaType) throws Exception {
- final Invocation.Builder invocationBuilder = sendHttpsRequest(HEALTHCHECK_ENDPOINT, mediaType, apiPort);
+ final Invocation.Builder invocationBuilder = sendHttpsRequest(
+ CONTEXT_PATH, HEALTHCHECK_ENDPOINT, mediaType, apiPort);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
}
@@ -334,11 +340,11 @@ public class TestApiRestServer extends CommonTestRestController {
}
private void testApiStatistics_200(String mediaType) throws Exception {
- Invocation.Builder invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType, apiPort);
+ Invocation.Builder invocationBuilder = sendHttpsRequest(CONTEXT_PATH, STATISTICS_ENDPOINT, mediaType, apiPort);
StatisticsReport report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 200);
updateApiStatistics();
- invocationBuilder = sendHttpsRequest(STATISTICS_ENDPOINT, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(CONTEXT_PATH, STATISTICS_ENDPOINT, mediaType, apiPort);
report = invocationBuilder.get(StatisticsReport.class);
validateStatisticsReport(report, 200);
// ApiStatisticsManager.resetAllStatistics();
diff --git a/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java b/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java
index 9289adb2..4f2e8b22 100644
--- a/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java
+++ b/main/src/test/java/org/onap/policy/api/main/rest/utils/CommonTestRestController.java
@@ -22,6 +22,8 @@
package org.onap.policy.api.main.rest.utils;
+import static org.junit.Assert.assertTrue;
+
import java.security.SecureRandom;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -54,6 +56,14 @@ public class CommonTestRestController {
protected static final StandardCoder standardCoder = new StandardCoder();
protected static StandardYamlCoder standardYamlCoder = new StandardYamlCoder();
+ protected static final String HTTPS_PREFIX = "https://localhost:";
+ protected static final String CONTEXT_PATH = "/policy/api/v1/";
+
+ protected void testSwagger(final int apiPort) throws Exception {
+ 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\""));
+ }
protected Response createResource(String endpoint, String resourceName, int apiPort)
throws Exception {
@@ -63,7 +73,7 @@ public class CommonTestRestController {
mediaType = mediaType == null ? APP_JSON : mediaType;
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
return invocationBuilder.post(entity);
}
@@ -71,14 +81,14 @@ public class CommonTestRestController {
protected Response readResource(String endpoint, String mediaType, int apiPort) throws Exception {
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
return invocationBuilder.get();
}
protected Response deleteResource(String endpoint, String mediaType, int apiPort) throws Exception {
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
return invocationBuilder.delete();
}
@@ -88,7 +98,7 @@ public class CommonTestRestController {
ToscaServiceTemplate rawServiceTemplate = getRawServiceTemplate(resourceName);
final Invocation.Builder invocationBuilder;
- invocationBuilder = sendHttpsRequest(endpoint, mediaType, apiPort);
+ invocationBuilder = sendHttpsRequest(CONTEXT_PATH, endpoint, mediaType, apiPort);
Entity<ToscaServiceTemplate> entity = Entity.entity(rawServiceTemplate, mediaType);
return invocationBuilder.put(entity);
}
@@ -101,8 +111,8 @@ public class CommonTestRestController {
return standardYamlCoder.decode(ResourceUtils.getResourceAsString(resourceName), ToscaServiceTemplate.class);
}
- protected Invocation.Builder sendHttpsRequest(final String endpoint, String mediaType, int apiPort)
- throws Exception {
+ protected Invocation.Builder sendHttpsRequest(
+ final String context, final String endpoint, String mediaType, int apiPort) throws Exception {
final TrustManager[] noopTrustManager = NetworkUtil.getAlwaysTrustingManager();
@@ -121,7 +131,7 @@ public class CommonTestRestController {
client.register(YamlMessageBodyHandler.class);
}
- final WebTarget webTarget = client.target("https://localhost:" + apiPort + "/policy/api/v1/" + endpoint);
+ final WebTarget webTarget = client.target(HTTPS_PREFIX + apiPort + context + endpoint);
final Invocation.Builder invocationBuilder = webTarget.request(mediaType);