Skip to content

Commit

Permalink
fix latest dep test
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Nov 29, 2024
1 parent f1a6f39 commit 7a91081
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.opentelemetry.instrumentation.jaxrs.v2_0.test.Resource;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import java.net.URISyntaxException;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.mock.MockDispatcherFactory;
Expand Down Expand Up @@ -59,13 +58,8 @@ protected String getContextPath() {
}

@Override
protected TestResponse makeRequest(String url) {
MockHttpRequest request;
try {
request = MockHttpRequest.post(url);
} catch (URISyntaxException exception) {
throw new IllegalStateException(exception);
}
protected TestResponse makeRequest(String url) throws Exception {
MockHttpRequest request = MockHttpRequest.post(url);
request.contentType(MediaType.TEXT_PLAIN_TYPE);
request.content(new byte[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import io.opentelemetry.instrumentation.jaxrs.v2_0.test.Resource;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import java.net.URISyntaxException;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.core.Dispatcher;
import org.jboss.resteasy.core.SynchronousDispatcher;
import org.jboss.resteasy.mock.MockDispatcherFactory;
import org.jboss.resteasy.mock.MockHttpRequest;
import org.jboss.resteasy.mock.MockHttpResponse;
Expand All @@ -24,7 +23,7 @@ class ResteasyFilterTest extends JaxRsFilterTest<Void> {
@RegisterExtension
static final InstrumentationExtension testing = HttpServerInstrumentationExtension.forAgent();

private Dispatcher dispatcher;
private SynchronousDispatcher dispatcher;

@BeforeAll
void setUp() {
Expand All @@ -38,7 +37,9 @@ void cleanUp() {

@Override
protected Void setupServer() {
dispatcher = MockDispatcherFactory.createDispatcher();
// using implementation class SynchronousDispatcher instead of the Dispatcher interface because
// the interface moves to a different package for the latest dep tests
dispatcher = (SynchronousDispatcher) MockDispatcherFactory.createDispatcher();
Registry registry = dispatcher.getRegistry();
registry.addSingletonResource(new Resource.Test1());
registry.addSingletonResource(new Resource.Test2());
Expand All @@ -59,13 +60,8 @@ protected String getContextPath() {
}

@Override
protected TestResponse makeRequest(String url) {
MockHttpRequest request;
try {
request = MockHttpRequest.post(url);
} catch (URISyntaxException exception) {
throw new IllegalStateException(exception);
}
protected TestResponse makeRequest(String url) throws Exception {
MockHttpRequest request = MockHttpRequest.post(url);
request.contentType(MediaType.TEXT_PLAIN_TYPE);
request.content(new byte[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.http.HttpServerInstrumentationExtension;
import jakarta.ws.rs.core.MediaType;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import org.jboss.resteasy.mock.MockDispatcherFactory;
import org.jboss.resteasy.mock.MockHttpRequest;
import org.jboss.resteasy.mock.MockHttpResponse;
Expand Down Expand Up @@ -60,26 +58,15 @@ protected String getContextPath() {
}

@Override
protected TestResponse makeRequest(String url) {
MockHttpRequest request;
try {
request = MockHttpRequest.post(url);
} catch (URISyntaxException exception) {
throw new IllegalStateException(exception);
}
protected TestResponse makeRequest(String url) throws Exception {
MockHttpRequest request = MockHttpRequest.post(url);
;
request.contentType(MediaType.TEXT_PLAIN_TYPE);
request.content(new byte[0]);

MockHttpResponse response = new MockHttpResponse();
dispatcher.invoke(request, response);

String responseText;
try {
responseText = response.getContentAsString();
} catch (UnsupportedEncodingException exception) {
throw new IllegalStateException(exception);
}

return new TestResponse(responseText, response.getStatus());
return new TestResponse(response.getContentAsString(), response.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public TestResponse(String text, int status) {
}
}

protected abstract TestResponse makeRequest(String url);
protected abstract TestResponse makeRequest(String url) throws Exception;

private TestResponse runRequest(String resource) {
private TestResponse runRequest(String resource) throws Exception {
if (runsOnServer()) {
return makeRequest(resource);
}
Expand Down Expand Up @@ -106,7 +106,8 @@ void request(
boolean abortPrematch,
String route,
String controllerName,
String expectedResponse) {
String expectedResponse)
throws Exception {
Assumptions.assumeTrue(!abortPrematch || testAbortPrematch());

setAbortStatus(abortNormal, abortPrematch);
Expand Down Expand Up @@ -153,7 +154,7 @@ void request(
}

@Test
void nestedCall() {
void nestedCall() throws Exception {
setAbortStatus(false, false);

TestResponse response = runRequest("/test3/nested");
Expand Down

0 comments on commit 7a91081

Please sign in to comment.