use of com.linkedin.restli.common.ResourceProperties in project rest.li by linkedin.
the class TestRequest method testResourceProperties.
@Test
public void testResourceProperties() {
Set<ResourceMethod> expectedSupportedMethods = new HashSet<ResourceMethod>();
expectedSupportedMethods.add(ResourceMethod.GET);
expectedSupportedMethods.add(ResourceMethod.BATCH_PARTIAL_UPDATE);
ResourceSpec expectedResourceSpec = new ResourceSpecImpl(expectedSupportedMethods, null, null, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, Object>emptyMap());
Map<String, Object> pathKeys = new HashMap<String, Object>();
pathKeys.put("id", new ComplexResourceKey<TestRecord, TestRecord>(new TestRecord(), new TestRecord()));
Request<TestRecord> request = new Request<TestRecord>(ResourceMethod.GET, null, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new EntityResponseDecoder<TestRecord>(TestRecord.class), expectedResourceSpec, Collections.<String, Object>emptyMap(), Collections.<String, Class<?>>emptyMap(), null, "testRecord", pathKeys, RestliRequestOptions.DEFAULT_OPTIONS, null);
ResourceProperties expectedResourceProperties = new ResourcePropertiesImpl(expectedResourceSpec.getSupportedMethods(), expectedResourceSpec.getKeyType(), expectedResourceSpec.getComplexKeyType(), expectedResourceSpec.getValueType(), expectedResourceSpec.getKeyParts());
Assert.assertEquals(request.getResourceProperties(), expectedResourceProperties);
}
use of com.linkedin.restli.common.ResourceProperties in project rest.li by linkedin.
the class TestScatterGather method testRequest.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void testRequest(BatchRequest<?> request, Set<String> expectedParams, Set<PathSpec> expectedFields, Map<Long, Greeting> expectedInput, Set<Set<String>> requestIdSets, Set<Long> requestIds) {
Assert.assertEquals(request.getQueryParamsObjects().keySet(), expectedParams);
if (expectedFields != null) {
Collection<PathSpec> actualFields = (Collection<PathSpec>) request.getQueryParamsObjects().get(RestConstants.FIELDS_PARAM);
for (PathSpec field : actualFields) {
Assert.assertTrue(expectedFields.contains(field));
}
}
Set<String> uriIds = new HashSet<String>();
for (Long id : (Collection<Long>) request.getQueryParamsObjects().get(RestConstants.QUERY_BATCH_IDS_PARAM)) {
uriIds.add(id.toString());
}
if (expectedInput != null) {
RecordTemplate inputRecordTemplate;
if (request instanceof BatchUpdateRequest) {
ResourceProperties resourceProperties = request.getResourceProperties();
CollectionRequest inputRecord = (CollectionRequest) request.getInputRecord();
inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord, resourceProperties.getKeyType(), resourceProperties.getComplexKeyType(), resourceProperties.getKeyParts(), resourceProperties.getValueType());
} else {
inputRecordTemplate = request.getInputRecord();
}
checkInput(inputRecordTemplate.data().getDataMap(com.linkedin.restli.common.BatchRequest.ENTITIES), expectedInput, uriIds);
}
Set<Object> idObjects = request.getObjectIds();
Set<String> theseIds = new HashSet<String>(idObjects.size());
for (Object o : idObjects) {
theseIds.add(o.toString());
}
Assert.assertEquals(uriIds, theseIds);
//no duplicate requests
Assert.assertFalse(requestIdSets.contains(theseIds));
for (String id : theseIds) {
//no duplicate ids
Assert.assertFalse(requestIds.contains(Long.parseLong(id)));
requestIds.add(Long.parseLong(id));
}
requestIdSets.add(theseIds);
}
use of com.linkedin.restli.common.ResourceProperties in project rest.li by linkedin.
the class TestScatterGather method testGetEntityRequest.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void testGetEntityRequest(BatchRequest<BatchKVResponse<Long, EntityResponse<Greeting>>> request, Set<String> expectedParams, Set<PathSpec> expectedFields, Map<Long, Greeting> expectedInput, Set<Set<String>> requestIdSets, Set<Long> requestIds) {
Assert.assertEquals(request.getQueryParamsObjects().keySet(), expectedParams);
if (expectedFields != null) {
Collection<PathSpec> actualFields = (Collection<PathSpec>) request.getQueryParamsObjects().get(RestConstants.FIELDS_PARAM);
for (PathSpec field : actualFields) {
Assert.assertTrue(expectedFields.contains(field));
}
}
Set<String> uriIds = new HashSet<String>();
for (Long id : (Collection<Long>) request.getQueryParamsObjects().get(RestConstants.QUERY_BATCH_IDS_PARAM)) {
uriIds.add(id.toString());
}
if (expectedInput != null) {
RecordTemplate inputRecordTemplate;
if (request instanceof BatchUpdateRequest) {
ResourceProperties resourceProperties = request.getResourceProperties();
CollectionRequest inputRecord = (CollectionRequest) request.getInputRecord();
inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord, resourceProperties.getKeyType(), resourceProperties.getComplexKeyType(), resourceProperties.getKeyParts(), resourceProperties.getValueType());
} else {
inputRecordTemplate = request.getInputRecord();
}
checkInput(inputRecordTemplate.data().getDataMap(com.linkedin.restli.common.BatchRequest.ENTITIES), expectedInput, uriIds);
}
Set<Object> idObjects = request.getObjectIds();
Set<String> theseIds = new HashSet<String>(idObjects.size());
for (Object o : idObjects) {
theseIds.add(o.toString());
}
Assert.assertEquals(uriIds, theseIds);
//no duplicate requests
Assert.assertFalse(requestIdSets.contains(theseIds));
for (String id : theseIds) {
//no duplicate ids
Assert.assertFalse(requestIds.contains(Long.parseLong(id)));
requestIds.add(Long.parseLong(id));
}
requestIdSets.add(theseIds);
}
Aggregations