### Question:
ProbeEndpointsStrategy implements EndpointDetectionStrategy { @Override public Mono<Endpoints> detectEndpoints(Instance instance) { if (instance.getRegistration().getManagementUrl() == null) { log.debug("Endpoint probe for instance {} omitted. No management-url registered.", instance.getId()); return Mono.empty(); } return Flux.fromIterable(this.endpoints).flatMap((endpoint) -> detectEndpoint(instance, endpoint)).collectList() .flatMap(this::convert); } ProbeEndpointsStrategy(InstanceWebClient instanceWebClient, String[] endpoints); @Override Mono<Endpoints> detectEndpoints(Instance instance);  }### Answer:
@Test public void should_return_detect_endpoints() { Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).willReturn(ok())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/error")).willReturn(serverError())); this.wireMock.stubFor( options(urlEqualTo("/mgmt/exception")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient, new String[] { "metrics:stats", "metrics", "info", "non-exist", "error", "exception" }); StepVerifier.create(strategy.detectEndpoints(instance)) .expectNext(Endpoints.single("metrics", this.wireMock.url("/mgmt/stats")).withEndpoint("info", this.wireMock.url("/mgmt/info"))) .verifyComplete(); }
@Test public void should_return_empty() { Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); this.wireMock.stubFor( options(urlEqualTo("/mgmt/stats")).willReturn(aResponse().withStatus(HttpStatus.NOT_FOUND_404))); ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient, new String[] { "metrics:stats" }); StepVerifier.create(strategy.detectEndpoints(instance)) .verifyComplete(); }
@Test public void should_retry() { Instance instance = Instance.create(InstanceId.of("id")).register(Registration .create("test", this.wireMock.url("/mgmt/health")).managementUrl(this.wireMock.url("/mgmt")).build()); this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).inScenario("retry").whenScenarioStateIs(STARTED) .willReturn(aResponse().withFixedDelay(5000)).willSetStateTo("recovered")); this.wireMock.stubFor(options(urlEqualTo("/mgmt/metrics")).inScenario("retry").whenScenarioStateIs("recovered") .willReturn(ok())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/stats")).willReturn(ok())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/info")).willReturn(ok())); this.wireMock.stubFor(options(urlEqualTo("/mgmt/non-exist")).willReturn(notFound())); ProbeEndpointsStrategy strategy = new ProbeEndpointsStrategy(this.instanceWebClient, new String[] { "metrics:stats", "metrics", "info", "non-exist" }); StepVerifier.create(strategy.detectEndpoints(instance)) .expectNext(Endpoints.single("metrics", this.wireMock.url("/mgmt/stats")).withEndpoint("info", this.wireMock.url("/mgmt/info"))) .verifyComplete(); }