use of com.linkedin.restli.examples.greetings.client.CreateGreetingBatchCreateAndGetRequestBuilder in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testBatchCreateReturnEntityOnDemand.
/**
* Ensures that different usages of {@link com.linkedin.restli.client.CreateIdEntityRequestBuilder#returnEntity(boolean)} are handled
* correctly and that the response appropriately contains the entities or nothing depending on how and if the provided
* method is used.
*/
@Test(dataProvider = "returnEntityOnDemandData")
public void testBatchCreateReturnEntityOnDemand(Boolean returnEntity, boolean expectReturnEntity) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("second time!");
greeting.setTone(Tone.FRIENDLY);
Greeting greeting2 = new Greeting();
greeting2.setMessage("first time!");
greeting2.setTone(Tone.FRIENDLY);
List<Greeting> greetings = new ArrayList<>();
greetings.add(greeting);
greetings.add(greeting2);
CreateGreetingRequestBuilders builders = new CreateGreetingRequestBuilders();
CreateGreetingBatchCreateAndGetRequestBuilder builder = builders.batchCreateAndGet().inputs(greetings);
if (returnEntity != null) {
builder.returnEntity(returnEntity);
}
BatchCreateIdEntityRequest<Long, Greeting> batchCreateIdEntityRequest = builder.build();
Response<BatchCreateIdEntityResponse<Long, Greeting>> response = getClient().sendRequest(batchCreateIdEntityRequest).getResponse();
List<CreateIdEntityStatus<Long, Greeting>> createIdEntityStatuses = response.getEntity().getElements();
Assert.assertEquals(createIdEntityStatuses.size(), greetings.size(), "Expected size of batch response list to match size of input entity list.");
for (int i = 0; i < createIdEntityStatuses.size(); i++) {
CreateIdEntityStatus<Long, Greeting> createIdEntityStatus = createIdEntityStatuses.get(i);
Greeting expectedGreeting = greetings.get(i);
long id = createIdEntityStatus.getKey();
Assert.assertEquals((int) createIdEntityStatus.getStatus(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(createIdEntityStatus.getLocation(), "/" + CreateGreetingRequestBuilders.getPrimaryResource() + "/" + id);
if (expectReturnEntity) {
Greeting returnedEntity = createIdEntityStatus.getEntity();
Assert.assertNotNull(returnedEntity, "RecordTemplate entity in response should not be null.");
Assert.assertEquals(returnedEntity.getMessage(), expectedGreeting.getMessage(), "Expect returned entity message to match original.");
Assert.assertEquals(returnedEntity.getTone(), expectedGreeting.getTone(), "Expect returned entity tone to match original.");
} else {
Assert.assertNull(createIdEntityStatus.getEntity(), "RecordTemplate entity in response should be null.");
}
}
}
Aggregations