-
Notifications
You must be signed in to change notification settings - Fork 873
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/v1.33.x] Convert Wicket groovy tests to java (#10818)
Co-authored-by: H <[email protected]> Co-authored-by: Lauri Tulmin <[email protected]>
- Loading branch information
1 parent
456ab3f
commit 64dec1e
Showing
9 changed files
with
180 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 0 additions & 102 deletions
102
instrumentation/wicket-8.0/javaagent/src/test/groovy/WicketTest.groovy
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
instrumentation/wicket-8.0/javaagent/src/test/groovy/hello/ExceptionPage.groovy
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
instrumentation/wicket-8.0/javaagent/src/test/groovy/hello/HelloApplication.groovy
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
instrumentation/wicket-8.0/javaagent/src/test/groovy/hello/HelloPage.groovy
This file was deleted.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
instrumentation/wicket-8.0/javaagent/src/test/java/hello/ExceptionPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package hello; | ||
|
||
import org.apache.wicket.markup.html.WebPage; | ||
|
||
public class ExceptionPage extends WebPage { | ||
public ExceptionPage() throws Exception { | ||
throw new Exception("test exception"); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
instrumentation/wicket-8.0/javaagent/src/test/java/hello/HelloApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package hello; | ||
|
||
import org.apache.wicket.Page; | ||
import org.apache.wicket.RuntimeConfigurationType; | ||
import org.apache.wicket.protocol.http.WebApplication; | ||
|
||
public class HelloApplication extends WebApplication { | ||
@Override | ||
public Class<? extends Page> getHomePage() { | ||
return HelloPage.class; | ||
} | ||
|
||
@Override | ||
protected void init() { | ||
super.init(); | ||
|
||
mountPage("/exception", ExceptionPage.class); | ||
} | ||
|
||
@Override | ||
public RuntimeConfigurationType getConfigurationType() { | ||
return RuntimeConfigurationType.DEPLOYMENT; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
instrumentation/wicket-8.0/javaagent/src/test/java/hello/HelloPage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package hello; | ||
|
||
import org.apache.wicket.markup.html.WebPage; | ||
import org.apache.wicket.markup.html.basic.Label; | ||
|
||
public class HelloPage extends WebPage { | ||
public HelloPage() { | ||
add(new Label("message", "Hello World!")); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/wicket/WicketTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.wicket; | ||
|
||
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> { | ||
|
||
@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"; | ||
} | ||
|
||
@BeforeAll | ||
void setup() { | ||
startServer(); | ||
} | ||
|
||
@Test | ||
void testHello() { | ||
AggregatedHttpResponse response = | ||
client.get(address.resolve("wicket-test/").toString()).aggregate().join(); | ||
Document doc = Jsoup.parse(response.contentUtf8()); | ||
|
||
assertThat(response.status().code()).isEqualTo(200); | ||
assertThat(doc.selectFirst("#message").text()).isEqualTo("Hello World!"); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("GET " + getContextPath() + "/wicket-test/hello.HelloPage") | ||
.hasNoParent() | ||
.hasKind(SpanKind.SERVER))); | ||
} | ||
|
||
@Test | ||
void testException() { | ||
AggregatedHttpResponse response = | ||
client.get(address.resolve("wicket-test/exception").toString()).aggregate().join(); | ||
|
||
assertThat(response.status().code()).isEqualTo(500); | ||
|
||
testing.waitAndAssertTraces( | ||
trace -> | ||
trace.hasSpansSatisfyingExactly( | ||
span -> | ||
span.hasName("GET " + getContextPath() + "/wicket-test/hello.ExceptionPage") | ||
.hasKind(SpanKind.SERVER) | ||
.hasNoParent() | ||
.hasStatus(StatusData.error()) | ||
.hasException(new Exception("test exception")))); | ||
} | ||
} |