From 3cf37dd781effcfe816deda6f5545a4f37184792 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 24 Oct 2024 14:57:33 +0300 Subject: [PATCH] Convert jaxws tests to java (#12509) Co-authored-by: Jay DeLuca --- .../src/test/groovy/Axis2JaxWsTest.groovy | 27 -- .../axis2/Axis2JaxWs2Test.java | 50 ++++ .../axis2}/CustomJaxWsDeployer.java | 7 +- .../src/main/groovy/AbstractJaxWsTest.groovy | 207 --------------- .../main/groovy/hello/BaseHelloService.groovy | 16 -- .../src/main/groovy/hello/HelloService.groovy | 24 -- .../main/groovy/hello/HelloServiceImpl.groovy | 19 -- .../jaxws/v2_0/AbstractJaxWs2Test.java | 235 ++++++++++++++++++ .../jaxws/v2_0/hello/BaseHelloService.java | 16 ++ .../jaxws/v2_0/hello/HelloService.java | 23 ++ .../jaxws/v2_0/hello/HelloServiceImpl.java | 23 ++ .../src/test/groovy/MetroJaxWsTest.groovy | 7 - .../metro/MetroJaxWs2Test.java | 10 + .../resources/test-app/WEB-INF/sun-jaxws.xml | 4 +- .../jaxws/v2_0/JaxWsAnnotationsTest.groovy | 30 --- .../jaxws/v2_0/JaxWsAnnotationsTest.java | 38 +++ .../src/main/groovy/AbstractJaxWsTest.groovy | 187 -------------- .../main/groovy/hello/BaseHelloService.groovy | 16 -- .../src/main/groovy/hello/HelloService.groovy | 24 -- .../main/groovy/hello/HelloServiceImpl.groovy | 19 -- .../jaxws/v3_0/AbstractJaxWs3Test.java | 137 ++++++++++ .../jaxws/v3_0/hello/HelloService.java | 19 ++ .../jaxws/v3_0/hello/HelloServiceImpl.java | 23 ++ .../src/main/schema/hello.xsd | 16 -- .../src/test/groovy/CxfJaxWsTest.groovy | 7 - .../src/test/groovy/TestWsServlet.groovy | 37 --- .../instrumentation/cxf/CxfJaxWs3Test.java | 10 + .../instrumentation/cxf/TestWsServlet.java | 43 ++++ .../test/resources/test-app/WEB-INF/web.xml | 2 +- .../src/test/groovy/MetroJaxWsTest.groovy | 7 - .../metro/MetroJaxWs3Test.java | 10 + .../resources/test-app/WEB-INF/sun-jaxws.xml | 4 +- .../src/test/groovy/CxfJaxWsTest.groovy | 7 - .../src/test/groovy/TestWsServlet.groovy | 37 --- .../instrumentation/cxf/CxfJaxWs2Test.java | 10 + .../instrumentation/cxf/TestWsServlet.java | 43 ++++ .../test/resources/test-app/WEB-INF/web.xml | 2 +- .../jaxws/jws/v1_1/JwsAnnotationsTest.groovy | 78 ------ .../jaxws/jws/v1_1/JwsAnnotationsTest.java | 91 +++++++ 39 files changed, 792 insertions(+), 773 deletions(-) delete mode 100644 instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/groovy/Axis2JaxWsTest.groovy create mode 100644 instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2JaxWs2Test.java rename instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/{test => io/opentelemetry/javaagent/instrumentation/axis2}/CustomJaxWsDeployer.java (60%) delete mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy delete mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy delete mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloService.groovy delete mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy create mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/AbstractJaxWs2Test.java create mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/BaseHelloService.java create mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloService.java create mode 100644 instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloServiceImpl.java delete mode 100644 instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy create mode 100644 instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs2Test.java delete mode 100644 instrumentation/jaxws/jaxws-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.groovy create mode 100644 instrumentation/jaxws/jaxws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.java delete mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy delete mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy delete mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloService.groovy delete mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy create mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/AbstractJaxWs3Test.java create mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloService.java create mode 100644 instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloServiceImpl.java delete mode 100644 instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/CxfJaxWsTest.groovy delete mode 100644 instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/TestWsServlet.groovy create mode 100644 instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs3Test.java create mode 100644 instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java delete mode 100644 instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy create mode 100644 instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs3Test.java delete mode 100644 instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/CxfJaxWsTest.groovy delete mode 100644 instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/TestWsServlet.groovy create mode 100644 instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs2Test.java create mode 100644 instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java delete mode 100644 instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.groovy create mode 100644 instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.java diff --git a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/groovy/Axis2JaxWsTest.groovy b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/groovy/Axis2JaxWsTest.groovy deleted file mode 100644 index acbbd52b5794..000000000000 --- a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/groovy/Axis2JaxWsTest.groovy +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import java.nio.charset.StandardCharsets - -class Axis2JaxWsTest extends AbstractJaxWsTest { - static { - updateConfiguration() - } - - static updateConfiguration() { - // read default configuration file inside axis2 jar - String configuration = Axis2JaxWsTest.getClassLoader().getResourceAsStream("axis2.xml").getText(StandardCharsets.UTF_8.name()) - - // customize deployer so axis2 can find our services - configuration = configuration.replace("org.apache.axis2.jaxws.framework.JAXWSDeployer", "test.CustomJaxWsDeployer") - configuration = configuration.replace("", "ws") - configuration = configuration.replace("false", "true") - configuration = configuration.replace("", "") - - File configurationDirectory = new File("build/axis-conf/") - configurationDirectory.mkdirs() - new File(configurationDirectory, "axis2.xml").setText(configuration, StandardCharsets.UTF_8.name()) - } -} diff --git a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2JaxWs2Test.java b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2JaxWs2Test.java new file mode 100644 index 000000000000..b71766ee47b9 --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2JaxWs2Test.java @@ -0,0 +1,50 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.axis2; + +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.AbstractJaxWs2Test; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; + +class Axis2JaxWs2Test extends AbstractJaxWs2Test { + static { + try { + updateConfiguration(); + } catch (IOException exception) { + throw new IllegalStateException(exception); + } + } + + private static void updateConfiguration() throws IOException { + // read default configuration file inside axis2 jar + String configuration = + IOUtils.toString( + Axis2JaxWs2Test.class.getClassLoader().getResourceAsStream("axis2.xml"), + StandardCharsets.UTF_8); + + // customize deployer so axis2 can find our services + configuration = + configuration.replace( + "org.apache.axis2.jaxws.framework.JAXWSDeployer", CustomJaxWsDeployer.class.getName()); + configuration = + configuration.replace( + "", + "ws"); + configuration = + configuration.replace( + "false", + "true"); + configuration = configuration.replace("", ""); + + File configurationDirectory = new File("build/axis-conf/"); + configurationDirectory.mkdirs(); + FileUtils.writeStringToFile( + new File(configurationDirectory, "axis2.xml"), configuration, StandardCharsets.UTF_8); + } +} diff --git a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/test/CustomJaxWsDeployer.java b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/CustomJaxWsDeployer.java similarity index 60% rename from instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/test/CustomJaxWsDeployer.java rename to instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/CustomJaxWsDeployer.java index d2bfc2617746..d79d3bde0979 100644 --- a/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/test/CustomJaxWsDeployer.java +++ b/instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/axis2/CustomJaxWsDeployer.java @@ -3,8 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package test; +package io.opentelemetry.javaagent.instrumentation.axis2; +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello.HelloService; +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello.HelloServiceImpl; import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -17,6 +19,7 @@ public class CustomJaxWsDeployer extends JAXWSDeployer { @SuppressWarnings("NonApiType") // errorprone bug that it doesn't recognize this is an override protected ArrayList getClassesInWebInfDirectory(File file) { // help axis find our webservice classes - return new ArrayList<>(Arrays.asList("hello.HelloService", "hello.HelloServiceImpl")); + return new ArrayList<>( + Arrays.asList(HelloService.class.getName(), HelloServiceImpl.class.getName())); } } diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy deleted file mode 100644 index 5f8040ae13d8..000000000000 --- a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.instrumentation.test.asserts.TraceAssert -import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait -import io.opentelemetry.sdk.trace.data.SpanData -import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes -import io.opentelemetry.test.hello_web_service.Hello2Request -import io.opentelemetry.test.hello_web_service.HelloRequest -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.util.resource.Resource -import org.eclipse.jetty.webapp.WebAppContext -import org.springframework.oxm.jaxb.Jaxb2Marshaller -import org.springframework.util.ClassUtils -import org.springframework.ws.client.core.WebServiceTemplate -import org.springframework.ws.soap.client.SoapFaultClientException -import spock.lang.Shared -import spock.lang.Unroll - -import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.api.trace.StatusCode.ERROR - -abstract class AbstractJaxWsTest extends AgentInstrumentationSpecification implements HttpServerTestTrait { - - @Shared - private Jaxb2Marshaller marshaller = new Jaxb2Marshaller() - - @Shared - protected WebServiceTemplate webServiceTemplate = new WebServiceTemplate(marshaller) - - def setupSpec() { - setupServer() - - marshaller.setPackagesToScan(ClassUtils.getPackageName(HelloRequest)) - marshaller.afterPropertiesSet() - } - - def cleanupSpec() { - cleanupServer() - } - - @Override - Server startServer(int port) { - List configurationClasses = new ArrayList<>() - Collections.addAll(configurationClasses, WebAppContext.getDefaultConfigurationClasses()) - - WebAppContext webAppContext = new WebAppContext() - webAppContext.setContextPath(getContextPath()) - webAppContext.setConfigurationClasses(configurationClasses) - // set up test application - webAppContext.setBaseResource(Resource.newSystemResource("test-app")) - webAppContext.getMetaData().getWebInfClassesDirs().add(Resource.newClassPathResource("/")) - - def jettyServer = new Server(port) - jettyServer.connectors.each { - it.setHost('localhost') - } - - jettyServer.setHandler(webAppContext) - jettyServer.start() - - return jettyServer - } - - @Override - void stopServer(Server server) { - server.stop() - server.destroy() - } - - @Override - String getContextPath() { - return "/jetty-context" - } - - String getServiceAddress(String serviceName) { - return address.resolve("ws/" + serviceName).toString() - } - - def makeRequest(methodName, name) { - Object request = null - if ("hello" == methodName) { - request = new HelloRequest(name: name) - } else if ("hello2" == methodName) { - request = new Hello2Request(name: name) - } else { - throw new IllegalArgumentException(methodName) - } - - return webServiceTemplate.marshalSendAndReceive(getServiceAddress("HelloService"), request) - } - - @Unroll - def "test #methodName"() { - setup: - def response = makeRequest(methodName, "Test") - - expect: - response.getMessage() == "Hello Test" - - and: - def spanCount = 2 - if (hasAnnotationHandlerSpan(methodName)) { - spanCount++ - } - assertTraces(1) { - trace(0, spanCount) { - serverSpan(it, 0, serverSpanName(methodName)) - handlerSpan(it, 1, methodName, span(0)) - if (hasAnnotationHandlerSpan(methodName)) { - annotationHandlerSpan(it, 2, methodName, span(1)) - } - } - } - - where: - methodName << ["hello", "hello2"] - } - - @Unroll - def "test #methodName exception"() { - when: - makeRequest(methodName, "exception") - - then: - def error = thrown(SoapFaultClientException) - error.getMessage() == "hello exception" - - and: - def spanCount = 2 - if (hasAnnotationHandlerSpan(methodName)) { - spanCount++ - } - def expectedException = new Exception("hello exception") - assertTraces(1) { - trace(0, spanCount) { - serverSpan(it, 0, serverSpanName(methodName), expectedException) - handlerSpan(it, 1, methodName, span(0), expectedException) - if (hasAnnotationHandlerSpan(methodName)) { - annotationHandlerSpan(it, 2, methodName, span(1), expectedException) - } - } - } - - where: - methodName << ["hello", "hello2"] - } - - def hasAnnotationHandlerSpan(methodName) { - methodName == "hello" - } - - def serverSpanName(String operation) { - return getContextPath() + "/ws/HelloService/" + operation - } - - static serverSpan(TraceAssert trace, int index, String operation, Throwable exception = null) { - trace.span(index) { - hasNoParent() - name operation - kind SERVER - if (exception != null) { - status ERROR - } - } - } - - static handlerSpan(TraceAssert trace, int index, String operation, Object parentSpan = null, Throwable exception = null) { - trace.span(index) { - if (parentSpan == null) { - hasNoParent() - } else { - childOf((SpanData) parentSpan) - } - name "HelloService/" + operation - kind INTERNAL - if (exception) { - status ERROR - errorEvent(exception.class, exception.message) - } - } - } - - static annotationHandlerSpan(TraceAssert trace, int index, String methodName, Object parentSpan = null, Throwable exception = null) { - trace.span(index) { - if (parentSpan == null) { - hasNoParent() - } else { - childOf((SpanData) parentSpan) - } - name "HelloServiceImpl." + methodName - kind INTERNAL - if (exception) { - status ERROR - errorEvent(exception.class, exception.message) - } - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" "hello.HelloServiceImpl" - "$CodeIncubatingAttributes.CODE_FUNCTION" methodName - } - } - } -} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy deleted file mode 100644 index a2d8da1e8a11..000000000000 --- a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package hello - -class BaseHelloService { - - String hello2(String name) { - if ("exception" == name) { - throw new Exception("hello exception") - } - return "Hello " + name - } -} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloService.groovy b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloService.groovy deleted file mode 100644 index 93ee2e9dcc3c..000000000000 --- a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloService.groovy +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package hello - -import javax.jws.WebParam -import javax.jws.WebResult -import javax.jws.WebService -import javax.xml.ws.RequestWrapper - -@WebService(targetNamespace = "http://opentelemetry.io/test/hello-web-service") -interface HelloService { - - @RequestWrapper(localName = "helloRequest") - @WebResult(name = "message") - String hello(@WebParam(name = "name") String name) - - @RequestWrapper(localName = "hello2Request") - @WebResult(name = "message") - String hello2(@WebParam(name = "name") String name) - -} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy deleted file mode 100644 index 781c4d9982a5..000000000000 --- a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package hello - -import javax.jws.WebService - -@WebService(serviceName = "HelloService", endpointInterface = "hello.HelloService", targetNamespace = "http://opentelemetry.io/test/hello-web-service") -class HelloServiceImpl extends BaseHelloService implements HelloService { - - String hello(String name) { - if ("exception" == name) { - throw new Exception("hello exception") - } - return "Hello " + name - } -} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/AbstractJaxWs2Test.java b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/AbstractJaxWs2Test.java new file mode 100644 index 000000000000..3cd815de87ff --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/AbstractJaxWs2Test.java @@ -0,0 +1,235 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello.HelloServiceImpl; +import io.opentelemetry.sdk.testing.assertj.SpanDataAssert; +import io.opentelemetry.sdk.trace.data.StatusData; +import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes; +import io.opentelemetry.test.hello_web_service.Hello2Request; +import io.opentelemetry.test.hello_web_service.Hello2Response; +import io.opentelemetry.test.hello_web_service.HelloRequest; +import io.opentelemetry.test.hello_web_service.HelloResponse; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.function.Consumer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.webapp.WebAppContext; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; +import org.springframework.util.ClassUtils; +import org.springframework.ws.client.core.WebServiceTemplate; +import org.springframework.ws.soap.client.SoapFaultClientException; + +public class AbstractJaxWs2Test extends AbstractHttpServerUsingTest { + @RegisterExtension + public static final InstrumentationExtension testing = + HttpServerInstrumentationExtension.forAgent(); + + private final Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + protected final WebServiceTemplate webServiceTemplate = new WebServiceTemplate(marshaller); + + @BeforeAll + protected void setUp() throws Exception { + marshaller.setPackagesToScan(ClassUtils.getPackageName(HelloRequest.class)); + marshaller.afterPropertiesSet(); + + startServer(); + } + + @AfterAll + protected void cleanUp() { + cleanupServer(); + } + + @Override + protected Server setupServer() throws Exception { + List configurationClasses = new ArrayList<>(); + Collections.addAll(configurationClasses, WebAppContext.getDefaultConfigurationClasses()); + + WebAppContext webAppContext = new WebAppContext(); + webAppContext.setContextPath(getContextPath()); + webAppContext.setConfigurationClasses(configurationClasses); + // set up test application + webAppContext.setBaseResource(Resource.newSystemResource("test-app")); + webAppContext.getMetaData().getWebInfClassesDirs().add(Resource.newClassPathResource("/")); + + Server jettyServer = new Server(port); + + jettyServer.setHandler(webAppContext); + jettyServer.start(); + + return jettyServer; + } + + @Override + protected void stopServer(Server server) throws Exception { + server.stop(); + server.destroy(); + } + + @Override + protected String getContextPath() { + return "/jetty-context"; + } + + private String getServiceAddress(String serviceName) { + return address.resolve("ws/" + serviceName).toString(); + } + + private Object makeRequest(TestMethod testMethod, String name) { + return webServiceTemplate.marshalSendAndReceive( + getServiceAddress("HelloService"), testMethod.request(name)); + } + + @ParameterizedTest + @EnumSource(TestMethod.class) + void successfulRequest(TestMethod testMethod) { + Object response = makeRequest(testMethod, "Test"); + + assertThat(testMethod.message(response)).isEqualTo("Hello Test"); + + testing() + .waitAndAssertTraces( + trace -> { + List> assertions = + new ArrayList<>( + Arrays.asList( + span -> + span.hasName(serverSpanName(testMethod.methodName())) + .hasNoParent() + .hasKind(SpanKind.SERVER) + .hasStatus(StatusData.unset()), + span -> + span.hasName("HelloService/" + testMethod.methodName()) + .hasParent(trace.getSpan(0)) + .hasKind(SpanKind.INTERNAL))); + if (hasAnnotationHandlerSpan(testMethod)) { + assertions.add( + span -> + span.hasName("HelloServiceImpl." + testMethod.methodName()) + .hasParent(trace.getSpan(1)) + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfyingExactly( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + HelloServiceImpl.class.getName()), + equalTo( + CodeIncubatingAttributes.CODE_FUNCTION, + testMethod.methodName()))); + } + + trace.hasSpansSatisfyingExactly(assertions); + }); + } + + @ParameterizedTest + @EnumSource(TestMethod.class) + void failingRequest(TestMethod testMethod) { + assertThatThrownBy(() -> makeRequest(testMethod, "exception")) + .isInstanceOf(SoapFaultClientException.class) + .hasMessage("hello exception"); + + Exception expectedException = new IllegalStateException("hello exception"); + testing() + .waitAndAssertTraces( + trace -> { + List> assertions = + new ArrayList<>( + Arrays.asList( + span -> + span.hasName(serverSpanName(testMethod.methodName())) + .hasNoParent() + .hasKind(SpanKind.SERVER) + .hasStatus(StatusData.error()), + span -> + span.hasName("HelloService/" + testMethod.methodName()) + .hasParent(trace.getSpan(0)) + .hasKind(SpanKind.INTERNAL) + .hasStatus(StatusData.error()) + .hasException(expectedException))); + if (hasAnnotationHandlerSpan(testMethod)) { + assertions.add( + span -> + span.hasName("HelloServiceImpl." + testMethod.methodName()) + .hasParent(trace.getSpan(1)) + .hasKind(SpanKind.INTERNAL) + .hasStatus(StatusData.error()) + .hasException(expectedException) + .hasAttributesSatisfyingExactly( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + HelloServiceImpl.class.getName()), + equalTo( + CodeIncubatingAttributes.CODE_FUNCTION, + testMethod.methodName()))); + } + + trace.hasSpansSatisfyingExactly(assertions); + }); + } + + private static boolean hasAnnotationHandlerSpan(TestMethod testMethod) { + return testMethod == TestMethod.HELLO; + } + + private String serverSpanName(String operation) { + return getContextPath() + "/ws/HelloService/" + operation; + } + + enum TestMethod { + HELLO { + @Override + Object request(String name) { + HelloRequest request = new HelloRequest(); + request.setName(name); + return request; + } + + @Override + String message(Object response) { + return ((HelloResponse) response).getMessage(); + } + }, + HELLO2 { + @Override + Object request(String name) { + Hello2Request request = new Hello2Request(); + request.setName(name); + return request; + } + + @Override + String message(Object response) { + return ((Hello2Response) response).getMessage(); + } + }; + + String methodName() { + return name().toLowerCase(Locale.ROOT); + } + + abstract Object request(String name); + + abstract String message(Object response); + } +} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/BaseHelloService.java b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/BaseHelloService.java new file mode 100644 index 000000000000..f1e566f1a706 --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/BaseHelloService.java @@ -0,0 +1,16 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello; + +public class BaseHelloService { + + public String hello2(String name) { + if ("exception".equals(name)) { + throw new IllegalStateException("hello exception"); + } + return "Hello " + name; + } +} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloService.java b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloService.java new file mode 100644 index 000000000000..418f2e6a574a --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloService.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello; + +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.xml.ws.RequestWrapper; + +@WebService(targetNamespace = "http://opentelemetry.io/test/hello-web-service") +public interface HelloService { + + @RequestWrapper(localName = "helloRequest") + @WebResult(name = "message") + String hello(@WebParam(name = "name") String name); + + @RequestWrapper(localName = "hello2Request") + @WebResult(name = "message") + String hello2(@WebParam(name = "name") String name); +} diff --git a/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloServiceImpl.java b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloServiceImpl.java new file mode 100644 index 000000000000..7796489c7566 --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/hello/HelloServiceImpl.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello; + +import javax.jws.WebService; + +@WebService( + serviceName = "HelloService", + endpointInterface = "io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello.HelloService", + targetNamespace = "http://opentelemetry.io/test/hello-web-service") +public class HelloServiceImpl extends BaseHelloService implements HelloService { + + @Override + public String hello(String name) { + if ("exception".equals(name)) { + throw new IllegalStateException("hello exception"); + } + return "Hello " + name; + } +} diff --git a/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy b/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy deleted file mode 100644 index c20abd4456f3..000000000000 --- a/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class MetroJaxWsTest extends AbstractJaxWsTest { -} diff --git a/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs2Test.java b/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs2Test.java new file mode 100644 index 000000000000..c57c39f1f6c1 --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs2Test.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.metro; + +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.AbstractJaxWs2Test; + +class MetroJaxWs2Test extends AbstractJaxWs2Test {} diff --git a/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml b/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml index 6bf3e05acba2..f230f6034eed 100644 --- a/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml +++ b/instrumentation/jaxws/jaxws-2.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml @@ -1,6 +1,6 @@ - - \ No newline at end of file + diff --git a/instrumentation/jaxws/jaxws-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.groovy b/instrumentation/jaxws/jaxws-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.groovy deleted file mode 100644 index 2bbf561d9a80..000000000000 --- a/instrumentation/jaxws/jaxws-2.0/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.groovy +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0 - -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes - -class JaxWsAnnotationsTest extends AgentInstrumentationSpecification { - - def "Web service providers generate spans"() { - when: - new SoapProvider().invoke(null) - - then: - assertTraces(1) { - trace(0, 1) { - span(0) { - name "SoapProvider.invoke" - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" "io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.SoapProvider" - "$CodeIncubatingAttributes.CODE_FUNCTION" "invoke" - } - } - } - } - } -} diff --git a/instrumentation/jaxws/jaxws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.java b/instrumentation/jaxws/jaxws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.java new file mode 100644 index 000000000000..b037348e88a8 --- /dev/null +++ b/instrumentation/jaxws/jaxws-2.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/v2_0/JaxWsAnnotationsTest.java @@ -0,0 +1,38 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v2_0; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; + +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +class JaxWsAnnotationsTest { + @RegisterExtension + static InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + @Test + void webServiceProviderSpan() { + new SoapProvider().invoke(null); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("SoapProvider.invoke") + .hasNoParent() + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfyingExactly( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + SoapProvider.class.getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "invoke")))); + } +} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy deleted file mode 100644 index ff0dac6a25e5..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/AbstractJaxWsTest.groovy +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.instrumentation.test.asserts.TraceAssert -import io.opentelemetry.instrumentation.test.base.HttpServerTestTrait -import io.opentelemetry.sdk.trace.data.SpanData -import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes -import io.opentelemetry.test.hello_web_service.Hello2Request -import io.opentelemetry.test.hello_web_service.HelloRequest -import org.eclipse.jetty.server.Server -import org.eclipse.jetty.util.resource.Resource -import org.eclipse.jetty.webapp.WebAppContext -import org.springframework.oxm.jaxb.Jaxb2Marshaller -import org.springframework.util.ClassUtils -import org.springframework.ws.client.core.WebServiceTemplate -import org.springframework.ws.soap.client.SoapFaultClientException -import spock.lang.Shared -import spock.lang.Unroll - -import static io.opentelemetry.api.trace.SpanKind.INTERNAL -import static io.opentelemetry.api.trace.SpanKind.SERVER -import static io.opentelemetry.api.trace.StatusCode.ERROR - -abstract class AbstractJaxWsTest extends AgentInstrumentationSpecification implements HttpServerTestTrait { - - @Shared - private Jaxb2Marshaller marshaller = new Jaxb2Marshaller() - - @Shared - protected WebServiceTemplate webServiceTemplate = new WebServiceTemplate(marshaller) - - def setupSpec() { - setupServer() - - marshaller.setPackagesToScan(ClassUtils.getPackageName(HelloRequest)) - marshaller.afterPropertiesSet() - } - - def cleanupSpec() { - cleanupServer() - } - - @Override - Server startServer(int port) { - WebAppContext webAppContext = new WebAppContext() - webAppContext.setContextPath(getContextPath()) - // set up test application - webAppContext.setBaseResource(Resource.newSystemResource("test-app")) - webAppContext.getMetaData().addWebInfResource(Resource.newClassPathResource("/")) - - def jettyServer = new Server(port) - jettyServer.connectors.each { - it.setHost('localhost') - } - - jettyServer.setHandler(webAppContext) - jettyServer.start() - - return jettyServer - } - - @Override - void stopServer(Server server) { - server.stop() - server.destroy() - } - - @Override - String getContextPath() { - return "/jetty-context" - } - - String getServiceAddress(String serviceName) { - return address.resolve("ws/" + serviceName).toString() - } - - def makeRequest(methodName, name) { - Object request = null - if ("hello" == methodName) { - request = new HelloRequest(name: name) - } else if ("hello2" == methodName) { - request = new Hello2Request(name: name) - } else { - throw new IllegalArgumentException(methodName) - } - - return webServiceTemplate.marshalSendAndReceive(getServiceAddress("HelloService"), request) - } - - @Unroll - def "test #methodName"() { - setup: - def response = makeRequest(methodName, "Test") - - expect: - response.getMessage() == "Hello Test" - - and: - def spanCount = 2 - assertTraces(1) { - trace(0, spanCount) { - serverSpan(it, 0, serverSpanName(methodName)) - handlerSpan(it, 1, methodName, span(0)) - } - } - - where: - methodName << ["hello", "hello2"] - } - - @Unroll - def "test #methodName exception"() { - when: - makeRequest(methodName, "exception") - - then: - def error = thrown(SoapFaultClientException) - error.getMessage() == "hello exception" - - and: - def spanCount = 2 - def expectedException = new Exception("hello exception") - assertTraces(1) { - trace(0, spanCount) { - serverSpan(it, 0, serverSpanName(methodName), expectedException) - handlerSpan(it, 1, methodName, span(0), expectedException) - } - } - - where: - methodName << ["hello", "hello2"] - } - - def serverSpanName(String operation) { - return getContextPath() + "/ws/HelloService/" + operation - } - - static serverSpan(TraceAssert trace, int index, String operation, Throwable exception = null) { - trace.span(index) { - hasNoParent() - name operation - kind SERVER - if (exception != null) { - status ERROR - } - } - } - - static handlerSpan(TraceAssert trace, int index, String operation, Object parentSpan = null, Throwable exception = null) { - trace.span(index) { - if (parentSpan == null) { - hasNoParent() - } else { - childOf((SpanData) parentSpan) - } - name "HelloService/" + operation - kind INTERNAL - if (exception) { - status ERROR - errorEvent(exception.class, exception.message) - } - } - } - - static annotationHandlerSpan(TraceAssert trace, int index, String methodName, Object parentSpan = null, Throwable exception = null) { - trace.span(index) { - if (parentSpan == null) { - hasNoParent() - } else { - childOf((SpanData) parentSpan) - } - name "HelloServiceImpl." + methodName - kind INTERNAL - if (exception) { - status ERROR - errorEvent(exception.class, exception.message) - } - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" "hello.HelloServiceImpl" - "$CodeIncubatingAttributes.CODE_FUNCTION" methodName - } - } - } -} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy deleted file mode 100644 index a2d8da1e8a11..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/BaseHelloService.groovy +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package hello - -class BaseHelloService { - - String hello2(String name) { - if ("exception" == name) { - throw new Exception("hello exception") - } - return "Hello " + name - } -} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloService.groovy b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloService.groovy deleted file mode 100644 index 6e79845e2063..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloService.groovy +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package hello - -import jakarta.jws.WebParam -import jakarta.jws.WebResult -import jakarta.jws.WebService -import jakarta.xml.ws.RequestWrapper - -@WebService(targetNamespace = "http://opentelemetry.io/test/hello-web-service") -interface HelloService { - - @RequestWrapper(localName = "helloRequest") - @WebResult(name = "message") - String hello(@WebParam(name = "name") String name) - - @RequestWrapper(localName = "hello2Request") - @WebResult(name = "message") - String hello2(@WebParam(name = "name") String name) - -} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy deleted file mode 100644 index 5a54f9e42021..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/groovy/hello/HelloServiceImpl.groovy +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package hello - -import jakarta.jws.WebService - -@WebService(serviceName = "HelloService", endpointInterface = "hello.HelloService", targetNamespace = "http://opentelemetry.io/test/hello-web-service") -class HelloServiceImpl extends BaseHelloService implements HelloService { - - String hello(String name) { - if ("exception" == name) { - throw new Exception("hello exception") - } - return "Hello " + name - } -} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/AbstractJaxWs3Test.java b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/AbstractJaxWs3Test.java new file mode 100644 index 000000000000..6da8307854ec --- /dev/null +++ b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/AbstractJaxWs3Test.java @@ -0,0 +1,137 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v3_0; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerUsingTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.sdk.trace.data.StatusData; +import io.opentelemetry.test.hello_web_service.HelloRequest; +import io.opentelemetry.test.hello_web_service.HelloResponse; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.resource.Resource; +import org.eclipse.jetty.webapp.WebAppContext; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; +import org.springframework.util.ClassUtils; +import org.springframework.ws.client.core.WebServiceTemplate; +import org.springframework.ws.soap.client.SoapFaultClientException; + +public class AbstractJaxWs3Test extends AbstractHttpServerUsingTest { + @RegisterExtension + public static final InstrumentationExtension testing = + HttpServerInstrumentationExtension.forAgent(); + + private final Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + protected final WebServiceTemplate webServiceTemplate = new WebServiceTemplate(marshaller); + + @BeforeAll + protected void setUp() throws Exception { + marshaller.setPackagesToScan(ClassUtils.getPackageName(HelloRequest.class)); + marshaller.afterPropertiesSet(); + + startServer(); + } + + @AfterAll + protected void cleanUp() { + cleanupServer(); + } + + @Override + protected Server setupServer() throws Exception { + WebAppContext webAppContext = new WebAppContext(); + webAppContext.setContextPath(getContextPath()); + // set up test application + webAppContext.setBaseResource(Resource.newSystemResource("test-app")); + webAppContext.getMetaData().addWebInfResource(Resource.newClassPathResource("/")); + + Server jettyServer = new Server(port); + + jettyServer.setHandler(webAppContext); + jettyServer.start(); + + return jettyServer; + } + + @Override + protected void stopServer(Server server) throws Exception { + server.stop(); + server.destroy(); + } + + @Override + protected String getContextPath() { + return "/jetty-context"; + } + + private String getServiceAddress(String serviceName) { + return address.resolve("ws/" + serviceName).toString(); + } + + private HelloResponse makeRequest(String name) { + HelloRequest request = new HelloRequest(); + request.setName(name); + return (HelloResponse) + webServiceTemplate.marshalSendAndReceive(getServiceAddress("HelloService"), request); + } + + @Test + void successfulRequest() { + HelloResponse response = makeRequest("Test"); + + assertThat(response.getMessage()).isEqualTo("Hello Test"); + + testing() + .waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(serverSpanName("hello")) + .hasNoParent() + .hasKind(SpanKind.SERVER) + .hasStatus(StatusData.unset()), + span -> + span.hasName("HelloService/hello") + .hasParent(trace.getSpan(0)) + .hasKind(SpanKind.INTERNAL))); + } + + @Test + void failingRequest() { + assertThatThrownBy(() -> makeRequest("exception")) + .isInstanceOf(SoapFaultClientException.class) + .hasMessage("hello exception"); + + Exception expectedException = new IllegalStateException("hello exception"); + testing() + .waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName(serverSpanName("hello")) + .hasNoParent() + .hasKind(SpanKind.SERVER) + .hasStatus(StatusData.error()), + span -> + span.hasName("HelloService/hello") + .hasParent(trace.getSpan(0)) + .hasKind(SpanKind.INTERNAL) + .hasStatus(StatusData.error()) + .hasException(expectedException))); + } + + private String serverSpanName(String operation) { + return getContextPath() + "/ws/HelloService/" + operation; + } +} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloService.java b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloService.java new file mode 100644 index 000000000000..5171a8936927 --- /dev/null +++ b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloService.java @@ -0,0 +1,19 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello; + +import jakarta.jws.WebParam; +import jakarta.jws.WebResult; +import jakarta.jws.WebService; +import jakarta.xml.ws.RequestWrapper; + +@WebService(targetNamespace = "http://opentelemetry.io/test/hello-web-service") +public interface HelloService { + + @RequestWrapper(localName = "helloRequest") + @WebResult(name = "message") + String hello(@WebParam(name = "name") String name); +} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloServiceImpl.java b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloServiceImpl.java new file mode 100644 index 000000000000..c85b6a72d187 --- /dev/null +++ b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/java/io/opentelemetry/javaagent/instrumentation/jaxws/v3_0/hello/HelloServiceImpl.java @@ -0,0 +1,23 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello; + +import jakarta.jws.WebService; + +@WebService( + serviceName = "HelloService", + endpointInterface = "io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello.HelloService", + targetNamespace = "http://opentelemetry.io/test/hello-web-service") +public class HelloServiceImpl implements HelloService { + + @Override + public String hello(String name) { + if ("exception".equals(name)) { + throw new IllegalStateException("hello exception"); + } + return "Hello " + name; + } +} diff --git a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/schema/hello.xsd b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/schema/hello.xsd index f46d7d715238..366214c14038 100644 --- a/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/schema/hello.xsd +++ b/instrumentation/jaxws/jaxws-3.0-common-testing/src/main/schema/hello.xsd @@ -16,20 +16,4 @@ - - - - - - - - - - - - - - - - diff --git a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/CxfJaxWsTest.groovy b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/CxfJaxWsTest.groovy deleted file mode 100644 index b81fa377c198..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/CxfJaxWsTest.groovy +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class CxfJaxWsTest extends AbstractJaxWsTest { -} diff --git a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/TestWsServlet.groovy b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/TestWsServlet.groovy deleted file mode 100644 index e68b2838d07c..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/groovy/TestWsServlet.groovy +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import hello.HelloServiceImpl -import io.opentelemetry.api.trace.Span -import io.opentelemetry.context.Context -import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan -import org.apache.cxf.jaxws.EndpointImpl -import org.apache.cxf.message.Message -import org.apache.cxf.phase.AbstractPhaseInterceptor -import org.apache.cxf.phase.Phase -import org.apache.cxf.transport.servlet.CXFNonSpringServlet - -import jakarta.servlet.ServletConfig - -class TestWsServlet extends CXFNonSpringServlet { - @Override - void loadBus(ServletConfig servletConfig) { - super.loadBus(servletConfig) - - // publish test webservice - Object implementor = new HelloServiceImpl() - EndpointImpl endpoint = new EndpointImpl(bus, implementor) - endpoint.publish("/HelloService") - endpoint.getOutInterceptors().add(new AbstractPhaseInterceptor(Phase.SETUP) { - @Override - void handleMessage(Message message) { - Context context = Context.current() - if (LocalRootSpan.fromContext(context) != Span.fromContext(context)) { - throw new IllegalStateException("handler span should be ended before outgoing interceptors") - } - } - }) - } -} diff --git a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs3Test.java b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs3Test.java new file mode 100644 index 000000000000..175b687ccce2 --- /dev/null +++ b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs3Test.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.cxf; + +import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.AbstractJaxWs3Test; + +class CxfJaxWs3Test extends AbstractJaxWs3Test {} diff --git a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java new file mode 100644 index 000000000000..2d1375e744dd --- /dev/null +++ b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java @@ -0,0 +1,43 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.cxf; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan; +import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello.HelloServiceImpl; +import jakarta.servlet.ServletConfig; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; +import org.apache.cxf.transport.servlet.CXFNonSpringServlet; + +public class TestWsServlet extends CXFNonSpringServlet { + + @Override + public void loadBus(ServletConfig servletConfig) { + super.loadBus(servletConfig); + + // publish test webservice + Object implementor = new HelloServiceImpl(); + EndpointImpl endpoint = new EndpointImpl(bus, implementor); + endpoint.publish("/HelloService"); + endpoint + .getOutInterceptors() + .add( + new AbstractPhaseInterceptor<>(Phase.SETUP) { + @Override + public void handleMessage(Message message) { + Context context = Context.current(); + if (!LocalRootSpan.fromContext(context).equals(Span.fromContext(context))) { + throw new IllegalStateException( + "handler span should be ended before outgoing interceptors"); + } + } + }); + } +} diff --git a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/resources/test-app/WEB-INF/web.xml b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/resources/test-app/WEB-INF/web.xml index 9c6ebc21da06..d02597b23248 100644 --- a/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/resources/test-app/WEB-INF/web.xml +++ b/instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/src/test/resources/test-app/WEB-INF/web.xml @@ -6,7 +6,7 @@ wsServlet - TestWsServlet + io.opentelemetry.javaagent.instrumentation.cxf.TestWsServlet 1 diff --git a/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy b/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy deleted file mode 100644 index c20abd4456f3..000000000000 --- a/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/groovy/MetroJaxWsTest.groovy +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class MetroJaxWsTest extends AbstractJaxWsTest { -} diff --git a/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs3Test.java b/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs3Test.java new file mode 100644 index 000000000000..c90b3b41d266 --- /dev/null +++ b/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/metro/MetroJaxWs3Test.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.metro; + +import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.AbstractJaxWs3Test; + +class MetroJaxWs3Test extends AbstractJaxWs3Test {} diff --git a/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml b/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml index 6bf3e05acba2..a516dfc03555 100644 --- a/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml +++ b/instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/src/test/resources/test-app/WEB-INF/sun-jaxws.xml @@ -1,6 +1,6 @@ - - \ No newline at end of file + diff --git a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/CxfJaxWsTest.groovy b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/CxfJaxWsTest.groovy deleted file mode 100644 index b81fa377c198..000000000000 --- a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/CxfJaxWsTest.groovy +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -class CxfJaxWsTest extends AbstractJaxWsTest { -} diff --git a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/TestWsServlet.groovy b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/TestWsServlet.groovy deleted file mode 100644 index 6e40c049ece0..000000000000 --- a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/groovy/TestWsServlet.groovy +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -import hello.HelloServiceImpl -import io.opentelemetry.api.trace.Span -import io.opentelemetry.context.Context -import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan -import org.apache.cxf.jaxws.EndpointImpl -import org.apache.cxf.message.Message -import org.apache.cxf.phase.AbstractPhaseInterceptor -import org.apache.cxf.phase.Phase -import org.apache.cxf.transport.servlet.CXFNonSpringServlet - -import javax.servlet.ServletConfig - -class TestWsServlet extends CXFNonSpringServlet { - @Override - void loadBus(ServletConfig servletConfig) { - super.loadBus(servletConfig) - - // publish test webservice - Object implementor = new HelloServiceImpl() - EndpointImpl endpoint = new EndpointImpl(bus, implementor) - endpoint.publish("/HelloService") - endpoint.getOutInterceptors().add(new AbstractPhaseInterceptor(Phase.SETUP) { - @Override - void handleMessage(Message message) { - Context context = Context.current() - if (LocalRootSpan.fromContext(context) != Span.fromContext(context)) { - throw new IllegalStateException("handler span should be ended before outgoing interceptors") - } - } - }) - } -} diff --git a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs2Test.java b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs2Test.java new file mode 100644 index 000000000000..fc5303853e62 --- /dev/null +++ b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/CxfJaxWs2Test.java @@ -0,0 +1,10 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.cxf; + +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.AbstractJaxWs2Test; + +class CxfJaxWs2Test extends AbstractJaxWs2Test {} diff --git a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java new file mode 100644 index 000000000000..0ae9ed213741 --- /dev/null +++ b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/cxf/TestWsServlet.java @@ -0,0 +1,43 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.cxf; + +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan; +import io.opentelemetry.javaagent.instrumentation.jaxws.v2_0.hello.HelloServiceImpl; +import javax.servlet.ServletConfig; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.message.Message; +import org.apache.cxf.phase.AbstractPhaseInterceptor; +import org.apache.cxf.phase.Phase; +import org.apache.cxf.transport.servlet.CXFNonSpringServlet; + +public class TestWsServlet extends CXFNonSpringServlet { + + @Override + public void loadBus(ServletConfig servletConfig) { + super.loadBus(servletConfig); + + // publish test webservice + Object implementor = new HelloServiceImpl(); + EndpointImpl endpoint = new EndpointImpl(bus, implementor); + endpoint.publish("/HelloService"); + endpoint + .getOutInterceptors() + .add( + new AbstractPhaseInterceptor(Phase.SETUP) { + @Override + public void handleMessage(Message message) { + Context context = Context.current(); + if (!LocalRootSpan.fromContext(context).equals(Span.fromContext(context))) { + throw new IllegalStateException( + "handler span should be ended before outgoing interceptors"); + } + } + }); + } +} diff --git a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/resources/test-app/WEB-INF/web.xml b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/resources/test-app/WEB-INF/web.xml index 9c6ebc21da06..d02597b23248 100644 --- a/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/resources/test-app/WEB-INF/web.xml +++ b/instrumentation/jaxws/jaxws-cxf-3.0/javaagent/src/test/resources/test-app/WEB-INF/web.xml @@ -6,7 +6,7 @@ wsServlet - TestWsServlet + io.opentelemetry.javaagent.instrumentation.cxf.TestWsServlet 1 diff --git a/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.groovy b/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.groovy deleted file mode 100644 index 9498fb9b6bc1..000000000000 --- a/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/groovy/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.groovy +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.instrumentation.jaxws.jws.v1_1 - -import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification -import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes - -import java.lang.reflect.Proxy - -class JwsAnnotationsTest extends AgentInstrumentationSpecification { - - def "WebService on a class generates spans only for public methods"() { - when: - new WebServiceClass().doSomethingPublic() - new WebServiceClass().doSomethingPackagePrivate() - new WebServiceClass().doSomethingProtected() - - then: - assertTraces(1) { - trace(0, 1) { - span(0) { - name "WebServiceClass.doSomethingPublic" - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" "io.opentelemetry.javaagent.instrumentation.jaxws.jws.v1_1.WebServiceClass" - "$CodeIncubatingAttributes.CODE_FUNCTION" "doSomethingPublic" - } - } - } - } - } - - def "WebService via interface generates spans only for methods of the interface"() { - when: - new WebServiceFromInterface().partOfPublicInterface() - new WebServiceFromInterface().notPartOfPublicInterface() - new WebServiceFromInterface().notPartOfAnything() - - then: - assertTraces(1) { - trace(0, 1) { - span(0) { - name "WebServiceFromInterface.partOfPublicInterface" - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" "io.opentelemetry.javaagent.instrumentation.jaxws.jws.v1_1.WebServiceFromInterface" - "$CodeIncubatingAttributes.CODE_FUNCTION" "partOfPublicInterface" - } - } - } - } - } - - def "WebService via proxy must have span attributes from actual implementation"() { - when: - WebServiceDefinitionInterface proxy = - Proxy.newProxyInstance( - WebServiceFromInterface.getClassLoader(), - [WebServiceDefinitionInterface] as Class[], - new ProxyInvocationHandler(new WebServiceFromInterface())) as WebServiceDefinitionInterface - proxy.partOfPublicInterface() - - then: - proxy.getClass() != WebServiceFromInterface - assertTraces(1) { - trace(0, 1) { - span(0) { - name "WebServiceFromInterface.partOfPublicInterface" - attributes { - "$CodeIncubatingAttributes.CODE_NAMESPACE" "io.opentelemetry.javaagent.instrumentation.jaxws.jws.v1_1.WebServiceFromInterface" - "$CodeIncubatingAttributes.CODE_FUNCTION" "partOfPublicInterface" - } - } - } - } - } -} diff --git a/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.java b/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.java new file mode 100644 index 000000000000..f9edd8f89ccc --- /dev/null +++ b/instrumentation/jaxws/jaxws-jws-api-1.1/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxws/jws/v1_1/JwsAnnotationsTest.java @@ -0,0 +1,91 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.instrumentation.jaxws.jws.v1_1; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; + +import io.opentelemetry.api.trace.SpanKind; +import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.semconv.incubating.CodeIncubatingAttributes; +import java.lang.reflect.Proxy; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +class JwsAnnotationsTest { + @RegisterExtension + static InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + @Test + @DisplayName("WebService on a class generates spans only for public methods") + void classMethods() { + new WebServiceClass().doSomethingPublic(); + new WebServiceClass().doSomethingPackagePrivate(); + new WebServiceClass().doSomethingProtected(); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("WebServiceClass.doSomethingPublic") + .hasNoParent() + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfyingExactly( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + WebServiceClass.class.getName()), + equalTo(CodeIncubatingAttributes.CODE_FUNCTION, "doSomethingPublic")))); + } + + @Test + @DisplayName("WebService via interface generates spans only for methods of the interface") + void interfaceMethods() { + new WebServiceFromInterface().partOfPublicInterface(); + new WebServiceFromInterface().notPartOfPublicInterface(); + new WebServiceFromInterface().notPartOfAnything(); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("WebServiceFromInterface.partOfPublicInterface") + .hasNoParent() + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfyingExactly( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + WebServiceFromInterface.class.getName()), + equalTo( + CodeIncubatingAttributes.CODE_FUNCTION, "partOfPublicInterface")))); + } + + @Test + @DisplayName("WebService via proxy must have span attributes from actual implementation") + void proxy() { + WebServiceDefinitionInterface proxy = + (WebServiceDefinitionInterface) + Proxy.newProxyInstance( + WebServiceFromInterface.class.getClassLoader(), + new Class[] {WebServiceDefinitionInterface.class}, + new ProxyInvocationHandler(new WebServiceFromInterface())); + proxy.partOfPublicInterface(); + + testing.waitAndAssertTraces( + trace -> + trace.hasSpansSatisfyingExactly( + span -> + span.hasName("WebServiceFromInterface.partOfPublicInterface") + .hasNoParent() + .hasKind(SpanKind.INTERNAL) + .hasAttributesSatisfyingExactly( + equalTo( + CodeIncubatingAttributes.CODE_NAMESPACE, + WebServiceFromInterface.class.getName()), + equalTo( + CodeIncubatingAttributes.CODE_FUNCTION, "partOfPublicInterface")))); + } +}