use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class ConsumerWithTracingAndMdcSupportTest method apply_handles_tracing_and_mdc_info_as_expected.
@DataProvider(value = { "true", "false" })
@Test
public void apply_handles_tracing_and_mdc_info_as_expected(boolean throwException) {
// given
throwExceptionDuringCall = throwException;
Tracer.getInstance().startRequestWithRootSpan("foo");
Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcInfo = MDC.getCopyOfContextMap();
ConsumerWithTracingAndMdcSupport instance = new ConsumerWithTracingAndMdcSupport(consumerMock, spanStack, mdcInfo);
resetTracingAndMdc();
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
// when
Throwable ex = catchThrowable(() -> instance.accept(inObj));
// then
verify(consumerMock).accept(inObj);
if (throwException) {
assertThat(ex).isNotNull();
} else {
assertThat(ex).isNull();
}
assertThat(currentSpanStackWhenConsumerWasCalled.get(0)).isEqualTo(spanStack);
assertThat(currentMdcInfoWhenConsumerWasCalled.get(0)).isEqualTo(mdcInfo);
assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull();
assertThat(MDC.getCopyOfContextMap()).isEmpty();
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class SignalFxEndpointMetricsHandlerTest method kitchen_sink_constructor_fails_with_IllegalArgumentException_if_certain_args_are_null.
@DataProvider(value = { "true | false | false | signalFxReporterMetricMetadata cannot be null", "false | true | false | metricRegistry cannot be null", "false | false | true | requestTimerBuilder cannot be null" }, splitBy = "\\|")
@Test
public void kitchen_sink_constructor_fails_with_IllegalArgumentException_if_certain_args_are_null(boolean metadataIsNull, boolean registryIsNull, boolean timerBuilderIsNull, String expectedMessage) {
// given
MetricMetadata metricMetadata = (metadataIsNull) ? null : metricMetadataMock;
MetricRegistry registry = (registryIsNull) ? null : metricRegistryMock;
MetricBuilder<Timer> timerBuilder = (timerBuilderIsNull) ? null : requestTimerBuilderMock;
// when
Throwable ex = catchThrowable(() -> new SignalFxEndpointMetricsHandler(metricMetadata, registry, timerBuilder, null));
// then
assertThat(ex).isInstanceOf(IllegalArgumentException.class).hasMessage(expectedMessage);
}
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