### Question:
ServiceProviderHandler implements WebServiceHandler { @Override public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { return urlRouter.handle(request, context); } ServiceProviderHandler(StyxObjectStore<StyxObjectRecord<StyxService>> providerDatabase); @Override Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context); static ObjectMapper yamlMapper();  }### Answer:
@Test public void returnsAllProviders() throws IOException { StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore(); ServiceProviderHandler handler = new ServiceProviderHandler(store); HttpRequest request = HttpRequest.get("/admin/service/providers").build(); HttpResponse response = Mono.from(handler.handle(request, requestContext())).block(); assertThat(response.status(), equalTo(OK)); List<StyxObjectDefinition> actualProviders = extractProviders(response.bodyAs(UTF_8)); assertThat(actualProviders.size(), equalTo(store.entrySet().size())); for (StyxObjectDefinition actual : actualProviders) { Optional<StyxObjectRecord<StyxService>> rec = store.get(actual.name()); assertTrue(rec.isPresent()); validateProvider(actual, rec.get()); } }
@Test public void returnsNoContentStatusWhenNoProvidersAvailable() { StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>(); ServiceProviderHandler handler = new ServiceProviderHandler(empty); HttpRequest request = HttpRequest.get("/admin/service/providers").build(); HttpResponse response = Mono.from(handler.handle(request, requestContext())).block(); assertThat(response.status(), equalTo(NO_CONTENT)); assertFalse(response.contentLength().isPresent()); }
@Test public void returnsNamedProvider() throws IOException { StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore(); ServiceProviderHandler handler = new ServiceProviderHandler(store); HttpRequest request = HttpRequest.get("/admin/service/provider/object2").build(); HttpResponse response = Mono.from(handler.handle(request, requestContext())).block(); assertThat(response.status(), equalTo(OK)); StyxObjectDefinition actualProvider = deserialiseProvider(response.bodyAs(UTF_8)); assertThat(actualProvider, notNullValue()); assertThat(actualProvider.name(), equalTo("object2")); validateProvider(actualProvider, store.get("object2").get()); }
@Test public void returnsNotFoundStatusWhenNamedProviderNotFound() throws IOException { StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore(); ServiceProviderHandler handler = new ServiceProviderHandler(store); HttpRequest request = HttpRequest.get("/admin/service/provider/nonexistent").build(); HttpResponse response = Mono.from(handler.handle(request, requestContext())).block(); assertThat(response.status(), equalTo(NOT_FOUND)); }
@Test public void returnsNotFoundStatusWithNonHandledUrl() { StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>(); ServiceProviderHandler handler = new ServiceProviderHandler(empty); HttpRequest request = HttpRequest.get("/not/my/url").build(); HttpResponse response = Mono.from(handler.handle(request, requestContext())).block(); assertThat(response.status(), equalTo(NOT_FOUND)); }