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));
}
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));
}
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));
}
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();
}
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);
}
}
Aggregations