Skip to content

Commit

Permalink
Correct assertEquals arguments wrong way round
Browse files Browse the repository at this point in the history
  • Loading branch information
Azquelt committed Aug 11, 2023
1 parent 78bfc10 commit cc80b3c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ public void readErrorSpans() {
Assert.assertEquals(httpGet.getSpanId(), secondURL.getParentSpanId());
Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId());

Assert.assertEquals(HttpMethod.GET, firstURL.getAttributes().get(HTTP_METHOD));
Assert.assertEquals("http", firstURL.getAttributes().get(HTTP_SCHEME));
Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http");

// getError returns an internal server error...
Assert.assertEquals(HTTP_BAD_REQUEST, secondURL.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(secondURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST);
// Which gets received by the client
Assert.assertEquals(HTTP_BAD_REQUEST, httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST);
// The exception from the client is inspected and handled so this method should return OK
Assert.assertEquals(HTTP_OK, firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK);

// There are many different URLs that will end up here. But all should contain "JaxRsClientAsyncTestEndpoint"
Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint"));

Assert.assertEquals(HttpMethod.GET, httpGet.getAttributes().get(HTTP_METHOD));
Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint"));
}

Expand Down Expand Up @@ -178,16 +178,16 @@ public void readSpans() {
Assert.assertEquals(httpGet.getSpanId(), secondURL.getParentSpanId());
Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId());

Assert.assertEquals(HTTP_OK, firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, firstURL.getAttributes().get(HTTP_METHOD));
Assert.assertEquals("http", firstURL.getAttributes().get(HTTP_SCHEME));
Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http");
Assert.assertTrue(firstURL.getAttributes().get(HTTP_TARGET).contains(QUERY_VALUE));

// There are many different URLs that will end up here. But all should contain "JaxRsClientAsyncTestEndpoint"
Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint"));

Assert.assertEquals(HTTP_OK, httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, httpGet.getAttributes().get(HTTP_METHOD));
Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK);
Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("JaxRsClientAsyncTestEndpoint"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public Response getJax(@Context UriInfo uriInfo, @QueryParam(value = "baggageVal

try (Scope s = Baggage.builder().put("foo", baggageValue).build().makeCurrent()) {
Baggage baggage = Baggage.current();
Assert.assertEquals(baggageValue, baggage.getEntryValue("foo"));
Assert.assertEquals(baggage.getEntryValue("foo"), baggageValue);

String url = new String(uriInfo.getAbsolutePath().toString());
// Use our own URL to work out the URL of the other test endpoint
Expand All @@ -90,7 +90,7 @@ public Response getJax(@Context UriInfo uriInfo, @QueryParam(value = "baggageVal
.queryParam("baggageValue", baggageValue)
.request(MediaType.TEXT_PLAIN)
.get(String.class);
Assert.assertEquals(TEST_PASSED, result);
Assert.assertEquals(result, TEST_PASSED);
} finally {
client.close();
}
Expand All @@ -104,7 +104,7 @@ public Response getJaxAsync(@Context UriInfo uriInfo, @QueryParam(value = "bagga

try (Scope s = Baggage.builder().put("foo", baggageValue).build().makeCurrent()) {
Baggage baggage = Baggage.current();
Assert.assertEquals(baggageValue, baggage.getEntryValue("foo"));
Assert.assertEquals(baggage.getEntryValue("foo"), baggageValue);

String url = new String(uriInfo.getAbsolutePath().toString());
// Use our own URL to work out the URL of the other test endpoint
Expand All @@ -118,7 +118,7 @@ public Response getJaxAsync(@Context UriInfo uriInfo, @QueryParam(value = "bagga
.get(String.class);
try {
String resultValue = result.get(10, SECONDS);
Assert.assertEquals(TEST_PASSED, resultValue);
Assert.assertEquals(resultValue, TEST_PASSED);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
Expand All @@ -135,7 +135,7 @@ public Response getJaxError(@Context UriInfo uriInfo, @QueryParam(value = "bagga

try (Scope s = Baggage.builder().put("foo", baggageValue).build().makeCurrent()) {
Baggage baggage = Baggage.current();
Assert.assertEquals(baggageValue, baggage.getEntryValue("foo"));
Assert.assertEquals(baggage.getEntryValue("foo"), baggageValue);

String url = new String(uriInfo.getAbsolutePath().toString());
// Use our own URL to work out the URL of the other test endpoint
Expand All @@ -152,7 +152,7 @@ public Response getJaxError(@Context UriInfo uriInfo, @QueryParam(value = "bagga
} catch (ExecutionException e) {
// Expected because server returned BAD_REQUEST
WebApplicationException webEx = (WebApplicationException) e.getCause();
assertEquals(HTTP_BAD_REQUEST, webEx.getResponse().getStatus());
assertEquals(webEx.getResponse().getStatus(), HTTP_BAD_REQUEST);
} catch (Exception e) {
// Wrap and throw unexpected exceptions
throw new RuntimeException(e);
Expand All @@ -171,7 +171,7 @@ public Response getJaxRsTwo(@QueryParam(value = "baggageValue") String baggageVa
Assert.assertNotNull(Span.current());
Baggage baggage = Baggage.current();
// Assert that Baggage is propagated from Jax Server to Jax Client
Assert.assertEquals(baggageValue, baggage.getEntryValue("foo"));
Assert.assertEquals(baggage.getEntryValue("foo"), baggageValue);
return Response.ok(TEST_PASSED).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private void doAsyncTest(Function<JaxRsServerAsyncTestEndpointClient, String> re
.baseUri(url.toURI())
.build(JaxRsServerAsyncTestEndpointClient.class);
String response = requestFunction.apply(client);
Assert.assertEquals("OK", response);
Assert.assertEquals(response, "OK");
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ private void doErrorAsyncTest(Function<JaxRsServerAsyncTestEndpointClient, Strin
requestFunction.apply(client);
fail("Client did not throw an exception");
} catch (WebApplicationException e) {
assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, e.getResponse().getStatus());
assertEquals(e.getResponse().getStatus(), HttpURLConnection.HTTP_BAD_REQUEST);
readErrorSpans();
}
} catch (URISyntaxException e) {
Expand All @@ -193,8 +193,8 @@ private void readErrorSpans() {
assertEquals(clientSpan.getSpanId(), serverSpan.getParentSpanId());

// Assert the status code for the client and server spans
assertEquals(HTTP_BAD_REQUEST, serverSpan.getAttributes().get(HTTP_STATUS_CODE).intValue());
assertEquals(HTTP_BAD_REQUEST, clientSpan.getAttributes().get(HTTP_STATUS_CODE).intValue());
assertEquals(serverSpan.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST);
assertEquals(clientSpan.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST);

// Assert that the expected headers were used
Assert.assertTrue(serverSpan.getAttributes().get(BAGGAGE_VALUE_ATTR).contains(TEST_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ public void readSpans() {
Assert.assertEquals(httpGet.getSpanId(), secondURL.getParentSpanId());
Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId());

Assert.assertEquals(HTTP_OK, firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, firstURL.getAttributes().get(HTTP_METHOD));
Assert.assertEquals("http", firstURL.getAttributes().get(HTTP_SCHEME));
Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http");

Assert.assertEquals(HTTP_OK, httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, httpGet.getAttributes().get(HTTP_METHOD));
Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK);
Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("MpRestClientAsyncTestEndpoint"));
}

Expand Down Expand Up @@ -169,18 +169,18 @@ public void readSpansError() {
Assert.assertEquals(firstURL.getSpanId(), httpGet.getParentSpanId());

// requestMpClientError() returns a BAD_REQUEST status
Assert.assertEquals(HTTP_BAD_REQUEST, secondURL.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, secondURL.getAttributes().get(HTTP_METHOD));
Assert.assertEquals("http", secondURL.getAttributes().get(HTTP_SCHEME));
Assert.assertEquals(secondURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST);
Assert.assertEquals(secondURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertEquals(secondURL.getAttributes().get(HTTP_SCHEME), "http");

// which is received by the client
Assert.assertEquals(HTTP_BAD_REQUEST, httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, httpGet.getAttributes().get(HTTP_METHOD));
Assert.assertEquals(httpGet.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_BAD_REQUEST);
Assert.assertEquals(httpGet.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertTrue(httpGet.getAttributes().get(HTTP_URL).contains("MpRestClientAsyncTestEndpoint"));

// Exception is handled in the receiving code so the status code here should be OK
Assert.assertEquals(HTTP_OK, firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue());
Assert.assertEquals(HttpMethod.GET, firstURL.getAttributes().get(HTTP_METHOD));
Assert.assertEquals("http", firstURL.getAttributes().get(HTTP_SCHEME));
Assert.assertEquals(firstURL.getAttributes().get(HTTP_STATUS_CODE).intValue(), HTTP_OK);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_METHOD), HttpMethod.GET);
Assert.assertEquals(firstURL.getAttributes().get(HTTP_SCHEME), "http");
}
}

0 comments on commit cc80b3c

Please sign in to comment.