Search in sources :

Example 6 with HttpMethod

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();
}
Also used : Optional(java.util.Optional) RequestInfo(com.nike.riposte.server.http.RequestInfo) HttpMethod(io.netty.handler.codec.http.HttpMethod) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 7 with HttpMethod

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));
}
Also used : ArrayList(java.util.ArrayList) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 8 with HttpMethod

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));
}
Also used : RequestContentDeserializationException(com.nike.riposte.server.error.exception.RequestContentDeserializationException) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 9 with HttpMethod

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));
}
Also used : HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Example 10 with HttpMethod

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);
}
Also used : Optional(java.util.Optional) Matchers.anyString(org.mockito.Matchers.anyString) HttpMethod(io.netty.handler.codec.http.HttpMethod) Test(org.junit.Test)

Aggregations

HttpMethod (io.netty.handler.codec.http.HttpMethod)83 Test (org.junit.Test)44 HttpRequest (io.netty.handler.codec.http.HttpRequest)24 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)20 URI (java.net.URI)15 IOException (java.io.IOException)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DefaultHttpClient (org.jocean.http.client.impl.DefaultHttpClient)11 TestChannelCreator (org.jocean.http.client.impl.TestChannelCreator)11 TestChannelPool (org.jocean.http.client.impl.TestChannelPool)11 DefaultSignalClient (org.jocean.http.rosa.impl.DefaultSignalClient)11 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)11 Subscription (rx.Subscription)11 Action2 (rx.functions.Action2)11 ByteBuf (io.netty.buffer.ByteBuf)10 HttpVersion (io.netty.handler.codec.http.HttpVersion)10 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 Map (java.util.Map)9 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)8