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
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.
17 * ============LICENSE_END=========================================================
20 package org.onap.policy.pap.main.rest;
22 import static org.junit.jupiter.api.Assertions.assertEquals;
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;
30 * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
32 @ActiveProfiles({"test", "default"})
33 class TestPolicyAuditControllerV1 extends CommonPapRestServer {
35 private static final String POLICY_AUDIT_ENDPOINT = "policies/audit";
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}");
46 void testGetAllAuditRecords() throws Exception {
47 String uri = POLICY_AUDIT_ENDPOINT;
49 // verify it fails when no authorization info is included
50 checkUnauthRequest(uri, req -> req.get());
54 void testGetAuditRecordsByGroup() throws Exception {
55 checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name");
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");
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());
69 // verify it fails when no authorization info is included
70 checkUnauthRequest(uri, req -> req.get());