2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020, 2022 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;
38 import org.springframework.test.context.ActiveProfiles;
41 * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
43 * @author Yehui Wang (yehui.wang@est.tech)
45 @ActiveProfiles({ "test", "default" })
46 public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
48 private static final String ENDPOINT = "components/healthcheck";
49 private List<RestClientParameters> savedRestClientParameters;
52 private PapParameterGroup papParameterGroup;
55 public void testSwagger() throws Exception {
56 super.testSwagger(ENDPOINT);
60 @SuppressWarnings("unchecked")
61 public void testPolicyComponentsHealthCheck() throws Exception {
62 // take out the other components for healthcheck
63 savedRestClientParameters = papParameterGroup.getHealthCheckRestClientParameters();
64 papParameterGroup.setHealthCheckRestClientParameters(null);
66 Invocation.Builder invocationBuilder = sendRequest(ENDPOINT);
67 Response response = invocationBuilder.get();
68 assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
69 Map<String, Object> result = new HashMap<>();
70 result = (Map<String, Object>) response.readEntity(GenericType.forInstance(result));
71 // No PDP configured, healthy is false
72 assertFalse((Boolean) result.get("healthy"));
74 // put back the other components
75 papParameterGroup.setHealthCheckRestClientParameters(savedRestClientParameters);