DetectorMappingRepositoryImpl implements DetectorMappingRepository { @Override public DetectorMapping findDetectorMapping(String id) { val getRequest = new GetRequest(elasticSearchProperties.getIndexName(), elasticSearchProperties.getDocType(), id); try { val response = legacyElasticSearchClient.get(getRequest, RequestOptions.DEFAULT); return getDetectorMapping(response.getSourceAsString(), response.getId(), Optional.empty()); } catch (IOException e) { log.error(String.format("Get mapping %s failed", id), e); throw new RuntimeException(e); } } @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);  }
@Test public void findDetectorMapping_successful() throws IOException { List<Map<String, String>> tagsList = new ArrayList<>(); val detectorUuid = "aeb4d849-847a-45c0-8312-dc0fcf22b639"; String id = "adsvade8^szx"; Long LastModifiedTimeInMillis = new Long(1554828886); Long CreatedTimeInMillis = new Long(1554828886); GetResponse getResponse = mockGetResponse(id); when(legacyElasticSearchClient.get(any(GetRequest.class), eq(RequestOptions.DEFAULT))).thenReturn(getResponse); DetectorMapping detectorMapping = repoUnderTest.findDetectorMapping(id); verify(legacyElasticSearchClient, atLeastOnce()).get(any(GetRequest.class), eq(RequestOptions.DEFAULT)); assertNotNull("Response can't be null", detectorMapping); assertEquals(id, detectorMapping.getId()); assertEquals("test-user", detectorMapping.getUser().getId()); assertEquals(LastModifiedTimeInMillis, Long.valueOf(detectorMapping.getLastModifiedTimeInMillis())); assertEquals(CreatedTimeInMillis, Long.valueOf(detectorMapping.getCreatedTimeInMillis())); assertTrue(detectorMapping.isEnabled()); assertEquals(UUID.fromString(detectorUuid), detectorMapping.getDetector().getUuid()); }
@Test(expected = RuntimeException.class) public void findDetectorMapping_fail() throws IOException { String id = "adsvade8^szx"; when(legacyElasticSearchClient.get(any(GetRequest.class), eq(RequestOptions.DEFAULT))).thenThrow(new IOException()); repoUnderTest.findDetectorMapping(id); }