@Test public void search_successful() throws IOException { List<DetectorMapping> tagsList = new ArrayList<>(); Map<String, String> tags = new HashMap<>(); Long LastModifiedTimeInMillis = new Long(1554828886); Long CreatedTimeInMillis = new Long(1554828886); val searchIndex = "2"; val lookUpTime = 100; val detectorUuid = "aeb4d849-847a-45c0-8312-dc0fcf22b639"; SearchMappingsRequest searchMappingsRequest = new SearchMappingsRequest(); SearchResponse searchResponse = mockSearchResponse(searchIndex, lookUpTime, detectorUuid); when(legacyElasticSearchClient.search(any(SearchRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(searchResponse); Mockito.when(elasticsearchUtil.getSourceBuilder(any(QueryBuilder.class))).thenReturn(new SearchSourceBuilder()); tagsList = repoUnderTest.search(searchMappingsRequest); verify(legacyElasticSearchClient, atLeastOnce()).search(any(SearchRequest.class), eq(RequestOptions.DEFAULT)); assertNotNull("Response can't be null", tagsList); assertEquals(1, tagsList.size()); assertEquals(UUID.fromString(detectorUuid), tagsList.get(0).getDetector().getUuid()); assertEquals("test-user", tagsList.get(0).getUser().getId()); assertEquals(LastModifiedTimeInMillis, Long.valueOf(tagsList.get(0).getLastModifiedTimeInMillis())); assertEquals(CreatedTimeInMillis, Long.valueOf(tagsList.get(0).getCreatedTimeInMillis())); assertTrue(tagsList.get(0).isEnabled()); }
@Override public List<DetectorMapping> search(SearchMappingsRequest request) { val query = QueryBuilders.boolQuery(); if (request.getUserId() != null) { query.must(userIdQuery(request)); } if (request.getDetectorUuid() != null) { query.must(detectorIdQuery(request)); } val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(query); searchSourceBuilder.size(500); SearchRequest searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, elasticSearchProperties.getIndexName(), elasticSearchProperties.getDocType()); List<DetectorMapping> result = getDetectorMappings(searchRequest); return result.stream().filter(detectorMapping -> detectorMapping.isEnabled()).collect(Collectors.toList()); }
DetectorMappingRepositoryImpl implements DetectorMappingRepository { @Override public List<DetectorMapping> search(SearchMappingsRequest request) { val query = QueryBuilders.boolQuery(); if (request.getUserId() != null) { query.must(userIdQuery(request)); } if (request.getDetectorUuid() != null) { query.must(detectorIdQuery(request)); } val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(query); searchSourceBuilder.size(500); SearchRequest searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, elasticSearchProperties.getIndexName(), elasticSearchProperties.getDocType()); List<DetectorMapping> result = getDetectorMappings(searchRequest); return result.stream().filter(detectorMapping -> detectorMapping.isEnabled()).collect(Collectors.toList()); } }
DetectorMappingRepositoryImpl implements DetectorMappingRepository { @Override public List<DetectorMapping> search(SearchMappingsRequest request) { val query = QueryBuilders.boolQuery(); if (request.getUserId() != null) { query.must(userIdQuery(request)); } if (request.getDetectorUuid() != null) { query.must(detectorIdQuery(request)); } val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(query); searchSourceBuilder.size(500); SearchRequest searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, elasticSearchProperties.getIndexName(), elasticSearchProperties.getDocType()); List<DetectorMapping> result = getDetectorMappings(searchRequest); return result.stream().filter(detectorMapping -> detectorMapping.isEnabled()).collect(Collectors.toList()); } @Autowired  DetectorMappingRepositoryImpl(MetricRegistry metricRegistry); }
DetectorMappingRepositoryImpl implements DetectorMappingRepository { @Override public List<DetectorMapping> search(SearchMappingsRequest request) { val query = QueryBuilders.boolQuery(); if (request.getUserId() != null) { query.must(userIdQuery(request)); } if (request.getDetectorUuid() != null) { query.must(detectorIdQuery(request)); } val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(query); searchSourceBuilder.size(500); SearchRequest searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, elasticSearchProperties.getIndexName(), elasticSearchProperties.getDocType()); List<DetectorMapping> result = getDetectorMappings(searchRequest); return result.stream().filter(detectorMapping -> detectorMapping.isEnabled()).collect(Collectors.toList()); } @Autowired  DetectorMappingRepositoryImpl(MetricRegistry metricRegistry); @Override String createDetectorMapping(CreateDetectorMappingRequest request); @Override MatchingDetectorsResponse findMatchingDetectorMappings(List<Map<String, String>> tagsList); @Override DetectorMapping findDetectorMapping(String id); @Override List<DetectorMapping> findLastUpdated(int timeInSeconds); @Override List<DetectorMapping> search(SearchMappingsRequest request); @Override void disableDetectorMapping(String id); @Override void deleteDetectorMapping(String id); @Override void deleteMappingsByDetectorUUID(UUID uuid); }
DetectorMappingRepositoryImpl implements DetectorMappingRepository { @Override public List<DetectorMapping> search(SearchMappingsRequest request) { val query = QueryBuilders.boolQuery(); if (request.getUserId() != null) { query.must(userIdQuery(request)); } if (request.getDetectorUuid() != null) { query.must(detectorIdQuery(request)); } val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(query); searchSourceBuilder.size(500); SearchRequest searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, elasticSearchProperties.getIndexName(), elasticSearchProperties.getDocType()); List<DetectorMapping> result = getDetectorMappings(searchRequest); return result.stream().filter(detectorMapping -> detectorMapping.isEnabled()).collect(Collectors.toList()); } @Autowired  DetectorMappingRepositoryImpl(MetricRegistry metricRegistry); @Override String createDetectorMapping(CreateDetectorMappingRequest request); @Override MatchingDetectorsResponse findMatchingDetectorMappings(List<Map<String, String>> tagsList); @Override DetectorMapping findDetectorMapping(String id); @Override List<DetectorMapping> findLastUpdated(int timeInSeconds); @Override List<DetectorMapping> search(SearchMappingsRequest request); @Override void disableDetectorMapping(String id); @Override void deleteDetectorMapping(String id); @Override void deleteMappingsByDetectorUUID(UUID uuid);  }