DetectorMappingController { @RequestMapping(value = "/search", method = RequestMethod.POST) public List<DetectorMapping> searchDetectorMapping(@RequestBody SearchMappingsRequest request, @RequestHeader HttpHeaders httpHeaders) { SpanContext parentSpanContext = trace.extractParentSpan(httpHeaders); Span span = trace.startSpan("mappings-search", parentSpanContext); AssertUtil.isTrue(request.getUserId() != null || request.getDetectorUuid() != null, "User id and Detector UUID can't both be null"); List<DetectorMapping> resultSearchDetectorMapping = detectorMappingRepo.search(request); span.finish(); return resultSearchDetectorMapping; }  @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 testDetectorMappingSearch() { List<DetectorMapping> detectorMappings = mockDetectorMappingsList(); SearchMappingsRequest searchMappingsRequest = new SearchMappingsRequest(); searchMappingsRequest.setDetectorUuid(UUID.fromString(detectorUuid)); searchMappingsRequest.setUserId(userVal); val testDetectorMappingSpanContext = new SpanContext(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()); val testChildSpan = noOpsTracer.buildSpan("mappings-search").asChildOf(testDetectorMappingSpanContext).start(); when(detectorMappingRepo.search(searchMappingsRequest)).thenReturn(detectorMappings); when(trace.extractParentSpan(httpHeaders)).thenReturn(testDetectorMappingSpanContext); when(trace.startSpan("mappings-search", testDetectorMappingSpanContext)).thenReturn(testChildSpan); List<DetectorMapping> detectorMappingsResponse = controllerUnderTest.searchDetectorMapping(searchMappingsRequest, httpHeaders); assertEquals(id, detectorMappingsResponse.get(0).getId()); assertEquals(detectorUuid, detectorMappingsResponse.get(0).getDetector().getUuid().toString()); assertEquals("test-user", detectorMappingsResponse.get(0).getUser().getId()); }
@Test public void testFindMatchingByTags() { val lookupTime = 60; List<Map<String, String>> tagsList = new ArrayList<>(); MatchingDetectorsResponse mockMatchingDetectorsResponse = mockMatchingDetectorsResponse(lookupTime, detectorUuid); when(detectorMappingRepo.findMatchingDetectorMappings(tagsList)).thenReturn(mockMatchingDetectorsResponse); MatchingDetectorsResponse matchingDetectorsResult = controllerUnderTest.searchDetectorMapping(tagsList); Assert.assertEquals(1, matchingDetectorsResult.getGroupedDetectorsBySearchIndex().size()); List<ConsumerDetectorMapping> consumerDetectorMappings = matchingDetectorsResult.getGroupedDetectorsBySearchIndex().get(1); assertEquals(1, consumerDetectorMappings.size()); assertEquals(UUID.fromString(detectorUuid), consumerDetectorMappings.get(0).getUuid()); }