Improve Test coverage of DFC
[nonrtric/plt/ranpm.git] / datafilecollector / src / test / java / org / oran / datafile / controllers / StatusControllerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2023 Nordix Foundation.
4  *  Copyright (C) 2020 Nokia. 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.oran.datafile.controllers;
23
24 import static org.junit.jupiter.api.Assertions.assertEquals;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import static org.mockito.Mockito.doReturn;
27
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.Mock;
32 import org.mockito.junit.jupiter.MockitoExtension;
33 import org.oran.datafile.model.Counters;
34 import org.oran.datafile.tasks.CollectAndReportFiles;
35 import org.springframework.http.HttpHeaders;
36 import org.springframework.http.HttpStatusCode;
37 import org.springframework.http.ResponseEntity;
38 import reactor.core.publisher.Mono;
39
40 @ExtendWith(MockitoExtension.class)
41 class StatusControllerTest {
42     @Mock
43     CollectAndReportFiles scheduledTasksMock;
44
45     StatusController controllerUnderTest;
46
47     @BeforeEach
48     public void setup() {
49         controllerUnderTest = new StatusController(scheduledTasksMock);
50     }
51
52     @Test
53     void heartbeat_success() {
54         HttpHeaders httpHeaders = new HttpHeaders();
55
56         Mono<ResponseEntity<String>> result = controllerUnderTest.heartbeat(httpHeaders);
57
58         String body = result.block().getBody();
59         assertTrue(body.startsWith("I'm living!"));
60     }
61
62     @Test
63     void status() {
64         Counters counters = new Counters();
65         doReturn(counters).when(scheduledTasksMock).getCounters();
66
67         HttpHeaders httpHeaders = new HttpHeaders();
68
69         Mono<ResponseEntity<String>> result = controllerUnderTest.status(httpHeaders);
70
71         String body = result.block().getBody();
72         HttpStatusCode httpStatusCode = result.block().getStatusCode();
73         assertEquals(200, httpStatusCode.value());
74         System.out.println(body);
75     }
76
77 }