1515import static io .opentelemetry .instrumentation .testing .junit .http .ServerEndpoint .QUERY_PARAM ;
1616import static io .opentelemetry .instrumentation .testing .junit .http .ServerEndpoint .REDIRECT ;
1717import static io .opentelemetry .instrumentation .testing .junit .http .ServerEndpoint .SUCCESS ;
18+ import static org .assertj .core .api .Assertions .assertThat ;
1819
1920import io .dropwizard .Application ;
2021import io .dropwizard .Configuration ;
@@ -66,7 +67,9 @@ protected void stopServer(DropwizardTestSupport<Configuration> server) {
6667 server .after ();
6768 }
6869
69- protected void customizeTestOptions (HttpServerTestOptions options ) {
70+ @ Override
71+ protected void configure (HttpServerTestOptions options ) {
72+ super .configure (options );
7073 // this override is needed because dropwizard reports peer ip as the client ip
7174 options .setSockPeerAddr (serverEndpoint -> TEST_CLIENT_IP );
7275 options .setHasHandlerSpan (endpoint -> endpoint != NOT_FOUND );
@@ -90,12 +93,6 @@ protected void customizeTestOptions(HttpServerTestOptions options) {
9093 });
9194 }
9295
93- @ Override
94- protected void configure (HttpServerTestOptions options ) {
95- super .configure (options );
96- customizeTestOptions (options );
97- }
98-
9996 Class <? extends Application <Configuration >> testApp () {
10097 return TestApp .class ;
10198 }
@@ -107,18 +104,32 @@ Class<?> testResource() {
107104 @ Override
108105 protected SpanDataAssert assertHandlerSpan (
109106 SpanDataAssert span , String method , ServerEndpoint endpoint ) {
110- span .hasName (testResource ().getSimpleName () + "." + endpoint . name (). toLowerCase ( Locale . ROOT ))
107+ span .hasName (testResource ().getSimpleName () + "." + getEndpointName ( endpoint ))
111108 .hasKind (INTERNAL );
112109 if (EXCEPTION .equals (endpoint )) {
113110 span .hasStatus (StatusData .error ()).hasException (new Exception (EXCEPTION .getBody ()));
114111 }
115112 return span ;
116113 }
117114
115+ private static String getEndpointName (ServerEndpoint endpoint ) {
116+ if (QUERY_PARAM .equals (endpoint )) {
117+ return "queryParam" ;
118+ } else if (PATH_PARAM .equals (endpoint )) {
119+ return "pathParam" ;
120+ } else if (CAPTURE_HEADERS .equals (endpoint )) {
121+ return "captureHeaders" ;
122+ } else if (INDEXED_CHILD .equals (endpoint )) {
123+ return "indexedChild" ;
124+ }
125+ return endpoint .name ().toLowerCase (Locale .ROOT );
126+ }
127+
118128 @ Override
119129 protected SpanDataAssert assertResponseSpan (
120130 SpanDataAssert span , SpanData parentSpan , String method , ServerEndpoint endpoint ) {
121- span .hasName ("CompressedResponseWrapper.sendError" ).hasKind (INTERNAL );
131+ span .satisfies (spanData -> assertThat (spanData .getName ()).endsWith (".sendError" ))
132+ .hasKind (INTERNAL );
122133 return span ;
123134 }
124135
@@ -149,7 +160,7 @@ public Response success() {
149160
150161 @ GET
151162 @ Path ("query" )
152- public Response query_param (@ QueryParam ("some" ) String param ) {
163+ public Response queryParam (@ QueryParam ("some" ) String param ) {
153164 return controller (
154165 QUERY_PARAM ,
155166 () -> Response .status (QUERY_PARAM .getStatus ()).entity ("some=" + param ).build ());
@@ -187,15 +198,15 @@ public Response exception() throws Exception {
187198
188199 @ GET
189200 @ Path ("path/{id}/param" )
190- public Response path_param (@ PathParam ("id" ) int param ) {
201+ public Response pathParam (@ PathParam ("id" ) int param ) {
191202 return controller (
192203 PATH_PARAM ,
193204 () -> Response .status (PATH_PARAM .getStatus ()).entity (String .valueOf (param )).build ());
194205 }
195206
196207 @ GET
197208 @ Path ("child" )
198- public Response indexed_child (@ QueryParam ("id" ) String param ) {
209+ public Response indexedChild (@ QueryParam ("id" ) String param ) {
199210 return controller (
200211 INDEXED_CHILD ,
201212 () -> {
@@ -208,7 +219,7 @@ public Response indexed_child(@QueryParam("id") String param) {
208219
209220 @ GET
210221 @ Path ("captureHeaders" )
211- public Response capture_headers (@ HeaderParam ("X-Test-Request" ) String header ) {
222+ public Response captureHeaders (@ HeaderParam ("X-Test-Request" ) String header ) {
212223 return controller (
213224 CAPTURE_HEADERS ,
214225 () ->
0 commit comments