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
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.core.Response;
28 import org.junit.Test;
29 import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
32 * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
34 public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
36 private static final String GROUP_NOT_FOUND = "group not found";
37 private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
38 private static final String DELETE_POLICIES_ENDPOINT = "pdps/policies";
41 public void testSwagger() throws Exception {
42 super.testSwagger(DELETE_GROUP_ENDPOINT + "/{name}");
44 super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}");
45 super.testSwagger(DELETE_POLICIES_ENDPOINT + "/{name}/versions/{version}");
49 public void testDeleteGroup() throws Exception {
50 String uri = DELETE_GROUP_ENDPOINT + "/my-name";
52 Invocation.Builder invocationBuilder = sendRequest(uri);
53 Response rawresp = invocationBuilder.delete();
54 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
55 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
56 assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
58 rawresp = invocationBuilder.delete();
59 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
60 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
61 assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
63 // verify it fails when no authorization info is included
64 checkUnauthRequest(uri, req -> req.delete());
68 public void testDeletePolicy() throws Exception {
69 String uri = DELETE_POLICIES_ENDPOINT + "/my-name";
71 Invocation.Builder invocationBuilder = sendRequest(uri);
72 Response rawresp = invocationBuilder.delete();
73 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
74 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
75 assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
77 rawresp = invocationBuilder.delete();
78 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
79 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
80 assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
82 // verify it fails when no authorization info is included
83 checkUnauthRequest(uri, req -> req.delete());
87 public void testDeletePolicyVersion() throws Exception {
88 String uri = DELETE_POLICIES_ENDPOINT + "/my-name/versions/3";
90 Invocation.Builder invocationBuilder = sendRequest(uri);
91 Response rawresp = invocationBuilder.delete();
92 PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
93 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
94 assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
96 rawresp = invocationBuilder.delete();
97 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
98 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
99 assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
101 // verify it fails when no authorization info is included
102 checkUnauthRequest(uri, req -> req.delete());