DetectorMappingController { @RequestMapping(value = "/lastUpdated", method = RequestMethod.GET) public List<DetectorMapping> findDetectorMapping(@RequestParam int timeInSecs) { AssertUtil.notNull(timeInSecs, "timeInSecs can't be null"); return detectorMappingRepo.findLastUpdated(timeInSecs); }  @RequestMapping(produces = "application/json", method = RequestMethod.GET) DetectorMapping getDetectorMapping(@RequestParam String id); @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) String createDetectorMapping(@RequestBody CreateDetectorMappingRequest request, @RequestHeader HttpHeaders header); @RequestMapping(value = "/disable", method = RequestMethod.PUT) @ResponseStatus(HttpStatus.OK) void disableDeleteDetectorMapping(@RequestParam String id); @RequestMapping(method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteDetectorMapping(@RequestParam String id); @RequestMapping(value = "/search", method = RequestMethod.POST) List<DetectorMapping> searchDetectorMapping(@RequestBody SearchMappingsRequest request,
                                                       @RequestHeader HttpHeaders httpHeaders); @RequestMapping(value = "/lastUpdated", method = RequestMethod.GET) List<DetectorMapping> findDetectorMapping(@RequestParam int timeInSecs); @RequestMapping(value = "/findMatchingByTags", method = RequestMethod.POST) MatchingDetectorsResponse searchDetectorMapping(@RequestBody List<Map<String, String>> tagsList); @RequestMapping(value = "/deleteMappingsByDetectorUuid", method = RequestMethod.DELETE) @ResponseStatus(HttpStatus.OK) void deleteMappingsByDetectorUUID(@RequestParam UUID uuid);  }
@Test public void testGetLastUpdated_successful() { val timeInSecs = 60; List<DetectorMapping> mockDetectorMappings = mockDetectorMappingsList(); when(detectorMappingRepo.findLastUpdated(timeInSecs)).thenReturn(mockDetectorMappings); List<DetectorMapping> detectorMappings = controllerUnderTest.findDetectorMapping(timeInSecs); assertNotNull("Response can't be null", detectorMappings); assertEquals(1, detectorMappings.size()); assertEquals(UUID.fromString(detectorUuid), detectorMappings.get(0).getDetector().getUuid()); assertEquals(id, detectorMappings.get(0).getId()); }
@Test(expected = RuntimeException.class) public void testGetLastUpdated_fail() { val timeInSecs = 60; when(detectorMappingRepo.findLastUpdated(timeInSecs)).thenThrow(new IOException()); List<DetectorMapping> detectorMappings = controllerUnderTest.findDetectorMapping(timeInSecs); assertNotNull("Response can't be null", detectorMappings); assertEquals(0, detectorMappings.size()); }