2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Bell Canada. All rights reserved.
4 * Modifications Copyright (C) 2022 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.Assert.assertEquals;
24 import javax.ws.rs.client.Invocation;
25 import javax.ws.rs.core.Response;
26 import org.junit.Test;
27 import org.springframework.test.annotation.DirtiesContext;
28 import org.springframework.test.context.ActiveProfiles;
31 * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
33 @ActiveProfiles("test")
34 public class TestPolicyAuditControllerV1 extends CommonPapRestServer {
36 private static final String POLICY_AUDIT_ENDPOINT = "policies/audit";
39 public void testSwagger() throws Exception {
41 super.testSwagger(POLICY_AUDIT_ENDPOINT);
42 super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}");
43 super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
44 super.testSwagger(POLICY_AUDIT_ENDPOINT + "/{policyName}/{policyVersion}");
48 public void testGetAllAuditRecords() throws Exception {
49 String uri = POLICY_AUDIT_ENDPOINT;
51 // verify it fails when no authorization info is included
52 checkUnauthRequest(uri, req -> req.get());
56 public void testGetAuditRecordsByGroup() throws Exception {
57 checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name");
61 public void testGetAuditRecordsOfPolicy() throws Exception {
62 checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name/my-name/1.2.3");
63 checkRequest(POLICY_AUDIT_ENDPOINT + "/my-name/1.2.3");
66 private void checkRequest(String uri) throws Exception {
67 Invocation.Builder invocationBuilder = sendRequest(uri);
68 Response rawresp = invocationBuilder.get();
69 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
71 // verify it fails when no authorization info is included
72 checkUnauthRequest(uri, req -> req.get());