Search in sources :

Example 41 with HttpMethod

use of io.netty.handler.codec.http.HttpMethod in project riposte by Nike-Inc.

the class AllowAllTheThingsCORSFilterTest method filterRequestLastChunkWithOptionalShortCircuitResponse_always_returns_null.

@DataProvider(value = { "OPTIONS", "GET", "POST", "PUT" }, splitBy = "\\|")
@Test
public void filterRequestLastChunkWithOptionalShortCircuitResponse_always_returns_null(String httpMethodString) {
    // given
    HttpMethod method = HttpMethod.valueOf(httpMethodString);
    doReturn(method).when(requestMock).getMethod();
    // when
    Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestLastChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
    // then
    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 42 with HttpMethod

use of 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 43 with HttpMethod

use of 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 44 with HttpMethod

use of 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 45 with HttpMethod

use of 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)

Aggregations

HttpMethod (io.netty.handler.codec.http.HttpMethod)95 Test (org.junit.Test)51 HttpRequest (io.netty.handler.codec.http.HttpRequest)28 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)25 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)21 URI (java.net.URI)15 IOException (java.io.IOException)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)11 HttpVersion (io.netty.handler.codec.http.HttpVersion)11 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 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)10 Map (java.util.Map)9