2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2022 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;
26 import javax.ws.rs.client.Invocation;
27 import javax.ws.rs.client.SyncInvoker;
28 import javax.ws.rs.core.Response;
29 import org.junit.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 public 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 public void testSwagger() throws Exception {
45 super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
47 super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
48 super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
52 public void testDeleteGroup() throws Exception {
53 String uri = DELETE_GROUP_ENDPOINT + "/my-name";
55 Invocation.Builder invocationBuilder = sendRequest(uri);
56 Response rawresp = invocationBuilder.delete();
57 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
58 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
59 assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
61 rawresp = invocationBuilder.delete();
62 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
63 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
64 assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
66 // verify it fails when no authorization info is included
67 checkUnauthRequest(uri, SyncInvoker::delete);
71 public void testDeletePolicy() throws Exception {
72 String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
74 Invocation.Builder invocationBuilder = sendRequest(uri);
75 Response rawresp = invocationBuilder.delete();
76 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
77 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
78 assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
80 rawresp = invocationBuilder.delete();
81 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
82 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
83 assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
85 // verify it fails when no authorization info is included
86 checkUnauthRequest(uri, SyncInvoker::delete);
90 public void testDeletePolicyVersion() throws Exception {
91 String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
93 Invocation.Builder invocationBuilder = sendRequest(uri);
94 Response rawresp = invocationBuilder.delete();
95 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
96 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
97 assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
99 rawresp = invocationBuilder.delete();
100 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
101 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
102 assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
104 // verify it fails when no authorization info is included
105 checkUnauthRequest(uri, SyncInvoker::delete);