summaryrefslogtreecommitdiffstats
path: root/main/src/test/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-03-13 17:58:17 -0400
committerJim Hahn <jrh3@att.com>2019-03-13 21:51:14 -0400
commitdddf89d93ba7482bbee05c6967e0065b9c4fbb0e (patch)
tree66e133ff24d68ccf0380b475eb88f24e371b216e /main/src/test/java/org/onap
parent4a3cfdff6285a516f1e05d4cebd748ea623177e5 (diff)
Add simple deploy/undeploy REST API
Change-Id: I4b789bfe4f92dae930f3675c6648b90f3c9fc9e4 Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'main/src/test/java/org/onap')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java52
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java50
2 files changed, 90 insertions, 12 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
index 107c46ad..0384bf7e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
@@ -31,17 +31,21 @@ import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
- private static final String DELETE_ENDPOINT = "pdps/groups";
+ private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
+ private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies";
@Test
public void testSwagger() throws Exception {
- super.testSwagger(DELETE_ENDPOINT + "/{name}");
- super.testSwagger(DELETE_ENDPOINT + "/{name}/versions/{version}");
+ super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
+ super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}/versions/{version}");
+
+ super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
+ super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
}
@Test
public void testDeleteGroup() throws Exception {
- String uri = DELETE_ENDPOINT + "/my-name";
+ String uri = DELETE_GROUP_ENDPOINT + "/my-name";
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
@@ -60,7 +64,45 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
@Test
public void testDeleteGroupVersion() throws Exception {
- String uri = DELETE_ENDPOINT + "/my-name/versions/1.2.3";
+ String uri = DELETE_GROUP_ENDPOINT + "/my-name/versions/1.2.3";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.delete();
+ PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ rawresp = invocationBuilder.delete();
+ resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(uri, req -> req.delete());
+ }
+
+ @Test
+ public void testDeletePolicies() throws Exception {
+ String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.delete();
+ PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ rawresp = invocationBuilder.delete();
+ resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(uri, req -> req.delete());
+ }
+
+ @Test
+ public void testDeletePoliciesVersion() throws Exception {
+ String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
index d49f00cc..0fc3577e 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
@@ -32,22 +32,26 @@ import javax.ws.rs.core.Response;
import org.junit.Test;
import org.onap.policy.models.pap.concepts.PdpGroup;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
+import org.onap.policy.models.pap.concepts.PdpPolicies;
import org.onap.policy.models.pap.concepts.PdpSubGroup;
+import org.onap.policy.pdp.common.models.Policy;
public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
- private static final String DEPLOY_ENDPOINT = "pdps";
+ private static final String DEPLOY_GROUP_ENDPOINT = "pdps";
+ private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies";
@Test
public void testSwagger() throws Exception {
- super.testSwagger(DEPLOY_ENDPOINT);
+ super.testSwagger(DEPLOY_GROUP_ENDPOINT);
+ super.testSwagger(DEPLOY_POLICIES_ENDPOINT);
}
@Test
- public void testDeploy() throws Exception {
+ public void testDeployGroup() throws Exception {
Entity<PdpGroup> entgrp = makePdpGroupEntity();
- Invocation.Builder invocationBuilder = sendRequest(DEPLOY_ENDPOINT);
+ Invocation.Builder invocationBuilder = sendRequest(DEPLOY_GROUP_ENDPOINT);
Response rawresp = invocationBuilder.post(entgrp);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
@@ -59,7 +63,26 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
assertNull(resp.getErrorDetails());
// verify it fails when no authorization info is included
- checkUnauthRequest(DEPLOY_ENDPOINT, req -> req.post(entgrp));
+ checkUnauthRequest(DEPLOY_GROUP_ENDPOINT, req -> req.post(entgrp));
+ }
+
+ @Test
+ public void testDeployPolicies() throws Exception {
+ Entity<PdpPolicies> entgrp = makePdpPoliciesEntity();
+
+ Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
+ Response rawresp = invocationBuilder.post(entgrp);
+ PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ rawresp = invocationBuilder.post(entgrp);
+ resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertNull(resp.getErrorDetails());
+
+ // verify it fails when no authorization info is included
+ checkUnauthRequest(DEPLOY_POLICIES_ENDPOINT, req -> req.post(entgrp));
}
private Entity<PdpGroup> makePdpGroupEntity() {
@@ -72,7 +95,20 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
group.setVersion("my-version");
group.setPdpSubgroups(Arrays.asList(subgrp));
- Entity<PdpGroup> entgrp = Entity.entity(group, MediaType.APPLICATION_JSON);
- return entgrp;
+ return Entity.entity(group, MediaType.APPLICATION_JSON);
+ }
+
+ private Entity<PdpPolicies> makePdpPoliciesEntity() {
+ Policy pol1 = new Policy();
+ pol1.setName("policy-a");
+ pol1.setPolicyVersion("1");
+
+ Policy pol2 = new Policy();
+ pol2.setName("policy-b");
+
+ PdpPolicies policies = new PdpPolicies();
+ policies.setPolicies(Arrays.asList(pol1, pol2));
+
+ return Entity.entity(policies, MediaType.APPLICATION_JSON);
}
}