Skip to content
Snippets Groups Projects
Commit 303e8fe6 authored by kbeyro's avatar kbeyro
Browse files

fix typo

parent d9c21ced
No related branches found
No related tags found
1 merge request!210Fix dashboard issue
Pipeline #94328 failed
...@@ -49,14 +49,14 @@ public interface AppInstanceRepository extends JpaRepository<AppInstance, Long> ...@@ -49,14 +49,14 @@ public interface AppInstanceRepository extends JpaRepository<AppInstance, Long>
@Query("select count(ai.id) FROM AppInstance ai where ai.createdAt >= :sinceTime") @Query("select count(ai.id) FROM AppInstance ai where ai.createdAt >= :sinceTime")
int countAllDeployedSinceTime(@Param("sinceTime") long sinceTime); int countAllDeployedSinceTime(@Param("sinceTime") long sinceTime);
@Query("select count(ai.id) FROM AppInstance ai where ai.createdAt >= :sinceTime AND ai.createdAt <= :endTime") @Query("select count(ai.id) FROM AppInstance ai where ai.createdAt >= :sinceTime AND ai.createdAt < :endTime")
int countAllDeployedSinceTime(@Param("sinceTime") long sinceTime, @Param("sinceTime") long toTime); int countAllDeployedSinceTime(@Param("sinceTime") long sinceTime, @Param("endTime") long endTime);
@Query("select count(ai.id) FROM AppInstance ai JOIN AppDeployment ad on ad.deploymentId = ai.internalId where ai.application.name = ?1") @Query("select count(ai.id) FROM AppInstance ai JOIN AppDeployment ad on ad.deploymentId = ai.internalId where ai.application.name = ?1")
int countByName(String name); int countByName(String name);
@Query("select ai FROM AppInstance ai where ai.createdAt >= :sinceTime AND ai.createdAt <= :endTime") @Query("select ai FROM AppInstance ai where ai.createdAt >= :sinceTime AND ai.createdAt <= :endTime")
List<AppInstance> findAllInTimePeriod(@Param("sinceTime") long start, @Param("endTime") long end); List<AppInstance> findAllInTimePeriod(@Param("sinceTime") long start, @Param("endTime") long endTime);
int countAllByOwner(User user); int countAllByOwner(User user);
......
...@@ -49,8 +49,10 @@ public class DashboardServiceImpl implements DashboardService { ...@@ -49,8 +49,10 @@ public class DashboardServiceImpl implements DashboardService {
@Override @Override
public DashboardView getSystemDashboard(OffsetDateTime startDate, OffsetDateTime endDate) { public DashboardView getSystemDashboard(OffsetDateTime startDate, OffsetDateTime endDate) {
long startTimeStamp = System.currentTimeMillis() - startDate.toEpochSecond(); log.warn("Start date {} / end date {}", startDate, endDate);
long endTimeStamp = System.currentTimeMillis() - endDate.toEpochSecond();
long startTimeStamp = startDate.toEpochSecond();
long endTimeStamp = endDate.toEpochSecond();
List<String> baseNames = applicationBaseRepository.findAllNames(); List<String> baseNames = applicationBaseRepository.findAllNames();
...@@ -68,7 +70,8 @@ public class DashboardServiceImpl implements DashboardService { ...@@ -68,7 +70,8 @@ public class DashboardServiceImpl implements DashboardService {
//filter not deployed application //filter not deployed application
applicationDeploymentCountPerName.entrySet().removeIf(app -> app.getValue() == 0); applicationDeploymentCountPerName.entrySet().removeIf(app -> app.getValue() == 0);
log.warn("Start stamp {} / end stamp {}", startTimeStamp, endTimeStamp);
log.warn("Result: {}", appInstanceRepo.countAllDeployedSinceTime(startTimeStamp, endTimeStamp));
return DashboardView.builder() return DashboardView.builder()
.domainsCount(domainRepository.count()) .domainsCount(domainRepository.count())
......
...@@ -158,4 +158,45 @@ void getSystemDashboardShouldCalculateCorrectTimestamps() { ...@@ -158,4 +158,45 @@ void getSystemDashboardShouldCalculateCorrectTimestamps() {
assert endTimestamp > 0; assert endTimestamp > 0;
assert startTimestamp > endTimestamp; assert startTimestamp > endTimestamp;
} }
@Test
void countAllDeployedSinceTimeShouldReturnCorrectCount() {
long sinceTime = 1000L;
long toTime = 2000L;
int expectedCount = 7;
when(appInstanceRepo.countAllDeployedSinceTime(sinceTime, toTime)).thenReturn(expectedCount);
int actualCount = appInstanceRepo.countAllDeployedSinceTime(sinceTime, toTime);
assert actualCount == expectedCount;
org.mockito.Mockito.verify(appInstanceRepo).countAllDeployedSinceTime(sinceTime, toTime);
}
@Test
void getSystemDashboardShouldCallCountAllDeployedSinceTimeWithCorrectArguments() {
OffsetDateTime startDate = OffsetDateTime.now().minusDays(2);
OffsetDateTime endDate = OffsetDateTime.now();
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(5);
when(applicationBaseRepository.findAllNames()).thenReturn(Collections.emptyList());
when(appInstanceRepo.findAllInTimePeriod(org.mockito.ArgumentMatchers.anyLong(), org.mockito.ArgumentMatchers.anyLong())).thenReturn(Collections.emptyList());
dashboardService.getSystemDashboard(startDate, endDate);
ArgumentCaptor<Long> sinceCaptor = ArgumentCaptor.forClass(Long.class);
ArgumentCaptor<Long> toCaptor = ArgumentCaptor.forClass(Long.class);
org.mockito.Mockito.verify(appInstanceRepo).countAllDeployedSinceTime(sinceCaptor.capture(), toCaptor.capture());
long sinceTime = sinceCaptor.getValue();
long toTime = toCaptor.getValue();
assert sinceTime > 0;
assert toTime > 0;
assert sinceTime < toTime;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment