2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2020-2021 AT&T Inc.
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;
26 import static org.junit.Assert.assertFalse;
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.Test;
35 import org.onap.policy.common.endpoints.parameters.RestClientParameters;
36 import org.onap.policy.pap.main.parameters.PapParameterGroup;
37 import org.springframework.beans.factory.annotation.Autowired;
40 * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
42 * @author Yehui Wang (yehui.wang@est.tech)
44 public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
46 private static final String ENDPOINT = "components/healthcheck";
47 private List<RestClientParameters> savedRestClientParameters;
50 private PapParameterGroup papParameterGroup;
53 public void testSwagger() throws Exception {
54 super.testSwagger(ENDPOINT);
58 @SuppressWarnings("unchecked")
59 public void testPolicyComponentsHealthCheck() throws Exception {
60 // take out the other components for healthcheck
61 savedRestClientParameters = papParameterGroup.getHealthCheckRestClientParameters();
62 papParameterGroup.setHealthCheckRestClientParameters(null);
64 Invocation.Builder invocationBuilder = sendRequest(ENDPOINT);
65 Response response = invocationBuilder.get();
66 assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
67 Map<String, Object> result = new HashMap<>();
68 result = (Map<String, Object>) response.readEntity(GenericType.forInstance(result));
69 // No PDP configured, healthy is false
70 assertFalse((Boolean) result.get("healthy"));
72 // put back the other components
73 papParameterGroup.setHealthCheckRestClientParameters(savedRestClientParameters);