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
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.jupiter.api.Assertions.assertEquals;
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;
34 * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
36 @ActiveProfiles({ "test", "default" })
37 class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
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";
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}");
51 void testDeleteGroup() throws Exception {
52 String uri = DELETE_GROUP_ENDPOINT + "/my-name";
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());
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());
65 // verify it fails when no authorization info is included
66 checkUnauthRequest(uri, SyncInvoker::delete);
70 void testDeletePolicy() throws Exception {
71 String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
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());
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());
84 // verify it fails when no authorization info is included
85 checkUnauthRequest(uri, SyncInvoker::delete);
89 void testDeletePolicyVersion() throws Exception {
90 String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
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());
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());
103 // verify it fails when no authorization info is included
104 checkUnauthRequest(uri, SyncInvoker::delete);