use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestMaskCreation method testComposingPositiveMaskWithNegativeSubmasks.
/**
* When positive mask for a PathSpec is composed with negative mask, which is sub-PathSpec, then
* the result is a mask, which selects all fields in PathSpec using wildcard with negative mask
* for sub-PathSpec. This is because negative mask has a higher priority then a positive mask.
* @throws IOException
*/
@Test
public void testComposingPositiveMaskWithNegativeSubmasks() throws IOException {
MaskTree mask = new MaskTree();
mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.NEGATIVE_MASK_OP);
mask.addOperation(new PathSpec("a"), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.toString(), dataMapFromString("{'a': {'$*': 1, 'b': {'c': 0}}}".replace('\'', '"')).toString());
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestMaskCreation method testPositiveMaskSingleField.
@Test
public void testPositiveMaskSingleField() {
MaskTree mask = MaskCreator.createPositiveMask(new PathSpec("foo"));
Assert.assertEquals(mask.toString(), "{foo=1}");
}
use of com.linkedin.data.transform.filter.request.MaskTree 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.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestResourceContext method testResourceContextURIDecoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "uriDecoding")
public void testResourceContextURIDecoding(ProtocolVersion version, String stringUri) throws Exception {
URI uri = URI.create(stringUri);
Map<String, String> headers = new HashMap<String, String>(1);
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), new MockRequest(uri, headers), new RequestContext());
final MaskTree entityMask = context.getProjectionMask();
//"{baz=1, foo=1, bar=1}"
final DataMap expectedEntityMap = new DataMap();
expectedEntityMap.put("baz", 1);
expectedEntityMap.put("foo", 1);
expectedEntityMap.put("bar", 1);
Assert.assertEquals(entityMask.getDataMap(), expectedEntityMap, "The generated DataMap for the MaskTree should be correct");
final MaskTree metadataMask = context.getMetadataProjectionMask();
//"{region=1, city=1}"
final DataMap expectedmetadataMap = new DataMap();
expectedmetadataMap.put("region", 1);
expectedmetadataMap.put("city", 1);
Assert.assertEquals(metadataMask.getDataMap(), expectedmetadataMap, "The generated DataMap for the MaskTree should be correct");
final MaskTree pagingMask = context.getPagingProjectionMask();
//"{start=1, links=1}"
final DataMap expectedPagingMap = new DataMap();
expectedPagingMap.put("start", 1);
expectedPagingMap.put("links", 1);
Assert.assertEquals(pagingMask.getDataMap(), expectedPagingMap, "The generated DataMap for the MaskTree should be correct");
DataMap parameters = context.getParameters();
DataMap expectedParameters = new DataMap();
expectedParameters.put("fields", "foo,bar,baz");
expectedParameters.put("metadataFields", "city,region");
expectedParameters.put("pagingFields", "start,links");
expectedParameters.put("q", "test");
DataMap testParam = new DataMap();
DataList aValue = new DataList();
aValue.add("b");
aValue.add("c");
aValue.add("d");
testParam.put("a", aValue);
expectedParameters.put("testParam", testParam);
Assert.assertEquals(parameters, expectedParameters);
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestResourceContext method testResourceContextWithQueryParamsGetProjectionMaskWithMaskSyntax.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "queryParamsProjectionMaskWithSyntax")
public void testResourceContextWithQueryParamsGetProjectionMaskWithMaskSyntax(ProtocolVersion version, String stringUri) throws Exception {
URI uri = URI.create(stringUri);
Map<String, String> headers = new HashMap<String, String>(1);
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
ResourceContext context = new ResourceContextImpl(new PathKeysImpl(), new MockRequest(uri, headers), new RequestContext());
//Assert.assertEquals(mask.toString(), "{location={longitude=1, latitude=1}, locale=1, state=1}");
final MaskTree entityMask = context.getProjectionMask();
final DataMap expectedEntityMap = new DataMap();
expectedEntityMap.put("locale", 1);
expectedEntityMap.put("state", 1);
final DataMap locationMap = new DataMap();
locationMap.put("longitude", 1);
locationMap.put("latitude", 1);
expectedEntityMap.put("location", locationMap);
Assert.assertEquals(entityMask.getDataMap(), expectedEntityMap, "The generated DataMap for the MaskTree should be correct");
//"{region=1, profile={weight=1, height=1}, city=1}"
final MaskTree metadataMask = context.getMetadataProjectionMask();
final DataMap expectedMetadataMap = new DataMap();
expectedMetadataMap.put("city", 1);
expectedMetadataMap.put("region", 1);
final DataMap profileMap = new DataMap();
profileMap.put("weight", 1);
profileMap.put("height", 1);
expectedMetadataMap.put("profile", profileMap);
Assert.assertEquals(metadataMask.getDataMap(), expectedMetadataMap, "The generated DataMap for the MaskTree should be correct");
//Note the lack of a test with paging here. This is because paging (CollectionMetadata) has a LinkArray which
//requires a wildcard path spec in the URI. That behavior is inconsistent with the other projections in this test,
//therefore it will be included in the subsequent test.
}
Aggregations