From bafe122c2436577fde92c8af604cd537f89d28bc Mon Sep 17 00:00:00 2001 From: danworth Date: Fri, 7 Feb 2020 11:11:44 +0000 Subject: [PATCH] PP-6085 Add accept header to test There are two methods within `TransactionResource` named `search` and `streamCsv`. Both use the path `/` and http method `GET` but provide either "application/json" or "text/csv" respectively. According to the jax-rs specification when the client does not specify the "accept" header then it is not garanteed as to which method will be invoked, since both methods have the same level of specificity in what they provide. When `shouldReturn400IfTransactionGatewayAccountIdIsNotProvidedForSearch` runs locally and on Jenkins the `search` method is invoked as expected, however on Travis `streamCsv` is called and an NPE is thrown as the test provides a mock config with null parameters. This shouldn't be a concern in production since the client of this service is publicApi which provides an accept header. Therefore we feel it is exceptable to add the header to the test and not disambiguate the two methods any further. --- .../transaction/resource/TransactionResourceTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/uk/gov/pay/ledger/transaction/resource/TransactionResourceTest.java b/src/test/java/uk/gov/pay/ledger/transaction/resource/TransactionResourceTest.java index 03935f2d9..72e26d09c 100644 --- a/src/test/java/uk/gov/pay/ledger/transaction/resource/TransactionResourceTest.java +++ b/src/test/java/uk/gov/pay/ledger/transaction/resource/TransactionResourceTest.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Optional; +import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -92,7 +93,11 @@ public void shouldReturn404IfTransactionDoesNotExistWhenGettingEvents() { @Test public void shouldReturn400IfTransactionGatewayAccountIdIsNotProvidedForSearch() { - Response response = resources.target("/v1/transaction/").request().get(); + Response response = resources.target("/v1/transaction/") + .request() + .header("Accept", APPLICATION_JSON) + .get(); + assertThat(response.getStatus(), is(400)); }