a63824a0eb9c5c42598af1ce0e01fc738d25f2ec
[policy/apex-pdp.git] /
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.services.onappf.rest;
23
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;
27
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;
33
34 /**
35  * Class to perform unit test of {@link HealthCheckRestControllerV1}.
36  *
37  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
38  */
39 class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
40
41     private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
42
43     @Test
44     void testHealthCheckSuccess() throws Exception {
45         final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
46         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
47         validateHealthCheckReport(report);
48
49         // verify it fails when no authorization info is included
50         checkUnauthorizedRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
51     }
52
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());
59     }
60 }