policy/pap jdk11 upgrades
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / TestPolicyStatusControllerV1.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2020 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.Assert.assertEquals;
25
26 import javax.ws.rs.client.Invocation;
27 import javax.ws.rs.core.Response;
28 import org.junit.Test;
29
30 /**
31  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
32  */
33 public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
34
35     private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
36
37     @Test
38     public void testSwagger() throws Exception {
39         super.testSwagger(POLICY_STATUS_ENDPOINT);
40
41         super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}");
42         super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}/{version}");
43     }
44
45     @Test
46     public void testQueryAllDeployedPolicies() throws Exception {
47         String uri = POLICY_STATUS_ENDPOINT;
48
49         // verify it fails when no authorization info is included
50         checkUnauthRequest(uri, req -> req.get());
51     }
52
53     @Test
54     public void testQueryDeployedPolicies() throws Exception {
55         String uri = POLICY_STATUS_ENDPOINT + "/my-name";
56
57         Invocation.Builder invocationBuilder = sendRequest(uri);
58         Response rawresp = invocationBuilder.get();
59         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
60
61         // verify it fails when no authorization info is included
62         checkUnauthRequest(uri, req -> req.get());
63     }
64
65     @Test
66     public void testQueryDeployedPolicy() throws Exception {
67         String uri = POLICY_STATUS_ENDPOINT + "/my-name/1.2.3";
68
69         Invocation.Builder invocationBuilder = sendRequest(uri);
70         Response rawresp = invocationBuilder.get();
71         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
72
73         // verify it fails when no authorization info is included
74         checkUnauthRequest(uri, req -> req.get());
75     }
76 }