use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestRestLiResponseHandler method testFieldProjection_batch.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicDataWithBatchUri")
public void testFieldProjection_batch(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String uri, String errorResponseHeaderName) throws Exception {
RestResponse response;
Map<Integer, Status> statusBatch = buildStatusBatchResponse(10, "f1", "f2", "f3");
RestRequest request = buildRequest(uri, acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request, buildRoutingResult(ResourceMethod.BATCH_GET, request, acceptTypeData.acceptHeaders), statusBatch);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), Status.class.getName(), true, errorResponseHeaderName);
DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());
BatchResponse<Status> batchResponse = new BatchResponse<Status>(dataMap, Status.class);
assertEquals(batchResponse.getResults().size(), 10);
for (Status status : batchResponse.getResults().values()) {
assertTrue(status.data().containsKey("f1"));
assertTrue(status.data().containsKey("f2"));
assertFalse(status.data().containsKey("f3"));
}
// ensure that output map was not modified by rest.li!
Status status1 = statusBatch.get(1);
assertNotNull(status1);
assertTrue(status1.data().containsKey("f3"));
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestRestLiResponseHandler method testRestLiResponseData.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testRestLiResponseData(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
RestLiResponseData responseData;
RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
// #1 simple record template
responseData = _responseHandler.buildRestLiResponseData(request, routingResult1, buildStatusRecord());
checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
assertEquals(responseData.getRecordResponseEnvelope().getRecord().toString(), response1);
// #2 DataTemplate response
StringMap map = new StringMap();
map.put("key1", "value1");
map.put("key2", "value2");
RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
responseData = _responseHandler.buildRestLiResponseData(request, routingResult2, map);
checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
//Obtain the maps necessary for comparison
final DataMap actualMap;
final DataMap expectedMap;
actualMap = responseData.getRecordResponseEnvelope().getRecord().data();
expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
assertEquals(actualMap, expectedMap);
RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
// #3 empty response
responseData = _responseHandler.buildRestLiResponseData(request, routingResult3, null);
checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
assertEquals(responseData.getRecordResponseEnvelope().getRecord(), null);
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseGetAssociativeResource.
@Test
public void testPromiseGetAssociativeResource() throws Exception {
ResourceModel followsResourceModel = buildResourceModel(PromiseFollowsAssociativeResource.class);
ResourceMethodDescriptor methodDescriptor;
PromiseFollowsAssociativeResource resource;
// #1: get
methodDescriptor = followsResourceModel.findMethod(ResourceMethod.GET);
resource = getMockResource(PromiseFollowsAssociativeResource.class);
CompoundKey rawKey = new CompoundKey();
rawKey.append("followerID", 1L);
rawKey.append("followeeID", 2L);
CompoundKey key = eq(rawKey);
EasyMock.expect(resource.get(key)).andReturn(Promises.value(new Followed(new DataMap()))).once();
checkInvocation(resource, methodDescriptor, "GET", version, "/promisefollows/(followerID:1,followeeID:2)", buildPathKeys("followerID", 1L, "followeeID", 2L, followsResourceModel.getKeyName(), rawKey));
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class BatchCreateRequestBuilder method buildReadOnlyInput.
private CollectionRequest<V> buildReadOnlyInput() {
try {
DataMap map = new DataMap();
CollectionRequest<V> input = new CollectionRequest<V>(map, _valueClass);
for (V entity : _entities) {
input.getElements().add(getReadOnlyOrCopyDataTemplate(entity));
}
map.setReadOnly();
return input;
} catch (CloneNotSupportedException cloneException) {
throw new IllegalArgumentException("Entity cannot be copied.", cloneException);
}
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class BatchPartialUpdateRequestBuilder method buildReadOnlyInput.
private CollectionRequest<KeyValueRecord<K, PatchRequest<V>>> buildReadOnlyInput() {
try {
DataMap map = new DataMap();
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord<K, PatchRequest<V>>> input = new CollectionRequest(map, KeyValueRecord.class);
for (Map.Entry<K, PatchRequest<V>> inputEntityEntry : _partialUpdateInputMap.entrySet()) {
K key = getReadOnlyOrCopyKey(inputEntityEntry.getKey());
PatchRequest<V> entity = getReadOnlyOrCopyDataTemplate(inputEntityEntry.getValue());
KeyValueRecord<K, PatchRequest<V>> keyValueRecord = _keyValueRecordFactory.create(key, entity);
keyValueRecord.data().setReadOnly();
input.getElements().add(keyValueRecord);
}
map.setReadOnly();
return input;
} catch (CloneNotSupportedException cloneException) {
throw new IllegalArgumentException("Entity cannot be copied.", cloneException);
}
}
Aggregations