use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestAbstractRequestBuilder method testProjectionFields.
@Test
public void testProjectionFields() {
final AbstractRequestBuilder<?, ?, ?> builder = new DummyAbstractRequestBuilder();
builder.addFields(new PathSpec("firstField"), new PathSpec("secondField", PathSpec.WILDCARD, "thirdField"));
Assert.assertTrue(builder.getParam(RestConstants.FIELDS_PARAM) instanceof PathSpec[]);
final PathSpec[] fieldsPathSpecs = (PathSpec[]) builder.getParam(RestConstants.FIELDS_PARAM);
Assert.assertEquals(fieldsPathSpecs[0].toString(), "/firstField", "The path spec(s) should match!");
Assert.assertEquals(fieldsPathSpecs[1].toString(), "/secondField/*/thirdField", "The path spec(s) should match!");
builder.addMetadataFields(new PathSpec(PathSpec.WILDCARD, "fourthField"), new PathSpec("fifthField"));
Assert.assertTrue(builder.getParam(RestConstants.METADATA_FIELDS_PARAM) instanceof PathSpec[]);
final PathSpec[] metadataFieldsPathSpecs = (PathSpec[]) builder.getParam(RestConstants.METADATA_FIELDS_PARAM);
Assert.assertEquals(metadataFieldsPathSpecs[0].toString(), "/*/fourthField", "The path spec(s) should match!");
Assert.assertEquals(metadataFieldsPathSpecs[1].toString(), "/fifthField", "The path spec(s) should match!");
builder.addPagingFields(new PathSpec("sixthField", PathSpec.WILDCARD), new PathSpec("seventhField"), new PathSpec(PathSpec.WILDCARD));
Assert.assertTrue(builder.getParam(RestConstants.PAGING_FIELDS_PARAM) instanceof PathSpec[]);
final PathSpec[] pagingFieldsPathSpecs = (PathSpec[]) builder.getParam(RestConstants.PAGING_FIELDS_PARAM);
Assert.assertEquals(pagingFieldsPathSpecs[0].toString(), "/sixthField/*", "The path spec(s) should match!");
Assert.assertEquals(pagingFieldsPathSpecs[1].toString(), "/seventhField", "The path spec(s) should match!");
Assert.assertEquals(builder.buildReadOnlyQueryParameters().size(), 3, "We should have 3 query parameters, one for each projection type");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testMixedMask.
@Test
public void testMixedMask() {
MaskTree mask = new MaskTree();
mask.addOperation(new PathSpec("foo", "bar"), MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(new PathSpec("baz", "qux"), MaskOperation.NEGATIVE_MASK_OP);
//"{baz={qux=0}, foo={bar=1}}"
final DataMap bazFooMap = new DataMap();
final DataMap bazMap = new DataMap();
final DataMap fooMap = new DataMap();
bazMap.put("qux", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
fooMap.put("bar", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
bazFooMap.put("baz", bazMap);
bazFooMap.put("foo", fooMap);
Assert.assertEquals(mask.getDataMap(), bazFooMap, "The MaskTree DataMap should match");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPatchCreation method testExplicitPatchCreationSet.
@Test
public void testExplicitPatchCreationSet() {
PatchTree patch = new PatchTree();
patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.setFieldOp("The quick brown fox"));
//"{$set={foo=42}, bar={$set={baz=The quick brown fox}}}"
final DataMap setBarMap = new DataMap();
final DataMap bazMap = new DataMap();
bazMap.put("baz", "The quick brown fox");
final DataMap setMap = new DataMap();
setMap.put(PatchConstants.SET_COMMAND, bazMap);
setBarMap.put("bar", setMap);
final DataMap fooMap = new DataMap();
fooMap.put("foo", 42);
setBarMap.put(PatchConstants.SET_COMMAND, fooMap);
assertEquals(patch.getDataMap(), setBarMap, "PatchTree DataMap must be correct");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPatchCreation method testExplicitPatchCreationRemove.
@Test
public void testExplicitPatchCreationRemove() {
PatchTree patch = new PatchTree();
patch.addOperation(new PathSpec("foo"), PatchOpFactory.REMOVE_FIELD_OP);
patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
Assert.assertEquals(patch.toString(), "{bar={$delete=[baz]}, $delete=[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);
}
Aggregations