DetectorController { @GetMapping(path = "/findByUuid", produces = "application/json") @ResponseStatus(HttpStatus.OK) public Detector findByUuid(@RequestParam String uuid, @RequestHeader HttpHeaders headers) { SpanContext parentSpanContext = trace.extractParentSpan(headers); Span span = trace.startSpan("find-detector-by-uuid", parentSpanContext); Detector detector = service.findByUuid(uuid); if (detector == null) { span.setTag("Error", "Invalid UUID"); span.finish(); throw new RecordNotFoundException("Invalid UUID: " + uuid); } span.finish(); return detector; }  @PostMapping @ResponseStatus(HttpStatus.CREATED) String createDetector(@Valid @RequestBody Detector detector, @RequestHeader HttpHeaders headers); @GetMapping(path = "/findByUuid", produces = "application/json") @ResponseStatus(HttpStatus.OK) Detector findByUuid(@RequestParam String uuid, @RequestHeader HttpHeaders headers); @GetMapping(path = "/findByCreatedBy", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<Detector> findByCreatedBy(@RequestParam String user); @PostMapping(path = "/toggleDetector") @ResponseStatus(HttpStatus.OK) void toggleDetector(@RequestParam String uuid, @RequestParam Boolean enabled); @PostMapping(path = "/trustDetector") @ResponseStatus(HttpStatus.OK) void trustDetector(@RequestParam String uuid, @RequestParam Boolean trusted); @GetMapping(path = "/getLastUpdatedDetectors", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<Detector> getLastUpdatedDetectors(@RequestParam long interval); @GetMapping(path = "/getLastUsedDetectors", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<Detector> getLastUsedDetectors(@RequestParam int noOfDays); @PutMapping @ResponseStatus(HttpStatus.OK) void updateDetector(@RequestParam String uuid, @RequestBody Detector detector); @PostMapping(path = "/updateDetectorLastUsed", consumes = "application/json", produces = "application/json") @ResponseStatus(HttpStatus.OK) void updatedDetectorLastUsed(@RequestBody Map<String, String> params); @DeleteMapping @ResponseStatus(HttpStatus.OK) void deleteDetector(@RequestParam String uuid); @GetMapping(path = "/getDetectorsToTrain", produces = "application/json") @ResponseStatus(HttpStatus.OK) List<Detector> getDetectorsToTrain(@RequestParam Long timestampMs, @RequestHeader HttpHeaders headers); @PostMapping(path = "/updateDetectorTrainingTime") void updateDetectorTrainingTime(@RequestParam String uuid,
                                           @RequestParam Long nextRun,
                                           @RequestHeader HttpHeaders headers);  }
@Test public void testFindByUuid() { val testDetectorMappingSpanContext = new SpanContext(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()); val testChildSpan = noOpsTracer.buildSpan("find-detector-by-uuid").asChildOf(testDetectorMappingSpanContext).start(); when(trace.extractParentSpan(httpHeaders)).thenReturn(testDetectorMappingSpanContext); when(trace.startSpan("find-detector-by-uuid", testDetectorMappingSpanContext)).thenReturn(testChildSpan); val actualDetector = controllerUnderTest.findByUuid(someUuid.toString(), httpHeaders); assertNotNull(actualDetector); }
@Test(expected = RecordNotFoundException.class) public void testFindByUuid_record_not_found_null_response() { val testDetectorMappingSpanContext = new SpanContext(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()); val testChildSpan = noOpsTracer.buildSpan("find-detector-by-uuid").asChildOf(testDetectorMappingSpanContext).start(); when(trace.extractParentSpan(httpHeaders)).thenReturn(testDetectorMappingSpanContext); when(trace.startSpan("find-detector-by-uuid", testDetectorMappingSpanContext)).thenReturn(testChildSpan); when(detectorService.findByUuid(anyString())).thenReturn(null); controllerUnderTest.findByUuid(someUuid.toString(), httpHeaders); }