MetricController { @GetMapping public Map<String, Long> getNumberOfPes( @RequestParam(value = "fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime fromDate, @RequestParam(value = "toDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime toDate, @RequestParam(value = "statusType", required = false) StatusType statusType) { return metricService.getNumberOfPes(fromDate, toDate, statusType); } MetricController(MetricService metricService); @GetMapping Map<String, Long> getNumberOfPes(
            @RequestParam(value = "fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime fromDate,
            @RequestParam(value = "toDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime toDate,
            @RequestParam(value = "statusType", required = false) StatusType statusType); @GetMapping("/sample") Map<String, List<Map<LocalDateTime, Long>>> getNumberOfPesWithSample(
            @RequestParam(value = "fromDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime fromDate,
            @RequestParam(value = "toDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime toDate,
            @RequestParam(value = "statusType", required = false) StatusType statusType,
            @RequestParam(value = "sample", required = false) String sample);  }
@Test public void getNumberOfPesWithoutType() throws Exception { LocalDateTime localDateTimeNow = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formatedDateTime = localDateTimeNow.format(formatter); Map<String, Long> listPesNumberByType = new HashMap<>(); for(StatusType statusType: StatusType.values()) { listPesNumberByType.put(statusType.name(), (long) 0); } given(metricService.getNumberOfPes(any(), any(), eq(null))).willReturn(listPesNumberByType); this.mockMvc.perform(get("/api/pes/metric") .param("fromDate", formatedDateTime) .param("toDate", formatedDateTime)) .andExpect(status().isOk()); verify(metricService, times(1)).getNumberOfPes(any(), any(),eq(null)); verifyNoMoreInteractions(metricService); }
@Test public void getNumberOfPesWithType() throws Exception { LocalDateTime localDateTimeNow = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formatedDateTime = localDateTimeNow.format(formatter); Map<String, Long> listPesNumberByType = new HashMap<>(); listPesNumberByType.put(StatusType.CLASSEUR_SIGNED.name(), (long) 0); given(metricService.getNumberOfPes(any(), any(), eq(StatusType.CLASSEUR_SIGNED))).willReturn(listPesNumberByType); this.mockMvc.perform(get("/api/pes/metric") .param("fromDate", formatedDateTime) .param("toDate", formatedDateTime) .param("statusType", StatusType.CLASSEUR_SIGNED.name())) .andExpect(status().isOk()); verify(metricService, times(1)).getNumberOfPes(any(), any(),eq(StatusType.CLASSEUR_SIGNED)); verifyNoMoreInteractions(metricService); }