Search in sources :

Example 16 with HttpRequest

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));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 17 with HttpRequest

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));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 18 with HttpRequest

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));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 19 with HttpRequest

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());
    }
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition) Test(org.junit.jupiter.api.Test)

Example 20 with HttpRequest

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());
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpRequest (com.hotels.styx.api.HttpRequest)22 Test (org.junit.jupiter.api.Test)19 HttpResponse (com.hotels.styx.api.HttpResponse)16 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)5 WebServiceHandler (com.hotels.styx.api.WebServiceHandler)3 StyxObjectDefinition (com.hotels.styx.routing.config.StyxObjectDefinition)2 StyxObjectStore (com.hotels.styx.routing.db.StyxObjectStore)2 Eventual (com.hotels.styx.api.Eventual)1 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)1 HttpMethod (com.hotels.styx.api.HttpMethod)1 DELETE (com.hotels.styx.api.HttpMethod.DELETE)1 GET (com.hotels.styx.api.HttpMethod.GET)1 POST (com.hotels.styx.api.HttpMethod.POST)1 PUT (com.hotels.styx.api.HttpMethod.PUT)1 HttpResponse.response (com.hotels.styx.api.HttpResponse.response)1 INTERNAL_SERVER_ERROR (com.hotels.styx.api.HttpResponseStatus.INTERNAL_SERVER_ERROR)1 NOT_FOUND (com.hotels.styx.api.HttpResponseStatus.NOT_FOUND)1 Support.requestContext (com.hotels.styx.support.Support.requestContext)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1