use of com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders in project rest.li by linkedin.
the class TestReturnEntityWithPartialUpdate method testInvalidReturnEntityParameter.
/**
* Ensures that using an invalid value for the {@link RestConstants#RETURN_ENTITY_PARAM} query parameter results
* in a 400 bad request error response for PARTIAL_UPDATE.
*/
@Test
@SuppressWarnings({ "Duplicates" })
public void testInvalidReturnEntityParameter() throws RemoteInvocationException {
final long expectedId = 8L;
Greeting expectedGreeting = new Greeting();
expectedGreeting.setMessage("Message " + expectedId);
expectedGreeting.setTone(Tone.FRIENDLY);
final String invalidParamValue = "NOTaBoolean";
PartialUpdateEntityRequest<Greeting> request = new PartialUpdateGreetingRequestBuilders().partialUpdateAndGet().id(expectedId).input(PatchRequest.createFromEmptyPatchDocument()).setParam(RestConstants.RETURN_ENTITY_PARAM, invalidParamValue).build();
try {
getClient().sendRequest(request).getResponse();
Assert.fail(String.format("Query parameter should cause an exception: %s=%s", RestConstants.RETURN_ENTITY_PARAM, invalidParamValue));
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode(), "Invalid response status.");
Assert.assertTrue(e.getServiceErrorMessage().contains(String.format("Invalid \"%s\" parameter: %s", RestConstants.RETURN_ENTITY_PARAM, invalidParamValue)), "Invalid error response message");
}
}
Aggregations