56833520cc2110859b02daa7c41413c7858744d2
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / TestPolicyAuditControllerV1.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2021 Bell Canada. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.pap.main.rest;
20
21 import static org.junit.Assert.assertEquals;
22
23 import javax.ws.rs.client.Invocation;
24 import javax.ws.rs.core.Response;
25 import org.junit.Test;
26
27 /**
28  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
29  */
30 public class TestPolicyAuditControllerV1 extends CommonPapRestServer {
31
32     private static final String POLICY_AUDIT_ENDPOINT = "policies/audit";
33
34     @Test
35     public void testSwagger() throws Exception {
36
37         super.testSwagger(POLICY_AUDIT_ENDPOINT);
38         super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}");
39         super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
40         super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{policyName}/{policyVersion}");
41     }
42
43     @Test
44     public void testGetAllAuditRecords() throws Exception {
45         String uri = POLICY_AUDIT_ENDPOINT;
46
47         // verify it fails when no authorization info is included
48         checkUnauthRequest(uri, req -> req.get());
49     }
50
51     @Test
52     public void testGetAuditRecordsByGroup() throws Exception {
53         checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name");
54     }
55
56     @Test
57     public void testGetAuditRecordsOfPolicy() throws Exception {
58         checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name/my-name/1.2.3");
59         checkRequest(POLICY_AUDIT_ENDPOINT + "/my-name/1.2.3");
60     }
61
62     private void checkRequest(String uri) throws Exception {
63         Invocation.Builder invocationBuilder = sendRequest(uri);
64         Response rawresp = invocationBuilder.get();
65         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
66
67         // verify it fails when no authorization info is included
68         checkUnauthRequest(uri, req -> req.get());
69     }
70 }