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);
}
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);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class VerifyResponseHttpStatusCodeHandlingRfcCorrectnessComponentTest method responseStatusCodeScenariosDataProvider.
@DataProvider
public static Object[][] responseStatusCodeScenariosDataProvider() {
// We don't need to test *ALL* possibilities, just the extended list (http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml)
// plus a few unassigned ones.
List<Integer> statusCodesToTest = IntStream.rangeClosed(200, // No good way to test codes less than 200 at the moment.
999).filter(val -> (val <= 230 || val >= 300)).filter(val -> (val <= 320 || val >= 400)).filter(val -> (val <= 435 || val == 451 || val >= 500)).filter(val -> (val <= 520 || val >= 600)).filter(val -> (val <= 610 || val >= 700)).filter(val -> (val <= 710 || val >= 800)).filter(val -> (val <= 810 || val >= 900)).filter(val -> val <= 910).boxed().collect(Collectors.toList());
Object[][] data = new Object[statusCodesToTest.size() * 2][2];
for (int i = 0; i < statusCodesToTest.size(); i++) {
int statusCode = statusCodesToTest.get(i);
int dataIndexBase = i * 2;
data[dataIndexBase] = new Object[] { statusCode, true };
data[dataIndexBase + 1] = new Object[] { statusCode, false };
}
return data;
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class VerifyRequestAndResponseFilteringComponentTest method verify_filters_work_for_non_short_circuit_calls_for_endpoints_and_errors.
@DataProvider(value = { "false", "true" }, splitBy = "\\|")
@Test
public void verify_filters_work_for_non_short_circuit_calls_for_endpoints_and_errors(boolean forceError) throws IOException, InterruptedException {
ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(BasicEndpoint.MATCHING_PATH).header(BasicEndpoint.FORCE_ERROR_HEADER_KEY, String.valueOf(forceError)).log().all().when().get().then().log().headers().extract();
// Should have hit the endpoint
if (forceError)
verifyErrorReceived(response, BasicEndpoint.FORCED_ERROR);
else
assertThat(response.asString()).isEqualTo(BasicEndpoint.RESPONSE_PAYLOAD);
// All the filter-specific request and response headers should be present.
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_RESPONSE_HEADER_VALUE));
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_RESPONSE_HEADER_VALUE));
assertThat(response.headers().getValues(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.headers().getValues(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.headers().getValues(THIRD_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_RESPONSE_HEADER_VALUE));
// The override request and response headers should be correct - last filter wins - so third filter for the request and first filter for the response
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_VALUE));
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_VALUE));
assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_RESPONSE_OVERRIDE_HEADER_KEY));
// The cumulative request and response headers should be correct (contain all values from all filters)
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, THIRD_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE));
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE, THIRD_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE));
assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(THIRD_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, SECOND_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, FIRST_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY));
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class VerifyRequestAndResponseFilteringComponentTest method verify_filters_work_for_last_chunk_short_circuit_calls.
@DataProvider(value = { "false", "true" }, splitBy = "\\|")
@Test
public void verify_filters_work_for_last_chunk_short_circuit_calls(boolean hit404Path) throws IOException, InterruptedException {
String basePath = (hit404Path) ? "/foobardoesnotexist" : BasicEndpoint.MATCHING_PATH;
ExtractableResponse response = given().baseUri("http://127.0.0.1").port(serverConfig.endpointsPort()).basePath(basePath).header(SecondFilterShortCircuiting.SHOULD_SHORT_CIRCUIT_LAST_CHUNK, "true").log().all().when().get().then().log().headers().extract();
// * Should have thrown a 404 after the first chunk was fully filtered for an invalid 404 path.
if (hit404Path)
verifyErrorReceived(response, SampleCoreApiError.NOT_FOUND);
else
assertThat(response.asString()).isEqualTo(SecondFilterShortCircuiting.SHORT_CIRCUIT_LAST_CHUNK_RESPONSE_PAYLOAD);
// Some of the filter-specific request and response headers should be present - the ones added after the short circuit should not be present.
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
if (hit404Path) {
// 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEmpty();
} else {
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
}
assertThat(response.headers().getValues(FIRST_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_ONLY_RESPONSE_HEADER_VALUE));
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
if (hit404Path) {
// 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEmpty();
} else {
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_VALUE));
}
assertThat(response.headers().getValues(SECOND_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_ONLY_RESPONSE_HEADER_VALUE));
assertThat(response.headers().getValues(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_FIRST_CHUNK_REQ_HEADER_VALUE));
assertThat(response.header(THIRD_FILTER_ONLY_LAST_CHUNK_REQ_HEADER_KEY)).isNull();
assertThat(response.headers().getValues(THIRD_FILTER_ONLY_RESPONSE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_ONLY_RESPONSE_HEADER_VALUE));
// The override request and response headers should be correct based on when the short circuit occurred
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(THIRD_FILTER_REQUEST_FIRST_CHUNK_OVERRIDE_HEADER_VALUE));
if (hit404Path) {
// 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isEmpty();
} else {
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(SECOND_FILTER_REQUEST_LAST_CHUNK_OVERRIDE_HEADER_VALUE));
}
assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_OVERRIDE_HEADER_KEY)).isEqualTo(singletonList(FIRST_FILTER_RESPONSE_OVERRIDE_HEADER_KEY));
// The cumulative request and response headers should be correct based on when the short circuit occurred
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE, THIRD_FILTER_REQUEST_FIRST_CHUNK_CUMULATIVE_HEADER_VALUE));
if (hit404Path) {
// 404 prevents last chunk filters from running because the 404 exception is thrown after the first chunk is processed but before the last chunk.
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isEmpty();
} else {
assertThat(response.headers().getValues(COMMON_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(FIRST_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE, SECOND_FILTER_REQUEST_LAST_CHUNK_CUMULATIVE_HEADER_VALUE));
}
assertThat(response.headers().getValues(COMMON_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY)).isEqualTo(Arrays.asList(THIRD_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, SECOND_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY, FIRST_FILTER_RESPONSE_CUMULATIVE_HEADER_KEY));
}
Aggregations