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
9 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
19 package org.onap.policy.pap.main.rest;
21 import static org.junit.Assert.assertEquals;
23 import javax.ws.rs.client.Invocation;
24 import javax.ws.rs.core.Response;
25 import org.junit.Test;
28 * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
30 public class TestPolicyAuditControllerV1 extends CommonPapRestServer {
32 private static final String POLICY_AUDIT_ENDPOINT = "policies/audit";
35 public void testSwagger() throws Exception {
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}");
44 public void testGetAllAuditRecords() throws Exception {
45 String uri = POLICY_AUDIT_ENDPOINT;
47 // verify it fails when no authorization info is included
48 checkUnauthRequest(uri, req -> req.get());
52 public void testGetAuditRecordsByGroup() throws Exception {
53 checkRequest(POLICY_AUDIT_ENDPOINT + "/my-group-name");
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");
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());
67 // verify it fails when no authorization info is included
68 checkUnauthRequest(uri, req -> req.get());