2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2023-2024 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
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.apex.services.onappf.rest;
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
28 import jakarta.ws.rs.client.Invocation;
29 import jakarta.ws.rs.client.SyncInvoker;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.common.endpoints.report.HealthCheckReport;
34 * Class to perform unit test of {@link HealthCheckRestControllerV1}.
36 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38 class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
40 private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
43 void testHealthCheckSuccess() throws Exception {
44 final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
45 final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
46 validateHealthCheckReport(report);
48 // verify it fails when no authorization info is included
49 checkUnauthorizedRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
52 private void validateHealthCheckReport(final HealthCheckReport report) {
53 assertThat(report.getName()).isNotBlank();
54 assertEquals(CommonApexStarterRestServer.SELF, report.getUrl());
55 assertTrue(report.isHealthy());
56 assertEquals(200, report.getCode());
57 assertEquals(CommonApexStarterRestServer.ALIVE, report.getMessage());