Search in sources :

Example 96 with DataProvider

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

the class RequestInfoImplTest method setupContentDeserializer_and_getContent_work_as_expected.

@Test
@DataProvider(value = { "UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE", "ISO-8859-1", "US-ASCII" })
public void setupContentDeserializer_and_getContent_work_as_expected(String charsetName) throws IOException {
    // given
    ObjectMapper objectMapper = new ObjectMapper();
    TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {
    };
    TestContentObject contentObj = new TestContentObject(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    String contentString = objectMapper.writeValueAsString(contentObj);
    RequestInfoImpl<TestContentObject> requestInfo = (RequestInfoImpl<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
    requestInfo.rawContentBytes = contentString.getBytes(Charset.forName(charsetName));
    // when
    requestInfo.setupContentDeserializer(objectMapper, typeRef);
    // then
    assertThat(requestInfo.getContent(), notNullValue());
    assertThat(requestInfo.getContent().foo, is(contentObj.foo));
    assertThat(requestInfo.getContent().bar, is(contentObj.bar));
}
Also used : TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 97 with DataProvider

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

the class RequestInfoImplTest method getMultipartParts_works_as_expected_with_known_valid_data.

@DataProvider(value = { "false  |   false", "false  |   true", "true   |   false", "true   |   true" }, splitBy = "\\|")
@Test
public void getMultipartParts_works_as_expected_with_known_valid_data(boolean httpVersionIsNull, boolean httpMethodIsNull) throws IOException {
    // given
    RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
    Whitebox.setInternalState(requestInfo, "isMultipart", true);
    Whitebox.setInternalState(requestInfo, "contentCharset", CharsetUtil.UTF_8);
    Whitebox.setInternalState(requestInfo, "protocolVersion", (httpVersionIsNull) ? null : HttpVersion.HTTP_1_1);
    Whitebox.setInternalState(requestInfo, "method", (httpMethodIsNull) ? null : HttpMethod.POST);
    requestInfo.isCompleteRequestWithAllChunks = true;
    requestInfo.rawContentBytes = KNOWN_MULTIPART_DATA_BODY.getBytes(CharsetUtil.UTF_8);
    requestInfo.getHeaders().set("Content-Type", KNOWN_MULTIPART_DATA_CONTENT_TYPE_HEADER);
    // when
    List<InterfaceHttpData> result = requestInfo.getMultipartParts();
    // then
    assertThat(result, notNullValue());
    assertThat(result.size(), is(1));
    InterfaceHttpData data = result.get(0);
    assertThat(data, instanceOf(FileUpload.class));
    FileUpload fileUploadData = (FileUpload) data;
    assertThat(fileUploadData.getName(), is(KNOWN_MULTIPART_DATA_NAME));
    assertThat(fileUploadData.getFilename(), is(KNOWN_MULTIPART_DATA_FILENAME));
    assertThat(fileUploadData.getString(CharsetUtil.UTF_8), is(KNOWN_MULTIPART_DATA_ATTR_UUID));
}
Also used : InterfaceHttpData(io.netty.handler.codec.http.multipart.InterfaceHttpData) FileUpload(io.netty.handler.codec.http.multipart.FileUpload) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 98 with DataProvider

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

the class HttpUtilsTest method determineCharsetFromContentType_works.

@Test
@DataProvider(value = { "text/text charset=US-ASCII |   UTF-8   | US-ASCII", "text/text charset=us-ascii |   UTF-8   | US-ASCII", "text/text                  |   UTF-8   | UTF-8", "                           |   UTF-8   | UTF-8", "null                       |   UTF-8   | UTF-8" }, splitBy = "\\|")
public void determineCharsetFromContentType_works(String contentTypeHeader, String defaultCharsetString, String expectedCharsetString) {
    // given
    Charset defaultCharset = Charset.forName(defaultCharsetString);
    Charset expectedCharset = Charset.forName(expectedCharsetString);
    HttpHeaders headers = new DefaultHttpHeaders().add(HttpHeaders.Names.CONTENT_TYPE, String.valueOf(contentTypeHeader));
    // when
    Charset actualCharset = HttpUtils.determineCharsetFromContentType(headers, defaultCharset);
    // then
    assertThat(actualCharset, is(expectedCharset));
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) Charset(java.nio.charset.Charset) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 99 with DataProvider

use of com.tngtech.java.junit.dataprovider.DataProvider 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 100 with DataProvider

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

the class MainClassUtilsTest method getAppIdAndEnvironmentFromSystemProperties_works_as_expected.

@DataProvider(value = { "foo    |   null    |   bar     |   null    |   false   |   foo     |   bar", "foo    |   notused |   bar     |   notused |   false   |   foo     |   bar", "null   |   foo     |   null    |   bar     |   false   |   foo     |   bar", "null   |   null    |   bar     |   notused |   true    |   null    |   null", "foo    |   notused |   null    |   null    |   true    |   null    |   null" }, splitBy = "\\|")
@Test
public void getAppIdAndEnvironmentFromSystemProperties_works_as_expected(String appId, String archaiusAppId, String environment, String archaiusEnvironment, boolean expectIllegalStateException, String expectedAppId, String expectedEnvironment) {
    // given
    setAppIdAndEnvironemntSystemProperties(appId, archaiusAppId, environment, archaiusEnvironment);
    // when
    Throwable ex = null;
    Pair<String, String> results = null;
    try {
        results = MainClassUtils.getAppIdAndEnvironmentFromSystemProperties();
    } catch (Throwable t) {
        ex = t;
    }
    // then
    if (expectIllegalStateException)
        assertThat(ex).isInstanceOf(IllegalStateException.class);
    else {
        assertThat(ex).isNull();
        assertThat(results.getLeft()).isEqualTo(expectedAppId);
        assertThat(results.getRight()).isEqualTo(expectedEnvironment);
    }
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)268 Test (org.junit.Test)239 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)47 Span (com.nike.wingtips.Span)41 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)37 AssertionInfo (org.assertj.core.api.AssertionInfo)34 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)26 Endpoint (com.nike.riposte.server.http.Endpoint)20 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)18 Pair (com.nike.internal.util.Pair)16 HttpMethod (io.netty.handler.codec.http.HttpMethod)13 HashMap (java.util.HashMap)13 ExtractableResponse (io.restassured.response.ExtractableResponse)12 Timer (com.codahale.metrics.Timer)11 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 Histogram (com.codahale.metrics.Histogram)10 NettyHttpClientRequestBuilder (com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientRequestBuilder)10 NettyHttpClientResponse (com.nike.riposte.server.testutils.ComponentTestUtils.NettyHttpClientResponse)10