Java 17 / Spring 6 / Spring Boot 3 Upgrade
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / TestPdpGroupDeleteControllerV1.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2022-2023 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.jupiter.api.Assertions.assertEquals;
25
26 import jakarta.ws.rs.client.Invocation;
27 import jakarta.ws.rs.client.SyncInvoker;
28 import jakarta.ws.rs.core.Response;
29 import org.junit.jupiter.api.Test;
30 import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
31 import org.springframework.test.context.ActiveProfiles;
32
33 /**
34  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
35  */
36 @ActiveProfiles({ "test", "default" })
37 class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
38
39     private static final String GROUP_NOT_FOUND = "group not found";
40     private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
41     private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies";
42
43     @Test
44     void testSwagger() throws Exception {
45         super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
46         super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
47         super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
48     }
49
50     @Test
51     void testDeleteGroup() throws Exception {
52         String uri = DELETE_GROUP_ENDPOINT + "/my-name";
53
54         Invocation.Builder invocationBuilder = sendRequest(uri);
55         Response rawresp = invocationBuilder.delete();
56         PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
57         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
58         assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
59
60         rawresp = invocationBuilder.delete();
61         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
62         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
63         assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
64
65         // verify it fails when no authorization info is included
66         checkUnauthRequest(uri, SyncInvoker::delete);
67     }
68
69     @Test
70     void testDeletePolicy() throws Exception {
71         String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
72
73         Invocation.Builder invocationBuilder = sendRequest(uri);
74         Response rawresp = invocationBuilder.delete();
75         PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
76         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
77         assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
78
79         rawresp = invocationBuilder.delete();
80         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
81         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
82         assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
83
84         // verify it fails when no authorization info is included
85         checkUnauthRequest(uri, SyncInvoker::delete);
86     }
87
88     @Test
89     void testDeletePolicyVersion() throws Exception {
90         String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
91
92         Invocation.Builder invocationBuilder = sendRequest(uri);
93         Response rawresp = invocationBuilder.delete();
94         PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
95         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
96         assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
97
98         rawresp = invocationBuilder.delete();
99         resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
100         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
101         assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
102
103         // verify it fails when no authorization info is included
104         checkUnauthRequest(uri, SyncInvoker::delete);
105     }
106 }