@Test public void testDetectorCreateMappings() { List<DetectorMapping> detectorMappings = mockDetectorMappingsList(); CreateDetectorMappingRequest createDetectorMappingRequest = new CreateDetectorMappingRequest(); List<Operand> operandsList = new ArrayList<Operand>(); Operand testOperand = new Operand(); testOperand.setField(new Field("name", "sample-web")); operandsList.add(testOperand); Expression validateExpression = new Expression(); validateExpression.setOperands(operandsList); validateExpression.setOperator(Operator.AND); createDetectorMappingRequest.setExpression(validateExpression); createDetectorMappingRequest.setConsumerDetectorMapping(buildDetector(UUID.randomUUID().toString())); createDetectorMappingRequest.setUser(new User(userVal)); String detectorMapping = mockDetectorMapping(id).toString(); val testDetectorMappingSpanContext = new SpanContext(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()); val testChildSpan = noOpsTracer.buildSpan("create-mappings").asChildOf(testDetectorMappingSpanContext).start(); when(detectorMappingRepo.createDetectorMapping(createDetectorMappingRequest)).thenReturn(detectorMapping); when(trace.extractParentSpan(httpHeaders)).thenReturn(testDetectorMappingSpanContext); when(trace.startSpan("create-mappings", testDetectorMappingSpanContext)).thenReturn(testChildSpan); String detectorMappingsResponse = controllerUnderTest.createDetectorMapping(createDetectorMappingRequest, httpHeaders); assertEquals(detectorMapping.toString(), detectorMappingsResponse); }
@RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public String createDetectorMapping(@RequestBody CreateDetectorMappingRequest request, @RequestHeader HttpHeaders header) { SpanContext parentSpanContext = trace.extractParentSpan(header); Span span = trace.startSpan("create-mappings", parentSpanContext); request.validate(); String detectorMappingJsonString = detectorMappingRepo.createDetectorMapping(request); span.finish(); return detectorMappingJsonString; }
DetectorMappingController { @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public String createDetectorMapping(@RequestBody CreateDetectorMappingRequest request, @RequestHeader HttpHeaders header) { SpanContext parentSpanContext = trace.extractParentSpan(header); Span span = trace.startSpan("create-mappings", parentSpanContext); request.validate(); String detectorMappingJsonString = detectorMappingRepo.createDetectorMapping(request); span.finish(); return detectorMappingJsonString; } }
DetectorMappingController { @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public String createDetectorMapping(@RequestBody CreateDetectorMappingRequest request, @RequestHeader HttpHeaders header) { SpanContext parentSpanContext = trace.extractParentSpan(header); Span span = trace.startSpan("create-mappings", parentSpanContext); request.validate(); String detectorMappingJsonString = detectorMappingRepo.createDetectorMapping(request); span.finish(); return detectorMappingJsonString; }  }
DetectorMappingController { @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public String createDetectorMapping(@RequestBody CreateDetectorMappingRequest request, @RequestHeader HttpHeaders header) { SpanContext parentSpanContext = trace.extractParentSpan(header); Span span = trace.startSpan("create-mappings", parentSpanContext); request.validate(); String detectorMappingJsonString = detectorMappingRepo.createDetectorMapping(request); span.finish(); return detectorMappingJsonString; }  @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); }
DetectorMappingController { @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) public String createDetectorMapping(@RequestBody CreateDetectorMappingRequest request, @RequestHeader HttpHeaders header) { SpanContext parentSpanContext = trace.extractParentSpan(header); Span span = trace.startSpan("create-mappings", parentSpanContext); request.validate(); String detectorMappingJsonString = detectorMappingRepo.createDetectorMapping(request); span.finish(); return detectorMappingJsonString; }  @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);  }