2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
5 * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pap.main.rest;
25 import static org.junit.Assert.assertEquals;
27 import javax.ws.rs.client.Invocation;
28 import javax.ws.rs.core.Response;
29 import org.junit.Test;
32 * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
34 public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
36 private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
37 private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
40 public void testSwagger() throws Exception {
41 super.testSwagger(POLICY_STATUS_ENDPOINT);
42 super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}");
43 super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}/{version}");
45 super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT);
46 super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}");
47 super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}");
48 super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
52 public void testQueryAllDeployedPolicies() throws Exception {
53 String uri = POLICY_STATUS_ENDPOINT;
55 // verify it fails when no authorization info is included
56 checkUnauthRequest(uri, req -> req.get());
60 public void testQueryDeployedPolicies() throws Exception {
61 checkRequest(POLICY_STATUS_ENDPOINT + "/my-name");
62 checkRequest(POLICY_STATUS_ENDPOINT + "/my-name/1.2.3");
66 public void testGetStatusOfAllPolicies() throws Exception {
67 String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
69 // verify it fails when no authorization info is included
70 checkUnauthRequest(uri, req -> req.get());
74 public void testGetStatusOfPolicies() throws Exception {
75 checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name");
76 checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name");
77 checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name/1.2.3");
80 private void checkRequest(String uri) throws Exception {
81 Invocation.Builder invocationBuilder = sendRequest(uri);
82 Response rawresp = invocationBuilder.get();
83 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
85 // verify it fails when no authorization info is included
86 checkUnauthRequest(uri, req -> req.get());