2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2020-2021 AT&T Inc.
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.rest;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
31 import javax.ws.rs.client.Invocation;
32 import javax.ws.rs.core.GenericType;
33 import javax.ws.rs.core.Response;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.onap.policy.common.endpoints.parameters.RestClientParameters;
38 import org.onap.policy.common.parameters.ParameterService;
39 import org.onap.policy.pap.main.parameters.PapParameterGroup;
40 import org.powermock.reflect.Whitebox;
43 * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
45 * @author Yehui Wang (yehui.wang@est.tech)
47 public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
49 private static final String ENDPOINT = "components/healthcheck";
50 private static List<RestClientParameters> savedRestClientParameters;
53 * Set up for the test class.
56 public static void setUpClass() {
57 // To skip calling to the remote components
58 PapParameterGroup papParameterGroup = ParameterService.get("PapGroup");
59 List<RestClientParameters> lo = Whitebox.getInternalState(papParameterGroup, "healthCheckRestClientParameters");
60 savedRestClientParameters = new ArrayList<>(lo);
65 * Tear down for the test class.
68 public static void tearDownClass() {
69 PapParameterGroup papParameterGroup = ParameterService.get("PapGroup");
70 List<RestClientParameters> lo = Whitebox.getInternalState(papParameterGroup, "healthCheckRestClientParameters");
71 lo.addAll(savedRestClientParameters);
75 public void testSwagger() throws Exception {
76 super.testSwagger(ENDPOINT);
80 @SuppressWarnings("unchecked")
81 public void testPolicyComponentsHealthCheck() throws Exception {
82 Invocation.Builder invocationBuilder = sendRequest(ENDPOINT);
83 Response response = invocationBuilder.get();
84 assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
85 Map<String, Object> result = new HashMap<>();
86 result = (Map<String, Object>) response.readEntity(GenericType.forInstance(result));
87 // No PDP configured, healthy is false
88 assertFalse((Boolean) result.get("healthy"));