Add simple deploy/undeploy REST API
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / TestPdpGroupDeleteControllerV1.java
1 /*
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.pap.main.rest;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26
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;
31
32 public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
33
34     private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
35     private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies";
36
37     @Test
38     public void testSwagger() throws Exception {
39         super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
40         super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}/versions/{version}");
41
42         super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
43         super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
44     }
45
46     @Test
47     public void testDeleteGroup() throws Exception {
48         String uri = DELETE_GROUP_ENDPOINT + "/my-name";
49
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());
55
56         rawresp = invocationBuilder.delete();
57         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
58         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
59         assertNull(resp.getErrorDetails());
60
61         // verify it fails when no authorization info is included
62         checkUnauthRequest(uri, req -> req.delete());
63     }
64
65     @Test
66     public void testDeleteGroupVersion() throws Exception {
67         String uri = DELETE_GROUP_ENDPOINT + "/my-name/versions/1.2.3";
68
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());
74
75         rawresp = invocationBuilder.delete();
76         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
77         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
78         assertNull(resp.getErrorDetails());
79
80         // verify it fails when no authorization info is included
81         checkUnauthRequest(uri, req -> req.delete());
82     }
83
84     @Test
85     public void testDeletePolicies() throws Exception {
86         String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
87
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());
93
94         rawresp = invocationBuilder.delete();
95         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
96         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
97         assertNull(resp.getErrorDetails());
98
99         // verify it fails when no authorization info is included
100         checkUnauthRequest(uri, req -> req.delete());
101     }
102
103     @Test
104     public void testDeletePoliciesVersion() throws Exception {
105         String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
106
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());
112
113         rawresp = invocationBuilder.delete();
114         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
115         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
116         assertNull(resp.getErrorDetails());
117
118         // verify it fails when no authorization info is included
119         checkUnauthRequest(uri, req -> req.delete());
120     }
121 }