diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy b/instrumentation/akka/akka-http-10.0/javaagent/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy index d3a9dec0e0b6..41bcfe73d1d4 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/test/groovy/AkkaHttpServerInstrumentationTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint abstract class AkkaHttpServerInstrumentationTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestAsyncWebServer.scala b/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestAsyncWebServer.scala index 49491aa80a21..fc204ce32b8d 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestAsyncWebServer.scala +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestAsyncWebServer.scala @@ -11,7 +11,8 @@ import akka.http.scaladsl.model._ import akka.stream.ActorMaterializer import groovy.lang.Closure import io.opentelemetry.instrumentation.test.base.HttpServerTest -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._ +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ import scala.concurrent.{Await, ExecutionContextExecutor, Future} @@ -23,8 +24,7 @@ object AkkaHttpTestAsyncWebServer { val asyncHandler: HttpRequest => Future[HttpResponse] = { case HttpRequest(GET, uri: Uri, _, _, _) => Future { - val endpoint = - HttpServerTest.ServerEndpoint.forPath(uri.path.toString()) + val endpoint = ServerEndpoint.forPath(uri.path.toString()) HttpServerTest.controller( endpoint, new Closure[HttpResponse](()) { diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestSyncWebServer.scala b/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestSyncWebServer.scala index bae57cd00add..bb7d59ce55b0 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestSyncWebServer.scala +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestSyncWebServer.scala @@ -11,7 +11,8 @@ import akka.http.scaladsl.model._ import akka.stream.ActorMaterializer import groovy.lang.Closure import io.opentelemetry.instrumentation.test.base.HttpServerTest -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._ +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ import scala.concurrent.Await @@ -22,7 +23,7 @@ object AkkaHttpTestSyncWebServer { implicit val executionContext = system.dispatcher val syncHandler: HttpRequest => HttpResponse = { case HttpRequest(GET, uri: Uri, _, _, _) => { - val endpoint = HttpServerTest.ServerEndpoint.forPath(uri.path.toString()) + val endpoint = ServerEndpoint.forPath(uri.path.toString()) HttpServerTest.controller( endpoint, new Closure[HttpResponse](()) { diff --git a/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestWebServer.scala b/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestWebServer.scala index 98d77d81f4ae..1bcb501a879c 100644 --- a/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestWebServer.scala +++ b/instrumentation/akka/akka-http-10.0/javaagent/src/test/scala/AkkaHttpTestWebServer.scala @@ -10,7 +10,7 @@ import akka.http.scaladsl.model._ import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.ExceptionHandler import akka.stream.ActorMaterializer -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._ +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ import scala.concurrent.Await diff --git a/instrumentation/armeria-1.3/testing/src/main/groovy/io/opentelemetry/instrumentation/armeria/v1_3/AbstractArmeriaHttpServerTest.groovy b/instrumentation/armeria-1.3/testing/src/main/groovy/io/opentelemetry/instrumentation/armeria/v1_3/AbstractArmeriaHttpServerTest.groovy index 0b06697c680e..61d806df93dd 100644 --- a/instrumentation/armeria-1.3/testing/src/main/groovy/io/opentelemetry/instrumentation/armeria/v1_3/AbstractArmeriaHttpServerTest.groovy +++ b/instrumentation/armeria-1.3/testing/src/main/groovy/io/opentelemetry/instrumentation/armeria/v1_3/AbstractArmeriaHttpServerTest.groovy @@ -21,19 +21,20 @@ import com.linecorp.armeria.server.ServiceRequestContext import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.Span import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import java.util.function.Function -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractArmeriaHttpServerTest extends HttpServerTest { diff --git a/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy b/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy index 3aff0d065066..8333aee4af42 100644 --- a/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy +++ b/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardAsyncTest.groovy @@ -18,14 +18,14 @@ import javax.ws.rs.container.Suspended import javax.ws.rs.core.Response import java.util.concurrent.Executors -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class DropwizardAsyncTest extends DropwizardTest { diff --git a/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy b/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy index 4fb59b4d0676..b2d7e924ae70 100644 --- a/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy +++ b/instrumentation/dropwizard/dropwizard-testing/src/test/groovy/DropwizardTest.groovy @@ -13,6 +13,7 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.instrumentation.test.utils.PortUtils import io.opentelemetry.sdk.trace.data.SpanData @@ -24,15 +25,15 @@ import javax.ws.rs.QueryParam import javax.ws.rs.core.Response import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class DropwizardTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/finatra-2.9/javaagent/src/latestDepTest/groovy/FinatraServerLatestTest.groovy b/instrumentation/finatra-2.9/javaagent/src/latestDepTest/groovy/FinatraServerLatestTest.groovy index 1f41975cc5e9..ba661d78b5ff 100644 --- a/instrumentation/finatra-2.9/javaagent/src/latestDepTest/groovy/FinatraServerLatestTest.groovy +++ b/instrumentation/finatra-2.9/javaagent/src/latestDepTest/groovy/FinatraServerLatestTest.groovy @@ -13,12 +13,13 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class FinatraServerLatestTest extends HttpServerTest implements AgentTestTrait { private static final Duration TIMEOUT = Duration.fromSeconds(5) diff --git a/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/FinatraController.scala b/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/FinatraController.scala index a0ba81a900d8..d6a4ec055bb3 100644 --- a/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/FinatraController.scala +++ b/instrumentation/finatra-2.9/javaagent/src/latestDepTest/scala/FinatraController.scala @@ -7,7 +7,7 @@ import com.twitter.finagle.http.{Request, Response} import com.twitter.finatra.http.Controller import com.twitter.util.Future import groovy.lang.Closure -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._ +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ import io.opentelemetry.instrumentation.test.base.HttpServerTest.controller class FinatraController extends Controller { diff --git a/instrumentation/finatra-2.9/javaagent/src/test/groovy/FinatraServerTest.groovy b/instrumentation/finatra-2.9/javaagent/src/test/groovy/FinatraServerTest.groovy index e785710940d0..2be4be2fba04 100644 --- a/instrumentation/finatra-2.9/javaagent/src/test/groovy/FinatraServerTest.groovy +++ b/instrumentation/finatra-2.9/javaagent/src/test/groovy/FinatraServerTest.groovy @@ -10,14 +10,15 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import java.util.concurrent.TimeUnit import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static org.awaitility.Awaitility.await class FinatraServerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/finatra-2.9/javaagent/src/test/scala/FinatraController.scala b/instrumentation/finatra-2.9/javaagent/src/test/scala/FinatraController.scala index c567da5ca290..70b708f47a68 100644 --- a/instrumentation/finatra-2.9/javaagent/src/test/scala/FinatraController.scala +++ b/instrumentation/finatra-2.9/javaagent/src/test/scala/FinatraController.scala @@ -7,7 +7,7 @@ import com.twitter.finagle.http.{Request, Response} import com.twitter.finatra.http.Controller import com.twitter.util.Future import groovy.lang.Closure -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint._ +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint._ import io.opentelemetry.instrumentation.test.base.HttpServerTest.controller class FinatraController extends Controller { diff --git a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/ErrorController.groovy b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/ErrorController.groovy index 5f8021b13121..fb024bccb5bf 100644 --- a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/ErrorController.groovy +++ b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/ErrorController.groovy @@ -8,7 +8,7 @@ package test import grails.artefact.Controller import grails.web.Action -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR class ErrorController implements Controller { diff --git a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy deleted file mode 100644 index aba6f9623880..000000000000 --- a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/GrailsTest.groovy +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package test - -import grails.boot.GrailsApp -import grails.boot.config.GrailsAutoConfiguration -import groovy.transform.CompileStatic -import io.opentelemetry.api.trace.StatusCode -import io.opentelemetry.instrumentation.test.AgentTestTrait -import io.opentelemetry.instrumentation.test.asserts.TraceAssert -import io.opentelemetry.instrumentation.test.base.HttpServerTest -import io.opentelemetry.sdk.trace.data.SpanData -import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.boot.autoconfigure.web.ServerProperties -import org.springframework.context.ConfigurableApplicationContext - -import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT - -class GrailsTest extends HttpServerTest implements AgentTestTrait { - - @CompileStatic - @SpringBootApplication - static class TestApplication extends GrailsAutoConfiguration { - static ConfigurableApplicationContext start(int port, String contextPath) { - GrailsApp grailsApp = new GrailsApp(TestApplication) - // context path configuration property name changes between spring boot versions - def contextPathKey = "server.context-path" - try { - ServerProperties.getDeclaredMethod("getServlet") - contextPathKey = "server.servlet.contextPath" - } catch (NoSuchMethodException ignore) { - } - Map properties = new HashMap<>() - properties.put("server.port", port) - properties.put(contextPathKey, contextPath) - grailsApp.setDefaultProperties(properties) - return grailsApp.run() - } - - @Override - Collection classes() { - return Arrays.asList(TestController, ErrorController, UrlMappings) - } - } - - @Override - String expectedHttpRoute(ServerEndpoint endpoint) { - if (endpoint == PATH_PARAM) { - return getContextPath() + "/test/path" - } else if (endpoint == QUERY_PARAM) { - return getContextPath() + "/test/query" - } else if (endpoint == ERROR) { - return getContextPath() + "/test/error" - } else if (endpoint == NOT_FOUND) { - return getContextPath() + "/**" - } - return getContextPath() + "/test" + endpoint.path - } - - @Override - ConfigurableApplicationContext startServer(int port) { - return TestApplication.start(port, getContextPath()) - } - - @Override - void stopServer(ConfigurableApplicationContext ctx) { - ctx.close() - } - - @Override - String getContextPath() { - return "/xyz" - } - - @Override - boolean hasHandlerSpan(ServerEndpoint endpoint) { - true - } - - @Override - boolean hasResponseSpan(ServerEndpoint endpoint) { - endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND - } - - @Override - boolean hasErrorPageSpans(ServerEndpoint endpoint) { - endpoint == ERROR || endpoint == EXCEPTION || endpoint == NOT_FOUND - } - - @Override - int getErrorPageSpansCount(ServerEndpoint endpoint) { - endpoint == NOT_FOUND ? 2 : 1 - } - - @Override - boolean testPathParam() { - true - } - - @Override - void errorPageSpans(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) { - trace.span(index) { - name endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index" - kind INTERNAL - attributes { - } - } - if (endpoint == NOT_FOUND) { - trace.span(index + 1) { - name ~/\.sendError$/ - kind INTERNAL - attributes { - } - } - } - } - - @Override - void responseSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) { - trace.span(index) { - name endpoint == REDIRECT ? ~/\.sendRedirect$/ : ~/\.sendError$/ - kind INTERNAL - attributes { - } - } - } - - @Override - void handlerSpan(TraceAssert trace, int index, Object parent, String method = "GET", ServerEndpoint endpoint) { - trace.span(index) { - if (endpoint == QUERY_PARAM) { - name "TestController.query" - } else if (endpoint == PATH_PARAM) { - name "TestController.path" - } else if (endpoint == CAPTURE_HEADERS) { - name "TestController.captureHeaders" - } else if (endpoint == INDEXED_CHILD) { - name "TestController.child" - } else if (endpoint == NOT_FOUND) { - name "ResourceHttpRequestHandler.handleRequest" - } else { - name "TestController.${endpoint.name().toLowerCase()}" - } - kind INTERNAL - if (endpoint == EXCEPTION) { - status StatusCode.ERROR - errorEvent(Exception, EXCEPTION.body) - } - childOf((SpanData) parent) - } - } -} diff --git a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy index b1771a85e8f8..8ccf0706eea4 100644 --- a/instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy +++ b/instrumentation/grails-3.0/javaagent/src/test/groovy/test/TestController.groovy @@ -9,14 +9,14 @@ import grails.artefact.Controller import grails.web.Action import io.opentelemetry.instrumentation.test.base.HttpServerTest -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class TestController implements Controller { diff --git a/instrumentation/grails-3.0/javaagent/src/test/java/test/GrailsTest.java b/instrumentation/grails-3.0/javaagent/src/test/java/test/GrailsTest.java new file mode 100644 index 000000000000..fc1eec1486e4 --- /dev/null +++ b/instrumentation/grails-3.0/javaagent/src/test/java/test/GrailsTest.java @@ -0,0 +1,186 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package test; + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; + +import grails.boot.GrailsApp; +import grails.boot.config.GrailsAutoConfiguration; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.sdk.trace.data.StatusData; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.function.Consumer; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.context.ConfigurableApplicationContext; + +public class GrailsTest extends AbstractHttpServerTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent(); + + @Override + protected ConfigurableApplicationContext setupServer() { + return startServer(port); + } + + @Override + protected void stopServer(ConfigurableApplicationContext ctx) { + ctx.close(); + } + + @Override + protected void configure(HttpServerTestOptions options) { + options.setContextPath(getContextPath()); + options.setHasHandlerSpan(unused -> true); + options.setHasResponseSpan( + endpoint -> endpoint == REDIRECT || endpoint == ERROR || endpoint == NOT_FOUND); + options.setHasErrorPageSpans( + endpoint -> endpoint == ERROR || endpoint == EXCEPTION || endpoint == NOT_FOUND); + options.setTestPathParam(true); + } + + @SpringBootApplication + static class TestApplication extends GrailsAutoConfiguration { + static ConfigurableApplicationContext start(int port, String contextPath) { + GrailsApp grailsApp = new GrailsApp(TestApplication.class); + // context path configuration property name changes between spring boot versions + String contextPathKey; + try { + Method method = ServerProperties.class.getDeclaredMethod("getServlet"); + contextPathKey = "server.servlet.contextPath"; + } catch (NoSuchMethodException ignore) { + contextPathKey = "server.context-path"; + } + Map properties = new HashMap<>(); + properties.put("server.port", port); + properties.put(contextPathKey, contextPath); + grailsApp.setDefaultProperties(properties); + return grailsApp.run(); + } + + @SuppressWarnings("rawtypes") + @Override + public Collection classes() { + // java compiler does not see groovy classes + return Arrays.asList( + load("test.TestController"), load("test.ErrorController"), load("test.UrlMappings")); + } + + private static Class load(String name) { + try { + return Class.forName(name); + } catch (ClassNotFoundException exception) { + throw new IllegalStateException(exception); + } + } + } + + private static String getContextPath() { + return "/xyz"; + } + + @Override + public String expectedHttpRoute(ServerEndpoint endpoint) { + switch (endpoint) { + case PATH_PARAM: + return getContextPath() + "/test/path"; + case QUERY_PARAM: + return getContextPath() + "/test/query"; + case ERROR: + return getContextPath() + "/test/error"; + case NOT_FOUND: + return getContextPath() + "/**"; + default: + return getContextPath() + "/test" + endpoint.getPath(); + } + } + + ConfigurableApplicationContext startServer(int port) { + return TestApplication.start(port, getContextPath()); + } + + private static String getHandlerSpanName(ServerEndpoint endpoint) { + switch (endpoint) { + case QUERY_PARAM: + return "TestController.query"; + case PATH_PARAM: + return "TestController.path"; + case CAPTURE_HEADERS: + return "TestController.captureHeaders"; + case INDEXED_CHILD: + return "TestController.child"; + case NOT_FOUND: + return "ResourceHttpRequestHandler.handleRequest"; + default: + return "TestController." + endpoint.name().toLowerCase(Locale.ROOT); + } + } + + @Override + public SpanDataAssert assertHandlerSpan( + SpanDataAssert span, String method, ServerEndpoint endpoint) { + span.hasName(getHandlerSpanName(endpoint)).hasKind(SpanKind.INTERNAL); + if (endpoint == EXCEPTION) { + span.hasStatus(StatusData.error()); + span.hasException(new Exception(EXCEPTION.getBody())); + } + return span; + } + + @Override + public SpanDataAssert assertResponseSpan( + SpanDataAssert span, String method, ServerEndpoint endpoint) { + if (endpoint == REDIRECT) { + span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendRedirect")); + } else { + span.satisfies(spanData -> assertThat(spanData.getName()).endsWith(".sendError")); + } + span.hasKind(SpanKind.INTERNAL).hasAttributesSatisfying(Attributes::isEmpty); + return span; + } + + @Override + public List> errorPageSpanAssertions( + String method, ServerEndpoint endpoint) { + List> spanAssertions = new ArrayList<>(); + spanAssertions.add( + span -> + span.hasName( + endpoint == NOT_FOUND ? "ErrorController.notFound" : "ErrorController.index") + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfying(Attributes::isEmpty)); + if (endpoint == NOT_FOUND) { + spanAssertions.add( + span -> + span.satisfies( + spanData -> Assertions.assertThat(spanData.getName()).endsWith(".sendError")) + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfying(Attributes::isEmpty)); + } + return spanAssertions; + } +} diff --git a/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyAsyncTest.groovy b/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyAsyncTest.groovy index d7d7626e1375..7475f81a7882 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyAsyncTest.groovy +++ b/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyAsyncTest.groovy @@ -16,12 +16,12 @@ import javax.ws.rs.core.Response import java.util.concurrent.ExecutorService import java.util.concurrent.Executors -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class GrizzlyAsyncTest extends GrizzlyTest { diff --git a/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy b/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy index 9f8e4f094d85..df603aef684f 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy +++ b/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyFilterchainServerTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.glassfish.grizzly.filterchain.BaseFilter import org.glassfish.grizzly.filterchain.FilterChain @@ -29,15 +30,15 @@ import org.glassfish.grizzly.utils.IdleTimeoutFilter import java.nio.charset.StandardCharsets import java.util.concurrent.Executors -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static java.lang.String.valueOf import static java.nio.charset.Charset.defaultCharset import static java.util.concurrent.TimeUnit.MILLISECONDS @@ -150,7 +151,7 @@ class GrizzlyFilterchainServerTest extends HttpServerTest implements String uri = request.getRequestURI() Map headers = new HashMap<>() - HttpServerTest.ServerEndpoint endpoint + ServerEndpoint endpoint Closure closure switch (uri) { case "/success": @@ -198,12 +199,12 @@ class GrizzlyFilterchainServerTest extends HttpServerTest implements static class ResponseParameters { Map headers - HttpServerTest.ServerEndpoint endpoint + ServerEndpoint endpoint int status byte[] responseBody Closure closure - ResponseParameters(HttpServerTest.ServerEndpoint endpoint, + ResponseParameters(ServerEndpoint endpoint, int status, byte[] responseBody, Map headers, @@ -223,7 +224,7 @@ class GrizzlyFilterchainServerTest extends HttpServerTest implements return responseBody } - HttpServerTest.ServerEndpoint getEndpoint() { + ServerEndpoint getEndpoint() { return endpoint } diff --git a/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyTest.groovy b/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyTest.groovy index 4f0afe124e88..e638be4e0de4 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyTest.groovy +++ b/instrumentation/grizzly-2.0/javaagent/src/test/groovy/GrizzlyTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.glassfish.grizzly.http.server.HttpHandler import org.glassfish.grizzly.http.server.HttpServer @@ -20,12 +21,12 @@ import javax.ws.rs.QueryParam import javax.ws.rs.core.Response import javax.ws.rs.ext.ExceptionMapper -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class GrizzlyTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsHttpServerTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsHttpServerTest.groovy index 4affc65d56fa..06128e0f7b6a 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsHttpServerTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/JaxRsHttpServerTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import spock.lang.Unroll @@ -14,9 +15,9 @@ import test.JaxRsTestResource import static io.opentelemetry.api.trace.SpanKind.INTERNAL import static io.opentelemetry.api.trace.SpanKind.SERVER import static io.opentelemetry.api.trace.StatusCode.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP import static java.util.concurrent.TimeUnit.SECONDS import static org.junit.jupiter.api.Assumptions.assumeTrue diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/test/JaxRsTestResource.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/test/JaxRsTestResource.groovy index 1c60b7ab2481..67ae91078f0d 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/test/JaxRsTestResource.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-common/testing/src/main/groovy/test/JaxRsTestResource.groovy @@ -24,14 +24,14 @@ import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletionStage import java.util.concurrent.CyclicBarrier -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static java.util.concurrent.TimeUnit.SECONDS @Path("") diff --git a/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy b/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy index eb66c39deb6d..ef0e0f03b93f 100644 --- a/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy +++ b/instrumentation/jetty/jetty-11.0/javaagent/src/test/groovy/JettyHandlerTest.groovy @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import jakarta.servlet.DispatcherType import jakarta.servlet.ServletException @@ -19,14 +20,14 @@ import org.eclipse.jetty.server.handler.AbstractHandler import org.eclipse.jetty.server.handler.ErrorHandler import spock.lang.Shared -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class JettyHandlerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy b/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy index 742ebb842242..37b1dc0bf24b 100644 --- a/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy +++ b/instrumentation/jetty/jetty-8.0/javaagent/src/test/groovy/JettyHandlerTest.groovy @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.eclipse.jetty.server.Request import org.eclipse.jetty.server.Response @@ -20,14 +21,14 @@ import javax.servlet.ServletException import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class JettyHandlerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/ktor-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.groovy b/instrumentation/ktor-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.groovy index 52c021a743b6..9c4511d20f8f 100644 --- a/instrumentation/ktor-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.groovy +++ b/instrumentation/ktor-1.0/library/src/test/groovy/io/opentelemetry/instrumentation/ktor/v1_0/KtorHttpServerTest.groovy @@ -9,11 +9,12 @@ import io.ktor.server.engine.ApplicationEngine import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.LibraryTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import java.util.concurrent.TimeUnit -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM class KtorHttpServerTest extends HttpServerTest implements LibraryTestTrait { diff --git a/instrumentation/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/TestServer.kt b/instrumentation/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/TestServer.kt index fdf676834d68..0abee3630a8e 100644 --- a/instrumentation/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/TestServer.kt +++ b/instrumentation/ktor-1.0/library/src/test/kotlin/io/opentelemetry/instrumentation/ktor/v1_0/TestServer.kt @@ -19,8 +19,8 @@ import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.context.Context import io.opentelemetry.extension.kotlin.asContextElement -import io.opentelemetry.instrumentation.test.base.HttpServerTest -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.* +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.* import kotlinx.coroutines.withContext import java.util.concurrent.ExecutionException @@ -90,7 +90,7 @@ class TestServer { } // Copy in HttpServerTest.controller but make it a suspending function - private suspend fun controller(endpoint: HttpServerTest.ServerEndpoint, wrapped: suspend () -> Unit) { + private suspend fun controller(endpoint: ServerEndpoint, wrapped: suspend () -> Unit) { assert(Span.current().spanContext.isValid, { "Controller should have a parent span. " }) if (endpoint == NOT_FOUND) { wrapped() diff --git a/instrumentation/netty/netty-3.8/javaagent/src/test/groovy/Netty38ServerTest.groovy b/instrumentation/netty/netty-3.8/javaagent/src/test/groovy/Netty38ServerTest.groovy index 07968d3efdc5..968ffcdb8d56 100644 --- a/instrumentation/netty/netty-3.8/javaagent/src/test/groovy/Netty38ServerTest.groovy +++ b/instrumentation/netty/netty-3.8/javaagent/src/test/groovy/Netty38ServerTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.jboss.netty.bootstrap.ServerBootstrap import org.jboss.netty.buffer.ChannelBuffer @@ -33,15 +34,15 @@ import org.jboss.netty.logging.InternalLoggerFactory import org.jboss.netty.logging.Slf4JLoggerFactory import org.jboss.netty.util.CharsetUtil -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.forPath +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.forPath import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE import static org.jboss.netty.handler.codec.http.HttpHeaders.Names.LOCATION @@ -66,7 +67,7 @@ class Netty38ServerTest extends HttpServerTest implements Agent if (msg.getMessage() instanceof HttpRequest) { def request = msg.getMessage() as HttpRequest def uri = URI.create(request.getUri()) - HttpServerTest.ServerEndpoint endpoint = forPath(uri.path) + ServerEndpoint endpoint = forPath(uri.path) ctx.sendDownstream controller(endpoint) { HttpResponse response ChannelBuffer responseContent = null diff --git a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ServerTest.groovy b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ServerTest.groovy index ac7e1bef87a3..26706f23bdff 100644 --- a/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ServerTest.groovy +++ b/instrumentation/netty/netty-4.0/javaagent/src/test/groovy/Netty40ServerTest.groovy @@ -27,20 +27,21 @@ import io.netty.util.CharsetUtil import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1 -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class Netty40ServerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ServerTest.groovy b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ServerTest.groovy index c0b805a3ce72..8b1a55a00682 100644 --- a/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ServerTest.groovy +++ b/instrumentation/netty/netty-4.1/javaagent/src/test/groovy/Netty41ServerTest.groovy @@ -26,20 +26,21 @@ import io.netty.util.CharsetUtil import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1 -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class Netty41ServerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy b/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy index e1fbccf21a00..de342030bba2 100644 --- a/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy +++ b/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy @@ -13,13 +13,13 @@ import play.server.Server import java.util.concurrent.CompletableFuture import java.util.function.Supplier -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static play.mvc.Http.Context.Implicit.request class PlayAsyncServerTest extends PlayServerTest { diff --git a/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayServerTest.groovy b/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayServerTest.groovy index 907be6612483..1a56b14ae179 100644 --- a/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayServerTest.groovy +++ b/instrumentation/play/play-2.4/javaagent/src/test/groovy/server/PlayServerTest.groovy @@ -10,6 +10,7 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import play.mvc.Results @@ -19,13 +20,13 @@ import play.server.Server import java.util.function.Supplier import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static play.mvc.Http.Context.Implicit.request class PlayServerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy b/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy index b6daed486224..a5e95d66372e 100644 --- a/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy +++ b/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayAsyncServerTest.groovy @@ -18,13 +18,13 @@ import java.util.concurrent.CompletableFuture import java.util.concurrent.Executors import java.util.function.Supplier -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class PlayAsyncServerTest extends PlayServerTest { @Shared diff --git a/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayServerTest.groovy b/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayServerTest.groovy index cad1e7a8b45f..0bc7c3802b41 100644 --- a/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayServerTest.groovy +++ b/instrumentation/play/play-2.6/javaagent/src/test/groovy/server/PlayServerTest.groovy @@ -10,6 +10,7 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import play.BuiltInComponents import play.Mode @@ -21,13 +22,13 @@ import play.server.Server import java.util.function.Supplier import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class PlayServerTest extends HttpServerTest implements AgentTestTrait { @Override diff --git a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackAsyncHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackAsyncHttpServerTest.groovy index 712edad6e686..f8cda9195c4f 100644 --- a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackAsyncHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackAsyncHttpServerTest.groovy @@ -9,14 +9,14 @@ import ratpack.error.ServerErrorHandler import ratpack.exec.Promise import ratpack.server.RatpackServer -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractRatpackAsyncHttpServerTest extends AbstractRatpackHttpServerTest { diff --git a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy index 1bb6b1ba2103..4a4ee2f4c8db 100644 --- a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackForkedHttpServerTest.groovy @@ -16,14 +16,14 @@ import ratpack.exec.Result import ratpack.exec.util.ParallelBatch import ratpack.server.RatpackServer -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractRatpackForkedHttpServerTest extends AbstractRatpackHttpServerTest { diff --git a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackHttpServerTest.groovy index e3b467ec3b42..67b73a52c652 100644 --- a/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.4/testing/src/main/groovy/io/opentelemetry/instrumentation/ratpack/server/AbstractRatpackHttpServerTest.groovy @@ -9,6 +9,7 @@ package io.opentelemetry.instrumentation.ratpack.server import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import ratpack.error.ServerErrorHandler import ratpack.handling.Context @@ -16,14 +17,14 @@ import ratpack.server.RatpackServer import ratpack.server.RatpackServerSpec import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractRatpackHttpServerTest extends HttpServerTest { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackAsyncHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackAsyncHttpServerTest.groovy index a52e5fd0b591..9c0995dc12b0 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackAsyncHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackAsyncHttpServerTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ratpack.server import io.opentelemetry.instrumentation.ratpack.RatpackTracing import io.opentelemetry.instrumentation.test.LibraryTestTrait +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import ratpack.server.RatpackServerSpec class RatpackAsyncHttpServerTest extends AbstractRatpackAsyncHttpServerTest implements LibraryTestTrait { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackForkedHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackForkedHttpServerTest.groovy index 48e5ce0a218c..5b06101948e2 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackForkedHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackForkedHttpServerTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ratpack.server import io.opentelemetry.instrumentation.ratpack.RatpackTracing import io.opentelemetry.instrumentation.test.LibraryTestTrait +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import ratpack.server.RatpackServerSpec class RatpackForkedHttpServerTest extends AbstractRatpackForkedHttpServerTest implements LibraryTestTrait { diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackHttpServerTest.groovy b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackHttpServerTest.groovy index 010764519b5e..3996e6cc9f10 100644 --- a/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackHttpServerTest.groovy +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/groovy/io/opentelemetry/instrumentation/ratpack/server/RatpackHttpServerTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.ratpack.server import io.opentelemetry.instrumentation.ratpack.RatpackTracing import io.opentelemetry.instrumentation.test.LibraryTestTrait +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import ratpack.server.RatpackServerSpec class RatpackHttpServerTest extends AbstractRatpackHttpServerTest implements LibraryTestTrait { diff --git a/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractRestletServerTest.groovy b/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractRestletServerTest.groovy index b4171d589632..a33b4a2c219c 100644 --- a/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractRestletServerTest.groovy +++ b/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractRestletServerTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.restlet.v1_0 import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.restlet.Component import org.restlet.Context import org.restlet.Redirector @@ -22,15 +23,15 @@ import org.restlet.data.Response import org.restlet.data.Status import org.restlet.util.Template -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractRestletServerTest extends HttpServerTest { @@ -156,6 +157,11 @@ abstract class AbstractRestletServerTest extends HttpServerTest { true } + @Override + boolean testErrorBody() { + false + } + @Override String expectedHttpRoute(ServerEndpoint endpoint) { switch (endpoint) { diff --git a/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractServletServerTest.groovy b/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractServletServerTest.groovy index 30aae670671d..fb48543db412 100644 --- a/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractServletServerTest.groovy +++ b/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/AbstractServletServerTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.restlet.v1_0 import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server import org.eclipse.jetty.util.resource.Resource import org.eclipse.jetty.webapp.WebAppContext @@ -14,15 +15,15 @@ import org.restlet.Application import org.restlet.Restlet import org.restlet.Router -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractServletServerTest extends HttpServerTest { diff --git a/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/RestletAppTestBase.groovy b/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/RestletAppTestBase.groovy index 1bcdbbb3e68a..472296fb4f26 100644 --- a/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/RestletAppTestBase.groovy +++ b/instrumentation/restlet/restlet-1.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v1_0/RestletAppTestBase.groovy @@ -17,14 +17,14 @@ import org.restlet.resource.Resource import org.restlet.resource.StringRepresentation import org.restlet.resource.Variant -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static io.opentelemetry.instrumentation.test.base.HttpServerTest.controller class RestletAppTestBase { diff --git a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy index 3be858294370..baad1e390e7c 100644 --- a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy +++ b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/AbstractRestletServerTest.groovy @@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.restlet.v2_0 import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.restlet.Component import org.restlet.Context import org.restlet.Request @@ -22,15 +23,15 @@ import org.restlet.routing.Router import org.restlet.routing.Template import org.restlet.routing.VirtualHost -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractRestletServerTest extends HttpServerTest { @@ -169,6 +170,11 @@ abstract class AbstractRestletServerTest extends HttpServerTest { true } + @Override + boolean testErrorBody() { + false + } + @Override String expectedHttpRoute(ServerEndpoint endpoint) { switch (endpoint) { diff --git a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/RestletAppTestBase.groovy b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/RestletAppTestBase.groovy index 4af9dcf41298..b61b3f20db17 100644 --- a/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/RestletAppTestBase.groovy +++ b/instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/RestletAppTestBase.groovy @@ -11,14 +11,14 @@ import org.restlet.data.Status import org.restlet.resource.Get import org.restlet.resource.ServerResource -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static io.opentelemetry.instrumentation.test.base.HttpServerTest.controller class RestletAppTestBase { diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy index b0796f8b1ffa..cf22b521b103 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/JettyServlet2Test.groovy @@ -7,6 +7,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.eclipse.jetty.server.Server @@ -16,15 +17,15 @@ import org.eclipse.jetty.servlet.ServletContextHandler import javax.servlet.http.HttpServletRequest import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class JettyServlet2Test extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/TestServlet2.groovy b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/TestServlet2.groovy index ff59631fd4f4..d645df3feb76 100644 --- a/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/TestServlet2.groovy +++ b/instrumentation/servlet/servlet-2.2/javaagent/src/test/groovy/TestServlet2.groovy @@ -5,16 +5,16 @@ import groovy.servlet.AbstractHttpServlet import io.opentelemetry.instrumentation.test.base.HttpServerTest - +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class TestServlet2 { @@ -22,7 +22,7 @@ class TestServlet2 { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) { req.getRequestDispatcher() - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) HttpServerTest.controller(endpoint) { resp.contentType = "text/plain" switch (endpoint) { diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy index 9aad64fd555e..6dbdb60eb1b7 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/AbstractServlet3Test.groovy @@ -6,20 +6,21 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import javax.servlet.Servlet -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractServlet3Test extends HttpServerTest implements AgentTestTrait { @Override diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServlet3Test.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServlet3Test.groovy index a254b028b472..cfd2beaca89c 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServlet3Test.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServlet3Test.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.ErrorHandler import org.eclipse.jetty.servlet.ServletContextHandler @@ -12,15 +13,15 @@ import javax.servlet.Servlet import javax.servlet.ServletException import javax.servlet.http.HttpServletRequest -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class JettyServlet3Test extends AbstractServlet3Test { diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy index 83360b1ea1d9..dd14c3732e1e 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy @@ -5,6 +5,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import org.eclipse.jetty.server.Server import org.eclipse.jetty.server.handler.ErrorHandler @@ -14,7 +15,7 @@ import javax.servlet.Servlet import javax.servlet.ServletException import javax.servlet.http.HttpServletRequest -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION class JettyServletHandlerTest extends AbstractServlet3Test { diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TestServlet3.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TestServlet3.groovy index a994a8c1eb2f..cf6827e5fe56 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TestServlet3.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TestServlet3.groovy @@ -5,7 +5,7 @@ import groovy.servlet.AbstractHttpServlet import io.opentelemetry.instrumentation.test.base.HttpServerTest - +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import javax.servlet.RequestDispatcher import javax.servlet.ServletException import javax.servlet.annotation.WebServlet @@ -13,14 +13,14 @@ import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse import java.util.concurrent.CountDownLatch -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class TestServlet3 { @@ -32,7 +32,7 @@ class TestServlet3 { if (servletPath == null) { servletPath = req.servletPath } - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(servletPath) HttpServerTest.controller(endpoint) { resp.contentType = "text/plain" switch (endpoint) { @@ -79,7 +79,7 @@ class TestServlet3 { static class Async extends AbstractHttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) { - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) def latch = new CountDownLatch(1) def context = req.startAsync() if (endpoint == EXCEPTION) { @@ -157,7 +157,7 @@ class TestServlet3 { protected void service(HttpServletRequest req, HttpServletResponse resp) { def context = req.startAsync() try { - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) HttpServerTest.controller(endpoint) { resp.contentType = "text/plain" switch (endpoint) { diff --git a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy index 0a8f5426556d..99ec5f07d1a6 100644 --- a/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy +++ b/instrumentation/servlet/servlet-3.0/javaagent/src/test/groovy/TomcatServlet3Test.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse import org.apache.catalina.AccessLog import org.apache.catalina.Context @@ -24,16 +25,16 @@ import java.nio.file.Files import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static org.junit.jupiter.api.Assumptions.assumeTrue @Unroll diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy index 64bdcb20a4f7..99a64cd5ac38 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/AbstractServlet5Test.groovy @@ -6,19 +6,20 @@ import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import jakarta.servlet.Servlet -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class AbstractServlet5Test extends HttpServerTest implements AgentTestTrait { @Override diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServlet5Test.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServlet5Test.groovy index 593035467d30..86baf1079ec9 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServlet5Test.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServlet5Test.groovy @@ -11,15 +11,15 @@ import org.eclipse.jetty.server.handler.ErrorHandler import org.eclipse.jetty.servlet.ServletContextHandler import spock.lang.IgnoreIf -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS abstract class JettyServlet5Test extends AbstractServlet5Test { diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy index e631d9fdf1d7..d1d2ad3ac945 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/JettyServletHandlerTest.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.api.common.AttributeKey +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import jakarta.servlet.Servlet import jakarta.servlet.ServletException diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TestServlet5.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TestServlet5.groovy index 7ea0f137a942..077a9c5d3131 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TestServlet5.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TestServlet5.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import jakarta.servlet.RequestDispatcher import jakarta.servlet.ServletException import jakarta.servlet.annotation.WebServlet @@ -13,14 +14,14 @@ import jakarta.servlet.http.HttpServletResponse import java.util.concurrent.CountDownLatch -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class TestServlet5 { @@ -32,7 +33,7 @@ class TestServlet5 { if (servletPath == null) { servletPath = req.servletPath } - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(servletPath) HttpServerTest.controller(endpoint) { resp.contentType = "text/plain" switch (endpoint) { @@ -79,7 +80,7 @@ class TestServlet5 { static class Async extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) { - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) def latch = new CountDownLatch(1) def context = req.startAsync() if (endpoint == EXCEPTION) { @@ -157,7 +158,7 @@ class TestServlet5 { protected void service(HttpServletRequest req, HttpServletResponse resp) { def context = req.startAsync() try { - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) HttpServerTest.controller(endpoint) { resp.contentType = "text/plain" switch (endpoint) { diff --git a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy index 72cdc24628c9..cdde7f24ba67 100644 --- a/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy +++ b/instrumentation/servlet/servlet-5.0/javaagent/src/test/groovy/TomcatServlet5Test.groovy @@ -4,6 +4,7 @@ */ import io.opentelemetry.instrumentation.test.asserts.TraceAssert +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse import jakarta.servlet.Servlet import jakarta.servlet.ServletException @@ -24,16 +25,16 @@ import java.nio.file.Files import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static org.junit.jupiter.api.Assumptions.assumeTrue @Unroll diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ControllerSpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ControllerSpringWebFluxServerTest.groovy index 85952f1ae0d9..538b4a7556f0 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ControllerSpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ControllerSpringWebFluxServerTest.groovy @@ -7,17 +7,17 @@ package server.base import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.asserts.TraceAssert -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import org.springframework.web.server.ResponseStatusException import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND abstract class ControllerSpringWebFluxServerTest extends SpringWebFluxServerTest { @Override - void handlerSpan(TraceAssert trace, int index, Object parent, String method, HttpServerTest.ServerEndpoint endpoint) { + void handlerSpan(TraceAssert trace, int index, Object parent, String method, ServerEndpoint endpoint) { def handlerSpanName = "${ServerTestController.simpleName}.${endpoint.name().toLowerCase()}" if (endpoint == NOT_FOUND) { handlerSpanName = "ResourceWebHandler.handle" @@ -41,7 +41,7 @@ abstract class ControllerSpringWebFluxServerTest extends SpringWebFluxServerTest } @Override - boolean hasHandlerAsControllerParentSpan(HttpServerTest.ServerEndpoint endpoint) { + boolean hasHandlerAsControllerParentSpan(ServerEndpoint endpoint) { return false } diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedControllerSpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedControllerSpringWebFluxServerTest.groovy index a77abf332d86..928e6214c4f2 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedControllerSpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedControllerSpringWebFluxServerTest.groovy @@ -5,7 +5,7 @@ package server.base -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory import org.springframework.context.annotation.Bean @@ -44,8 +44,7 @@ class DelayedControllerSpringWebFluxServerTest extends ControllerSpringWebFluxSe @RestController static class Controller extends ServerTestController { @Override - protected Mono wrapControllerMethod( - HttpServerTest.ServerEndpoint endpoint, Callable handler) { + protected Mono wrapControllerMethod(ServerEndpoint endpoint, Callable handler) { return Mono.just("") .delayElement(Duration.ofMillis(10)) diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedHandlerSpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedHandlerSpringWebFluxServerTest.groovy index ae8a0449a697..89544af7c28f 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedHandlerSpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/DelayedHandlerSpringWebFluxServerTest.groovy @@ -5,7 +5,8 @@ package server.base -import io.opentelemetry.instrumentation.test.base.HttpServerTest + +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory import org.springframework.context.annotation.Bean @@ -44,7 +45,7 @@ class DelayedHandlerSpringWebFluxServerTest extends HandlerSpringWebFluxServerTe static class RouteFactory extends ServerTestRouteFactory { @Override - protected Mono wrapResponse(HttpServerTest.ServerEndpoint endpoint, Mono response, Runnable spanAction) { + protected Mono wrapResponse(ServerEndpoint endpoint, Mono response, Runnable spanAction) { return response.delayElement(Duration.ofMillis(10)).map({ original -> return controller(endpoint, { spanAction.run() @@ -55,7 +56,7 @@ class DelayedHandlerSpringWebFluxServerTest extends HandlerSpringWebFluxServerTe } @Override - boolean hasHandlerAsControllerParentSpan(HttpServerTest.ServerEndpoint endpoint) { + boolean hasHandlerAsControllerParentSpan(ServerEndpoint endpoint) { return false } } diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/HandlerSpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/HandlerSpringWebFluxServerTest.groovy index 442cfd22f2e3..3a1ee6f3ddfe 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/HandlerSpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/HandlerSpringWebFluxServerTest.groovy @@ -7,17 +7,17 @@ package server.base import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.asserts.TraceAssert -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import org.springframework.web.server.ResponseStatusException import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND abstract class HandlerSpringWebFluxServerTest extends SpringWebFluxServerTest { @Override - void handlerSpan(TraceAssert trace, int index, Object parent, String method, HttpServerTest.ServerEndpoint endpoint) { + void handlerSpan(TraceAssert trace, int index, Object parent, String method, ServerEndpoint endpoint) { def handlerSpanName = "${ServerTestRouteFactory.simpleName}.lambda" if (endpoint == NOT_FOUND) { handlerSpanName = "ResourceWebHandler.handle" diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateControllerSpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateControllerSpringWebFluxServerTest.groovy index 9081cd9e0151..8e357d534e29 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateControllerSpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateControllerSpringWebFluxServerTest.groovy @@ -5,7 +5,7 @@ package server.base -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory import org.springframework.context.annotation.Bean @@ -43,7 +43,7 @@ class ImmediateControllerSpringWebFluxServerTest extends ControllerSpringWebFlux @RestController static class Controller extends ServerTestController { @Override - protected Mono wrapControllerMethod(HttpServerTest.ServerEndpoint endpoint, Callable controllerMethod) { + protected Mono wrapControllerMethod(ServerEndpoint endpoint, Callable controllerMethod) { return Mono.just(controller(endpoint, controllerMethod)) } } diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateHandlerSpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateHandlerSpringWebFluxServerTest.groovy index a1433ea24b4e..41c774d93d7c 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateHandlerSpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/ImmediateHandlerSpringWebFluxServerTest.groovy @@ -5,7 +5,7 @@ package server.base -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.springframework.boot.autoconfigure.EnableAutoConfiguration import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory import org.springframework.context.annotation.Bean @@ -42,7 +42,7 @@ class ImmediateHandlerSpringWebFluxServerTest extends HandlerSpringWebFluxServer static class RouteFactory extends ServerTestRouteFactory { @Override - protected Mono wrapResponse(HttpServerTest.ServerEndpoint endpoint, Mono response, Runnable spanAction) { + protected Mono wrapResponse(ServerEndpoint endpoint, Mono response, Runnable spanAction) { return controller(endpoint, { spanAction.run() return response diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/SpringWebFluxServerTest.groovy b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/SpringWebFluxServerTest.groovy index 1cfa22580153..27e3fa0a1637 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/SpringWebFluxServerTest.groovy +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/groovy/server/base/SpringWebFluxServerTest.groovy @@ -7,11 +7,12 @@ package server.base import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.springframework.boot.SpringApplication import org.springframework.context.ConfigurableApplicationContext -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM abstract class SpringWebFluxServerTest extends HttpServerTest implements AgentTestTrait { protected abstract Class getApplicationClass(); diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java index f0023ff3f211..7d8ebb69123b 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestController.java @@ -5,7 +5,7 @@ package server.base; -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import java.net.URI; import java.util.concurrent.Callable; import org.springframework.http.HttpStatus; diff --git a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java index d16fa89d2ad8..5be798362686 100644 --- a/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java +++ b/instrumentation/spring/spring-webflux-5.0/javaagent/src/test/java/server/base/ServerTestRouteFactory.java @@ -9,7 +9,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.route; import io.opentelemetry.api.trace.Span; -import io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import org.springframework.http.HttpHeaders; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.ServerResponse; diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy index b9769096ca3c..f5d191e10777 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/SpringBootBasedTest.groovy @@ -9,6 +9,7 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import io.opentelemetry.testing.internal.armeria.common.HttpData @@ -19,13 +20,13 @@ import org.springframework.context.ConfigurableApplicationContext import org.springframework.web.servlet.view.RedirectView import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.LOGIN -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.LOGIN +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class SpringBootBasedTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/TestController.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/TestController.groovy index ed937202ac12..605b89ea3e92 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/TestController.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/boot/TestController.groovy @@ -17,14 +17,14 @@ import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseBody import org.springframework.web.servlet.view.RedirectView -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS @Controller class TestController { diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/FilteredAppConfig.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/FilteredAppConfig.groovy index 961dba9f048f..8a36c4259631 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/FilteredAppConfig.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/FilteredAppConfig.groovy @@ -6,6 +6,7 @@ package test.filter import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.context.annotation.Bean import org.springframework.http.HttpInputMessage @@ -32,14 +33,14 @@ import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse import java.nio.charset.StandardCharsets -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS @SpringBootApplication class FilteredAppConfig extends WebMvcConfigurerAdapter { @@ -91,7 +92,7 @@ class FilteredAppConfig extends WebMvcConfigurerAdapter { void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request HttpServletResponse resp = (HttpServletResponse) response - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) HttpServerTest.controller(endpoint) { resp.contentType = "text/plain" switch (endpoint) { diff --git a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy index 7235a31afa25..78cddf51bf3b 100644 --- a/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy +++ b/instrumentation/spring/spring-webmvc-3.1/javaagent/src/test/groovy/test/filter/ServletFilterTest.groovy @@ -9,18 +9,19 @@ package test.filter import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import org.springframework.boot.SpringApplication import org.springframework.context.ConfigurableApplicationContext import test.boot.SecurityConfig import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class ServletFilterTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy b/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy index 243c076deb73..bda4006f3a0b 100644 --- a/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy +++ b/instrumentation/struts-2.3/javaagent/src/test/groovy/Struts2ActionSpanTest.groovy @@ -8,6 +8,7 @@ import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.struts.GreetingServlet @@ -19,11 +20,11 @@ import org.eclipse.jetty.util.resource.FileResource import javax.servlet.DispatcherType import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT class Struts2ActionSpanTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/struts-2.3/javaagent/src/test/java/io/opentelemetry/struts/GreetingAction.java b/instrumentation/struts-2.3/javaagent/src/test/java/io/opentelemetry/struts/GreetingAction.java index 3138cb70cb96..6fd550c4c514 100644 --- a/instrumentation/struts-2.3/javaagent/src/test/java/io/opentelemetry/struts/GreetingAction.java +++ b/instrumentation/struts-2.3/javaagent/src/test/java/io/opentelemetry/struts/GreetingAction.java @@ -7,6 +7,7 @@ import com.opensymphony.xwork2.ActionSupport; import io.opentelemetry.instrumentation.test.base.HttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; @@ -17,46 +18,40 @@ public class GreetingAction extends ActionSupport { public String success() { responseBody = - HttpServerTest.controller( - HttpServerTest.ServerEndpoint.SUCCESS, HttpServerTest.ServerEndpoint.SUCCESS::getBody); + HttpServerTest.controller(ServerEndpoint.SUCCESS, ServerEndpoint.SUCCESS::getBody); return "greeting"; } public String redirect() { responseBody = - HttpServerTest.controller( - HttpServerTest.ServerEndpoint.REDIRECT, - HttpServerTest.ServerEndpoint.REDIRECT::getBody); + HttpServerTest.controller(ServerEndpoint.REDIRECT, ServerEndpoint.REDIRECT::getBody); return "redirect"; } public String query_param() { responseBody = - HttpServerTest.controller( - HttpServerTest.ServerEndpoint.QUERY_PARAM, - HttpServerTest.ServerEndpoint.QUERY_PARAM::getBody); + HttpServerTest.controller(ServerEndpoint.QUERY_PARAM, ServerEndpoint.QUERY_PARAM::getBody); return "greeting"; } public String error() { - HttpServerTest.controller( - HttpServerTest.ServerEndpoint.ERROR, HttpServerTest.ServerEndpoint.ERROR::getBody); + HttpServerTest.controller(ServerEndpoint.ERROR, ServerEndpoint.ERROR::getBody); return "error"; } public String exception() { HttpServerTest.controller( - HttpServerTest.ServerEndpoint.EXCEPTION, + ServerEndpoint.EXCEPTION, () -> { - throw new Exception(HttpServerTest.ServerEndpoint.EXCEPTION.getBody()); + throw new Exception(ServerEndpoint.EXCEPTION.getBody()); }); throw new AssertionError(); // should not reach here } public String path_param() { HttpServerTest.controller( - HttpServerTest.ServerEndpoint.PATH_PARAM, + ServerEndpoint.PATH_PARAM, () -> "this does nothing, as responseBody is set in setId, but we need this controller span nevertheless"); return "greeting"; @@ -65,11 +60,11 @@ public String path_param() { public String indexed_child() { responseBody = HttpServerTest.controller( - HttpServerTest.ServerEndpoint.INDEXED_CHILD, + ServerEndpoint.INDEXED_CHILD, () -> { - HttpServerTest.ServerEndpoint.INDEXED_CHILD.collectSpanAttributes( + ServerEndpoint.INDEXED_CHILD.collectSpanAttributes( (name) -> ServletActionContext.getRequest().getParameter(name)); - return HttpServerTest.ServerEndpoint.INDEXED_CHILD.getBody(); + return ServerEndpoint.INDEXED_CHILD.getBody(); }); return "greeting"; } @@ -80,8 +75,7 @@ public String capture_headers() { response.setHeader("X-Test-Response", request.getHeader("X-Test-Request")); responseBody = HttpServerTest.controller( - HttpServerTest.ServerEndpoint.CAPTURE_HEADERS, - HttpServerTest.ServerEndpoint.CAPTURE_HEADERS::getBody); + ServerEndpoint.CAPTURE_HEADERS, ServerEndpoint.CAPTURE_HEADERS::getBody); return "greeting"; } diff --git a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/AsyncServlet.groovy b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/AsyncServlet.groovy index 9de21943f17a..e76556ba100c 100644 --- a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/AsyncServlet.groovy +++ b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/AsyncServlet.groovy @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0 import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import jakarta.servlet.ServletException import jakarta.servlet.annotation.WebServlet import jakarta.servlet.http.HttpServlet @@ -14,19 +15,19 @@ import jakarta.servlet.http.HttpServletResponse import java.util.concurrent.CountDownLatch -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS @WebServlet(asyncSupported = true) class AsyncServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) { - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) def latch = new CountDownLatch(1) def context = req.startAsync() if (endpoint == EXCEPTION) { diff --git a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TestServlet.java b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TestServlet.java index eccc1c042265..ce0ef83a5bf1 100644 --- a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TestServlet.java +++ b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TestServlet.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0; import io.opentelemetry.instrumentation.test.base.HttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; @@ -18,18 +19,18 @@ public class TestServlet extends HttpServlet { protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { String path = req.getServletPath(); - HttpServerTest.ServerEndpoint serverEndpoint = HttpServerTest.ServerEndpoint.forPath(path); + ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path); if (serverEndpoint != null) { HttpServerTest.controller( serverEndpoint, () -> { - if (serverEndpoint == HttpServerTest.ServerEndpoint.EXCEPTION) { + if (serverEndpoint == ServerEndpoint.EXCEPTION) { throw new Exception(serverEndpoint.getBody()); } - if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_HEADERS) { + if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) { resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); } - if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS) { + if (serverEndpoint == ServerEndpoint.CAPTURE_PARAMETERS) { req.setCharacterEncoding("UTF8"); String value = req.getParameter("test-parameter"); if (!"test value õäöü".equals(value)) { @@ -37,13 +38,13 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws "request parameter does not have expected value " + value); } } - if (serverEndpoint == HttpServerTest.ServerEndpoint.INDEXED_CHILD) { - HttpServerTest.ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter); + if (serverEndpoint == ServerEndpoint.INDEXED_CHILD) { + ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter); } resp.getWriter().print(serverEndpoint.getBody()); - if (serverEndpoint == HttpServerTest.ServerEndpoint.REDIRECT) { + if (serverEndpoint == ServerEndpoint.REDIRECT) { resp.sendRedirect(serverEndpoint.getBody()); - } else if (serverEndpoint == HttpServerTest.ServerEndpoint.ERROR) { + } else if (serverEndpoint == ServerEndpoint.ERROR) { resp.sendError(serverEndpoint.getStatus(), serverEndpoint.getBody()); } else { resp.setStatus(serverEndpoint.getStatus()); diff --git a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy index e6b42165f2b3..452d323438be 100644 --- a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy +++ b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatAsyncTest.groovy @@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0 import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import jakarta.servlet.Servlet import jakarta.servlet.ServletException import org.apache.catalina.Context @@ -19,15 +20,15 @@ import spock.lang.Unroll import java.nio.file.Files -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS @Unroll class TomcatAsyncTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy index c217d734358c..a190601dcecc 100644 --- a/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy +++ b/instrumentation/tomcat/tomcat-10.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v10_0/TomcatHandlerTest.groovy @@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v10_0 import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.apache.catalina.Context import org.apache.catalina.connector.Request import org.apache.catalina.connector.Response @@ -16,9 +17,9 @@ import org.apache.catalina.core.StandardHost import org.apache.catalina.startup.Tomcat import org.apache.catalina.valves.ErrorReportValve -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT class TomcatHandlerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/AsyncServlet.groovy b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/AsyncServlet.groovy index 8f14e2073e05..a5c855886e41 100644 --- a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/AsyncServlet.groovy +++ b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/AsyncServlet.groovy @@ -7,26 +7,26 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0 import groovy.servlet.AbstractHttpServlet import io.opentelemetry.instrumentation.test.base.HttpServerTest - +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import javax.servlet.ServletException import javax.servlet.annotation.WebServlet import javax.servlet.http.HttpServletRequest import javax.servlet.http.HttpServletResponse import java.util.concurrent.CountDownLatch -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS @WebServlet(asyncSupported = true) class AsyncServlet extends AbstractHttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) { - HttpServerTest.ServerEndpoint endpoint = HttpServerTest.ServerEndpoint.forPath(req.servletPath) + ServerEndpoint endpoint = ServerEndpoint.forPath(req.servletPath) def latch = new CountDownLatch(1) def context = req.startAsync() if (endpoint == EXCEPTION) { diff --git a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TestServlet.java b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TestServlet.java index d660bf5e619a..e80df4226194 100644 --- a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TestServlet.java +++ b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TestServlet.java @@ -6,6 +6,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0; import io.opentelemetry.instrumentation.test.base.HttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -18,18 +19,18 @@ public class TestServlet extends HttpServlet { protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException { String path = req.getServletPath(); - HttpServerTest.ServerEndpoint serverEndpoint = HttpServerTest.ServerEndpoint.forPath(path); + ServerEndpoint serverEndpoint = ServerEndpoint.forPath(path); if (serverEndpoint != null) { HttpServerTest.controller( serverEndpoint, () -> { - if (serverEndpoint == HttpServerTest.ServerEndpoint.EXCEPTION) { + if (serverEndpoint == ServerEndpoint.EXCEPTION) { throw new Exception(serverEndpoint.getBody()); } - if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_HEADERS) { + if (serverEndpoint == ServerEndpoint.CAPTURE_HEADERS) { resp.setHeader("X-Test-Response", req.getHeader("X-Test-Request")); } - if (serverEndpoint == HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS) { + if (serverEndpoint == ServerEndpoint.CAPTURE_PARAMETERS) { req.setCharacterEncoding("UTF8"); String value = req.getParameter("test-parameter"); if (!"test value õäöü".equals(value)) { @@ -37,13 +38,13 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws "request parameter does not have expected value " + value); } } - if (serverEndpoint == HttpServerTest.ServerEndpoint.INDEXED_CHILD) { - HttpServerTest.ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter); + if (serverEndpoint == ServerEndpoint.INDEXED_CHILD) { + ServerEndpoint.INDEXED_CHILD.collectSpanAttributes(req::getParameter); } resp.getWriter().print(serverEndpoint.getBody()); - if (serverEndpoint == HttpServerTest.ServerEndpoint.REDIRECT) { + if (serverEndpoint == ServerEndpoint.REDIRECT) { resp.sendRedirect(serverEndpoint.getBody()); - } else if (serverEndpoint == HttpServerTest.ServerEndpoint.ERROR) { + } else if (serverEndpoint == ServerEndpoint.ERROR) { resp.sendError(serverEndpoint.getStatus(), serverEndpoint.getBody()); } else { resp.setStatus(serverEndpoint.getStatus()); diff --git a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy index 115e3e93d34d..e4032f0c0f8c 100644 --- a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy +++ b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatAsyncTest.groovy @@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0 import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.apache.catalina.Context import org.apache.catalina.startup.Tomcat import org.apache.tomcat.JarScanFilter @@ -19,15 +20,15 @@ import javax.servlet.Servlet import javax.servlet.ServletException import java.nio.file.Files -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.AUTH_REQUIRED -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.AUTH_REQUIRED +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS @Unroll class TomcatAsyncTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy index b1e08e47597d..87d2205f622e 100644 --- a/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy +++ b/instrumentation/tomcat/tomcat-7.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/tomcat/v7_0/TomcatHandlerTest.groovy @@ -9,6 +9,7 @@ package io.opentelemetry.javaagent.instrumentation.tomcat.v7_0 import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import org.apache.catalina.Context import org.apache.catalina.connector.Request import org.apache.catalina.connector.Response @@ -16,9 +17,9 @@ import org.apache.catalina.core.StandardHost import org.apache.catalina.startup.Tomcat import org.apache.catalina.valves.ErrorReportValve -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT class TomcatHandlerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerDispatchTest.groovy b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerDispatchTest.groovy index 936dd2edd000..e262fb3cfb95 100644 --- a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerDispatchTest.groovy +++ b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerDispatchTest.groovy @@ -6,6 +6,7 @@ import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.undertow.Handlers import io.undertow.Undertow @@ -13,12 +14,12 @@ import io.undertow.util.Headers import io.undertow.util.HttpString import io.undertow.util.StatusCodes -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class UndertowServerDispatchTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy index 10460b704634..a07e616c2378 100644 --- a/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy +++ b/instrumentation/undertow-1.4/javaagent/src/test/groovy/UndertowServerTest.groovy @@ -9,6 +9,7 @@ import io.opentelemetry.api.trace.SpanKind import io.opentelemetry.api.trace.StatusCode import io.opentelemetry.instrumentation.test.AgentTestTrait import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse import io.undertow.Handlers @@ -17,13 +18,13 @@ import io.undertow.util.Headers import io.undertow.util.HttpString import io.undertow.util.StatusCodes -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS //TODO make test which mixes handlers and servlets class UndertowServerTest extends HttpServerTest implements AgentTestTrait { diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy index 70a5ee77b30b..bf748c67f68a 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/VertxReactivePropagationTest.groovy @@ -23,7 +23,7 @@ import static VertxReactiveWebServer.TEST_REQUEST_ID_ATTRIBUTE import static VertxReactiveWebServer.TEST_REQUEST_ID_PARAMETER import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP class VertxReactivePropagationTest extends AgentInstrumentationSpecification { diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy index fee37d1b5aee..c153189403b0 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy @@ -5,21 +5,21 @@ package server -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.vertx.circuitbreaker.CircuitBreakerOptions import io.vertx.core.Promise import io.vertx.reactivex.circuitbreaker.CircuitBreaker import io.vertx.reactivex.core.AbstractVerticle import io.vertx.reactivex.ext.web.Router -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { @@ -49,7 +49,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(endpoint.body) } @@ -62,7 +62,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { endpoint.collectSpanAttributes { ctx.request().params().get(it) } ctx.response().setStatusCode(endpoint.status).end() @@ -76,7 +76,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(ctx.request().query()) } @@ -89,7 +89,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).putHeader("location", endpoint.body).end() } @@ -102,7 +102,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(endpoint.body) } @@ -129,7 +129,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(ctx.request().getParam("id")) } @@ -142,7 +142,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status) .putHeader("X-Test-Response", ctx.request().getHeader("X-Test-Request")) @@ -159,7 +159,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { } @Override - boolean hasExceptionOnServerSpan(HttpServerTest.ServerEndpoint endpoint) { + boolean hasExceptionOnServerSpan(ServerEndpoint endpoint) { return endpoint != EXCEPTION && super.hasExceptionOnServerSpan(endpoint) } } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy index 7d630f46a3fd..d732601f5b7c 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/groovy/server/VertxRxHttpServerTest.groovy @@ -19,14 +19,14 @@ import io.vertx.reactivex.ext.web.Router import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class VertxRxHttpServerTest extends HttpServerTest implements AgentTestTrait { public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port" diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/VertxReactiveWebServer.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/VertxReactiveWebServer.java index 667dc33cd482..77cef04c0aad 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/VertxReactiveWebServer.java +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/latestDepTest/java/VertxReactiveWebServer.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.trace.Span; diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy index 70a5ee77b30b..bf748c67f68a 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/VertxReactivePropagationTest.groovy @@ -23,7 +23,7 @@ import static VertxReactiveWebServer.TEST_REQUEST_ID_ATTRIBUTE import static VertxReactiveWebServer.TEST_REQUEST_ID_PARAMETER import static io.opentelemetry.api.trace.SpanKind.CLIENT import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP class VertxReactivePropagationTest extends AgentInstrumentationSpecification { diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy index 58e2d0c339df..e557806d4d2f 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxCircuitBreakerHttpServerTest.groovy @@ -5,21 +5,21 @@ package server -import io.opentelemetry.instrumentation.test.base.HttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint import io.vertx.circuitbreaker.CircuitBreakerOptions import io.vertx.core.Future import io.vertx.reactivex.circuitbreaker.CircuitBreaker import io.vertx.reactivex.core.AbstractVerticle import io.vertx.reactivex.ext.web.Router -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { @@ -49,7 +49,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(endpoint.body) } @@ -62,7 +62,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { endpoint.collectSpanAttributes { ctx.request().params().get(it) } ctx.response().setStatusCode(endpoint.status).end() @@ -76,7 +76,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(ctx.request().query()) } @@ -89,7 +89,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).putHeader("location", endpoint.body).end() } @@ -102,7 +102,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(endpoint.body) } @@ -129,7 +129,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status).end(ctx.request().getParam("id")) } @@ -142,7 +142,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { if (it.failed()) { throw it.cause() } - HttpServerTest.ServerEndpoint endpoint = it.result() + ServerEndpoint endpoint = it.result() controller(endpoint) { ctx.response().setStatusCode(endpoint.status) .putHeader("X-Test-Response", ctx.request().getHeader("X-Test-Request")) @@ -158,7 +158,7 @@ class VertxRxCircuitBreakerHttpServerTest extends VertxRxHttpServerTest { } @Override - boolean hasExceptionOnServerSpan(HttpServerTest.ServerEndpoint endpoint) { + boolean hasExceptionOnServerSpan(ServerEndpoint endpoint) { return endpoint != EXCEPTION && super.hasExceptionOnServerSpan(endpoint) } } diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy index 8a60ca0e23eb..d74f7ab9e48b 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/groovy/server/VertxRxHttpServerTest.groovy @@ -19,14 +19,14 @@ import io.vertx.reactivex.ext.web.Router import java.util.concurrent.CompletableFuture import java.util.concurrent.TimeUnit -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS class VertxRxHttpServerTest extends HttpServerTest implements AgentTestTrait { public static final String CONFIG_HTTP_SERVER_PORT = "http.server.port" diff --git a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/VertxReactiveWebServer.java b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/VertxReactiveWebServer.java index e1baba954685..1a8124699053 100644 --- a/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/VertxReactiveWebServer.java +++ b/instrumentation/vertx/vertx-rx-java-3.5/javaagent/src/version35Test/java/VertxReactiveWebServer.java @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; import io.opentelemetry.api.GlobalOpenTelemetry; import io.opentelemetry.api.trace.Span; diff --git a/instrumentation/vertx/vertx-web-3.0/testing/src/main/java/server/AbstractVertxWebServer.java b/instrumentation/vertx/vertx-web-3.0/testing/src/main/java/server/AbstractVertxWebServer.java index 4832bccaec41..b1791f238b3c 100644 --- a/instrumentation/vertx/vertx-web-3.0/testing/src/main/java/server/AbstractVertxWebServer.java +++ b/instrumentation/vertx/vertx-web-3.0/testing/src/main/java/server/AbstractVertxWebServer.java @@ -5,14 +5,14 @@ package server; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT; -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; import io.opentelemetry.instrumentation.test.base.HttpServerTest; import io.vertx.core.AbstractVerticle; diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy index 8db8be056b77..a3d96da65a47 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTest.groovy @@ -5,54 +5,42 @@ package io.opentelemetry.instrumentation.test.base -import io.opentelemetry.api.GlobalOpenTelemetry import io.opentelemetry.api.common.AttributeKey import io.opentelemetry.api.trace.Span +import io.opentelemetry.api.trace.SpanId import io.opentelemetry.api.trace.SpanKind -import io.opentelemetry.api.trace.StatusCode -import io.opentelemetry.context.Context import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders import io.opentelemetry.instrumentation.test.InstrumentationSpecification import io.opentelemetry.instrumentation.test.asserts.TraceAssert import io.opentelemetry.instrumentation.testing.GlobalTraceUtil +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions +import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint +import io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions import io.opentelemetry.sdk.trace.data.SpanData import io.opentelemetry.semconv.trace.attributes.SemanticAttributes import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse -import io.opentelemetry.testing.internal.armeria.common.HttpData import io.opentelemetry.testing.internal.armeria.common.HttpMethod -import io.opentelemetry.testing.internal.armeria.common.HttpRequest -import io.opentelemetry.testing.internal.armeria.common.HttpRequestBuilder -import io.opentelemetry.testing.internal.armeria.common.MediaType -import io.opentelemetry.testing.internal.armeria.common.QueryParams -import io.opentelemetry.testing.internal.armeria.common.RequestHeaders +import spock.lang.Shared import spock.lang.Unroll import java.util.concurrent.Callable -import java.util.concurrent.CountDownLatch - -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_HEADERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.CAPTURE_PARAMETERS -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.ERROR -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.EXCEPTION -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.INDEXED_CHILD -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.NOT_FOUND -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.PATH_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.QUERY_PARAM -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.REDIRECT -import static io.opentelemetry.instrumentation.test.base.HttpServerTest.ServerEndpoint.SUCCESS -import static io.opentelemetry.semconv.trace.attributes.SemanticAttributes.NetTransportValues.IP_TCP -import static java.util.Collections.singletonList + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS import static org.junit.jupiter.api.Assumptions.assumeTrue @Unroll abstract class HttpServerTest extends InstrumentationSpecification implements HttpServerTestTrait { - static final String TEST_REQUEST_HEADER = "X-Test-Request" - static final String TEST_RESPONSE_HEADER = "X-Test-Response" - def setupSpec() { setupServer() + junitTest.setupOptions() + junitTest.setTesting(testRunner(), client, port, address) } def cleanupSpec() { @@ -60,9 +48,7 @@ abstract class HttpServerTest extends InstrumentationSpecification imple } static CapturedHttpHeaders capturedHttpHeadersForTesting() { - CapturedHttpHeaders.create( - singletonList(TEST_REQUEST_HEADER), - singletonList(TEST_RESPONSE_HEADER)) + return AbstractHttpServerTest.capturedHttpHeadersForTesting() } String expectedServerSpanName(ServerEndpoint endpoint, String method) { @@ -171,101 +157,9 @@ abstract class HttpServerTest extends InstrumentationSpecification imple ] as Set } - enum ServerEndpoint { - SUCCESS("success", 200, "success"), - REDIRECT("redirect", 302, "/redirected"), - ERROR("error-status", 500, "controller error"), // "error" is a special path for some frameworks - EXCEPTION("exception", 500, "controller exception"), - NOT_FOUND("notFound", 404, "not found"), - CAPTURE_HEADERS("captureHeaders", 200, "headers captured"), - CAPTURE_PARAMETERS("captureParameters", 200, "parameters captured"), - - // TODO: add tests for the following cases: - QUERY_PARAM("query?some=query", 200, "some=query"), - // OkHttp never sends the fragment in the request, so these cases don't work. -// FRAGMENT_PARAM("fragment#some-fragment", 200, "some-fragment"), -// QUERY_FRAGMENT_PARAM("query/fragment?some=query#some-fragment", 200, "some=query#some-fragment"), - PATH_PARAM("path/123/param", 200, "123"), - AUTH_REQUIRED("authRequired", 200, null), - LOGIN("login", 302, null), - AUTH_ERROR("basicsecured/endpoint", 401, null), - INDEXED_CHILD("child", 200, ""), - - public static final String ID_ATTRIBUTE_NAME = "test.request.id" - public static final String ID_PARAMETER_NAME = "id" - - private final URI uriObj - private final String path - final String query - final String fragment - final int status - final String body - - ServerEndpoint(String uri, int status, String body) { - this.uriObj = URI.create(uri) - this.path = uriObj.path - this.query = uriObj.query - this.fragment = uriObj.fragment - this.status = status - this.body = body - } - - String getPath() { - return "/$path" - } - - String rawPath() { - return path - } - - URI resolvePath(URI address) { - return address.resolve(path) - } - - URI resolve(URI address) { - return address.resolve(uriObj) - } - - URI resolveWithoutFragment(URI address) { - def uri = resolve(address) - return new URI(uri.scheme, null, uri.host, uri.port, uri.path, uri.query, null) - } - - /** - * Populates custom test attributes for the {@link HttpServerTest#controller} span (which must - * be the current span when this is called) based on URL parameters. Required for - * {@link #INDEXED_CHILD}. - */ - void collectSpanAttributes(UrlParameterProvider parameterProvider) { - if (this == INDEXED_CHILD) { - String value = parameterProvider.getParameter(ID_PARAMETER_NAME) - - if (value != null) { - Span.current().setAttribute(ID_ATTRIBUTE_NAME, value as long) - } - } - } - - private static final Map PATH_MAP = values().collectEntries { [it.path, it] } - - static ServerEndpoint forPath(String path) { - return PATH_MAP.get(path) - } - - // Static keyword required for Scala interop - static interface UrlParameterProvider { - String getParameter(String name) - } - } - String resolveAddress(ServerEndpoint uri) { - def url = uri.resolvePath(address).toString() - // Force HTTP/1 via h1c so upgrade requests don't show up as traces - url = url.replace("http://", "h1c://") - if (uri.query != null) { - url += "?${uri.query}" - } - return url + final String resolveAddress(ServerEndpoint endpoint) { + return junitTest.resolveAddress(endpoint) } AggregatedHttpRequest request(ServerEndpoint uri, String method) { @@ -282,257 +176,141 @@ abstract class HttpServerTest extends InstrumentationSpecification imple } } - def "test success with #count requests"() { - setup: - def request = request(SUCCESS, method) - List responses = (1..count).collect { - return client.execute(request).aggregate().join() + @Shared + def junitTest = new AbstractHttpServerTest() { + @Override + protected Void setupServer() { + return null } - expect: - responses.each { response -> - assert response.status().code() == SUCCESS.status - assert response.contentUtf8() == SUCCESS.body + @Override + protected void stopServer(Void o) { } - and: - assertTheTraces(count, null, null, method, SUCCESS, null, responses[0]) + @Override + protected void configure(HttpServerTestOptions options) { + options.expectedServerSpanNameMapper = { endpoint, method -> + HttpServerTest.this.expectedServerSpanName(endpoint, method) + } + options.expectedHttpRoute = { endpoint -> + HttpServerTest.this.expectedHttpRoute(endpoint) + } + options.contextPath = getContextPath() + options.httpAttributes = { endpoint -> + HttpServerTest.this.httpAttributes(endpoint) + } + options.expectedExceptionClass = expectedExceptionClass() + options.hasExceptionOnServerSpan = { endpoint -> + HttpServerTest.this.hasExceptionOnServerSpan(endpoint) + } + + options.testRedirect = testRedirect() + options.testError = testError() + options.testErrorBody = testErrorBody() + options.testException = testException() + options.testNotFound = testNotFound() + options.testPathParam = testPathParam() + options.testCaptureHttpHeaders = testCapturedHttpHeaders() + options.testCaptureRequestParameters = testCapturedRequestParameters() + } + + // Override trace assertion method. We can call java assertions from groovy but not the other + // way around. As we have a bunch of groovy tests that do custom assertions we need to duplicate + // the main trace assertion method to groovy to be able to call these assertions. + @Override + void assertTheTraces( + int size, + String traceId, + String parentId, + String method, + ServerEndpoint endpoint, + String errorMessage, + AggregatedHttpResponse response) { + HttpServerTest.this.assertTheTraces(size, traceId, parentId, method, endpoint, errorMessage, response) + } + + @Override + void assertHighConcurrency(int count) { + HttpServerTest.this.assertHighConcurrency(count) + } + } + + def "test success with #count requests"() { + expect: + junitTest.successfulGetRequest(count) where: - method = "GET" count << [1, 4, 50] // make multiple requests. } def "test success with parent"() { - setup: - def traceId = "00000000000000000000000000000123" - def parentId = "0000000000000456" - def request = AggregatedHttpRequest.of( - // intentionally sending mixed-case "tracePARENT" to make sure that TextMapGetters are not case-sensitive - request(SUCCESS, method).headers().toBuilder() - .set("tracePARENT", "00-" + traceId.toString() + "-" + parentId.toString() + "-01") - .build()) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == SUCCESS.status - response.contentUtf8() == SUCCESS.body - - and: - assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response) - - where: - method = "GET" + junitTest.successfulGetRequestWithParent() } // make sure that TextMapGetters are not case-sensitive def "test success with uppercase TRACEPARENT header"() { - setup: - def traceId = "00000000000000000000000000000123" - def parentId = "0000000000000456" - def request = AggregatedHttpRequest.of( - request(SUCCESS, method).headers().toBuilder() - .set("TRACEPARENT", "00-" + traceId.toString() + "-" + parentId.toString() + "-01") - .build()) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == SUCCESS.status - response.contentUtf8() == SUCCESS.body - - and: - assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response) - - where: - method = "GET" + junitTest.tracingHeaderIsCaseInsensitive() } def "test tag query string for #endpoint"() { - setup: - def request = request(endpoint, method) - AggregatedHttpResponse response = client.execute(request).aggregate().join() - expect: - response.status().code() == endpoint.status - response.contentUtf8() == endpoint.body - - and: - assertTheTraces(1, null, null, method, endpoint, null, response) + junitTest.requestWithQueryString(endpoint) where: - method = "GET" endpoint << [SUCCESS, QUERY_PARAM] } def "test redirect"() { - setup: assumeTrue(testRedirect()) - def request = request(REDIRECT, method) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == REDIRECT.status - response.headers().get("location") == REDIRECT.body || - new URI(response.headers().get("location")).normalize().toString() == "${address.resolve(REDIRECT.body)}" - - and: - assertTheTraces(1, null, null, method, REDIRECT, null, response) - - where: - method = "GET" + junitTest.requestWithRedirect() } def "test error"() { - setup: assumeTrue(testError()) - def request = request(ERROR, method) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == ERROR.status - if (testErrorBody()) { - response.contentUtf8() == ERROR.body - } - - and: - assertTheTraces(1, null, null, method, ERROR, null, response) - - where: - method = "GET" + junitTest.requestWithError() } def "test exception"() { - setup: assumeTrue(testException()) - def request = request(EXCEPTION, method) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == EXCEPTION.status - - and: - assertTheTraces(1, null, null, method, EXCEPTION, EXCEPTION.body, response) - - where: - method = "GET" + junitTest.requestWithException() } - def "test notFound"() { - setup: + def "test not found"() { assumeTrue(testNotFound()) - def request = request(NOT_FOUND, method) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == NOT_FOUND.status - - and: - assertTheTraces(1, null, null, method, NOT_FOUND, null, response) - - where: - method = "GET" + junitTest.requestForNotFound() } def "test path param"() { - setup: assumeTrue(testPathParam()) - def request = request(PATH_PARAM, method) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == PATH_PARAM.status - response.contentUtf8() == PATH_PARAM.body - - and: - assertTheTraces(1, null, null, method, PATH_PARAM, null, response) - - where: - method = "GET" + junitTest.requestWithPathParameter() } def "test captured HTTP headers"() { - setup: assumeTrue(testCapturedHttpHeaders()) - - def request = AggregatedHttpRequest.of(request(CAPTURE_HEADERS, "GET").headers() - .toBuilder() - .add(TEST_REQUEST_HEADER, "test") - .build()) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == CAPTURE_HEADERS.status - response.contentUtf8() == CAPTURE_HEADERS.body - - and: - assertTheTraces(1, null, null, "GET", CAPTURE_HEADERS, null, response) + junitTest.captureHttpHeaders() } def "test captured request parameters"() { - setup: assumeTrue(testCapturedRequestParameters()) - - QueryParams formBody = QueryParams.builder() - .add("test-parameter", "test value õäöü") - .build() - def request = AggregatedHttpRequest.of( - RequestHeaders.builder(HttpMethod.POST, resolveAddress(CAPTURE_PARAMETERS)) - .contentType(MediaType.FORM_DATA) - .build(), - HttpData.ofUtf8(formBody.toQueryString())) - def response = client.execute(request).aggregate().join() - expect: - response.status().code() == CAPTURE_PARAMETERS.status - response.contentUtf8() == CAPTURE_PARAMETERS.body - - and: - assertTheTraces(1, null, null, "POST", CAPTURE_PARAMETERS, null, response) + junitTest.captureRequestParameters() } - /* - This test fires a bunch of parallel request to the fixed backend endpoint. - That endpoint is supposed to create a new child span in the context of the SERVER span. - That child span is expected to have an attribute called "test.request.id". - The value of that attribute should be the value of request's parameter called "id". - - This test then asserts that there is the correct number of traces (one per request executed) - and that each trace has exactly three spans and both first and the last spans have "test.request.id" - attribute with equal value. Server span is not going to have that attribute because it is not - under the control of this test. - - This way we verify that child span created by the server actually corresponds to the client request. - */ - def "high concurrency test"() { - setup: - int count = 100 - def endpoint = INDEXED_CHILD - - def latch = new CountDownLatch(count) - - def propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator() - def setter = { HttpRequestBuilder carrier, String name, String value -> - carrier.header(name, value) - } - - when: - count.times { index -> - HttpRequestBuilder request = HttpRequest.builder() - // Force HTTP/1 via h1c so upgrade requests don't show up as traces - .get(endpoint.resolvePath(address).toString().replace("http://", "h1c://")) - .queryParam(ServerEndpoint.ID_PARAMETER_NAME, "$index") - runWithSpan("client " + index) { - Span.current().setAttribute(ServerEndpoint.ID_ATTRIBUTE_NAME, index) - propagator.inject(Context.current(), request, setter) - client.execute(request.build()).aggregate().thenRun { - latch.countDown() - } - } - } - latch.await() + expect: + junitTest.highConcurrency() + } - then: + void assertHighConcurrency(int count) { + def endpoint = INDEXED_CHILD assertTraces(count) { (0..count - 1).each { trace(it, hasHandlerSpan(endpoint) ? 4 : 3) { @@ -548,7 +326,7 @@ abstract class HttpServerTest extends InstrumentationSpecification imple "${ServerEndpoint.ID_ATTRIBUTE_NAME}" requestId } } - indexedServerSpan(it, span(0), requestId) + indexedServerSpan(it, 1, span(0), requestId) def controllerSpanIndex = 2 @@ -619,13 +397,13 @@ abstract class HttpServerTest extends InstrumentationSpecification imple } void controllerSpan(TraceAssert trace, int index, Object parent, String errorMessage = null, Class exceptionClass = Exception) { - trace.span(index) { - name "controller" - if (errorMessage) { - status StatusCode.ERROR - errorEvent(exceptionClass, errorMessage) - } - childOf((SpanData) parent) + trace.assertedIndexes.add(index) + def spanData = trace.span(index) + def assertion = junitTest.assertControllerSpan(OpenTelemetryAssertions.assertThat(spanData), errorMessage, exceptionClass) + if (parent == null) { + assertion.hasParentSpanId(SpanId.invalid) + } else { + assertion.hasParentSpanId(((SpanData) parent).spanId) } } @@ -665,145 +443,37 @@ abstract class HttpServerTest extends InstrumentationSpecification imple } } - // parent span must be cast otherwise it breaks debugging classloading (junit loads it early) void serverSpan(TraceAssert trace, int index, String traceID = null, String parentID = null, String method = "GET", Long responseContentLength = null, ServerEndpoint endpoint = SUCCESS) { - def httpAttributes = this.httpAttributes(endpoint) - trace.span(index) { - name expectedServerSpanName(endpoint, method) - kind SpanKind.SERVER // can't use static import because of SERVER type parameter - if (endpoint.status >= 500) { - status StatusCode.ERROR - } - if (parentID != null) { - traceId traceID - parentSpanId parentID - } else { - hasNoParent() - } - if (endpoint == EXCEPTION && hasExceptionOnServerSpan(endpoint)) { - event(0) { - eventName(SemanticAttributes.EXCEPTION_EVENT_NAME) - attributes { - "$SemanticAttributes.EXCEPTION_TYPE" { it == null || it == expectedExceptionClass().name } - "$SemanticAttributes.EXCEPTION_MESSAGE" { it == null || it == endpoint.body } - "$SemanticAttributes.EXCEPTION_STACKTRACE" { it == null || it instanceof String } - } - } - } - attributes { - if (httpAttributes.contains(SemanticAttributes.NET_TRANSPORT)) { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - } - if (httpAttributes.contains(SemanticAttributes.NET_PEER_PORT)) { - "$SemanticAttributes.NET_PEER_PORT" { (it instanceof Long && it.intValue() != port) } - } - if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)) { - "$SemanticAttributes.NET_PEER_IP" { it == peerIp(endpoint) } - } else { - // Optional - "$SemanticAttributes.NET_PEER_IP" { it == null || it == peerIp(endpoint) } - } - - "$SemanticAttributes.HTTP_CLIENT_IP" { it == null || it == TEST_CLIENT_IP } - "$SemanticAttributes.HTTP_METHOD" method - "$SemanticAttributes.HTTP_STATUS_CODE" endpoint.status - "$SemanticAttributes.HTTP_FLAVOR" { it == "1.1" || it == "2.0" } - "$SemanticAttributes.HTTP_USER_AGENT" TEST_USER_AGENT - - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_HOST" { it == "localhost" || it == "localhost:${port}" } - "$SemanticAttributes.HTTP_TARGET" endpoint.resolvePath(address).getPath() + "${endpoint == QUERY_PARAM ? "?${endpoint.body}" : ""}" - - if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) { - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long - } else { - // Optional - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - } - if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) { - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long - } else { - // Optional - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } - } - if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) { - "$SemanticAttributes.HTTP_SERVER_NAME" String - } - if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) { - "$SemanticAttributes.HTTP_ROUTE" { it == expectedHttpRoute(endpoint) } - } - - if (endpoint == CAPTURE_HEADERS) { - "http.request.header.x_test_request" { it == ["test"] } - "http.response.header.x_test_response" { it == ["test"] } - } - if (endpoint == CAPTURE_PARAMETERS) { - "servlet.request.parameter.test_parameter" { it == ["test value õäöü"] } - } - } + trace.assertedIndexes.add(index) + def spanData = trace.span(index) + def assertion = junitTest.assertServerSpan(OpenTelemetryAssertions.assertThat(spanData), method, endpoint) + if (parentID == null) { + assertion.hasParentSpanId(SpanId.invalid) + } else { + assertion.hasParentSpanId(parentID) + assertion.hasTraceId(traceID) } } - void indexedServerSpan(TraceAssert trace, Object parent, int requestId) { - ServerEndpoint endpoint = INDEXED_CHILD - def httpAttributes = this.httpAttributes(endpoint) - trace.span(1) { - name expectedServerSpanName(endpoint, "GET") - kind SpanKind.SERVER // can't use static import because of SERVER type parameter - childOf((SpanData) parent) - attributes { - if (httpAttributes.contains(SemanticAttributes.NET_TRANSPORT)) { - "$SemanticAttributes.NET_TRANSPORT" IP_TCP - } - if (httpAttributes.contains(SemanticAttributes.NET_PEER_PORT)) { - "$SemanticAttributes.NET_PEER_PORT" { (it instanceof Long && it.intValue() != port) } - } - if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP)) { - "$SemanticAttributes.NET_PEER_IP" { it == peerIp(endpoint) } - } else { - // Optional - "$SemanticAttributes.NET_PEER_IP" { it == null || it == peerIp(endpoint) } - } - - "$SemanticAttributes.HTTP_CLIENT_IP" { it == null || it == TEST_CLIENT_IP } - "$SemanticAttributes.HTTP_METHOD" "GET" - "$SemanticAttributes.HTTP_STATUS_CODE" 200 - "$SemanticAttributes.HTTP_FLAVOR" "1.1" - "$SemanticAttributes.HTTP_USER_AGENT" TEST_USER_AGENT - - "$SemanticAttributes.HTTP_HOST" { it == "localhost" || it == "localhost:${port}" } - "$SemanticAttributes.HTTP_SCHEME" "http" - "$SemanticAttributes.HTTP_TARGET" endpoint.resolvePath(address).getPath() + "?id=$requestId" - - if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH)) { - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" Long - } else { - // Optional - "$SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH" { it == null || it instanceof Long } - } - if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH)) { - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" Long - } else { - // Optional - "$SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH" { it == null || it instanceof Long } - } - if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) { - "$SemanticAttributes.HTTP_SERVER_NAME" String - } - if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) { - "$SemanticAttributes.HTTP_ROUTE" { it == expectedHttpRoute(endpoint) } - } - } + void indexedServerSpan(TraceAssert trace, int index, Object parent, int requestId) { + trace.assertedIndexes.add(index) + def spanData = trace.span(index) + def assertion = junitTest.assertIndexedServerSpan(OpenTelemetryAssertions.assertThat(spanData), requestId) + if (parent == null) { + assertion.hasParentSpanId(SpanId.invalid) + } else { + assertion.hasParentSpanId(((SpanData) parent).spanId) } } void indexedControllerSpan(TraceAssert trace, int index, Object parent, int requestId) { - trace.span(index) { - name "controller" - childOf((SpanData) parent) - attributes { - "${ServerEndpoint.ID_ATTRIBUTE_NAME}" requestId - } + trace.assertedIndexes.add(index) + def spanData = trace.span(index) + def assertion = junitTest.assertIndexedControllerSpan(OpenTelemetryAssertions.assertThat(spanData), requestId) + if (parent == null) { + assertion.hasParentSpanId(SpanId.invalid) + } else { + assertion.hasParentSpanId(((SpanData) parent).spanId) } } } diff --git a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTestTrait.groovy b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTestTrait.groovy index f823fe009634..3526b32a3a9e 100644 --- a/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTestTrait.groovy +++ b/testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpServerTestTrait.groovy @@ -9,6 +9,7 @@ import ch.qos.logback.classic.Level import io.opentelemetry.instrumentation.test.RetryOnAddressAlreadyInUseTrait import io.opentelemetry.instrumentation.test.utils.LoggerUtils import io.opentelemetry.instrumentation.test.utils.PortUtils +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest import io.opentelemetry.testing.internal.armeria.client.ClientFactory import io.opentelemetry.testing.internal.armeria.client.WebClient import io.opentelemetry.testing.internal.armeria.client.logging.LoggingClient @@ -26,8 +27,8 @@ trait HttpServerTestTrait implements RetryOnAddressAlreadyInUseTrait { static { LoggerUtils.setLevel(SERVER_LOGGER, Level.DEBUG) } - static final String TEST_CLIENT_IP = "1.1.1.1" - static final String TEST_USER_AGENT = "test-user-agent" + static final String TEST_CLIENT_IP = AbstractHttpServerTest.TEST_CLIENT_IP + static final String TEST_USER_AGENT = AbstractHttpServerTest.TEST_USER_AGENT // not using SERVER as type because it triggers a bug in groovy and java joint compilation static Object server diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java index 4f28fc6a1680..61aa2d0842cd 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java @@ -199,9 +199,7 @@ void setupOptions() { void verifyExtension() { if (testing == null) { throw new AssertionError( - "Subclasses of AbstractHttpClientTest must register either " - + "HttpClientLibraryInstrumentationExtension or " - + "HttpClientAgentInstrumentationExtension"); + "Subclasses of AbstractHttpClientTest must register HttpClientInstrumentationExtension"); } } diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java new file mode 100644 index 000000000000..0ab16587e2ba --- /dev/null +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpServerTest.java @@ -0,0 +1,695 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.testing.junit.http; + +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_HEADERS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.CAPTURE_PARAMETERS; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.ERROR; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.EXCEPTION; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.INDEXED_CHILD; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.NOT_FOUND; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.PATH_PARAM; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.QUERY_PARAM; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.REDIRECT; +import static io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint.SUCCESS; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static java.util.Collections.singletonList; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.propagation.TextMapPropagator; +import io.opentelemetry.context.propagation.TextMapSetter; +import io.opentelemetry.instrumentation.api.instrumenter.http.CapturedHttpHeaders; +import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.sdk.testing.assertj.TraceAssert; +import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.sdk.trace.data.StatusData; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.opentelemetry.testing.internal.armeria.client.WebClient; +import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpRequest; +import io.opentelemetry.testing.internal.armeria.common.AggregatedHttpResponse; +import io.opentelemetry.testing.internal.armeria.common.HttpData; +import io.opentelemetry.testing.internal.armeria.common.HttpMethod; +import io.opentelemetry.testing.internal.armeria.common.HttpRequest; +import io.opentelemetry.testing.internal.armeria.common.HttpRequestBuilder; +import io.opentelemetry.testing.internal.armeria.common.MediaType; +import io.opentelemetry.testing.internal.armeria.common.QueryParams; +import io.opentelemetry.testing.internal.armeria.common.RequestHeaders; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.function.Consumer; +import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.ValueSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public abstract class AbstractHttpServerTest { + private static final Logger logger = LoggerFactory.getLogger(AbstractHttpServerTest.class); + + private static final String TEST_REQUEST_HEADER = "X-Test-Request"; + private static final String TEST_RESPONSE_HEADER = "X-Test-Response"; + + public static final String TEST_CLIENT_IP = "1.1.1.1"; + public static final String TEST_USER_AGENT = "test-user-agent"; + + private final HttpServerTestOptions options = new HttpServerTestOptions(); + private InstrumentationTestRunner testing; + private SERVER server; + public WebClient client; + public int port; + public URI address; + + protected abstract SERVER setupServer(); + + protected abstract void stopServer(SERVER server); + + @BeforeAll + void setupOptions() { + options.expectedServerSpanNameMapper = this::expectedServerSpanName; + options.expectedHttpRoute = this::expectedHttpRoute; + + configure(options); + + if (address == null) { + address = buildAddress(); + } + + server = setupServer(); + if (server != null) { + logger.info( + getClass().getName() + + " http server started at: http://localhost:" + + port + + options.contextPath); + } + } + + @AfterAll + void cleanup() { + if (server == null) { + logger.info(getClass().getName() + " can't stop null server"); + return; + } + stopServer(server); + server = null; + logger.info(getClass().getName() + " http server stopped at: http://localhost:" + port + "/"); + } + + protected URI buildAddress() { + try { + return new URI("http://localhost:" + port + options.contextPath + "/"); + } catch (URISyntaxException exception) { + throw new IllegalStateException(exception); + } + } + + protected void configure(HttpServerTestOptions options) {} + + @BeforeEach + void verifyExtension() { + if (testing == null) { + throw new AssertionError( + "Subclasses of AbstractHttpServerTest must register HttpServerInstrumentationExtension"); + } + } + + public static CapturedHttpHeaders capturedHttpHeadersForTesting() { + return CapturedHttpHeaders.create( + singletonList(TEST_REQUEST_HEADER), singletonList(TEST_RESPONSE_HEADER)); + } + + String resolveAddress(ServerEndpoint uri) { + String url = uri.resolvePath(address).toString(); + // Force HTTP/1 via h1c so upgrade requests don't show up as traces + url = url.replace("http://", "h1c://"); + if (uri.getQuery() != null) { + url += "?" + uri.getQuery(); + } + return url; + } + + private AggregatedHttpRequest request(ServerEndpoint uri, String method) { + return AggregatedHttpRequest.of(HttpMethod.valueOf(method), resolveAddress(uri)); + } + + @ParameterizedTest + @ValueSource(ints = {1, 4, 50}) + void successfulGetRequest(int count) { + String method = "GET"; + AggregatedHttpRequest request = request(SUCCESS, method); + List responses = new ArrayList<>(); + for (int i = 0; i < count; i++) { + responses.add(client.execute(request).aggregate().join()); + } + + for (AggregatedHttpResponse response : responses) { + assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody()); + } + + assertTheTraces(count, null, null, method, SUCCESS, null, responses.get(0)); + } + + @Test + void successfulGetRequestWithParent() { + String method = "GET"; + String traceId = "00000000000000000000000000000123"; + String parentId = "0000000000000456"; + AggregatedHttpRequest request = + AggregatedHttpRequest.of( + // intentionally sending mixed-case "tracePARENT" to make sure that TextMapGetters are + // not case-sensitive + request(SUCCESS, method).headers().toBuilder() + .set("tracePARENT", "00-" + traceId + "-" + parentId + "-01") + .build()); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody()); + + assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response); + } + + @Test + void tracingHeaderIsCaseInsensitive() { + String method = "GET"; + String traceId = "00000000000000000000000000000123"; + String parentId = "0000000000000456"; + AggregatedHttpRequest request = + AggregatedHttpRequest.of( + request(SUCCESS, method).headers().toBuilder() + .set("TRACEPARENT", "00-" + traceId + "-" + parentId + "-01") + .build()); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(SUCCESS.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(SUCCESS.getBody()); + + assertTheTraces(1, traceId, parentId, "GET", SUCCESS, null, response); + } + + @ParameterizedTest + @EnumSource( + value = ServerEndpoint.class, + names = {"SUCCESS", "QUERY_PARAM"}) + void requestWithQueryString(ServerEndpoint endpoint) { + String method = "GET"; + AggregatedHttpRequest request = request(endpoint, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(endpoint.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(endpoint.getBody()); + + assertTheTraces(1, null, null, method, endpoint, null, response); + } + + @Test + void requestWithRedirect() { + assumeTrue(options.testRedirect); + + String method = "GET"; + AggregatedHttpRequest request = request(REDIRECT, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(REDIRECT.getStatus()); + assertThat(response.headers().get("location")) + .satisfiesAnyOf( + location -> assertThat(location).isEqualTo(REDIRECT.getBody()), + location -> + assertThat(new URI(location).normalize().toString()) + .isEqualTo(address.resolve(REDIRECT.getBody()).toString())); + + assertTheTraces(1, null, null, method, REDIRECT, null, response); + } + + @Test + void requestWithError() { + assumeTrue(options.testError); + + String method = "GET"; + AggregatedHttpRequest request = request(ERROR, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(ERROR.getStatus()); + if (options.testErrorBody) { + assertThat(response.contentUtf8()).isEqualTo(ERROR.getBody()); + } + + assertTheTraces(1, null, null, method, ERROR, null, response); + } + + @Test + void requestWithException() { + assumeTrue(options.testException); + + // async servlet tests may produce uncaught exceptions + // awaitility rethrows uncaught exceptions while it is waiting on a condition + Awaitility.doNotCatchUncaughtExceptionsByDefault(); + try { + String method = "GET"; + AggregatedHttpRequest request = request(EXCEPTION, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(EXCEPTION.getStatus()); + + assertTheTraces(1, null, null, method, EXCEPTION, EXCEPTION.body, response); + } finally { + Awaitility.reset(); + } + } + + @Test + void requestForNotFound() { + assumeTrue(options.testNotFound); + + String method = "GET"; + AggregatedHttpRequest request = request(NOT_FOUND, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(NOT_FOUND.getStatus()); + + assertTheTraces(1, null, null, method, NOT_FOUND, null, response); + } + + @Test + void requestWithPathParameter() { + assumeTrue(options.testPathParam); + + String method = "GET"; + AggregatedHttpRequest request = request(PATH_PARAM, method); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(PATH_PARAM.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(PATH_PARAM.getBody()); + + assertTheTraces(1, null, null, method, PATH_PARAM, null, response); + } + + @Test + void captureHttpHeaders() { + assumeTrue(options.testCaptureHttpHeaders); + + AggregatedHttpRequest request = + AggregatedHttpRequest.of( + request(CAPTURE_HEADERS, "GET").headers().toBuilder() + .add(TEST_REQUEST_HEADER, "test") + .build()); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(CAPTURE_HEADERS.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(CAPTURE_HEADERS.getBody()); + + assertTheTraces(1, null, null, "GET", CAPTURE_HEADERS, null, response); + } + + @Test + void captureRequestParameters() { + assumeTrue(options.testCaptureRequestParameters); + + QueryParams formBody = QueryParams.builder().add("test-parameter", "test value õäöü").build(); + AggregatedHttpRequest request = + AggregatedHttpRequest.of( + RequestHeaders.builder(HttpMethod.POST, resolveAddress(CAPTURE_PARAMETERS)) + .contentType(MediaType.FORM_DATA) + .build(), + HttpData.ofUtf8(formBody.toQueryString())); + AggregatedHttpResponse response = client.execute(request).aggregate().join(); + + assertThat(response.status().code()).isEqualTo(CAPTURE_PARAMETERS.getStatus()); + assertThat(response.contentUtf8()).isEqualTo(CAPTURE_PARAMETERS.getBody()); + + assertTheTraces(1, null, null, "POST", CAPTURE_PARAMETERS, null, response); + } + + /** + * This test fires a bunch of parallel request to the fixed backend endpoint. That endpoint is + * supposed to create a new child span in the context of the SERVER span. That child span is + * expected to have an attribute called "test.request.id". The value of that attribute should be + * the value of request's parameter called "id". + * + *

This test then asserts that there is the correct number of traces (one per request executed) + * and that each trace has exactly three spans and both first and the last spans have + * "test.request.id" attribute with equal value. Server span is not going to have that attribute + * because it is not under the control of this test. + * + *

This way we verify that child span created by the server actually corresponds to the client + * request. + */ + @Test + void highConcurrency() throws InterruptedException { + int count = 100; + ServerEndpoint endpoint = INDEXED_CHILD; + CountDownLatch latch = new CountDownLatch(count); + + TextMapPropagator propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator(); + TextMapSetter setter = HttpRequestBuilder::header; + + for (int i = 0; i < count; i++) { + int index = i; + HttpRequestBuilder request = + HttpRequest.builder() + // Force HTTP/1 via h1c so upgrade requests don't show up as traces + .get(endpoint.resolvePath(address).toString().replace("http://", "h1c://")) + .queryParam(ServerEndpoint.ID_PARAMETER_NAME, index); + + testing.runWithSpan( + "client " + index, + () -> { + Span.current().setAttribute(ServerEndpoint.ID_ATTRIBUTE_NAME, index); + propagator.inject(Context.current(), request, setter); + client.execute(request.build()).aggregate().thenRun(latch::countDown); + }); + } + latch.await(); + + assertHighConcurrency(count); + } + + protected void assertHighConcurrency(int count) { + ServerEndpoint endpoint = INDEXED_CHILD; + List> assertions = new ArrayList<>(); + for (int i = 0; i < count; i++) { + assertions.add( + trace -> { + SpanData rootSpan = trace.getSpan(0); + // Traces can be in arbitrary order, let us find out the request id of the current one + int requestId = Integer.parseInt(rootSpan.getName().substring("client ".length())); + + List> spanAssertions = new ArrayList<>(); + spanAssertions.add( + span -> + span.hasName(rootSpan.getName()) + .hasKind(SpanKind.INTERNAL) + .hasNoParent() + .hasAttributesSatisfying( + attrs -> + assertThat(attrs) + .containsEntry(ServerEndpoint.ID_ATTRIBUTE_NAME, requestId))); + spanAssertions.add( + span -> assertIndexedServerSpan(span, requestId).hasParent(rootSpan)); + + if (options.hasHandlerSpan.test(endpoint)) { + spanAssertions.add( + span -> assertHandlerSpan(span, "GET", endpoint).hasParent(trace.getSpan(1))); + } + + int parentIndex = spanAssertions.size() - 1; + spanAssertions.add( + span -> + assertIndexedControllerSpan(span, requestId) + .hasParent(trace.getSpan(parentIndex))); + + trace.hasSpansSatisfyingExactly(spanAssertions); + }); + } + testing.waitAndAssertTraces(assertions); + } + + // NOTE: this method does not currently implement asserting all the span types that groovy + // HttpServerTest does + protected void assertTheTraces( + int size, + String traceId, + String parentId, + String method, + ServerEndpoint endpoint, + String errorMessage, + AggregatedHttpResponse response) { + List> assertions = new ArrayList<>(); + for (int i = 0; i < size; i++) { + assertions.add( + trace -> { + List> spanAssertions = new ArrayList<>(); + spanAssertions.add( + span -> { + assertServerSpan(span, method, endpoint); + if (parentId != null) { + span.hasTraceId(traceId).hasParentSpanId(parentId); + } else { + span.hasNoParent(); + } + }); + + if (options.hasHandlerSpan.test(endpoint)) { + spanAssertions.add( + span -> { + assertHandlerSpan(span, method, endpoint); + span.hasParent(trace.getSpan(0)); + }); + } + + if (endpoint != NOT_FOUND) { + int parentIndex = spanAssertions.size() - 1; + spanAssertions.add( + span -> { + assertControllerSpan(span, errorMessage, options.expectedExceptionClass); + span.hasParent(trace.getSpan(parentIndex)); + }); + } + + if (options.hasResponseSpan.test(endpoint)) { + int parentIndex = spanAssertions.size() - 1; + spanAssertions.add( + span -> { + assertResponseSpan(span, method, endpoint); + span.hasParent(trace.getSpan(parentIndex)); + }); + } + + if (options.hasErrorPageSpans.test(endpoint)) { + spanAssertions.addAll(errorPageSpanAssertions(method, endpoint)); + } + + trace.hasSpansSatisfyingExactly(spanAssertions); + }); + } + + testing.waitAndAssertTraces(assertions); + } + + protected SpanDataAssert assertControllerSpan( + SpanDataAssert span, String errorMessage, Class exceptionClass) { + span.hasName("controller").hasKind(SpanKind.INTERNAL); + if (errorMessage != null) { + span.hasStatus(StatusData.error()); + span.hasException(getExceptionInstance(exceptionClass, errorMessage)); + } + return span; + } + + protected SpanDataAssert assertHandlerSpan( + SpanDataAssert span, String method, ServerEndpoint endpoint) { + throw new UnsupportedOperationException( + "assertHandlerSpan not implemented in " + getClass().getName()); + } + + protected SpanDataAssert assertResponseSpan( + SpanDataAssert span, String method, ServerEndpoint endpoint) { + throw new UnsupportedOperationException( + "assertResponseSpan not implemented in " + getClass().getName()); + } + + protected List> errorPageSpanAssertions( + String method, ServerEndpoint endpoint) { + throw new UnsupportedOperationException( + "errorPageSpanAssertions not implemented in " + getClass().getName()); + } + + protected SpanDataAssert assertServerSpan( + SpanDataAssert span, String method, ServerEndpoint endpoint) { + Set> httpAttributes = options.httpAttributes.apply(endpoint); + + span.hasName(options.expectedServerSpanNameMapper.apply(endpoint, method)) + .hasKind(SpanKind.SERVER); + if (endpoint.status >= 500) { + span.hasStatus(StatusData.error()); + } + + if (endpoint == EXCEPTION && options.hasExceptionOnServerSpan.test(endpoint)) { + span.hasException(getExceptionInstance(options.expectedExceptionClass, endpoint.body)); + } + + span.hasAttributesSatisfying( + attrs -> { + if (httpAttributes.contains(SemanticAttributes.NET_TRANSPORT)) { + assertThat(attrs) + .containsEntry( + SemanticAttributes.NET_TRANSPORT, SemanticAttributes.NetTransportValues.IP_TCP); + } + if (httpAttributes.contains(SemanticAttributes.NET_PEER_PORT)) { + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.NET_PEER_PORT, + value -> + assertThat(value) + .isInstanceOf(Long.class) + .isNotEqualTo(Long.valueOf(port))); + } + if (httpAttributes.contains(SemanticAttributes.NET_PEER_IP) + || attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) { + assertThat(attrs) + .containsEntry(SemanticAttributes.NET_PEER_IP, options.peerIp.apply(endpoint)); + } + + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.HTTP_CLIENT_IP, + entry -> + assertThat(entry) + .satisfiesAnyOf( + value -> assertThat(value).isNull(), + value -> assertThat(value).isEqualTo(TEST_CLIENT_IP))); + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_METHOD, method); + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_STATUS_CODE, endpoint.status); + + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.HTTP_FLAVOR, entry -> assertThat(entry).isIn("1.1", "2.0")); + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_USER_AGENT, TEST_USER_AGENT); + + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_SCHEME, "http"); + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.HTTP_HOST, + entry -> assertThat(entry).isIn("localhost", "localhost:" + port)); + if (endpoint != INDEXED_CHILD) { + assertThat(attrs) + .containsEntry( + SemanticAttributes.HTTP_TARGET, + endpoint.resolvePath(address).getPath() + + (endpoint == QUERY_PARAM ? "?" + endpoint.body : "")); + } + + if (httpAttributes.contains(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) + || attrs.get(SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH) != null) { + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, + entry -> assertThat(entry).isInstanceOf(Long.class)); + } + if (httpAttributes.contains(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH) + || attrs.get(SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH) != null) { + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, + entry -> assertThat(entry).isInstanceOf(Long.class)); + } + if (httpAttributes.contains(SemanticAttributes.HTTP_SERVER_NAME)) { + assertThat(attrs) + .hasEntrySatisfying( + SemanticAttributes.HTTP_SERVER_NAME, + entry -> assertThat(entry).isInstanceOf(String.class)); + } + if (httpAttributes.contains(SemanticAttributes.HTTP_ROUTE)) { + String expectedRoute = options.expectedHttpRoute.apply(endpoint); + if (expectedRoute != null) { + assertThat(attrs).containsEntry(SemanticAttributes.HTTP_ROUTE, expectedRoute); + } + } + + if (endpoint == CAPTURE_HEADERS) { + assertThat(attrs) + .containsEntry("http.request.header.x_test_request", new String[] {"test"}); + assertThat(attrs) + .containsEntry("http.response.header.x_test_response", new String[] {"test"}); + } + if (endpoint == CAPTURE_PARAMETERS) { + assertThat(attrs) + .containsEntry( + "servlet.request.parameter.test_parameter", new String[] {"test value õäöü"}); + } + }); + + return span; + } + + private static Throwable getExceptionInstance(Class exceptionClass, String exceptionMessage) { + try { + Constructor constructor = exceptionClass.getDeclaredConstructor(String.class); + return (Throwable) constructor.newInstance(exceptionMessage); + } catch (NoSuchMethodException + | InstantiationException + | IllegalAccessException + | InvocationTargetException exception) { + throw new IllegalStateException(exception); + } + } + + protected SpanDataAssert assertIndexedServerSpan(SpanDataAssert span, int requestId) { + ServerEndpoint endpoint = INDEXED_CHILD; + String method = "GET"; + assertServerSpan(span, method, endpoint); + + span.hasAttributesSatisfying( + attrs -> + assertThat(attrs) + .containsEntry( + SemanticAttributes.HTTP_TARGET, + endpoint.resolvePath(address).getPath() + "?id=" + requestId)); + + return span; + } + + protected SpanDataAssert assertIndexedControllerSpan(SpanDataAssert span, int requestId) { + span.hasName("controller") + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfying( + attrs -> assertThat(attrs).containsEntry(ServerEndpoint.ID_ATTRIBUTE_NAME, requestId)); + return span; + } + + public String expectedServerSpanName(ServerEndpoint endpoint, String method) { + String route = expectedHttpRoute(endpoint); + return route == null ? "HTTP " + method : route; + } + + public String expectedHttpRoute(ServerEndpoint endpoint) { + // no need to compute route if we're not expecting it + if (!options.httpAttributes.apply(endpoint).contains(SemanticAttributes.HTTP_ROUTE)) { + return null; + } + + switch (endpoint) { + case NOT_FOUND: + return null; + case PATH_PARAM: + return options.contextPath + "/path/:id/param"; + default: + return endpoint.resolvePath(address).getPath(); + } + } + + final void setTesting(InstrumentationTestRunner testing, WebClient client, int port) { + setTesting(testing, client, port, null); + } + + final void setTesting( + InstrumentationTestRunner testing, WebClient client, int port, URI address) { + this.testing = testing; + this.client = client; + this.port = port; + this.address = address; + } +} diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientInstrumentationExtension.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientInstrumentationExtension.java index 26d3acb70827..6567d5a8145d 100644 --- a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientInstrumentationExtension.java +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientInstrumentationExtension.java @@ -54,7 +54,7 @@ public void beforeEach(ExtensionContext extensionContext) { if (!(testInstance instanceof AbstractHttpClientTest)) { throw new AssertionError( - "HttpClientLibraryInstrumentationExtension can only be applied to a subclass of " + "HttpClientInstrumentationExtension can only be applied to a subclass of " + "AbstractHttpClientTest"); } diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerInstrumentationExtension.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerInstrumentationExtension.java new file mode 100644 index 000000000000..4098f8dd4e39 --- /dev/null +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerInstrumentationExtension.java @@ -0,0 +1,76 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.testing.junit.http; + +import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.TEST_CLIENT_IP; +import static io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest.TEST_USER_AGENT; + +import io.opentelemetry.instrumentation.test.utils.PortUtils; +import io.opentelemetry.instrumentation.testing.AgentTestRunner; +import io.opentelemetry.instrumentation.testing.InstrumentationTestRunner; +import io.opentelemetry.instrumentation.testing.LibraryTestRunner; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.testing.internal.armeria.client.ClientFactory; +import io.opentelemetry.testing.internal.armeria.client.WebClient; +import io.opentelemetry.testing.internal.armeria.client.logging.LoggingClient; +import io.opentelemetry.testing.internal.armeria.common.HttpHeaderNames; +import java.time.Duration; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * A {@link InstrumentationExtension} which sets up infrastructure, such as a test HTTP client, for + * {@link AbstractHttpServerTest}. + */ +public final class HttpServerInstrumentationExtension extends InstrumentationExtension { + + /** + * Returns a {@link InstrumentationExtension} to be used with {@link AbstractHttpClientTest} for + * javaagent instrumentation. + */ + public static InstrumentationExtension forAgent() { + return new HttpServerInstrumentationExtension(AgentTestRunner.instance()); + } + + /** + * Returns a {@link InstrumentationExtension} to be used with {@link AbstractHttpClientTest} for + * library instrumentation. + */ + public static InstrumentationExtension forLibrary() { + return new HttpServerInstrumentationExtension(LibraryTestRunner.instance()); + } + + private final int port; + private final WebClient client; + + private HttpServerInstrumentationExtension(InstrumentationTestRunner runner) { + super(runner); + + port = PortUtils.findOpenPort(); + client = + WebClient.builder() + .responseTimeout(Duration.ofMinutes(1)) + .writeTimeout(Duration.ofMinutes(1)) + .factory(ClientFactory.builder().connectTimeout(Duration.ofMinutes(1)).build()) + .setHeader(HttpHeaderNames.USER_AGENT, TEST_USER_AGENT) + .setHeader(HttpHeaderNames.X_FORWARDED_FOR, TEST_CLIENT_IP) + .decorator(LoggingClient.newDecorator()) + .build(); + } + + @Override + public void beforeAll(ExtensionContext extensionContext) throws Exception { + super.beforeAll(extensionContext); + Object testInstance = extensionContext.getRequiredTestInstance(); + + if (!(testInstance instanceof AbstractHttpServerTest)) { + throw new AssertionError( + "HttpServerInstrumentationExtension can only be applied to a subclass of " + + "AbstractHttpServerTest"); + } + + ((AbstractHttpServerTest) testInstance).setTesting(getTestRunner(), client, port); + } +} diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java new file mode 100644 index 000000000000..6baf56173587 --- /dev/null +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpServerTestOptions.java @@ -0,0 +1,151 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.testing.junit.http; + +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 peerIp = unused -> "127.0.0.1"; + String contextPath = ""; + Class expectedExceptionClass = Exception.class; + + 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() {} + + public HttpServerTestOptions setHttpAttributes( + Function>> httpAttributes) { + this.httpAttributes = httpAttributes; + return this; + } + + public HttpServerTestOptions setExpectedServerSpanNameMapper( + BiFunction expectedServerSpanNameMapper) { + this.expectedServerSpanNameMapper = expectedServerSpanNameMapper; + return this; + } + + public HttpServerTestOptions setExpectedHttpRoute( + Function expectedHttpRoute) { + this.expectedHttpRoute = expectedHttpRoute; + return this; + } + + public HttpServerTestOptions setPeerIp(Function peerIp) { + this.peerIp = peerIp; + return this; + } + + public HttpServerTestOptions setContextPath(String contextPath) { + this.contextPath = contextPath; + return this; + } + + public HttpServerTestOptions setExpectedExceptionClass( + Class expectedExceptionClass) { + this.expectedExceptionClass = expectedExceptionClass; + return this; + } + + public HttpServerTestOptions setHasHandlerSpan(Predicate hasHandlerSpan) { + this.hasHandlerSpan = hasHandlerSpan; + return this; + } + + public HttpServerTestOptions setHasResponseSpan(Predicate hasResponseSpan) { + this.hasResponseSpan = hasResponseSpan; + return this; + } + + public HttpServerTestOptions setHasErrorPageSpans(Predicate hasErrorPageSpans) { + this.hasErrorPageSpans = hasErrorPageSpans; + return this; + } + + public HttpServerTestOptions setHasExceptionOnServerSpan( + Predicate hasExceptionOnServerSpan) { + this.hasExceptionOnServerSpan = hasExceptionOnServerSpan; + return this; + } + + public HttpServerTestOptions setTestRedirect(boolean testRedirect) { + this.testRedirect = testRedirect; + return this; + } + + public HttpServerTestOptions setTestError(boolean testError) { + this.testError = testError; + return this; + } + + public HttpServerTestOptions setTestErrorBody(boolean testErrorBody) { + this.testErrorBody = testErrorBody; + return this; + } + + public HttpServerTestOptions setTestException(boolean testException) { + this.testException = testException; + return this; + } + + public HttpServerTestOptions setTestNotFound(boolean testNotFound) { + this.testNotFound = testNotFound; + return this; + } + + public HttpServerTestOptions setTestPathParam(boolean testPathParam) { + this.testPathParam = testPathParam; + return this; + } + + public HttpServerTestOptions setTestCaptureHttpHeaders(boolean testCaptureHttpHeaders) { + this.testCaptureHttpHeaders = testCaptureHttpHeaders; + return this; + } + + public HttpServerTestOptions setTestCaptureRequestParameters( + boolean testCaptureRequestParameters) { + this.testCaptureRequestParameters = testCaptureRequestParameters; + return this; + } +} diff --git a/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/ServerEndpoint.java b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/ServerEndpoint.java new file mode 100644 index 000000000000..bccb9b2e323f --- /dev/null +++ b/testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/ServerEndpoint.java @@ -0,0 +1,118 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.testing.junit.http; + +import io.opentelemetry.api.trace.Span; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; + +public enum ServerEndpoint { + SUCCESS("success", 200, "success"), + REDIRECT("redirect", 302, "/redirected"), + ERROR("error-status", 500, "controller error"), // "error" is a special path for some frameworks + EXCEPTION("exception", 500, "controller exception"), + NOT_FOUND("notFound", 404, "not found"), + CAPTURE_HEADERS("captureHeaders", 200, "headers captured"), + CAPTURE_PARAMETERS("captureParameters", 200, "parameters captured"), + + // TODO: add tests for the following cases: + QUERY_PARAM("query?some=query", 200, "some=query"), + // OkHttp never sends the fragment in the request, so these cases don't work. + // FRAGMENT_PARAM("fragment#some-fragment", 200, "some-fragment"), + // QUERY_FRAGMENT_PARAM("query/fragment?some=query#some-fragment", 200, + // "some=query#some-fragment"), + PATH_PARAM("path/123/param", 200, "123"), + AUTH_REQUIRED("authRequired", 200, null), + LOGIN("login", 302, null), + AUTH_ERROR("basicsecured/endpoint", 401, null), + INDEXED_CHILD("child", 200, ""); + + public static final String ID_ATTRIBUTE_NAME = "test.request.id"; + public static final String ID_PARAMETER_NAME = "id"; + + private final URI uriObj; + private final String path; + final String query; + final String fragment; + final int status; + final String body; + + public String getQuery() { + return query; + } + + public String getFragment() { + return fragment; + } + + public int getStatus() { + return status; + } + + public String getBody() { + return body; + } + + ServerEndpoint(String uri, int status, String body) { + this.uriObj = URI.create(uri); + this.path = uriObj.getPath(); + this.query = uriObj.getQuery(); + this.fragment = uriObj.getFragment(); + this.status = status; + this.body = body; + } + + public String getPath() { + return "/" + path; + } + + public String rawPath() { + return path; + } + + URI resolvePath(URI address) { + return address.resolve(path); + } + + URI resolve(URI address) { + return address.resolve(uriObj); + } + + URI resolveWithoutFragment(URI address) throws URISyntaxException { + URI uri = resolve(address); + return new URI( + uri.getScheme(), null, uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), null); + } + + /** + * Populates custom test attributes for the {@link + * io.opentelemetry.instrumentation.test.base.HttpServerTest#controller} span (which must be the + * current span when this is called) based on URL parameters. Required for {@link #INDEXED_CHILD}. + */ + public void collectSpanAttributes(ServerEndpoint.UrlParameterProvider parameterProvider) { + if (this == INDEXED_CHILD) { + String value = parameterProvider.getParameter(ID_PARAMETER_NAME); + + if (value != null) { + Span.current().setAttribute(ID_ATTRIBUTE_NAME, Long.parseLong(value)); + } + } + } + + private static final Map PATH_MAP = + Arrays.stream(values()).collect(Collectors.toMap(x -> x.getPath(), x -> x)); + + public static ServerEndpoint forPath(String path) { + return PATH_MAP.get(path); + } + + public interface UrlParameterProvider { + String getParameter(String name); + } +}