@Test public void showsEndpointsForAllConfiguredProviders() throws JsonProcessingException { JsonNode config = new ObjectMapper().readTree("{\"setting1\" : \"A\", \"setting2\" : \"A\"}"); StyxObjectStore<StyxObjectRecord<StyxService>> store = new StyxObjectStore<>(); store.insert("Service-A1", new StyxObjectRecord<>("ServiceA", new HashSet<>(), config, new SampleServiceA("Service-A-1"))); store.insert("Service-A2", new StyxObjectRecord<>("ServiceA", new HashSet<>(), config, new SampleServiceA("Service-A-2"))); store.insert("Service-B", new StyxObjectRecord<>("ServiceB", new HashSet<>(), config, new SampleServiceB("Service-B"))); ProviderListHandler handler = new ProviderListHandler(store); HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block(); assertThat(response.status(), equalTo(OK)); assertThat(response.bodyAs(UTF_8), stringContainsInOrder( "Service-A1 (ServiceA)", "<a href=\"/admin/providers/Service-A1/status\">/admin/providers/Service-A1/status</a>", "Service-A2 (ServiceA)", "<a href=\"/admin/providers/Service-A2/status\">/admin/providers/Service-A2/status</a>", "Service-B (ServiceB)", "<a href=\"/admin/providers/Service-B/withslash/\">/admin/providers/Service-B/withslash/</a>", "<a href=\"/admin/providers/Service-B/noslash\">/admin/providers/Service-B/noslash</a>", "<a href=\"/admin/providers/Service-B/\">/admin/providers/Service-B/</a>" )); }
@Override public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { String providerList = providerDb.entrySet().stream() .map(entry -> htmlForProvider(entry.getKey(), entry.getValue())) .collect(joining()); String html = String.format(HTML_TEMPLATE, TITLE, h2(TITLE) + providerList); return Eventual.of(response(OK) .body(html, UTF_8) .addHeader(CONTENT_TYPE, HTML_UTF_8.toString()) .build()); }
ProviderListHandler implements WebServiceHandler { @Override public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { String providerList = providerDb.entrySet().stream() .map(entry -> htmlForProvider(entry.getKey(), entry.getValue())) .collect(joining()); String html = String.format(HTML_TEMPLATE, TITLE, h2(TITLE) + providerList); return Eventual.of(response(OK) .body(html, UTF_8) .addHeader(CONTENT_TYPE, HTML_UTF_8.toString()) .build()); } }
ProviderListHandler implements WebServiceHandler { @Override public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { String providerList = providerDb.entrySet().stream() .map(entry -> htmlForProvider(entry.getKey(), entry.getValue())) .collect(joining()); String html = String.format(HTML_TEMPLATE, TITLE, h2(TITLE) + providerList); return Eventual.of(response(OK) .body(html, UTF_8) .addHeader(CONTENT_TYPE, HTML_UTF_8.toString()) .build()); } ProviderListHandler(ObjectStore<? extends StyxObjectRecord<? extends StyxService>> providerDb); }
ProviderListHandler implements WebServiceHandler { @Override public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { String providerList = providerDb.entrySet().stream() .map(entry -> htmlForProvider(entry.getKey(), entry.getValue())) .collect(joining()); String html = String.format(HTML_TEMPLATE, TITLE, h2(TITLE) + providerList); return Eventual.of(response(OK) .body(html, UTF_8) .addHeader(CONTENT_TYPE, HTML_UTF_8.toString()) .build()); } ProviderListHandler(ObjectStore<? extends StyxObjectRecord<? extends StyxService>> providerDb); @Override Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context); }
ProviderListHandler implements WebServiceHandler { @Override public Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context) { String providerList = providerDb.entrySet().stream() .map(entry -> htmlForProvider(entry.getKey(), entry.getValue())) .collect(joining()); String html = String.format(HTML_TEMPLATE, TITLE, h2(TITLE) + providerList); return Eventual.of(response(OK) .body(html, UTF_8) .addHeader(CONTENT_TYPE, HTML_UTF_8.toString()) .build()); } ProviderListHandler(ObjectStore<? extends StyxObjectRecord<? extends StyxService>> providerDb); @Override Eventual<HttpResponse> handle(HttpRequest request, HttpInterceptor.Context context);  }