use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method initServerConfigMetrics_adds_expected_metrics.
@DataProvider(value = { "true", "false" })
@Test
public void initServerConfigMetrics_adds_expected_metrics(boolean includeServerConfigMetrics) {
// given
setupMetricRegistryAndCodahaleMetricsCollector();
CodahaleMetricsListener instance = CodahaleMetricsListener.newBuilder(cmcMock).withEndpointMetricsHandler(endpointMetricsHandlerMock).withIncludeServerConfigMetrics(includeServerConfigMetrics).build();
verifyServerStatisticMetrics(instance);
String expectedBossThreadsGaugeName = name(ServerConfig.class.getSimpleName(), "boss_threads");
String expectedWorkerThreadsGaugeName = name(ServerConfig.class.getSimpleName(), "worker_threads");
String expectedMaxRequestSizeInBytesGaugeName = name(ServerConfig.class.getSimpleName(), "max_request_size_in_bytes");
String expectedEndpointsListGaugeName = name(ServerConfig.class.getSimpleName(), "endpoints");
List<String> expectedEndpointsListValue = serverConfig.appEndpoints().stream().map(endpoint -> endpoint.getClass().getName() + "-" + instance.getMatchingHttpMethodsAsCombinedString(endpoint) + "-" + endpoint.requestMatcher().matchingPathTemplates()).collect(Collectors.toList());
// when
instance.initEndpointAndServerConfigMetrics(serverConfig);
// then
if (includeServerConfigMetrics) {
// Metrics for server config values
assertThat(registeredGauges).containsKey(expectedBossThreadsGaugeName);
assertThat(registeredGauges.get(expectedBossThreadsGaugeName).getValue()).isEqualTo(serverConfig.numBossThreads());
assertThat(registeredGauges).containsKey(expectedWorkerThreadsGaugeName);
assertThat(registeredGauges.get(expectedWorkerThreadsGaugeName).getValue()).isEqualTo(serverConfig.numWorkerThreads());
assertThat(registeredGauges).containsKey(expectedMaxRequestSizeInBytesGaugeName);
assertThat(registeredGauges.get(expectedMaxRequestSizeInBytesGaugeName).getValue()).isEqualTo(serverConfig.maxRequestSizeInBytes());
assertThat(registeredGauges).containsKey(expectedEndpointsListGaugeName);
assertThat(registeredGauges.get(expectedEndpointsListGaugeName).getValue()).isEqualTo(expectedEndpointsListValue);
} else {
// No server config values should have been registered.
verifyNoMoreInteractions(metricRegistryMock);
}
// In either case, the EndpointMetricsHandler should have been called to delegate setting up endpoint-specific metrics.
verify(endpointMetricsHandlerMock).setupEndpointsMetrics(serverConfig, metricRegistryMock);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class CodahaleMetricsListenerTest method builder_works_as_expected_for_specified_fields.
@DataProvider(value = { "true | true", "true | false", "false | true", "false | false" }, splitBy = "\\|")
@Test
public void builder_works_as_expected_for_specified_fields(boolean overrideCodahaleMetricsCollector, boolean includeServerConfigMetrics) {
// given
setupMetricRegistryAndCodahaleMetricsCollector();
CodahaleMetricsCollector alternateCmcMock = mock(CodahaleMetricsCollector.class);
doReturn(metricRegistryMock).when(alternateCmcMock).getMetricRegistry();
MetricNamingStrategy<ServerStatisticsMetricNames> statsNamingStrat = new DefaultMetricNamingStrategy<>();
MetricNamingStrategy<ServerConfigMetricNames> configNamingStrat = new DefaultMetricNamingStrategy<>();
Supplier<Histogram> histogramSupplier = () -> mock(Histogram.class);
Builder builder = CodahaleMetricsListener.newBuilder(cmcMock);
if (overrideCodahaleMetricsCollector)
builder = builder.withMetricsCollector(alternateCmcMock);
builder = builder.withEndpointMetricsHandler(endpointMetricsHandlerMock).withIncludeServerConfigMetrics(includeServerConfigMetrics).withServerConfigMetricNamingStrategy(configNamingStrat).withServerStatsMetricNamingStrategy(statsNamingStrat).withRequestAndResponseSizeHistogramSupplier(histogramSupplier);
// when
CodahaleMetricsListener result = builder.build();
// then
if (overrideCodahaleMetricsCollector)
assertThat(result.metricsCollector).isSameAs(alternateCmcMock);
else
assertThat(result.metricsCollector).isSameAs(cmcMock);
assertThat(result.endpointMetricsHandler).isSameAs(endpointMetricsHandlerMock);
assertThat(result.includeServerConfigMetrics).isEqualTo(includeServerConfigMetrics);
assertThat(result.serverConfigMetricNamingStrategy).isSameAs(configNamingStrat);
assertThat(result.serverStatsMetricNamingStrategy).isSameAs(statsNamingStrat);
assertThat(result.requestAndResponseSizeHistogramSupplier).isSameAs(histogramSupplier);
}
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 AllowAllTheThingsCORSFilterTest method filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request.
@DataProvider(value = { "OPTIONS | true", "GET | false", "POST | false", "PUT | false" }, splitBy = "\\|")
@Test
public void filterRequestFirstChunkWithOptionalShortCircuitResponse_short_circuits_on_CORS_preflight_OPTIONS_request(String httpMethodString, boolean expectShortCircuit) {
// given
HttpMethod method = HttpMethod.valueOf(httpMethodString);
doReturn(method).when(requestMock).getMethod();
// when
Pair<RequestInfo<?>, Optional<ResponseInfo<?>>> result = filter.filterRequestFirstChunkWithOptionalShortCircuitResponse(requestMock, ctxMock);
// then
if (expectShortCircuit) {
assertThat(result).isNotNull();
assertThat(result.getLeft()).isSameAs(requestMock);
assertThat(result.getRight()).isPresent();
assertThat(result.getRight().get().getHttpStatusCode()).isEqualTo(200);
} else
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