Updating PAP deployment API to reflect actual status
[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  *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pap.main.rest;
24
25 import static org.junit.Assert.assertEquals;
26
27 import javax.ws.rs.client.Invocation;
28 import javax.ws.rs.core.Response;
29 import org.junit.Test;
30
31 /**
32  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
33  */
34 public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
35
36     private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
37     private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
38
39     @Test
40     public void testSwagger() throws Exception {
41         super.testSwagger(POLICY_STATUS_ENDPOINT);
42         super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}");
43         super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}/{version}");
44
45         super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT);
46         super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}");
47         super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}");
48         super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
49     }
50
51     @Test
52     public void testQueryAllDeployedPolicies() throws Exception {
53         String uri = POLICY_STATUS_ENDPOINT;
54
55         // verify it fails when no authorization info is included
56         checkUnauthRequest(uri, req -> req.get());
57     }
58
59     @Test
60     public void testQueryDeployedPolicies() throws Exception {
61         checkRequest(POLICY_STATUS_ENDPOINT + "/my-name");
62         checkRequest(POLICY_STATUS_ENDPOINT + "/my-name/1.2.3");
63     }
64
65     @Test
66     public void testGetStatusOfAllPolicies() throws Exception {
67         String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
68
69         // verify it fails when no authorization info is included
70         checkUnauthRequest(uri, req -> req.get());
71     }
72
73     @Test
74     public void testGetStatusOfPolicies() throws Exception {
75         checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name");
76         checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name");
77         checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name/1.2.3");
78     }
79
80     private void checkRequest(String uri) throws Exception {
81         Invocation.Builder invocationBuilder = sendRequest(uri);
82         Response rawresp = invocationBuilder.get();
83         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
84
85         // verify it fails when no authorization info is included
86         checkUnauthRequest(uri, req -> req.get());
87     }
88 }