Skip to content

Commit 8c0aafb

Browse files
shalklaurit
andauthored
Feat add a test case in AbstractHttpClientTest.java (#12924)
Co-authored-by: Lauri Tulmin <[email protected]>
1 parent 7ae8069 commit 8c0aafb

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyClientTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public int sendRequest(
5858
response = proxy.put_success(param, isTestServer, requestId);
5959
} else if (proxyMethodName.equals("get_error")) {
6060
response = proxy.get_error(param, isTestServer, requestId);
61+
} else if (proxyMethodName.equals("get_client_error")) {
62+
response = proxy.get_client_error(param, isTestServer, requestId);
6163
} else {
6264
throw new IllegalArgumentException("Unknown method: " + proxyMethodName);
6365
}

instrumentation/jaxrs-client/jaxrs-client-2.0-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/jaxrsclient/ResteasyProxyResource.java

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Response get_error(
2222
@HeaderParam("is-test-server") String isTestServer,
2323
@HeaderParam("test-request-id") String requestId);
2424

25+
@GET
26+
@Path("client-error")
27+
Response get_client_error(
28+
@QueryParam("with") String param,
29+
@HeaderParam("is-test-server") String isTestServer,
30+
@HeaderParam("test-request-id") String requestId);
31+
2532
@GET
2633
@Path("success")
2734
Response get_success(

testing-common/src/main/groovy/io/opentelemetry/instrumentation/test/base/HttpClientTest.groovy

+7-2
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,14 @@ abstract class HttpClientTest<REQUEST> extends InstrumentationSpecification {
256256
junitTest.redirectToSecuredCopiesAuthHeader()
257257
}
258258
259-
def "error span"() {
259+
def "error span for #path"() {
260260
expect:
261-
junitTest.errorSpan()
261+
junitTest.errorSpan(path, statusCode)
262+
263+
where:
264+
path | statusCode
265+
"/client-error" | 400
266+
"/error" | 500
262267
}
263268
264269
def "reuse request"() {

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.junit.jupiter.api.TestInstance;
5656
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
5757
import org.junit.jupiter.params.ParameterizedTest;
58+
import org.junit.jupiter.params.provider.CsvSource;
5859
import org.junit.jupiter.params.provider.ValueSource;
5960

6061
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@@ -437,10 +438,11 @@ void redirectToSecuredCopiesAuthHeader() throws Exception {
437438

438439
// TODO: add basic auth scenario
439440

440-
@Test
441-
void errorSpan() {
441+
@ParameterizedTest
442+
@CsvSource({"/error,500", "/client-error,400"})
443+
void errorSpan(String path, int responseCode) {
442444
String method = "GET";
443-
URI uri = resolveAddress("/error");
445+
URI uri = resolveAddress(path);
444446

445447
testing.runWithSpan(
446448
"parent",
@@ -456,7 +458,9 @@ void errorSpan() {
456458
trace -> {
457459
trace.hasSpansSatisfyingExactly(
458460
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
459-
span -> assertClientSpan(span, uri, method, 500, null).hasParent(trace.getSpan(0)),
461+
span ->
462+
assertClientSpan(span, uri, method, responseCode, null)
463+
.hasParent(trace.getSpan(0)),
460464
span -> assertServerSpan(span).hasParent(trace.getSpan(1)));
461465
});
462466
}

0 commit comments

Comments
 (0)