Search in sources :

Example 86 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_mixed_type_and_return_null.

@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_mixed_type_and_return_null(boolean isFirstChunk) {
    // given
    HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
    doReturn(true).when(filtersList.get(0)).isShortCircuitRequestFilter();
    doReturn(false).when(filtersList.get(1)).isShortCircuitRequestFilter();
    // when
    PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.normalFilterCall, args.shortCircuitFilterCall);
    // then
    assertThat(result).isEqualTo(CONTINUE);
    filtersList.forEach(filter -> {
        boolean shortCircuiting = filter.isShortCircuitRequestFilter();
        if (isFirstChunk) {
            if (shortCircuiting)
                verify(filter).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
            else
                verify(filter).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
        } else {
            if (shortCircuiting)
                verify(filter).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
            else
                verify(filter).filterRequestLastChunkWithFullPayload(requestInfoMock, ctxMock);
        }
    });
    assertThat(state.getRequestInfo()).isSameAs(requestInfoMock);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 87 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.

the class HttpServletResponseWrapperForResponseInfoTest method getContentType_delegates_to_responseInfo.

@DataProvider(value = { "null               |   null        |   null", "text/plain         |   null        |   text/plain", "text/plain         |   ISO-8859-1  |   text/plain; charset=ISO-8859-1", "application/json   |   UTF-8       |   application/json; charset=UTF-8" }, splitBy = "\\|")
@Test
public void getContentType_delegates_to_responseInfo(String contentWriterMimeType, String contentWriterEncodingName, String expectedResult) {
    // given
    doReturn(contentWriterMimeType).when(responseInfoMock).getDesiredContentWriterMimeType();
    Charset contentWriterEncoding = (contentWriterEncodingName == null) ? null : Charset.forName(contentWriterEncodingName);
    doReturn(contentWriterEncoding).when(responseInfoMock).getDesiredContentWriterEncoding();
    // when
    String result = wrapper.getContentType();
    // expect
    assertThat(result).isEqualTo(expectedResult);
}
Also used : Charset(java.nio.charset.Charset) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)87 Test (org.junit.Test)85 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)20 Span (com.nike.wingtips.Span)19 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)19 Matchers.anyString (org.mockito.Matchers.anyString)11 HttpMethod (io.netty.handler.codec.http.HttpMethod)9 Endpoint (com.nike.riposte.server.http.Endpoint)8 Timer (com.codahale.metrics.Timer)7 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 RequestInfo (com.nike.riposte.server.http.RequestInfo)5 Charset (java.nio.charset.Charset)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Meter (com.codahale.metrics.Meter)4 Response (com.ning.http.client.Response)4 ExtractableResponse (io.restassured.response.ExtractableResponse)4 Deque (java.util.Deque)4 Optional (java.util.Optional)4