use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPatchGeneration method testSimplePositiveMask.
@Test
public void testSimplePositiveMask() throws Exception {
List<PathSpec> fields = Arrays.asList(Group.fields().name(), Group.fields().description(), Group.fields().id());
MaskTree mask = MaskCreator.createPositiveMask(fields);
//"{id=1, description=1, name=1}"
final DataMap idDescriptionNameMap = new DataMap();
idDescriptionNameMap.put("id", 1);
idDescriptionNameMap.put("description", 1);
idDescriptionNameMap.put("name", 1);
assertEquals(mask.getDataMap(), idDescriptionNameMap, "The MaskTree DataMap should be correct");
//The ordering might be different but the URI should look something like:
//"id,description,name";
final String actualEncodedMaskURI = URIMaskUtil.encodeMaskForURI(mask);
final Set<String> maskURISet = new HashSet<String>(Arrays.asList(actualEncodedMaskURI.split(",")));
final Set<String> expectedURISet = new HashSet<String>();
expectedURISet.add("id");
expectedURISet.add("description");
expectedURISet.add("name");
Assert.assertEquals(maskURISet, expectedURISet, "The encoded mask should be correct");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionPartialUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionPartialUpdate")
public void testCustomCrudParamsCollectionPartialUpdate(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.PARTIAL_UPDATE);
CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
PatchTree p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
PatchRequest<CombinedTestDataModels.Foo> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(resource.myUpdate(eq("foo"), eq(expected), eq(1), eq("bar"))).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "POST", version, uri, body, buildPathKeys("testId", "foo"));
}
use of com.linkedin.data.schema.PathSpec 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.data.schema.PathSpec in project rest.li by linkedin.
the class TestScatterGather method testBuildSGGetRequests.
private static void testBuildSGGetRequests(int numEndpoints, ScatterGatherBuilder<Greeting> sg, Long[] ids) throws ServiceUnavailableException {
Collection<ScatterGatherBuilder.RequestInfo<Greeting>> requests = buildScatterGatherGetRequests(sg, ids);
Assert.assertEquals(requests.size(), numEndpoints);
Set<Set<String>> requestIdSets = new HashSet<Set<String>>();
Set<Long> requestIds = new HashSet<Long>();
for (ScatterGatherBuilder.RequestInfo<Greeting> requestInfo : requests) {
//URI will be something like "greetings/?ids=21&ids=4&ids=53&ids=60&ids=66&ids=88&ids=93&foo=bar"
BatchRequest<BatchResponse<Greeting>> request = requestInfo.getBatchRequest();
Set<String> expectedParams = new HashSet<String>();
expectedParams.add(RestConstants.QUERY_BATCH_IDS_PARAM);
expectedParams.add("foo");
expectedParams.add(RestConstants.FIELDS_PARAM);
Set<PathSpec> expectedFields = Collections.singleton(new PathSpec("message"));
testRequest(request, expectedParams, expectedFields, null, requestIdSets, requestIds);
}
Assert.assertTrue(requestIds.containsAll(Arrays.asList(ids)));
Assert.assertEquals(requestIds.size(), ids.length);
}
use of com.linkedin.data.schema.PathSpec 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