use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class OriginsHandlerTest method respondsToRequestWithJsonResponse.
@Test
public void respondsToRequestWithJsonResponse() throws IOException {
String originsFile = fixturesHome() + "conf/origins/origins-for-jsontest.yml";
Iterable<BackendService> expected = loadFromPath(originsFile).get();
withOriginsHandler(originsFile, handler -> {
HttpResponse response = Mono.from(handler.handle(get("/admin/configuration/origins").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.contentType(), isValue(APPLICATION_JSON));
Iterable<BackendService> result = newBackendServices(unmarshalApplications(response.bodyAs(UTF_8)));
assertThat(result, is(expected));
});
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class OriginsHandlerTest method respondsWithEmptyArrayWhenNoOrigins.
@Test
public void respondsWithEmptyArrayWhenNoOrigins() {
Registry<BackendService> backendServicesRegistry = new MemoryBackedRegistry<>();
OriginsHandler handler = new OriginsHandler(backendServicesRegistry);
HttpResponse response = Mono.from(handler.handle(get("/admin/configuration/origins").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.contentType(), isValue(APPLICATION_JSON));
assertThat(response.bodyAs(UTF_8), is("[]"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class OriginsInventoryHandlerTest method prettyPrintsOriginsSnapshot.
@Test
public void prettyPrintsOriginsSnapshot() {
EventBus eventBus = new EventBus();
OriginsInventoryHandler handler = new OriginsInventoryHandler(eventBus);
Set<Origin> disabledOrigins = generateOrigins(2);
eventBus.post(new OriginsSnapshot(APP_ID, pool(emptySet()), pool(emptySet()), pool(disabledOrigins)));
HttpResponse response = Mono.from(handler.handle(get("/?pretty=1").build(), requestContext())).block();
assertThat(body(response).replace("\r\n", "\n"), matchesRegex("\\{\n" + " \"" + APP_ID + "\" : \\{\n" + " \"appId\" : \"" + APP_ID + "\",\n" + " \"activeOrigins\" : \\[ ],\n" + " \"inactiveOrigins\" : \\[ ],\n" + " \"disabledOrigins\" : \\[ \\{\n" + " \"id\" : \"origin.\",\n" + " \"host\" : \"localhost:....\"\n" + " }, \\{\n" + " \"id\" : \"origin.\",\n" + " \"host\" : \"localhost:....\"\n" + " } ]\n" + " }\n" + "}"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class OriginsInventoryHandlerTest method respondsWithCorrectSnapshot.
@Test
public void respondsWithCorrectSnapshot() throws IOException {
EventBus eventBus = new EventBus();
OriginsInventoryHandler handler = new OriginsInventoryHandler(eventBus);
Set<Origin> activeOrigins = generateOrigins(3);
Set<Origin> inactiveOrigins = generateOrigins(4);
Set<Origin> disabledOrigins = generateOrigins(2);
eventBus.post(new OriginsSnapshot(APP_ID, pool(activeOrigins), pool(inactiveOrigins), pool(disabledOrigins)));
HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
assertThat(response.bodyAs(UTF_8).split("\n").length, is(1));
Map<Id, OriginsSnapshot> output = deserialiseJson(response.bodyAs(UTF_8));
assertThat(output.keySet(), contains(APP_ID));
OriginsSnapshot snapshot = output.get(APP_ID);
assertThat(snapshot.appId(), is(APP_ID));
assertThat(snapshot.activeOrigins(), is(activeOrigins));
assertThat(snapshot.inactiveOrigins(), is(inactiveOrigins));
assertThat(snapshot.disabledOrigins(), is(disabledOrigins));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class PingHandlerTest method respondsPongToPingRequest.
@Test
public void respondsPongToPingRequest() {
HttpResponse response = Mono.from(handler.handle(get("/ping").build(), requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(response.headers(), isNotCacheable());
assertThat(response.contentType().get(), is("text/plain; charset=utf-8"));
assertThat(response.bodyAs(UTF_8), is("pong"));
}
Aggregations