use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class PluginToggleHandlerTest method saysBadRequestWhenValueIsInvalid.
@Test
public void saysBadRequestWhenValueIsInvalid() {
HttpRequest request = put("/foo/off/enabled").body("invalid", UTF_8).build();
HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
assertThat(response.status(), is(BAD_REQUEST));
assertThat(body(response), is("No such state: only 'true' and 'false' are valid."));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ProviderListHandlerTest method showsEndpointsForAllConfiguredProviders.
@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>"));
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ServiceProviderHandlerTest method returnsAllProviders.
@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());
}
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ServiceProviderHandlerTest method returnsNoContentStatusWhenNoProvidersAvailable.
@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());
}
use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.
the class ServiceProviderHandlerTest method returnsNamedProvider.
@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());
}
Aggregations