Allow semantic versioning in all templates in pap
[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  * Modifications Copyright (C) 2022-2023 Nordix Foundation.
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  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.policy.pap.main.rest;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23
24 import jakarta.ws.rs.client.Invocation;
25 import jakarta.ws.rs.core.Response;
26 import org.junit.jupiter.api.Test;
27 import org.springframework.test.context.ActiveProfiles;
28
29 /**
30  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
31  */
32 @ActiveProfiles({"test", "default"})
33 class TestPolicyAuditControllerV1 extends CommonPapRestServer {
34
35     private static final String POLICY_AUDIT_ENDPOINT = "policies/audit";
36
37     @Test
38     void testSwagger() throws Exception {
39         super.testSwagger(POLICY_AUDIT_ENDPOINT);
40         super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}");
41         super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
42         super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{policyName}/{policyVersion}");
43     }
44
45     @Test
46     void testGetAllAuditRecords() throws Exception {
47         String uri = POLICY_AUDIT_ENDPOINT;
48
49         // verify it fails when no authorization info is included
50         checkUnauthRequest(uri, req -> req.get());
51     }
52
53     @Test
54     void testGetAuditRecordsByGroup() throws Exception {
55         checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name");
56     }
57
58     @Test
59     void testGetAuditRecordsOfPolicy() throws Exception {
60         checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name/my-name/1.2.3");
61         checkRequest(POLICY_AUDIT_ENDPOINT + "/my-name/1.2.3");
62     }
63
64     private void checkRequest(String uri) throws Exception {
65         Invocation.Builder invocationBuilder = sendRequest(uri);
66         Response rawresp = invocationBuilder.get();
67         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
68
69         // verify it fails when no authorization info is included
70         checkUnauthRequest(uri, req -> req.get());
71     }
72 }