a49fb5070707664fa6e340b240ec51aef64cfc87
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2023 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.Assert.assertEquals;
26
27 import jakarta.ws.rs.client.Invocation;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.policy.common.endpoints.report.HealthCheckReport;
31
32 /**
33  * Class to perform unit test of {@link ApexStarterRestServer}.
34  *
35  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
36  */
37 public class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
38
39     private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
40
41     @Ignore
42     @Test
43     public void testSwagger() throws Exception {
44         super.testSwagger(HEALTHCHECK_ENDPOINT);
45     }
46
47     @Test
48     public void testHealthCheckSuccess() throws Exception {
49         final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
50         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
51         validateHealthCheckReport(SELF, true, 200, ALIVE, report);
52
53         // verify it fails when no authorization info is included
54         checkUnauthRequest(HEALTHCHECK_ENDPOINT, req -> req.get());
55     }
56
57     private void validateHealthCheckReport(final String url, final boolean healthy, final int code,
58             final String message, final HealthCheckReport report) {
59         assertThat(report.getName()).isNotBlank();
60         assertEquals(url, report.getUrl());
61         assertEquals(healthy, report.isHealthy());
62         assertEquals(code, report.getCode());
63         assertEquals(message, report.getMessage());
64     }
65 }