From 3e8e235205cb0edfb2bf99bd7c547e7e10d2b8a2 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Thu, 12 Dec 2024 14:15:47 -0800 Subject: [PATCH] add tests for deprecated code --- .../v1_7/RatpackHttpClientOldTest.java | 39 ++++++++++++++++ .../v1_7/server/RatpackHttpServerOldTest.java | 44 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java create mode 100644 instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java new file mode 100644 index 000000000000..0915f47eabee --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/RatpackHttpClientOldTest.java @@ -0,0 +1,39 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7; + +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpClientTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpClientInstrumentationExtension; +import java.util.Collections; +import org.junit.jupiter.api.extension.RegisterExtension; +import ratpack.func.Action; +import ratpack.http.client.HttpClient; +import ratpack.http.client.HttpClientSpec; + +@SuppressWarnings("deprecation") +class RatpackHttpClientOldTest extends AbstractRatpackHttpClientTest { + + @RegisterExtension + static final InstrumentationExtension testing = HttpClientInstrumentationExtension.forLibrary(); + + @Override + protected HttpClient buildHttpClient() throws Exception { + return RatpackTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedClientRequestHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_REQUEST_HEADER)) + .setCapturedClientResponseHeaders( + Collections.singletonList(AbstractHttpClientTest.TEST_RESPONSE_HEADER)) + .build() + .instrumentHttpClient(HttpClient.of(Action.noop())); + } + + @Override + protected HttpClient buildHttpClient(Action action) throws Exception { + return RatpackClientTelemetry.create(testing.getOpenTelemetry()) + .instrument(HttpClient.of(action)); + } +} diff --git a/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java new file mode 100644 index 000000000000..a78801815bb9 --- /dev/null +++ b/instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackHttpServerOldTest.java @@ -0,0 +1,44 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.ratpack.v1_7.server; + +import static java.util.Collections.singletonList; + +import io.opentelemetry.instrumentation.ratpack.server.AbstractRatpackHttpServerTest; +import io.opentelemetry.instrumentation.ratpack.v1_7.RatpackTelemetry; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.AbstractHttpServerTest; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions; +import org.junit.jupiter.api.extension.RegisterExtension; +import ratpack.server.RatpackServerSpec; + +@SuppressWarnings("deprecation") +class RatpackHttpServerOldTest extends AbstractRatpackHttpServerTest { + + @RegisterExtension + public static final InstrumentationExtension testing = + HttpServerInstrumentationExtension.forLibrary(); + + @Override + protected void configure(RatpackServerSpec serverSpec) throws Exception { + RatpackTelemetry telemetry = + RatpackTelemetry.builder(testing.getOpenTelemetry()) + .setCapturedServerRequestHeaders( + singletonList(AbstractHttpServerTest.TEST_REQUEST_HEADER)) + .setCapturedServerResponseHeaders( + singletonList(AbstractHttpServerTest.TEST_RESPONSE_HEADER)) + .build(); + serverSpec.registryOf(telemetry::configureServerRegistry); + } + + @Override + protected void configure(HttpServerTestOptions options) { + super.configure(options); + + options.setHasHandlerSpan(endpoint -> false); + } +}