|
| 1 | +/** |
| 2 | + * Copyright (c) 2025, Samsung Electronics Co., Ltd. All rights reserved. |
| 3 | + * |
| 4 | + * Use of this source code is governed by a MIT license that can be |
| 5 | + * found in the LICENSE file. |
| 6 | + */ |
| 7 | +package com.lpvs.controller; |
| 8 | + |
| 9 | +import com.lpvs.repository.LPVSQueueRepository; |
| 10 | +import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 12 | +import org.mockito.InjectMocks; |
| 13 | +import org.mockito.Mock; |
| 14 | +import org.mockito.junit.jupiter.MockitoExtension; |
| 15 | +import org.springframework.http.HttpStatus; |
| 16 | +import org.springframework.http.ResponseEntity; |
| 17 | + |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 21 | +import static org.mockito.Mockito.when; |
| 22 | + |
| 23 | +@ExtendWith(MockitoExtension.class) |
| 24 | +public class HealthControllerTest { |
| 25 | + |
| 26 | + @Mock private LPVSQueueRepository queueRepository; |
| 27 | + |
| 28 | + @InjectMocks private HealthController healthController; |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testGetHealthStatus_Success_EmptyQueue() { |
| 32 | + when(queueRepository.count()).thenReturn(0L); |
| 33 | + |
| 34 | + ResponseEntity<Map<String, Long>> response = healthController.getHealthStatus(); |
| 35 | + |
| 36 | + assertEquals(HttpStatus.OK, response.getStatusCode()); |
| 37 | + Map<String, Long> responseBody = response.getBody(); |
| 38 | + assertEquals(0L, responseBody.get("queueLength")); |
| 39 | + } |
| 40 | + |
| 41 | + @Test |
| 42 | + public void testGetHealthStatus_Success_WithItems() { |
| 43 | + long expectedQueueLength = 5L; |
| 44 | + when(queueRepository.count()).thenReturn(expectedQueueLength); |
| 45 | + |
| 46 | + ResponseEntity<Map<String, Long>> response = healthController.getHealthStatus(); |
| 47 | + |
| 48 | + assertEquals(HttpStatus.OK, response.getStatusCode()); |
| 49 | + Map<String, Long> responseBody = response.getBody(); |
| 50 | + assertEquals(expectedQueueLength, responseBody.get("queueLength")); |
| 51 | + } |
| 52 | +} |
0 commit comments