aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authorRam Krishna Verma <ram_krishna.verma@bell.ca>2022-02-10 14:35:12 -0500
committerRam Krishna Verma <ram_krishna.verma@bell.ca>2022-02-10 14:35:17 -0500
commitf5fda6421dad76d369774c59e89a448a6c4e8c07 (patch)
treed0636eee32fb0fcd383ada1488ae6cba2bcefac1 /main/src/test
parent873803eca00830dc3ecb61e610d90710f64a8242 (diff)
Add yaml support to pap api's
Adding yaml support to pap rest api's. Along with related unit tests. Issue-ID: POLICY-3864 Change-Id: I43bdbbd4151bcae5dcf4752a9385b115efa947d3 Signed-off-by: Ram Krishna Verma <ram_krishna.verma@bell.ca>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java29
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java20
-rw-r--r--main/src/test/resources/e2e/createGroups.yaml31
3 files changed, 69 insertions, 11 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
index e42cfd21..c2d9f038 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/CommonPapRestServer.java
@@ -46,6 +46,7 @@ import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.onap.policy.common.gson.GsonMessageBodyHandler;
import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.common.utils.security.SelfSignedKeyStore;
@@ -143,7 +144,8 @@ public abstract class CommonPapRestServer {
* @throws Exception if an error occurs
*/
protected void testSwagger(final String endpoint) throws Exception {
- final Invocation.Builder invocationBuilder = sendFqeRequest(httpsPrefix + "v2/api-docs", true);
+ final Invocation.Builder invocationBuilder =
+ sendFqeRequest(httpsPrefix + "v2/api-docs", true, MediaType.APPLICATION_JSON);
final String resp = invocationBuilder.get(String.class);
assertTrue(resp.contains(ENDPOINT_PREFIX + endpoint));
}
@@ -198,7 +200,19 @@ public abstract class CommonPapRestServer {
* @throws Exception if an error occurs
*/
protected Invocation.Builder sendRequest(final String endpoint) throws Exception {
- return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, true);
+ return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, true, MediaType.APPLICATION_JSON);
+ }
+
+ /**
+ * Sends a request to an endpoint.
+ *
+ * @param endpoint the target endpoint
+ * @param mediaType the media type for the request
+ * @return a request builder
+ * @throws Exception if an error occurs
+ */
+ protected Invocation.Builder sendRequest(final String endpoint, String mediaType) throws Exception {
+ return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, true, mediaType);
}
/**
@@ -209,7 +223,7 @@ public abstract class CommonPapRestServer {
* @throws Exception if an error occurs
*/
protected Invocation.Builder sendNoAuthRequest(final String endpoint) throws Exception {
- return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, false);
+ return sendFqeRequest(httpsPrefix + ENDPOINT_PREFIX + endpoint, false, MediaType.APPLICATION_JSON);
}
/**
@@ -220,8 +234,8 @@ public abstract class CommonPapRestServer {
* @return a request builder
* @throws Exception if an error occurs
*/
- protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth)
- throws Exception {
+ protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, boolean includeAuth,
+ String mediaType) throws Exception {
final SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, NetworkUtil.getAlwaysTrustingManager(), new SecureRandom());
final ClientBuilder clientBuilder =
@@ -229,7 +243,8 @@ public abstract class CommonPapRestServer {
final Client client = clientBuilder.build();
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
- client.register(GsonMessageBodyHandler.class);
+ client.register((mediaType.equalsIgnoreCase(MediaType.APPLICATION_JSON) ? GsonMessageBodyHandler.class
+ : YamlMessageBodyHandler.class));
if (includeAuth) {
final HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("policyadmin", "zb!XztG34");
@@ -238,6 +253,6 @@ public abstract class CommonPapRestServer {
final WebTarget webTarget = client.target(fullyQualifiedEndpoint);
- return webTarget.request(MediaType.APPLICATION_JSON);
+ return webTarget.request(mediaType);
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java
index 3f763863..650dd41a 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupCreateOrUpdateTest.java
@@ -77,18 +77,30 @@ public class PdpGroupCreateOrUpdateTest extends End2EndBase {
}
@Test
- public void testCreateGroups() throws Exception {
+ public void testCreateGroupsJson() throws Exception {
+ createPdpGroups("createGroups.json", MediaType.APPLICATION_JSON);
+ }
+
+ @Test
+ public void testCreateGroupsYaml() throws Exception {
+
+ createPdpGroups("createGroups.yaml", "application/yaml");
+ }
+
+ private void createPdpGroups(String fileName, String mediaType) throws Exception, InterruptedException {
context.addPdp("pdpAA_1", CREATE_SUBGROUP);
context.addPdp("pdpAA_2", CREATE_SUBGROUP);
context.addPdp("pdpAB_1", "pdpTypeB");
context.startThreads();
- Invocation.Builder invocationBuilder = sendRequest(CREATEORUPDATE_GROUPS_ENDPOINT);
+ Invocation.Builder invocationBuilder = sendRequest(CREATEORUPDATE_GROUPS_ENDPOINT, mediaType);
- PdpGroups groups = loadJsonFile("createGroups.json", PdpGroups.class);
- Entity<PdpGroups> entity = Entity.entity(groups, MediaType.APPLICATION_JSON);
+ PdpGroups groups = (mediaType.equalsIgnoreCase(MediaType.APPLICATION_JSON)
+ ? loadJsonFile(fileName, PdpGroups.class)
+ : loadYamlFile(fileName, PdpGroups.class));
+ Entity<PdpGroups> entity = Entity.entity(groups, mediaType);
Response rawresp = invocationBuilder.post(entity);
PdpGroupUpdateResponse resp = rawresp.readEntity(PdpGroupUpdateResponse.class);
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
diff --git a/main/src/test/resources/e2e/createGroups.yaml b/main/src/test/resources/e2e/createGroups.yaml
new file mode 100644
index 00000000..fc98e971
--- /dev/null
+++ b/main/src/test/resources/e2e/createGroups.yaml
@@ -0,0 +1,31 @@
+groups:
+ - name: createGroups
+ pdpGroupState: PASSIVE
+ properties:
+ hello: world
+ pdpSubgroups:
+ - pdpType: pdpTypeA
+ desiredInstanceCount: 2
+ properties: {}
+ pdpInstances:
+ - instanceId: pdpAA_1
+ pdpState: ACTIVE
+ healthy: HEALTHY
+ - instanceId: pdpAA_2
+ pdpState: ACTIVE
+ healthy: HEALTHY
+ supportedPolicyTypes:
+ - name: onap.policies.monitoring.cdap.tca.hi.lo.app
+ version: 1.0.0
+ policies: []
+ - pdpType: pdpTypeB
+ desiredInstanceCount: 1
+ properties: {}
+ pdpInstances:
+ - instanceId: pdpAB_1
+ pdpState: ACTIVE
+ healthy: HEALTHY
+ supportedPolicyTypes:
+ - name: onap.policies.monitoring.cdap.tca.hi.lo.app
+ version: 1.0.0
+ policies: []