add spring tests
ADD
instrumentation/restlet/restlet-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/spring/SpringBeanRouterTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.restlet.v2_0.spring
+
+import io.opentelemetry.instrumentation.restlet.v2_0.spring.AbstractSpringServerTest
+import io.opentelemetry.instrumentation.test.AgentTestTrait
+
+class SpringBeanRouterTest extends AbstractSpringServerTest implements AgentTestTrait {
+ @Override
+ String getConfigurationName() {
+ return "springBeanRouterConf.xml"
+ }
+
+}

ADD
instrumentation/restlet/restlet-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/restlet/v2_0/spring/SpringRouterTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.javaagent.instrumentation.restlet.v2_0.spring
+
+import io.opentelemetry.instrumentation.restlet.v2_0.spring.AbstractSpringServerTest
+import io.opentelemetry.instrumentation.test.AgentTestTrait
+
+class SpringRouterTest extends AbstractSpringServerTest implements AgentTestTrait {
+ @Override
+ String getConfigurationName() {
+ return "springRouterConf.xml"
+ }
+
+}

ADD
instrumentation/restlet/restlet-2.0/library/src/test/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/AbstractSpringServerLibraryTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.restlet.v2_0.spring
+
+import io.opentelemetry.instrumentation.restlet.v2_0.RestletTracing
+import io.opentelemetry.instrumentation.test.LibraryTestTrait
+import org.restlet.Request
+import org.restlet.Response
+import org.restlet.Restlet
+import org.restlet.data.Status
+import org.restlet.engine.application.StatusFilter
+import org.restlet.routing.Route
+import org.restlet.routing.Template
+import org.restlet.routing.TemplateRoute
+import org.restlet.service.StatusService
+import org.restlet.util.RouteList
+
+import java.lang.reflect.Modifier
+
+abstract class AbstractSpringServerLibraryTest extends AbstractSpringServerTest implements LibraryTestTrait {
+ @Override
+ Restlet wrapRestlet(Restlet restlet, String path) {
+
+ RestletTracing tracing = RestletTracing.builder(openTelemetry)
+ .captureHttpHeaders(capturedHttpHeadersForTesting())
+ .build()
+
+ def tracingFilter = tracing.newFilter(path)
+ def statusFilter = new StatusFilter(component.getContext(), new StatusService())
+
+ tracingFilter.setNext(statusFilter)
+ statusFilter.setNext(restlet)
+
+ return tracingFilter
+ }
+
+
+ @Override
+ void setupRouting() {
+ //for latestDepTest
+ def routeClass = Modifier.isAbstract(Route.getModifiers()) ? TemplateRoute : Route
+
+ List<Route> routes = []
+ for (Route route : router.getRoutes()) {
+ def pattern = route.getTemplate().getPattern()
+ routes.add((Route) routeClass.newInstance(router, pattern, wrapRestlet(route.getNext(), pattern)))
+ }
+
+ def notFoundRestlet = new Restlet(router.getContext()) {
+ @Override
+ void handle(Request request, Response response) {
+ super.handle(request, response)
+ response.setStatus(Status.CLIENT_ERROR_NOT_FOUND)
+ }
+ }
+ notFoundRestlet = wrapRestlet(notFoundRestlet, "/*")
+
+ def route = (Route) routeClass.newInstance(router, "/", notFoundRestlet)
+ route.setMatchingMode(Template.MODE_STARTS_WITH)
+ routes.add(route)
+
+ router.setRoutes(new RouteList(routes))
+
+ host.attach(router)
+
+ }
+}

ADD
instrumentation/restlet/restlet-2.0/library/src/test/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/SpringBeanRouterTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.restlet.v2_0.spring
+
+class SpringBeanRouterTest extends AbstractSpringServerLibraryTest {
+ @Override
+ String getConfigurationName() {
+ return "springBeanRouterConf.xml"
+ }
+
+}

ADD
instrumentation/restlet/restlet-2.0/library/src/test/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/SpringRouterTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.restlet.v2_0.spring
+
+class SpringRouterTest extends AbstractSpringServerLibraryTest {
+
+ @Override
+ String getConfigurationName() {
+ return "springRouterConf.xml"
+ }
+
+}

MODIFY
instrumentation/restlet/restlet-2.0/testing/build.gradle.kts
instrumentation/restlet/restlet-2.0/testing/build.gradle.kts
@@ -12,6 +12,7 @@ dependencies {
api(project(":testing-common"))
implementation("org.restlet.jse:org.restlet:2.0.2")
+ implementation("org.restlet.jse:org.restlet.ext.spring:2.0.2")
implementation("org.codehaus.groovy:groovy-all")
implementation("io.opentelemetry:opentelemetry-api")

ADD
instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/RestletAppTestBase.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.restlet.v2_0
+
+import org.restlet.data.Form
+import org.restlet.data.Reference
+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.test.base.HttpServerTest.controller
+
+class RestletAppTestBase {
+
+ static class SuccessResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(SUCCESS) {
+ return SUCCESS.getBody()
+ }
+ }
+
+ }
+
+ static class ErrorResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(ERROR) {
+ getResponse().setStatus(Status.valueOf(ERROR.getStatus()), ERROR.getBody())
+ return ERROR.getBody()
+ }
+ }
+
+ }
+
+ static class ExceptionResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(EXCEPTION) {
+ throw new Exception(EXCEPTION.getBody())
+ }
+ }
+
+ }
+
+ static class QueryParamResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(QUERY_PARAM) {
+ return QUERY_PARAM.getBody()
+ }
+ }
+
+ }
+
+ static class PathParamResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(PATH_PARAM) {
+ return PATH_PARAM.getBody()
+ }
+ }
+
+ }
+
+ static class RedirectResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(REDIRECT) {
+ redirectSeeOther(new Reference(getRootRef().toString() + REDIRECT.getBody()))
+ response.setStatus(Status.valueOf(REDIRECT.getStatus()))
+ return ""
+ }
+ }
+
+ }
+
+ static class CaptureHeadersResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(CAPTURE_HEADERS) {
+ def requestHeaders = request.getAttributes().get("org.restlet.http.headers")
+ def responseHeaders
+
+ try {
+ def headerClass = Class.forName("org.restlet.data.Header")
+ def seriesClass = Class.forName("org.restlet.util.Series")
+ //to avoid constructor error (Series is abstract in 2.0.x)
+ responseHeaders = response.getAttributes().computeIfAbsent("org.restlet.http.headers", { seriesClass.newInstance(headerClass) })
+
+ } catch (ClassNotFoundException | NoClassDefFoundError e) {
+
+ responseHeaders = response.getAttributes().computeIfAbsent("org.restlet.http.headers", { new Form() })
+ }
+
+ responseHeaders.add("X-Test-Response", requestHeaders.getValues("X-Test-Request"))
+ return CAPTURE_HEADERS.getBody()
+ }
+ }
+
+ }
+
+
+ static class IndexedChildResource extends ServerResource {
+
+ @Get("txt")
+ String represent() {
+ controller(INDEXED_CHILD) {
+ INDEXED_CHILD.collectSpanAttributes {
+ request.getOriginalRef().getQueryAsForm().getFirst(it).getValue()
+ }
+ //INDEXED_CHILD.getBody() returns an empty string, in which case Restlet sets status to 204
+ return "child"
+ }
+ }
+
+ }
+
+}

ADD
instrumentation/restlet/restlet-2.0/testing/src/main/groovy/io/opentelemetry/instrumentation/restlet/v2_0/spring/AbstractSpringServerTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+package io.opentelemetry.instrumentation.restlet.v2_0.spring
+
+import io.opentelemetry.instrumentation.restlet.v2_0.AbstractRestletServerTest
+import org.restlet.Component
+import org.restlet.Server
+import org.restlet.routing.Router
+import org.springframework.context.support.ClassPathXmlApplicationContext
+
+abstract class AbstractSpringServerTest extends AbstractRestletServerTest {
+
+ Router router
+
+ abstract String getConfigurationName()
+
+ @Override
+ Server setupServer(Component component) {
+ def context = new ClassPathXmlApplicationContext(getConfigurationName())
+ router = (Router) context.getBean("testRouter")
+ def server = (Server) context.getBean("testServer", "http", port)
+ component.getServers().add(server)
+ return server
+ }
+
+ @Override
+ void setupRouting() {
+ host.attach(router)
+ }
+
+}

ADD
instrumentation/restlet/restlet-2.0/testing/src/main/resources/springBeanRouterConf.xml
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="testServer" class="org.restlet.ext.spring.SpringServer" scope="prototype">
+ <constructor-arg value="http"/>
+ </bean>
+
+ <bean name="testRouter" class="org.restlet.ext.spring.SpringBeanRouter"/>
+
+ <bean name="/success" scope="prototype" id="successResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$SuccessResource"/>
+ <bean name="/error-status" scope="prototype" id="errorResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$ErrorResource"/>
+ <bean name="/exception" scope="prototype" id="exceptionResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$ExceptionResource"/>
+ <bean name="/query" scope="prototype" id="queryParamResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$QueryParamResource"/>
+ <bean name="/path/{id}/param" scope="prototype" id="pathParamResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$PathParamResource"/>
+ <bean name="/redirect" scope="prototype" id="redirectResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$RedirectResource"/>
+ <bean name="/captureHeaders" scope="prototype" id="captureHeadersResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$CaptureHeadersResource"/>
+ <bean name="/child" scope="prototype" id="indexedChildResource"
+ class="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$IndexedChildResource"/>
+
+</beans>
\ No newline at end of file

ADD
instrumentation/restlet/restlet-2.0/testing/src/main/resources/springRouterConf.xml
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <bean id="testServer" class="org.restlet.ext.spring.SpringServer" scope="prototype">
+ <constructor-arg value="http"/>
+ </bean>
+
+ <bean name="testRouter" class="org.restlet.ext.spring.SpringRouter">
+
+ <property name="attachments">
+ <map>
+ <entry key="/success"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$SuccessResource"/>
+ <entry key="/error-status"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$ErrorResource"/>
+ <entry key="/exception"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$ExceptionResource"/>
+ <entry key="/query"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$QueryParamResource"/>
+ <entry key="/path/{id}/param"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$PathParamResource"/>
+ <entry key="/redirect"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$RedirectResource"/>
+ <entry key="/captureHeaders"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$CaptureHeadersResource"/>
+ <entry key="/child"
+ value="io.opentelemetry.instrumentation.restlet.v2_0.RestletAppTestBase$IndexedChildResource"/>
+ </map>
+ </property>
+ </bean>
+
+</beans>
\ No newline at end of file

add spring tests (#4670)