Search in sources :

Example 11 with PartialUpdateGreetingRequestBuilders

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");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ByteString(com.linkedin.data.ByteString) Test(org.testng.annotations.Test)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)11 PartialUpdateGreetingRequestBuilders (com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders)11 Test (org.testng.annotations.Test)10 UpdateEntityStatus (com.linkedin.restli.common.UpdateEntityStatus)5 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)3 ByteString (com.linkedin.data.ByteString)2 PatchRequest (com.linkedin.restli.common.PatchRequest)2 HashMap (java.util.HashMap)2 ErrorResponse (com.linkedin.restli.common.ErrorResponse)1