use of com.linkedin.restli.examples.greetings.client.CreateGreetingCreateAndGetRequestBuilder in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testReturnEntityOnDemand.
/**
* Ensures that different usages of {@link com.linkedin.restli.client.CreateIdEntityRequestBuilder#returnEntity(boolean)} are handled
* correctly and that the response appropriately contains the entity or nothing depending on how and if the provided
* method is used.
*/
@Test(dataProvider = "returnEntityOnDemandData")
public void testReturnEntityOnDemand(Boolean returnEntity, boolean expectReturnEntity) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("second time!");
greeting.setTone(Tone.FRIENDLY);
CreateGreetingRequestBuilders builders = new CreateGreetingRequestBuilders();
CreateGreetingCreateAndGetRequestBuilder builder = builders.createAndGet().input(greeting);
if (returnEntity != null) {
builder.returnEntity(returnEntity);
}
CreateIdEntityRequest<Long, Greeting> createIdEntityRequest = builder.build();
Response<IdEntityResponse<Long, Greeting>> response = getClient().sendRequest(createIdEntityRequest).getResponse();
long id = response.getEntity().getId();
@SuppressWarnings("deprecation") String stringId = response.getId();
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + CreateGreetingRequestBuilders.getPrimaryResource() + "/" + id);
Assert.assertEquals(id, Long.parseLong(stringId));
if (expectReturnEntity) {
Greeting returnedEntity = response.getEntity().getEntity();
Assert.assertNotNull(returnedEntity, "RecordTemplate entity in response should not be null.");
Assert.assertEquals(returnedEntity.getMessage(), greeting.getMessage(), "Expect returned entity message to match original.");
Assert.assertEquals(returnedEntity.getTone(), greeting.getTone(), "Expect returned entity tone to match original.");
} else {
Assert.assertNull(response.getEntity().getEntity(), "RecordTemplate entity in response should be null.");
}
}
Aggregations