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.Disabled;
31 import org.junit.jupiter.api.Test;
32 import org.onap.policy.common.endpoints.report.HealthCheckReport;
35 * Class to perform unit test of {@link HealthCheckRestControllerV1}.
37 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
39 class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
41 private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
44 void testHealthCheckSuccess() throws Exception {
45 final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
46 final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
47 validateHealthCheckReport(report);
49 // verify it fails when no authorization info is included
50 checkUnauthorizedRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
53 private void validateHealthCheckReport(final HealthCheckReport report) {
54 assertThat(report.getName()).isNotBlank();
55 assertEquals(CommonApexStarterRestServer.SELF, report.getUrl());
56 assertTrue(report.isHealthy());
57 assertEquals(200, report.getCode());
58 assertEquals(CommonApexStarterRestServer.ALIVE, report.getMessage());