use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class AllowAllTheThingsCORSFilterTest method filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request.
@DataProvider(value = { "OPTIONS | true", "GET | false", "POST | false", "PUT | false" }, splitBy = "\\|")
@Test
public void filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request(String httpMethodString, boolean expectShortCircuit) {
// given
HttpMethod method = HttpMethod.valueOf(httpMethodString);
doReturn(method).when(requestMock).getMethod();
// when
Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestFirstChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
// then
if (expectShortCircuit) {
assertThat(result).isNotNull();
assertThat(result.getLeft()).isSameAs(requestMock);
assertThat(result.getRight()).isPresent();
assertThat(result.getRight().get().getHttpStatusCode()).isEqualTo(200);
} else
assertThat(result).isNull();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class MultiMatcherTest method static_factory_with_path_and_methods_varargs_sets_values_as_expected.
@Test
public void static_factory_with_path_and_methods_varargs_sets_values_as_expected() {
// given
String path = "/" + UUID.randomUUID().toString();
Collection<String> paths = new ArrayList<String>() {
{
add(path);
}
};
HttpMethod[] methodVarargs = new HttpMethod[] { HttpMethod.GET, HttpMethod.PUT };
// when
MultiMatcher matcher = MultiMatcher.match(paths, methodVarargs);
// then
assertThat(matcher.matchingPathTemplates(), is(paths));
assertThat(matcher.matchingMethods(), notNullValue());
assertThat(matcher.matchingMethods().size(), is(methodVarargs.length));
for (HttpMethod expectedMethod : methodVarargs) {
assertThat(matcher.matchingMethods().contains(expectedMethod), is(true));
}
assertThat(matcher.isMatchAllMethods(), is(false));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class RequestInfoImplTest method getContent_throws_RequestContentDeserializationException_if_an_error_occurs_during_deserialization.
@Test
public void getContent_throws_RequestContentDeserializationException_if_an_error_occurs_during_deserialization() throws IOException {
// given
RequestInfo<TestContentObject> requestInfoSpy = spy((RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests());
ObjectMapper objectMapperSpy = spy(new ObjectMapper());
byte[] rawBytes = new byte[] {};
doReturn(rawBytes).when(requestInfoSpy).getRawContentBytes();
RuntimeException expectedRootCause = new RuntimeException("splat");
doThrow(expectedRootCause).when(objectMapperSpy).readValue(any(byte[].class), any(TypeReference.class));
HttpMethod method = HttpMethod.CONNECT;
String path = UUID.randomUUID().toString();
TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {
};
doReturn(method).when(requestInfoSpy).getMethod();
doReturn(path).when(requestInfoSpy).getPath();
// when
requestInfoSpy.setupContentDeserializer(objectMapperSpy, typeRef);
Throwable actualEx = catchThrowable(() -> requestInfoSpy.getContent());
// then
assertThat(actualEx, notNullValue());
assertThat(actualEx, instanceOf(RequestContentDeserializationException.class));
RequestContentDeserializationException rcde = (RequestContentDeserializationException) actualEx;
assertThat(rcde.desiredObjectType, sameInstance(typeRef));
assertThat(rcde.httpMethod, is(String.valueOf(method)));
assertThat(rcde.requestPath, is(path));
assertThat(actualEx.getCause(), is(expectedRootCause));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class SingleMatcherTest method static_factory_with_path_and_methods_varargs_sets_values_as_expected.
@Test
public void static_factory_with_path_and_methods_varargs_sets_values_as_expected() {
// given
String path = "/" + UUID.randomUUID().toString();
HttpMethod[] methodVarargs = new HttpMethod[] { HttpMethod.GET, HttpMethod.PUT };
// when
SingleMatcher matcher = SingleMatcher.match(path, methodVarargs);
// then
assertThat(matcher.matchingPathTemplates(), is(Arrays.asList(path)));
assertThat(matcher.matchingMethods(), notNullValue());
assertThat(matcher.matchingMethods().size(), is(methodVarargs.length));
for (HttpMethod expectedMethod : methodVarargs) {
assertThat(matcher.matchingMethods().contains(expectedMethod), is(true));
}
assertThat(matcher.isMatchAllMethods(), is(false));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.
the class AsyncHttpClientHelperTest method getRequestBuilder_delegates_to_helper_with_default_circuit_breaker_args.
@Test
public void getRequestBuilder_delegates_to_helper_with_default_circuit_breaker_args() {
// given
String url = UUID.randomUUID().toString();
HttpMethod method = HttpMethod.valueOf(UUID.randomUUID().toString());
RequestBuilderWrapper rbwMock = mock(RequestBuilderWrapper.class);
doReturn(rbwMock).when(helperSpy).getRequestBuilder(anyString(), any(HttpMethod.class), any(Optional.class), anyBoolean());
// when
RequestBuilderWrapper rbw = helperSpy.getRequestBuilder(url, method);
// then
verify(helperSpy).getRequestBuilder(url, method, Optional.empty(), false);
assertThat(rbw).isSameAs(rbwMock);
}
Aggregations