Removing deprecated DMAAP library
[policy/drools-pdp.git] / feature-healthcheck / src / test / java / org / onap / policy / drools / healthcheck / HealthCheckTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.drools.healthcheck;
23
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;
30
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;
36
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";
42
43     @Test
44     void testReport() {
45         Report rpt = new Report();
46
47         assertNotNull(rpt.toString());
48
49         rpt.setCode(RPT_CODE);
50         rpt.setHealthy(true);
51         rpt.setMessage(RPT_MSG);
52         rpt.setName(RPT_NAME);
53         rpt.setUrl(RPT_URL);
54         rpt.setEndTime();
55
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());
61
62         assertNotEquals(0L, rpt.getStartTime());
63         assertNotEquals(0L, rpt.getEndTime());
64         assertEquals(rpt.getEndTime() - rpt.getStartTime(), rpt.getElapsedTime());
65
66         // flip the flag
67         rpt.setHealthy(false);
68         assertFalse(rpt.isHealthy());
69
70         // toString should work with populated data
71         assertNotNull(rpt.toString());
72
73         assertEquals(rpt, new Report(rpt));
74     }
75
76     @Test
77     void testReports() {
78         Reports reports = new Reports();
79
80         // toString should work with un-populated data
81         assertNotNull(reports.toString());
82
83         List<Report> lst = Collections.emptyList();
84         reports.setDetails(lst);
85         reports.setHealthy(true);
86
87         assertSame(lst, reports.getDetails());
88         assertTrue(reports.isHealthy());
89
90         // flip the flag
91         reports.setHealthy(false);
92         assertFalse(reports.isHealthy());
93
94         // toString should work with populated data
95         assertNotNull(reports.toString());
96
97         assertNotEquals(0L, reports.getStartTime());
98
99         reports.setEndTime();
100         assertNotEquals(0L, reports.getEndTime());
101         assertEquals(reports.getEndTime() - reports.getStartTime(), reports.getElapsedTime());
102     }
103 }