@Test public void testFindByUuid_emptyResult() throws IOException { SearchHits hits = new SearchHits(new SearchHit[]{}, 0, 0); SearchResponseSections searchResponseSections = new SearchResponseSections(hits, null, null, false, null, null, 5); SearchResponse emptySearchResponse = new SearchResponse(searchResponseSections, "", 0, 0, 0, 0, null, null); Mockito.when(legacyElasticSearchClient.search(any(SearchRequest.class), any(RequestOptions.class))).thenReturn(emptySearchResponse); DetectorDocument actualDetector = repoUnderTest.findByUuid("missing-uuid"); assertNull(actualDetector); }
@Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); } }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }  }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate); }
LegacyDetectorRepositoryImpl implements LegacyDetectorRepository { @Override public DetectorDocument findByUuid(String uuid) { MDC.put("DetectorUuid", uuid); val queryBuilder = QueryBuilders.termQuery("uuid", uuid); val searchSourceBuilder = elasticsearchUtil.getSourceBuilder(queryBuilder).size(DEFAULT_ES_RESULTS_SIZE); val searchRequest = elasticsearchUtil.getSearchRequest(searchSourceBuilder, DETECTOR_INDEX, DETECTOR_DOC_TYPE); val detectors = getDetectorsFromElasticSearch(searchRequest); MDC.remove("DetectorUuid"); return detectors.isEmpty() ? null : detectors.get(0); }  @Override UUID createDetector(DetectorDocument document); @Override void deleteDetector(String uuid); @Override void updateDetector(String uuid, DetectorDocument document); @Override DetectorDocument findByUuid(String uuid); @Override List<DetectorDocument> findByCreatedBy(String user); @Override void toggleDetector(String uuid, Boolean enabled); @Override void trustDetector(String uuid, Boolean trusted); @Override List<DetectorDocument> getLastUpdatedDetectors(long interval); @Override List<DetectorDocument> getLastUpdatedDetectors(String fromDate, String toDate);  }