2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.rest;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
30 import javax.ws.rs.client.Invocation;
31 import javax.ws.rs.core.GenericType;
32 import javax.ws.rs.core.Response;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.Test;
36 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
37 import org.onap.policy.common.parameters.ParameterService;
38 import org.onap.policy.pap.main.parameters.PapParameterGroup;
39 import org.powermock.reflect.Whitebox;
42 * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
44 * @author Yehui Wang (yehui.wang@est.tech)
46 public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
48 private static final String ENDPOINT = "components/healthcheck";
49 private static List<BusTopicParams> savedBusTopicParams;
52 * Set up for the test class.
55 public static void setUpClass() {
56 // To skip calling to the remote components
57 PapParameterGroup papParameterGroup = ParameterService.get("PapGroup");
58 List<BusTopicParams> lo = Whitebox.getInternalState(papParameterGroup,
59 "healthCheckRestClientParameters");
60 savedBusTopicParams = new ArrayList<>(lo);
65 * Tear down for the test class.
68 public static void tearDownClass() {
69 PapParameterGroup papParameterGroup = ParameterService.get("PapGroup");
70 List<BusTopicParams> lo = Whitebox.getInternalState(papParameterGroup,
71 "healthCheckRestClientParameters");
72 lo.addAll(savedBusTopicParams);
76 public void testSwagger() throws Exception {
77 super.testSwagger(ENDPOINT);
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"));