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;
25 import static org.junit.Assert.assertNull;
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;
32 public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
34 private static final String DELETE_ENDPOINT = "pdps/groups";
37 public void testSwagger() throws Exception {
38 super.testSwagger(DELETE_ENDPOINT + "/{name}");
39 super.testSwagger(DELETE_ENDPOINT + "/{name}/versions/{version}");
43 public void testDeleteGroup() throws Exception {
44 String uri = DELETE_ENDPOINT + "/my-name";
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());
52 rawresp = invocationBuilder.delete();
53 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
54 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
55 assertNull(resp.getErrorDetails());
57 // verify it fails when no authorization info is included
58 checkUnauthRequest(uri, req -> req.delete());
62 public void testDeleteGroupVersion() throws Exception {
63 String uri = DELETE_ENDPOINT + "/my-name/versions/1.2.3";
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());
71 rawresp = invocationBuilder.delete();
72 resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
73 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
74 assertNull(resp.getErrorDetails());
76 // verify it fails when no authorization info is included
77 checkUnauthRequest(uri, req -> req.delete());