Skip to content

Commit

Permalink
[release/v1.33.x] Fix tests for wicket 10 (#10819)
Browse files Browse the repository at this point in the history
Co-authored-by: Lauri Tulmin <[email protected]>
  • Loading branch information
opentelemetrybot and laurit authored Mar 12, 2024
1 parent 64dec1e commit 4f75a1d
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 58 deletions.
9 changes: 9 additions & 0 deletions instrumentation/wicket-8.0/common-testing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id("otel.java-conventions")
}

dependencies {
implementation(project(":testing-common"))
implementation("org.apache.wicket:wicket:8.0.0")
implementation("org.jsoup:jsoup:1.13.1")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.apache.wicket.markup.html.WebPage;

public class ExceptionPage extends WebPage {
private static final long serialVersionUID = 1L;

public ExceptionPage() throws Exception {
throw new Exception("test exception");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.apache.wicket.markup.html.basic.Label;

public class HelloPage extends WebPage {
private static final long serialVersionUID = 1L;

public HelloPage() {
add(new Label("message", "Hello World!"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,64 +7,24 @@

import static org.assertj.core.api.Assertions.assertThat;

import hello.HelloApplication;
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.testing.internal.armeria.common.AggregatedHttpResponse;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import org.apache.wicket.protocol.http.WicketFilter;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.resource.FileResource;
import org.eclipse.jetty.util.resource.Resource;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

class WicketTest extends AbstractHttpServerUsingTest<Server> {
abstract class AbstractWicketTest<SERVER> extends AbstractHttpServerUsingTest<SERVER> {

@RegisterExtension
public static final InstrumentationExtension testing =
HttpServerInstrumentationExtension.forAgent();

@Override
protected Server setupServer() throws Exception {
Server server = new Server(port);

ServletContextHandler context = new ServletContextHandler(0);
context.setContextPath(getContextPath());

Resource resource = new FileResource(getClass().getResource("/"));
context.setBaseResource(resource);
server.setHandler(context);

context.addServlet(DefaultServlet.class, "/");
FilterRegistration.Dynamic registration =
context.getServletContext().addFilter("WicketApplication", WicketFilter.class);
registration.setInitParameter("applicationClassName", HelloApplication.class.getName());
registration.setInitParameter("filterMappingUrlPattern", "/wicket-test/*");
registration.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST), false, "/wicket-test/*");

server.start();

return server;
}

@Override
protected void stopServer(Server server) throws Exception {
server.stop();
server.destroy();
}

@Override
protected String getContextPath() {
return "/jetty-context";
Expand Down
17 changes: 0 additions & 17 deletions instrumentation/wicket-8.0/javaagent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,4 @@ dependencies {
bootstrap(project(":instrumentation:servlet:servlet-common:bootstrap"))

library("org.apache.wicket:wicket:8.0.0")

testImplementation(project(":testing-common"))
testImplementation("org.jsoup:jsoup:1.13.1")
testImplementation("org.eclipse.jetty:jetty-server:8.0.0.v20110901")
testImplementation("org.eclipse.jetty:jetty-servlet:8.0.0.v20110901")

testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
testInstrumentation(project(":instrumentation:servlet:servlet-javax-common:javaagent"))
}

val latestDepTest = findProperty("testLatestDeps") as Boolean

// Wicket 9 requires Java 11
if (latestDepTest) {
otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_11)
}
}
20 changes: 20 additions & 0 deletions instrumentation/wicket-8.0/wicket10-testing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id("otel.javaagent-testing")
}

dependencies {
library("org.apache.wicket:wicket:10.0.0")

testImplementation(project(":instrumentation:wicket-8.0:common-testing"))
testImplementation("org.jsoup:jsoup:1.13.1")
testImplementation("org.eclipse.jetty:jetty-server:11.0.0")
testImplementation("org.eclipse.jetty:jetty-servlet:11.0.0")

testInstrumentation(project(":instrumentation:wicket-8.0:javaagent"))
testInstrumentation(project(":instrumentation:servlet:servlet-5.0:javaagent"))
testInstrumentation(project(":instrumentation:servlet:servlet-javax-common:javaagent"))
}

otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_11)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.wicket;

import hello.HelloApplication;
import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
import java.util.EnumSet;
import org.apache.wicket.protocol.http.WicketFilter;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.resource.Resource;

class WicketTest extends AbstractWicketTest<Server> {

@Override
protected Server setupServer() throws Exception {
Server server = new Server(port);

ServletContextHandler context = new ServletContextHandler(0);
context.setContextPath(getContextPath());

Resource resource = Resource.newResource(getClass().getResource("/"));
context.setBaseResource(resource);
server.setHandler(context);

context.addServlet(DefaultServlet.class, "/");
FilterRegistration.Dynamic registration =
context.getServletContext().addFilter("WicketApplication", WicketFilter.class);
registration.setInitParameter("applicationClassName", HelloApplication.class.getName());
registration.setInitParameter("filterMappingUrlPattern", "/wicket-test/*");
registration.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST), false, "/wicket-test/*");

server.start();

return server;
}

@Override
protected void stopServer(Server server) throws Exception {
server.stop();
server.destroy();
}
}
27 changes: 27 additions & 0 deletions instrumentation/wicket-8.0/wicket8-testing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id("otel.javaagent-testing")
}

dependencies {
library("org.apache.wicket:wicket:8.0.0")

testImplementation(project(":instrumentation:wicket-8.0:common-testing"))
testImplementation("org.jsoup:jsoup:1.13.1")
testImplementation("org.eclipse.jetty:jetty-server:8.0.0.v20110901")
testImplementation("org.eclipse.jetty:jetty-servlet:8.0.0.v20110901")

testInstrumentation(project(":instrumentation:wicket-8.0:javaagent"))
testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
testInstrumentation(project(":instrumentation:servlet:servlet-javax-common:javaagent"))

latestDepTestLibrary("org.apache.wicket:wicket:9.+")
}

val latestDepTest = findProperty("testLatestDeps") as Boolean

// Wicket 9 requires Java 11
if (latestDepTest) {
otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_11)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.wicket;

import hello.HelloApplication;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.FilterRegistration;
import org.apache.wicket.protocol.http.WicketFilter;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.resource.FileResource;
import org.eclipse.jetty.util.resource.Resource;

class WicketTest extends AbstractWicketTest<Server> {

@Override
protected Server setupServer() throws Exception {
Server server = new Server(port);

ServletContextHandler context = new ServletContextHandler(0);
context.setContextPath(getContextPath());

Resource resource = new FileResource(getClass().getResource("/"));
context.setBaseResource(resource);
server.setHandler(context);

context.addServlet(DefaultServlet.class, "/");
FilterRegistration.Dynamic registration =
context.getServletContext().addFilter("WicketApplication", WicketFilter.class);
registration.setInitParameter("applicationClassName", HelloApplication.class.getName());
registration.setInitParameter("filterMappingUrlPattern", "/wicket-test/*");
registration.addMappingForUrlPatterns(
EnumSet.of(DispatcherType.REQUEST), false, "/wicket-test/*");

server.start();

return server;
}

@Override
protected void stopServer(Server server) throws Exception {
server.stop();
server.destroy();
}
}

0 comments on commit 4f75a1d

Please sign in to comment.