Add PDP Group Deploy and Delete REST API stubs
[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_ENDPOINT = "pdps/groups";
35
36     @Test
37     public void testSwagger() throws Exception {
38         super.testSwagger(DELETE_ENDPOINT + "/{name}");
39         super.testSwagger(DELETE_ENDPOINT + "/{name}/versions/{version}");
40     }
41
42     @Test
43     public void testDeleteGroup() throws Exception {
44         String uri = DELETE_ENDPOINT + "/my-name";
45
46         Invocation.Builder invocationBuilder = sendRequest(uri);
47         Response rawresp = invocationBuilder.delete();
48         PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
49         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
50         assertNull(resp.getErrorDetails());
51
52         rawresp = invocationBuilder.delete();
53         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
54         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
55         assertNull(resp.getErrorDetails());
56
57         // verify it fails when no authorization info is included
58         checkUnauthRequest(uri, req -> req.delete());
59     }
60
61     @Test
62     public void testDeleteGroupVersion() throws Exception {
63         String uri = DELETE_ENDPOINT + "/my-name/versions/1.2.3";
64
65         Invocation.Builder invocationBuilder = sendRequest(uri);
66         Response rawresp = invocationBuilder.delete();
67         PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
68         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
69         assertNull(resp.getErrorDetails());
70
71         rawresp = invocationBuilder.delete();
72         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
73         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
74         assertNull(resp.getErrorDetails());
75
76         // verify it fails when no authorization info is included
77         checkUnauthRequest(uri, req -> req.delete());
78     }
79 }