Skip to content
Snippets Groups Projects
Commit 593e1b08 authored by kbeyro's avatar kbeyro
Browse files

update test

parent d49498c7
No related branches found
No related tags found
1 merge request!210Fix dashboard issue
Pipeline #94346 failed
......@@ -128,36 +128,35 @@ public class DashboardServiceImplTest {
}
@Test
void getSystemDashboardShouldCalculateCorrectTimestamps() {
OffsetDateTime startDate = OffsetDateTime.now().minusHours(5);
OffsetDateTime endDate = OffsetDateTime.now();
// Mock required repository methods
when(domainRepository.count()).thenReturn(1L);
when(userRepository.count()).thenReturn(1L);
when(appInstanceRepo.count()).thenReturn(1L);
when(appInstanceRepo.countAllDeployedSinceTime(org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.anyLong())).thenReturn(1);
when(applicationBaseRepository.findAllNames()).thenReturn(Collections.emptyList());
when(appInstanceRepo.findAllInTimePeriod(org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.anyLong())).thenReturn(Collections.emptyList());
// Call the method
dashboardService.getSystemDashboard(startDate, endDate);
// Capture the arguments
ArgumentCaptor<Long> startCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Long> endCaptor = ArgumentCaptor.forClass(Long.class);
// Verify that the method was called with calculated timestamps
org.mockito.Mockito.verify(appInstanceRepo).countAllDeployedSinceTime(startCaptor.capture(), endCaptor.capture());
long startTimestamp = startCaptor.getValue();
long endTimestamp = endCaptor.getValue();
// The timestamps should be positive and start should be greater than end (since it's calculated as now - toEpochSecond)
assert startTimestamp > 0;
assert endTimestamp > 0;
assert startTimestamp > endTimestamp;
}
void getSystemDashboardShouldCalculateCorrectTimestamps() {
OffsetDateTime startDate = OffsetDateTime.now().minusHours(5);
OffsetDateTime endDate = OffsetDateTime.now();
// Mock required repository methods
when(domainRepository.count()).thenReturn(1L);
when(userRepository.count()).thenReturn(1L);
when(appInstanceRepo.count()).thenReturn(1L);
when(appInstanceRepo.countAllDeployedSinceTime(org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.anyLong())).thenReturn(1);
when(applicationBaseRepository.findAllNames()).thenReturn(Collections.emptyList());
when(appInstanceRepo.findAllInTimePeriod(org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.anyLong())).thenReturn(Collections.emptyList());
// Call the method
dashboardService.getSystemDashboard(startDate, endDate);
// Capture the arguments
ArgumentCaptor<Long> startCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Long> endCaptor = ArgumentCaptor.forClass(Long.class);
org.mockito.Mockito.verify(appInstanceRepo).countAllDeployedSinceTime(startCaptor.capture(), endCaptor.capture());
long startTimestamp = startCaptor.getValue();
long endTimestamp = endCaptor.getValue();
// The timestamps should be positive and start should be less than or equal to end
assert startTimestamp > 0;
assert endTimestamp > 0;
assert startTimestamp <= endTimestamp;
}
@Test
void countAllDeployedSinceTimeShouldReturnCorrectCount() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment