use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testComplexKey_partialUpdate.
@Test
public void testComplexKey_partialUpdate() throws Exception {
ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Message message = new Message();
message.setTone(Tone.FRIENDLY);
PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> inputs = new HashMap<>();
ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
inputs.put(key1, patch);
inputs.put(key2, patch);
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> result = complexKeyClient.batchPartialUpdate(inputs).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
// Update return valid result
Assert.assertEquals(result.get(key1).getStatus().intValue(), 204);
Assert.assertEquals(result.get(key2).getStatus().intValue(), 204);
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResult = complexKeyClient.batchGet(new HashSet<>(Arrays.asList(key1, key2))).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(getResult.get(key1).getEntity().getTone(), Tone.FRIENDLY);
Assert.assertEquals(getResult.get(key2).getEntity().getTone(), Tone.FRIENDLY);
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testAssociateResourceBatchGet.
@Test
public void testAssociateResourceBatchGet() throws Exception {
Associations associations = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Map<CompoundKey, EntityResponse<Message>> entityResponse = associations.batchGet(getAssociateResourceMockDB(associations).keySet()).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
for (CompoundKey id : getAssociateResourceMockDB(associations).keySet()) {
Assert.assertTrue(entityResponse.containsKey(id));
EntityResponse<Message> single = entityResponse.get(id);
Assert.assertEquals(single.getEntity(), getAssociateResourceMockDB(associations).get(id));
}
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class BatchGetResponseBuilder method toBatchResponse.
private static <K, V extends RecordTemplate> BatchResponse<AnyRecord> toBatchResponse(Map<K, EntityResponse<V>> entities, ProtocolVersion protocolVersion) {
final DataMap splitResponseData = new DataMap();
final DataMap splitResults = new DataMap();
final DataMap splitStatuses = new DataMap();
final DataMap splitErrors = new DataMap();
for (Map.Entry<K, EntityResponse<V>> resultEntry : entities.entrySet()) {
final DataMap entityResponseData = resultEntry.getValue().data();
final String stringKey = URIParamUtils.encodeKeyForBody(resultEntry.getKey(), false, protocolVersion);
final DataMap entityData = entityResponseData.getDataMap(EntityResponse.ENTITY);
if (entityData != null) {
CheckedUtil.putWithoutChecking(splitResults, stringKey, entityData);
}
final Integer status = entityResponseData.getInteger(EntityResponse.STATUS);
if (status != null) {
CheckedUtil.putWithoutChecking(splitStatuses, stringKey, status);
}
final DataMap error = entityResponseData.getDataMap(EntityResponse.ERROR);
if (error != null) {
CheckedUtil.putWithoutChecking(splitErrors, stringKey, error);
}
}
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.RESULTS, splitResults);
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.STATUSES, splitStatuses);
CheckedUtil.putWithoutChecking(splitResponseData, BatchResponse.ERRORS, splitErrors);
return new BatchResponse<>(splitResponseData, AnyRecord.class);
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class BatchGetResponseBuilder method buildResponse.
@Override
@SuppressWarnings("unchecked")
public RestLiResponse buildResponse(RoutingResult routingResult, RestLiResponseData<BatchGetResponseEnvelope> responseData) {
final Map<Object, BatchResponseEntry> responses = (Map<Object, BatchResponseEntry>) responseData.getResponseEnvelope().getBatchResponseMap();
// Build the EntityResponse for each key from the merged map with mask from routingResult.
Map<Object, EntityResponse<RecordTemplate>> entityBatchResponse = buildEntityResponse(routingResult, responses);
RestLiResponse.Builder builder = new RestLiResponse.Builder();
final ProtocolVersion protocolVersion = routingResult.getContext().getRestliProtocolVersion();
@SuppressWarnings("unchecked") final BatchResponse<AnyRecord> response = toBatchResponse(entityBatchResponse, protocolVersion);
builder.entity(response);
return builder.headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
use of com.linkedin.restli.common.EntityResponse in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchGetWithProjection.
@Test
public void testBatchGetWithProjection() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Set<Long> ids = Sets.newHashSet(Arrays.asList(1L, 2L, 3L));
CompletionStage<Map<Long, EntityResponse<Greeting>>> result = greetings.batchGet(ids, optionalParams -> optionalParams.withMask(mask -> mask.withTone()));
CompletableFuture<Map<Long, EntityResponse<Greeting>>> future = result.toCompletableFuture();
Map<Long, EntityResponse<Greeting>> resultMap = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(resultMap.size(), ids.size());
for (Long id : ids) {
EntityResponse<Greeting> g = resultMap.get(id);
Assert.assertNotNull(g);
Assert.assertTrue(g.hasEntry());
Assert.assertFalse(g.getEntity().hasId());
Assert.assertFalse(g.getEntity().hasMessage());
Assert.assertTrue(g.getEntity().hasTone());
}
}
Aggregations