use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestPatchCreation method testExplicitPatchCreationMixed.
@Test
public void testExplicitPatchCreationMixed() {
PatchTree patch = new PatchTree();
patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
// "{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}"
final DataMap fooMap = new DataMap();
fooMap.put("foo", 42);
final DataMap deleteMap = new DataMap();
deleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("baz")));
final DataMap setBarDeleteMap = new DataMap();
setBarDeleteMap.put(PatchConstants.SET_COMMAND, fooMap);
setBarDeleteMap.put("bar", deleteMap);
setBarDeleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("qux")));
assertEquals(patch.getDataMap(), setBarDeleteMap, "PatchTree DataMap must be correct");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testComposingNegativeMaskWithPositiveSubmasks.
/**
* When negative mask for a PathSpec is composed with positive mask, which is sub-PathSpec, then
* the result is a negative mask with PathSpec only for the parent, because negative mask has a
* higher priority then a positive mask.
* @throws IOException
*/
@Test
public void testComposingNegativeMaskWithPositiveSubmasks() throws IOException {
MaskTree mask = new MaskTree();
mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(new PathSpec("a"), MaskOperation.NEGATIVE_MASK_OP);
Assert.assertEquals(mask.toString(), "{a=0}");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testPositiveMaskWithArrayWildcardAndRange.
@Test
public void testPositiveMaskWithArrayWildcardAndRange() {
PathSpec parentPath = new PathSpec("parent");
PathSpec childPath = new PathSpec(parentPath.getPathComponents(), "child");
childPath.setAttribute(PathSpec.ATTR_ARRAY_START, 10);
childPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
PathSpec grandChildrenPath = new PathSpec(childPath.getPathComponents(), PathSpec.WILDCARD);
PathSpec specificGrandChildPath = new PathSpec(childPath.getPathComponents(), "TheKid");
// The pathspec 'specificGrandChildPath' should show up in the mask as we have the wildcard specified for grand children
MaskTree mask = MaskCreator.createPositiveMask(childPath, grandChildrenPath, specificGrandChildPath);
// {parent={child={$*=1, $start=10, $count=5}}}
DataMap childMap = new DataMap();
childMap.put(FilterConstants.START, 10);
childMap.put(FilterConstants.COUNT, 5);
childMap.put(FilterConstants.WILDCARD, MaskOperation.POSITIVE_MASK_OP.getRepresentation());
DataMap parentMap = new DataMap();
parentMap.put("child", childMap);
DataMap expectedMaskMap = new DataMap();
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
Map<PathSpec, MaskOperation> operations = mask.getOperations();
Assert.assertEquals(operations.size(), 2);
Assert.assertEquals(operations.get(childPath), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(operations.get(grandChildrenPath), MaskOperation.POSITIVE_MASK_OP);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testPositiveMaskWithRandomAttributes.
@Test
public void testPositiveMaskWithRandomAttributes() {
PathSpec parentPath = new PathSpec("parent");
PathSpec childPath = new PathSpec(parentPath.getPathComponents(), "child");
// This shouldn't be in the generated MaskTree
childPath.setAttribute("random", 10);
childPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
MaskTree mask = MaskCreator.createPositiveMask(childPath);
// {parent={child={$count=5}}}
DataMap childMap = new DataMap();
childMap.put(FilterConstants.COUNT, 5);
DataMap parentMap = new DataMap();
parentMap.put("child", childMap);
DataMap expectedMaskMap = new DataMap();
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
// Create a copy of the childPath without the random attribute as the generated mask won't include those attributes
PathSpec childPathCopy = new PathSpec(childPath.getPathComponents().toArray(new String[0]));
childPathCopy.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
Map<PathSpec, MaskOperation> operations = mask.getOperations();
Assert.assertEquals(operations.size(), 1);
Assert.assertEquals(operations.get(childPathCopy), MaskOperation.POSITIVE_MASK_OP);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testNegativeMaskSingleField.
@Test
public void testNegativeMaskSingleField() {
MaskTree mask = MaskCreator.createNegativeMask(new PathSpec("foo"));
Assert.assertEquals(mask.toString(), "{foo=0}");
}
Aggregations