Skip to content

Commit 0b5ffa1

Browse files
committed
Reduce some test duplication by moving common classes to the main directory.
This allowed me to declare a test dependency on the servlet-3.0:testing directory. (Test directories can't depend on other test directories.) Still needed to copy over all the actual test classes because of how the test hierarchy is declared.
1 parent 367f0a1 commit 0b5ffa1

32 files changed

+111
-746
lines changed

instrumentation/servlet/servlet-3.0/library/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ plugins {
55
dependencies {
66
compileOnly("javax.servlet:javax.servlet-api:3.0.1")
77

8+
testImplementation(project(":instrumentation:servlet:servlet-3.0:testing"))
9+
810
testLibrary("org.eclipse.jetty:jetty-server:8.0.0.v20110901")
911
testLibrary("org.eclipse.jetty:jetty-servlet:8.0.0.v20110901")
1012
testLibrary("org.apache.tomcat.embed:tomcat-embed-core:8.0.41")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.servlet.v3_0;
7+
8+
9+
import io.opentelemetry.instrumentation.api.internal.HttpConstants;
10+
import io.opentelemetry.instrumentation.servlet.v3_0.copied.HttpServerResponseCustomizerHolder;
11+
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
12+
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
13+
import io.opentelemetry.javaagent.instrumentation.servlet.v3_0.AbstractServlet3Test;
14+
15+
public abstract class AbstractServlet3LibraryTest<SERVER, CONTEXT>
16+
extends AbstractServlet3Test<SERVER, CONTEXT> {
17+
18+
@Override
19+
protected void configure(HttpServerTestOptions options) {
20+
super.configure(options);
21+
options.setTestCaptureRequestParameters(false); // Requires AgentConfig.
22+
options.setTestCaptureHttpHeaders(false); // Requires AgentConfig.
23+
options.disableTestNonStandardHttpMethod(); // test doesn't use route mapping correctly.
24+
options.setTestException(false); // filters don't have visibility into exception handling above.
25+
HttpServerResponseCustomizerHolder.setCustomizer(new TestAgentHttpResponseCustomizer());
26+
options.setHasResponseCustomizer(e -> true);
27+
}
28+
29+
@Override
30+
public String expectedHttpRoute(ServerEndpoint endpoint, String method) {
31+
// no need to compute route if we're not expecting it
32+
if (!hasHttpRouteAttribute(endpoint)) {
33+
return null;
34+
}
35+
36+
if (method.equals(HttpConstants._OTHER)) {
37+
return getContextPath() + endpoint.getPath();
38+
}
39+
40+
// NOTE: Primary difference from javaagent servlet instrumentation!
41+
// Since just we're working with a filter, we can't actually get the proper servlet path.
42+
return getContextPath() + "/*";
43+
}
44+
45+
@Override
46+
protected void snippetInjectionWithServletOutputStream() {
47+
// override
48+
}
49+
50+
@Override
51+
protected void snippetInjectionWithPrintWriter() {
52+
// override
53+
}
54+
}

instrumentation/servlet/servlet-3.0/library/src/test/java/io/opentelemetry/instrumentation/servlet/v3_0/AbstractServlet3Test.java

Lines changed: 0 additions & 144 deletions
This file was deleted.

instrumentation/servlet/servlet-3.0/library/src/test/java/io/opentelemetry/instrumentation/servlet/v3_0/RequestDispatcherServlet.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

instrumentation/servlet/servlet-3.0/library/src/test/java/io/opentelemetry/instrumentation/servlet/v3_0/Servlet3MappingResolverFactory.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)