Search in sources :

Example 1 with HttpRequest

use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.

the class PluginToggleHandlerTest method notifiesWhenPluginAlreadyDisabled.

@Test
public void notifiesWhenPluginAlreadyDisabled() {
    HttpRequest request = put("/foo/off/enabled").body("false", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(body(response), is("{\"message\":\"State of 'off' was already 'disabled'\",\"plugin\":{\"name\":\"off\",\"state\":\"disabled\"}}"));
    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 2 with HttpRequest

use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.

the class PluginToggleHandlerTest method saysBadRequestWhenPluginDoesNotExist.

@Test
public void saysBadRequestWhenPluginDoesNotExist() {
    HttpRequest request = put("/foo/nonexistent/enabled").body("true", UTF_8).build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), is(NOT_FOUND));
    assertThat(body(response), is("No such plugin: pluginName=nonexistent"));
    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 3 with HttpRequest

use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.

the class ServiceProviderHandlerTest method returnsNotFoundStatusWhenNamedProviderNotFound.

@Test
public void returnsNotFoundStatusWhenNamedProviderNotFound() throws IOException {
    StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore();
    ServiceProviderHandler handler = new ServiceProviderHandler(store);
    HttpRequest request = HttpRequest.get("/admin/service/provider/nonexistent").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NOT_FOUND));
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 4 with HttpRequest

use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.

the class ServiceProviderHandlerTest method returnsNotFoundStatusWithNonHandledUrl.

@Test
public void returnsNotFoundStatusWithNonHandledUrl() {
    StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>();
    ServiceProviderHandler handler = new ServiceProviderHandler(empty);
    HttpRequest request = HttpRequest.get("/not/my/url").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NOT_FOUND));
}
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)

Example 5 with HttpRequest

use of com.hotels.styx.api.HttpRequest in project styx by ExpediaGroup.

the class StyxHttpClientTest method replacesUserAgentIfAlreadyPresentInRequest.

/*
     * StyxHttpClient
     * - User-Agent string from the request takes precedence.
     */
@Test
public void replacesUserAgentIfAlreadyPresentInRequest() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().userAgent("My default user agent value").build();
    HttpRequest request = get("/").header(HOST, hostString(server.port())).header(USER_AGENT, "My previous user agent").build();
    client.send(request).get();
    server.verify(getRequestedFor(urlEqualTo("/")).withHeader("User-Agent", equalTo("My default user agent value")));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) 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