2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.rest;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
27 import javax.ws.rs.client.Invocation;
28 import javax.ws.rs.core.Response;
29 import org.junit.Test;
30 import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
32 public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
34 private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
35 private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies";
38 public void testSwagger() throws Exception {
39 super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
40 super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}/versions/{version}");
42 super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
43 super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
47 public void testDeleteGroup() throws Exception {
48 String uri = DELETE_GROUP_ENDPOINT + "/my-name";
50 Invocation.Builder invocationBuilder = sendRequest(uri);
51 Response rawresp = invocationBuilder.delete();
52 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
53 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
54 assertNull(resp.getErrorDetails());
56 rawresp = invocationBuilder.delete();
57 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
58 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
59 assertNull(resp.getErrorDetails());
61 // verify it fails when no authorization info is included
62 checkUnauthRequest(uri, req -> req.delete());
66 public void testDeleteGroupVersion() throws Exception {
67 String uri = DELETE_GROUP_ENDPOINT + "/my-name/versions/1.2.3";
69 Invocation.Builder invocationBuilder = sendRequest(uri);
70 Response rawresp = invocationBuilder.delete();
71 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
72 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
73 assertNull(resp.getErrorDetails());
75 rawresp = invocationBuilder.delete();
76 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
77 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
78 assertNull(resp.getErrorDetails());
80 // verify it fails when no authorization info is included
81 checkUnauthRequest(uri, req -> req.delete());
85 public void testDeletePolicies() throws Exception {
86 String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
88 Invocation.Builder invocationBuilder = sendRequest(uri);
89 Response rawresp = invocationBuilder.delete();
90 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
91 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
92 assertNull(resp.getErrorDetails());
94 rawresp = invocationBuilder.delete();
95 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
96 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
97 assertNull(resp.getErrorDetails());
99 // verify it fails when no authorization info is included
100 checkUnauthRequest(uri, req -> req.delete());
104 public void testDeletePoliciesVersion() throws Exception {
105 String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
107 Invocation.Builder invocationBuilder = sendRequest(uri);
108 Response rawresp = invocationBuilder.delete();
109 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
110 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
111 assertNull(resp.getErrorDetails());
113 rawresp = invocationBuilder.delete();
114 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
115 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
116 assertNull(resp.getErrorDetails());
118 // verify it fails when no authorization info is included
119 checkUnauthRequest(uri, req -> req.delete());