use of com.linkedin.restli.common.UpdateEntityStatus in project rest.li by linkedin.
the class TestReturnEntityWithBatchPartialUpdate method testBatchPartialUpdateEntities.
/**
* Sends batch partial update requests to the server and ensures that the returned entities for each request are
* consistent with the expected state of the server's entities.
*
* @param patches patches to send for this request
* @param expectedGreetings expected response entities for this request
*/
@Test(dataProvider = "batchPartialUpdateData")
public void testBatchPartialUpdateEntities(Map<Long, PatchRequest<Greeting>> patches, Map<Long, Greeting> expectedGreetings) throws RemoteInvocationException {
BatchPartialUpdateEntityRequest<Long, Greeting> request = new PartialUpdateGreetingRequestBuilders().batchPartialUpdateAndGet().inputs(patches).build();
Response<BatchKVResponse<Long, UpdateEntityStatus<Greeting>>> response = getClient().sendRequest(request).getResponse();
Assert.assertNotNull(response);
BatchKVResponse<Long, UpdateEntityStatus<Greeting>> batchKVResponse = response.getEntity();
Assert.assertNotNull(batchKVResponse);
Assert.assertTrue(batchKVResponse.getErrors().isEmpty());
Map<Long, UpdateEntityStatus<Greeting>> greetings = batchKVResponse.getResults();
Assert.assertNotNull(greetings);
for (Long key : greetings.keySet()) {
Assert.assertTrue(expectedGreetings.containsKey(key));
UpdateEntityStatus<Greeting> updateEntityStatus = greetings.get(key);
Assert.assertNotNull(updateEntityStatus);
Assert.assertEquals(updateEntityStatus.getStatus().intValue(), HttpStatus.S_200_OK.getCode());
Assert.assertTrue(updateEntityStatus.hasEntity());
Assert.assertFalse(updateEntityStatus.hasError());
Greeting greeting = updateEntityStatus.getEntity();
Greeting expectedGreeting = expectedGreetings.get(key);
Assert.assertNotNull(greeting);
Assert.assertNotNull(expectedGreeting);
Assert.assertEquals(greeting.getId(), expectedGreeting.getId());
Assert.assertEquals(greeting.getMessage(), expectedGreeting.getMessage());
Assert.assertEquals(greeting.getTone(), expectedGreeting.getTone());
}
}
use of com.linkedin.restli.common.UpdateEntityStatus in project rest.li by linkedin.
the class TestReturnEntityWithBatchPartialUpdate method testBatchPartialUpdateEntitiesWithProjection.
/**
* Same as {@link this#testBatchPartialUpdateEntities}, except the fields of the returned entities are projected.
*
* @param patches patches to send for this request
* @param expectedGreetings expected response entities for this request
*/
@Test(dataProvider = "batchPartialUpdateData")
public void testBatchPartialUpdateEntitiesWithProjection(Map<Long, PatchRequest<Greeting>> patches, Map<Long, Greeting> expectedGreetings) throws RemoteInvocationException {
final Greeting.Fields fields = Greeting.fields();
BatchPartialUpdateEntityRequest<Long, Greeting> request = new PartialUpdateGreetingRequestBuilders().batchPartialUpdateAndGet().inputs(patches).fields(fields.id(), fields.message()).build();
Response<BatchKVResponse<Long, UpdateEntityStatus<Greeting>>> response = getClient().sendRequest(request).getResponse();
Assert.assertNotNull(response);
BatchKVResponse<Long, UpdateEntityStatus<Greeting>> batchKVResponse = response.getEntity();
Assert.assertNotNull(batchKVResponse);
Assert.assertTrue(batchKVResponse.getErrors().isEmpty());
Map<Long, UpdateEntityStatus<Greeting>> greetings = batchKVResponse.getResults();
Assert.assertNotNull(greetings);
for (Long key : greetings.keySet()) {
Assert.assertTrue(expectedGreetings.containsKey(key));
UpdateEntityStatus<Greeting> updateEntityStatus = greetings.get(key);
Assert.assertNotNull(updateEntityStatus);
Assert.assertEquals(updateEntityStatus.getStatus().intValue(), HttpStatus.S_200_OK.getCode());
Assert.assertTrue(updateEntityStatus.hasEntity());
Assert.assertFalse(updateEntityStatus.hasError());
Greeting greeting = updateEntityStatus.getEntity();
Greeting expectedGreeting = expectedGreetings.get(key);
Assert.assertNotNull(greeting);
Assert.assertNotNull(expectedGreeting);
Assert.assertTrue(greeting.hasId(), "Response record should include an id field.");
Assert.assertTrue(greeting.hasMessage(), "Response record should include a message field.");
Assert.assertFalse(greeting.hasTone(), "Response record should not include a tone field due to projection.");
Assert.assertEquals(greeting.getId(), expectedGreeting.getId());
Assert.assertEquals(greeting.getMessage(), expectedGreeting.getMessage());
Assert.assertNull(greeting.getTone(GetMode.NULL), "Response record should have a null tone field due to projection.");
}
}
use of com.linkedin.restli.common.UpdateEntityStatus in project rest.li by linkedin.
the class BatchUpdateEntityResponse method deserializeValue.
@Override
protected UpdateEntityStatus<E> deserializeValue(Object valueData) {
DataMap valueDataMap = (DataMap) valueData;
E entity = valueDataMap.containsKey(UpdateEntityStatus.ENTITY) ? DataTemplateUtil.wrap(((DataMap) valueData).getDataMap(UpdateEntityStatus.ENTITY), _entityType.getType()) : null;
return new UpdateEntityStatus<>((DataMap) valueData, entity);
}
Aggregations