### Question:
MatchingServiceHealthCheckHandler { public AggregatedMatchingServicesHealthCheckResult handle() { return handle(false); } @Inject  MatchingServiceHealthCheckHandler(final MatchingServiceConfigProxy matchingServiceConfigProxy,
                                             final MatchingServiceHealthChecker matchingServiceHealthChecker); AggregatedMatchingServicesHealthCheckResult handle(); AggregatedMatchingServicesHealthCheckResult forceCheckAllMSAs();  }### Answer:
@Test public void handle_shouldReturnSuccessWhenMatchingServiceIsHealthy() throws Exception { MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto().build(); when(matchingServiceConfigProxy.getMatchingServices()).thenReturn(singletonList(matchingServiceConfigEntityDataDto)); when(matchingServiceHealthChecker.performHealthCheck(matchingServiceConfigEntityDataDto)) .thenReturn(MatchingServiceHealthCheckResult.healthy(MatchingServiceHealthCheckDetailsBuilder.aMatchingServiceHealthCheckDetails().build())); AggregatedMatchingServicesHealthCheckResult result = matchingServiceHealthCheckHandler.handle(); assertThat(result.isHealthy()).isEqualTo(true); }
@Test public void handle_shouldReturnSuccessWhenMatchingServiceIsNotHealthy() throws Exception { MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = MatchingServiceConfigEntityDataDtoBuilder.aMatchingServiceConfigEntityDataDto().build(); when(matchingServiceConfigProxy.getMatchingServices()).thenReturn(singletonList(matchingServiceConfigEntityDataDto)); when(matchingServiceHealthChecker.performHealthCheck(matchingServiceConfigEntityDataDto)) .thenReturn(MatchingServiceHealthCheckResult.unhealthy(MatchingServiceHealthCheckDetailsBuilder.aMatchingServiceHealthCheckDetails().build())); AggregatedMatchingServicesHealthCheckResult result = matchingServiceHealthCheckHandler.handle(); assertThat(result.isHealthy()).isEqualTo(false); }
@Test public void handle_shouldCheckHealthOfAllMatchingServices() throws Exception { MatchingServiceConfigEntityDataDto firstMatchingService = aMatchingServiceConfigEntityDataDto().withUri(URI.create("/a-matching-service-uri-1")).withEntityId("1").build(); MatchingServiceConfigEntityDataDto secondMatchingService = aMatchingServiceConfigEntityDataDto().withUri(URI.create("/a-matching-service-uri-2")).withEntityId("2").build(); Collection<MatchingServiceConfigEntityDataDto> matchingServiceConfigEntityDatas = asList(firstMatchingService, secondMatchingService); when(matchingServiceConfigProxy.getMatchingServices()).thenReturn(matchingServiceConfigEntityDatas); when(matchingServiceHealthChecker.performHealthCheck(any(MatchingServiceConfigEntityDataDto.class))) .thenReturn(MatchingServiceHealthCheckResult.healthy(MatchingServiceHealthCheckDetailsBuilder.aMatchingServiceHealthCheckDetails().build())); AggregatedMatchingServicesHealthCheckResult result = matchingServiceHealthCheckHandler.handle(); verify(matchingServiceHealthChecker).performHealthCheck(firstMatchingService); verify(matchingServiceHealthChecker).performHealthCheck(secondMatchingService); assertThat(result.getResults().size()).isEqualTo(2); }
@Test public void handle_shouldNotExecuteHealthCheckForMatchingServiceWithHealthCheckDisabled() { MatchingServiceConfigEntityDataDto matchingServiceConfigEntityDataDto = aMatchingServiceConfigEntityDataDto().withHealthCheckDisabled().build(); when(matchingServiceConfigProxy.getMatchingServices()).thenReturn(singletonList(matchingServiceConfigEntityDataDto)); matchingServiceHealthCheckHandler.handle(); verify(matchingServiceHealthChecker, never()) .performHealthCheck(any(MatchingServiceConfigEntityDataDto.class)); }