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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.oran.datafile.controllers;
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;
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;
40 @ExtendWith(MockitoExtension.class)
41 class StatusControllerTest {
43 CollectAndReportFiles scheduledTasksMock;
45 StatusController controllerUnderTest;
49 controllerUnderTest = new StatusController(scheduledTasksMock);
53 void heartbeat_success() {
54 HttpHeaders httpHeaders = new HttpHeaders();
56 Mono<ResponseEntity<String>> result = controllerUnderTest.heartbeat(httpHeaders);
58 String body = result.block().getBody();
59 assertTrue(body.startsWith("I'm living!"));
64 Counters counters = new Counters();
65 doReturn(counters).when(scheduledTasksMock).getCounters();
67 HttpHeaders httpHeaders = new HttpHeaders();
69 Mono<ResponseEntity<String>> result = controllerUnderTest.status(httpHeaders);
71 String body = result.block().getBody();
72 HttpStatusCode httpStatusCode = result.block().getStatusCode();
73 assertEquals(200, httpStatusCode.value());
74 System.out.println(body);