Skip to content

Commit

Permalink
Convert restlet-2.0 tests to java (#12348)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Sep 30, 2024
1 parent 0f0477a commit f0115c6
Show file tree
Hide file tree
Showing 20 changed files with 688 additions and 571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class RestletAppTestBase {
class RestletAppTestBase {

abstract static class BaseResource extends Resource {

@Override
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

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 io.opentelemetry.javaagent.instrumentation.restlet.v2_0;

import io.opentelemetry.instrumentation.restlet.v2_0.AbstractRestletServerTest;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
import org.junit.jupiter.api.extension.RegisterExtension;

class RestletServerTest extends AbstractRestletServerTest {

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

@Override
protected void configure(HttpServerTestOptions options) {
super.configure(options);
options.setHasResponseCustomizer((endpoint) -> true);
}

@Override
protected String notFoundRoute() {
return "/";
}
}
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 io.opentelemetry.javaagent.instrumentation.restlet.v2_0.spring;

import io.opentelemetry.instrumentation.restlet.v2_0.spring.AbstractSpringServerTest;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
import org.junit.jupiter.api.extension.RegisterExtension;

class SpringBeanRouterTest extends AbstractSpringServerTest {

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

@Override
protected void configure(HttpServerTestOptions options) {
super.configure(options);
options.setHasResponseCustomizer((endpoint) -> true);
}

@Override
protected String getConfigurationName() {
return "springBeanRouterConf.xml";
}
}
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 io.opentelemetry.javaagent.instrumentation.restlet.v2_0.spring;

import io.opentelemetry.instrumentation.restlet.v2_0.spring.AbstractSpringServerTest;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions;
import org.junit.jupiter.api.extension.RegisterExtension;

class SpringRouterTest extends AbstractSpringServerTest {

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

@Override
protected void configure(HttpServerTestOptions options) {
super.configure(options);
options.setHasResponseCustomizer((endpoint) -> true);
}

@Override
protected String getConfigurationName() {
return "springRouterConf.xml";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ repositories {
}

dependencies {

library("org.restlet.jse:org.restlet:2.0.2")

testImplementation(project(":instrumentation:restlet:restlet-2.0:testing"))
testLibrary("org.restlet.jse:org.restlet.ext.jetty:2.0.2")
}

// restlet registers the first engine that is present on classpath, so we need to enforce the appropriate version
if (findProperty("testLatestDeps") as Boolean) {
configurations.configureEach {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.restlet.v2_0;

import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.restlet.Restlet;
import org.restlet.engine.application.StatusFilter;
import org.restlet.routing.Filter;
import org.restlet.service.StatusService;

class RestletServerTest extends AbstractRestletServerTest {

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

@Override
protected Restlet wrapRestlet(Restlet restlet, String path) {
RestletTelemetry telemetry =
RestletTelemetry.builder(testing.getOpenTelemetry())
.setCapturedRequestHeaders(singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER))
.setCapturedResponseHeaders(singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER))
.build();

Filter tracingFilter = telemetry.newFilter(path);
Filter statusFilter = new StatusFilter(component.getContext(), new StatusService());

tracingFilter.setNext(statusFilter);
statusFilter.setNext(restlet);

return tracingFilter;
}
}
Loading

0 comments on commit f0115c6

Please sign in to comment.