
io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions Maven / Gradle / Ivy
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.instrumentation.testing.junit.http;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Predicate;
public final class HttpServerTestOptions {
public static final Set> DEFAULT_HTTP_ATTRIBUTES =
Collections.unmodifiableSet(
new HashSet<>(
Arrays.asList(
SemanticAttributes.HTTP_ROUTE,
SemanticAttributes.NET_TRANSPORT,
SemanticAttributes.NET_PEER_PORT)));
public static final BiFunction
DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER = (uri, method) -> "HTTP " + method;
Function>> httpAttributes = unused -> DEFAULT_HTTP_ATTRIBUTES;
BiFunction expectedServerSpanNameMapper =
DEFAULT_EXPECTED_SERVER_SPAN_NAME_MAPPER;
Function expectedHttpRoute = unused -> null;
Function sockPeerAddr = unused -> "127.0.0.1";
String contextPath = "";
Throwable expectedException = new Exception(ServerEndpoint.EXCEPTION.getBody());
Predicate hasHandlerSpan = unused -> false;
Predicate hasResponseSpan = unused -> false;
Predicate hasErrorPageSpans = unused -> false;
Predicate hasExceptionOnServerSpan = endpoint -> !hasHandlerSpan.test(endpoint);
boolean testRedirect = true;
boolean testError = true;
boolean testErrorBody = true;
boolean testException = true;
boolean testNotFound = true;
boolean testPathParam = false;
boolean testCaptureHttpHeaders = true;
boolean testCaptureRequestParameters = false;
HttpServerTestOptions() {}
@CanIgnoreReturnValue
public HttpServerTestOptions setHttpAttributes(
Function>> httpAttributes) {
this.httpAttributes = httpAttributes;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setExpectedServerSpanNameMapper(
BiFunction expectedServerSpanNameMapper) {
this.expectedServerSpanNameMapper = expectedServerSpanNameMapper;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setExpectedHttpRoute(
Function expectedHttpRoute) {
this.expectedHttpRoute = expectedHttpRoute;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setSockPeerAddr(Function sockPeerAddr) {
this.sockPeerAddr = sockPeerAddr;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setContextPath(String contextPath) {
this.contextPath = contextPath;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setExpectedException(Throwable expectedException) {
this.expectedException = expectedException;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setHasHandlerSpan(Predicate hasHandlerSpan) {
this.hasHandlerSpan = hasHandlerSpan;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setHasResponseSpan(Predicate hasResponseSpan) {
this.hasResponseSpan = hasResponseSpan;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setHasErrorPageSpans(Predicate hasErrorPageSpans) {
this.hasErrorPageSpans = hasErrorPageSpans;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setHasExceptionOnServerSpan(
Predicate hasExceptionOnServerSpan) {
this.hasExceptionOnServerSpan = hasExceptionOnServerSpan;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestRedirect(boolean testRedirect) {
this.testRedirect = testRedirect;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestError(boolean testError) {
this.testError = testError;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestErrorBody(boolean testErrorBody) {
this.testErrorBody = testErrorBody;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestException(boolean testException) {
this.testException = testException;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestNotFound(boolean testNotFound) {
this.testNotFound = testNotFound;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestPathParam(boolean testPathParam) {
this.testPathParam = testPathParam;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestCaptureHttpHeaders(boolean testCaptureHttpHeaders) {
this.testCaptureHttpHeaders = testCaptureHttpHeaders;
return this;
}
@CanIgnoreReturnValue
public HttpServerTestOptions setTestCaptureRequestParameters(
boolean testCaptureRequestParameters) {
this.testCaptureRequestParameters = testCaptureRequestParameters;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy