use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class StyxServerTest method exposesAdminEndpoints.
@Test
public void exposesAdminEndpoints() {
setUpStyxAndPluginWithAdminPages(Map.of("adminPage1", (request, ctx) -> Eventual.of(LiveHttpResponse.response().header("AdminPage1", "yes").build()), "adminPage2", (request, ctx) -> Eventual.of(LiveHttpResponse.response().header("AdminPage2", "yes").build())));
HttpResponse response = doAdminRequest("/admin/plugins/plugin-with-admin-pages/adminPage1");
assertThat(response.status(), is(OK));
assertThat(response.header("AdminPage1"), isValue("yes"));
response = doAdminRequest("/admin/plugins/plugin-with-admin-pages/adminPage2");
assertThat(response.status(), is(OK));
assertThat(response.header("AdminPage2"), isValue("yes"));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class ModifyHeadersExamplePluginTest method addsExtraHeaders.
/**
* This tests the behaviours added in the ModifyHeadersExamplePlugin.
*/
@Test
public void addsExtraHeaders() {
// a simple way to mock the downstream system
HttpInterceptor.Chain chain = request -> {
assertThat(request.header("myRequestHeader").orElse(null), is("foo"));
return Eventual.of(response(OK).build());
};
// an example request you expect your plugin to receive
LiveHttpRequest request = get("/foo").build();
// since this is a test, we want to wait for the response
LiveHttpResponse response = Mono.from(plugin.intercept(request, chain)).block();
assertThat(response.header("myResponseHeader").orElse(null), is("bar"));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method interceptorsCanPassInformationThroughContextBeforeRequest.
@Test
public void interceptorsCanPassInformationThroughContextBeforeRequest() {
HttpInterceptor addsToContext = (request, chain) -> {
chain.context().add("contextValue", "expected");
return chain.proceed(request);
};
AtomicReference<String> foundInContext = new AtomicReference<>();
HttpInterceptor takesFromContext = (request, chain) -> {
foundInContext.set(chain.context().get("contextValue", String.class));
return chain.proceed(request);
};
StandardHttpPipeline pipeline = pipeline(addsToContext, takesFromContext);
LiveHttpResponse response = sendRequestTo(pipeline);
assertThat(response.status(), is(OK));
assertThat(foundInContext.get(), is("expected"));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method contextValuesAddedBeforeRequestCanBeRetrievedAfterward.
@Test
public void contextValuesAddedBeforeRequestCanBeRetrievedAfterward() {
HttpInterceptor addsToContext = (request, chain) -> {
chain.context().add("contextValue", "expected");
return chain.proceed(request);
};
AtomicReference<String> foundInContext = new AtomicReference<>();
HttpInterceptor takesFromContext = (request, chain) -> chain.proceed(request).map(response -> {
foundInContext.set(chain.context().get("contextValue", String.class));
return response;
});
StandardHttpPipeline pipeline = pipeline(addsToContext, takesFromContext);
LiveHttpResponse response = sendRequestTo(pipeline);
assertThat(response.status(), is(OK));
assertThat(foundInContext.get(), is("expected"));
}
use of com.hotels.styx.api.HttpResponseStatus.OK in project styx by ExpediaGroup.
the class StandardHttpPipelineTest method interceptorsCanPassInformationThroughContextAfterRequest.
@Test
public void interceptorsCanPassInformationThroughContextAfterRequest() {
HttpInterceptor addsToContext = (request, chain) -> chain.proceed(request).map(response -> {
chain.context().add("contextValue", "expected");
return response;
});
AtomicReference<String> foundInContext = new AtomicReference<>();
HttpInterceptor takesFromContext = (request, chain) -> chain.proceed(request).map(response -> {
foundInContext.set(chain.context().get("contextValue", String.class));
return response;
});
// add + take happens on the way back, so order must be reserved
StandardHttpPipeline pipeline = pipeline(takesFromContext, addsToContext);
LiveHttpResponse response = sendRequestTo(pipeline);
assertThat(response.status(), is(OK));
assertThat(foundInContext.get(), is("expected"));
}
Aggregations