Added support for using oauth token for Kafka
[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.assertTrue;
25 import static org.mockito.Mockito.doReturn;
26
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.mockito.Mock;
31 import org.mockito.junit.jupiter.MockitoExtension;
32 import org.oran.datafile.model.Counters;
33 import org.oran.datafile.tasks.CollectAndReportFiles;
34 import org.springframework.http.HttpHeaders;
35 import org.springframework.http.ResponseEntity;
36 import reactor.core.publisher.Mono;
37
38 @ExtendWith(MockitoExtension.class)
39 public class StatusControllerTest {
40     @Mock
41     CollectAndReportFiles scheduledTasksMock;
42
43     StatusController controllerUnderTest;
44
45     @BeforeEach
46     public void setup() {
47         controllerUnderTest = new StatusController(scheduledTasksMock);
48     }
49
50     @Test
51     public void heartbeat_success() {
52         HttpHeaders httpHeaders = new HttpHeaders();
53
54         Mono<ResponseEntity<String>> result = controllerUnderTest.heartbeat(httpHeaders);
55
56         String body = result.block().getBody();
57         assertTrue(body.startsWith("I'm living!"));
58     }
59
60     @Test
61     public void status() {
62         Counters counters = new Counters();
63         doReturn(counters).when(scheduledTasksMock).getCounters();
64
65         HttpHeaders httpHeaders = new HttpHeaders();
66
67         Mono<ResponseEntity<String>> result = controllerUnderTest.status(httpHeaders);
68
69         String body = result.block().getBody();
70         System.out.println(body);
71     }
72
73 }