2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018, 2021-2022 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.drools.healthcheck;
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertFalse;
26 import static org.junit.jupiter.api.Assertions.assertNotEquals;
27 import static org.junit.jupiter.api.Assertions.assertNotNull;
28 import static org.junit.jupiter.api.Assertions.assertSame;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
31 import java.util.Collections;
32 import java.util.List;
33 import org.junit.jupiter.api.Test;
34 import org.onap.policy.drools.healthcheck.HealthCheck.Report;
35 import org.onap.policy.drools.healthcheck.HealthCheck.Reports;
37 class HealthCheckTest {
38 private static final long RPT_CODE = 100;
39 private static final String RPT_MSG = "report-message";
40 private static final String RPT_NAME = "report-name";
41 private static final String RPT_URL = "report-url";
45 Report rpt = new Report();
47 assertNotNull(rpt.toString());
49 rpt.setCode(RPT_CODE);
51 rpt.setMessage(RPT_MSG);
52 rpt.setName(RPT_NAME);
56 assertEquals(RPT_CODE, rpt.getCode());
57 assertTrue(rpt.isHealthy());
58 assertEquals(RPT_MSG, rpt.getMessage());
59 assertEquals(RPT_NAME, rpt.getName());
60 assertEquals(RPT_URL, rpt.getUrl());
62 assertNotEquals(0L, rpt.getStartTime());
63 assertNotEquals(0L, rpt.getEndTime());
64 assertEquals(rpt.getEndTime() - rpt.getStartTime(), rpt.getElapsedTime());
67 rpt.setHealthy(false);
68 assertFalse(rpt.isHealthy());
70 // toString should work with populated data
71 assertNotNull(rpt.toString());
73 assertEquals(rpt, new Report(rpt));
78 Reports reports = new Reports();
80 // toString should work with un-populated data
81 assertNotNull(reports.toString());
83 List<Report> lst = Collections.emptyList();
84 reports.setDetails(lst);
85 reports.setHealthy(true);
87 assertSame(lst, reports.getDetails());
88 assertTrue(reports.isHealthy());
91 reports.setHealthy(false);
92 assertFalse(reports.isHealthy());
94 // toString should work with populated data
95 assertNotNull(reports.toString());
97 assertNotEquals(0L, reports.getStartTime());
100 assertNotEquals(0L, reports.getEndTime());
101 assertEquals(reports.getEndTime() - reports.getStartTime(), reports.getElapsedTime());