@Test(expected = RuntimeException.class) public void search_conditional_branches() throws IOException { SearchMappingsRequest searchMappingsRequest = new SearchMappingsRequest(); searchMappingsRequest.setUserId("test-user"); searchMappingsRequest.setDetectorUuid(UUID.fromString("aeb4d849-847a-45c0-8312-dc0fcf22b639")); when(legacyElasticSearchClient.search(any(SearchRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new IOException()); repoUnderTest.search(searchMappingsRequest); }
@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);  }