use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testNegativeMaskNestedFields.
@Test
public void testNegativeMaskNestedFields() {
MaskTree mask = MaskCreator.createNegativeMask(new PathSpec("foo", "bar"), new PathSpec("bar", "baz"), new PathSpec("qux"));
// "{foo={bar=0}, bar={baz=0}, qux=0}"
final DataMap fooBarQuxMap = new DataMap();
fooBarQuxMap.put("qux", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
final DataMap barMap = new DataMap();
barMap.put("baz", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
final DataMap fooMap = new DataMap();
fooMap.put("bar", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
fooBarQuxMap.put("foo", fooMap);
fooBarQuxMap.put("bar", barMap);
Assert.assertEquals(mask.getDataMap(), fooBarQuxMap, "The MaskTree DataMap should match");
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testMaskWithWildcard.
@Test
public void testMaskWithWildcard() {
MaskTree mask = new MaskTree();
PathSpec wildcardSpec = new PathSpec("foo", PathSpec.WILDCARD, "bar");
PathSpec asterixSpec = new PathSpec("foo", "*", "bar");
Assert.assertFalse(wildcardSpec.equals(asterixSpec));
mask.addOperation(wildcardSpec, MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.toString(), "{foo={$*={bar=1}}}");
Assert.assertEquals(mask.getOperations().get(wildcardSpec), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(asterixSpec), null);
mask = new MaskTree();
mask.addOperation(asterixSpec, MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.toString(), "{foo={*={bar=1}}}");
Assert.assertEquals(mask.getOperations().get(asterixSpec), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(wildcardSpec), null);
mask = new MaskTree();
mask.addOperation(asterixSpec, MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(wildcardSpec, MaskOperation.NEGATIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(wildcardSpec), MaskOperation.NEGATIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(asterixSpec), MaskOperation.POSITIVE_MASK_OP);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testComposingNegativeSubmasks.
/**
* When negative mask for a PathSpec is composed with another negative mask, which is sub-PathSpec, then
* the result is a negative mask with PathSpec only for the parent, because negative mask means
* "remove field and all it's children".
*/
@Test
public void testComposingNegativeSubmasks() {
MaskTree mask = new MaskTree();
mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.NEGATIVE_MASK_OP);
mask.addOperation(new PathSpec("a", "b"), MaskOperation.NEGATIVE_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 testPositiveMaskWithFullArrayRangeValues.
@Test
public void testPositiveMaskWithFullArrayRangeValues() {
PathSpec parentPath = new PathSpec("parent");
// Build the array field's path with range (0 to 999)
PathSpec arrayFirstHalfPath = new PathSpec(parentPath.getPathComponents(), "arrayField");
arrayFirstHalfPath.setAttribute(PathSpec.ATTR_ARRAY_START, 0);
arrayFirstHalfPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 1000);
// Build the array field's path with range (1000 to Integer.MAX_INT)
PathSpec arraySecondHalfPath = new PathSpec(parentPath.getPathComponents(), "arrayField");
arraySecondHalfPath.setAttribute(PathSpec.ATTR_ARRAY_START, 1000);
arraySecondHalfPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, Integer.MAX_VALUE);
MaskTree mask = MaskCreator.createPositiveMask(arrayFirstHalfPath, arraySecondHalfPath);
// Build the expected map with both start and count filtered out
// {parent={arrayField={$*=1}}}
DataMap parentMap = new DataMap();
DataMap arrayFieldMap = new DataMap();
arrayFieldMap.put(FilterConstants.WILDCARD, MaskOperation.POSITIVE_MASK_OP.getRepresentation());
parentMap.put("arrayField", arrayFieldMap);
DataMap expectedMaskMap = new DataMap();
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestMaskCreation method testComposingPositiveSubmasks.
/**
* When positive mask for a PathSpec is composed with another positive mask, which is sub-PathSpec, then
* the result is a positive mask with PathSpec only for the parent, because positive mask means
* "select field and all it's children".
*/
@Test
public void testComposingPositiveSubmasks() {
MaskTree mask = new MaskTree();
mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(new PathSpec("a", "b"), MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(new PathSpec("a"), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.toString(), "{a=1}");
}
Aggregations