2484155a0e087f2bc33e42f1f19eb7a84c11e8e1
[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.Test;
31 import org.onap.policy.common.endpoints.report.HealthCheckReport;
32
33 /**
34  * Class to perform unit test of {@link HealthCheckRestControllerV1}.
35  *
36  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
37  */
38 class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
39
40     private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
41
42     @Test
43     void testHealthCheckSuccess() throws Exception {
44         final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
45         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
46         validateHealthCheckReport(report);
47
48         // verify it fails when no authorization info is included
49         checkUnauthorizedRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
50     }
51
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());
58     }
59 }