Search in sources :

Example 21 with HttpRequest

use of com.hotels.styx.api.HttpRequest 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());
}
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 22 with HttpRequest

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

the class HttpMethodFilteringHandlerTest method delegatesTheRequestIfRequestMethodIsSupported.

@Test
public void delegatesTheRequestIfRequestMethodIsSupported() {
    WebServiceHandler handler = mock(WebServiceHandler.class);
    HttpMethodFilteringHandler post = new HttpMethodFilteringHandler(POST, handler);
    HttpRequest request = post("/some-uri").build();
    post.handle(request, mock(HttpInterceptor.Context.class));
    verify(handler).handle(eq(request), any(HttpInterceptor.Context.class));
}
Also used : HttpRequest(com.hotels.styx.api.HttpRequest) Support.requestContext(com.hotels.styx.support.Support.requestContext) WebServiceHandler(com.hotels.styx.api.WebServiceHandler) 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