use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class PluginToggleHandlerTest method notifiesWhenPluginAlreadyEnabled.
@Test
public void notifiesWhenPluginAlreadyEnabled() {
HttpRequest request = put("/foo/on/enabled").body("true", UTF_8).build();
HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
assertThat(response.status(), is(OK));
assertThat(body(response), is("{\"message\":\"State of 'on' was already 'enabled'\",\"plugin\":{\"name\":\"on\",\"state\":\"enabled\"}}"));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.
the class PluginToggleHandlerTest method saysBadRequestWhenUrlIsInvalid.
@Test
public void saysBadRequestWhenUrlIsInvalid() {
HttpRequest request = put("/foo//enabled").body("true", UTF_8).build();
HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
assertThat(response.status(), is(BAD_REQUEST));
assertThat(body(response), is("Invalid URL"));
assertThat(initiallyEnabled.enabled(), is(true));
assertThat(initiallyDisabled.enabled(), is(false));
}
use of com.hotels.styx.api.HttpRequest 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.HttpRequest 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.HttpRequest 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());
}
Aggregations