use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestEmptyUnionValidation method testFailValidationWithFullUnionMemberProjection.
@Test(expectedExceptions = RestLiResponseException.class)
public void testFailValidationWithFullUnionMemberProjection() throws RemoteInvocationException {
ValidateEmptyUnion expected = new ValidateEmptyUnion();
expected.setFoo(new ValidateEmptyUnion.Foo());
List<PathSpec> spec = Arrays.asList(ValidateEmptyUnion.fields().foo().Fuzz(), ValidateEmptyUnion.fields().foo().Bar());
EmptyUnionRequestBuilders requestBuilders = new EmptyUnionRequestBuilders();
GetRequest<ValidateEmptyUnion> req = requestBuilders.get().id(1L).fields(spec.toArray(new PathSpec[spec.size()])).build();
ValidateEmptyUnion actual = getClient().sendRequest(req).getResponse().getEntity();
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestRestUtils method testOverrideMask.
@Test
public void testOverrideMask() throws CloneNotSupportedException {
RecordBar bar = new RecordBar();
bar.setLocation("mountain view");
bar.data().put("SF", "CA");
RecordBar expected = bar.clone();
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("SF"), MaskOperation.POSITIVE_MASK_OP);
RestUtils.trimRecordTemplate(bar, maskTree, false);
Assert.assertEquals(bar, expected);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestRestUtils method testOverrideMaskNestedWithMap.
@Test
public void testOverrideMaskNestedWithMap() throws CloneNotSupportedException {
TyperefTest test = new TyperefTest();
RecordBar bar = new RecordBar();
bar.setLocation("foo");
bar.data().put("bar", "keep me");
RecordBar expected = bar.clone();
test.setBarRefMap(new RecordBarMap());
test.getBarRefMap().put("foo", bar);
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("barRefMap", PathSpec.WILDCARD, "location"), MaskOperation.POSITIVE_MASK_OP);
maskTree.addOperation(new PathSpec("barRefMap", PathSpec.WILDCARD, "bar"), MaskOperation.POSITIVE_MASK_OP);
RestUtils.trimRecordTemplate(test, maskTree, false);
Assert.assertEquals(test.getBarRefMap().get("foo"), expected);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestRestUtils method testOverrideMaskNestedRecord.
@Test
public void testOverrideMaskNestedRecord() throws CloneNotSupportedException {
LinkedListNode node1 = new LinkedListNode();
node1.setIntField(1);
LinkedListNode node2 = new LinkedListNode();
node2.setIntField(2);
node1.setNext(node2);
node2.data().put("keep me", "foo");
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("next", "keep me"), MaskOperation.POSITIVE_MASK_OP);
maskTree.addOperation(new PathSpec("next", "intField"), MaskOperation.POSITIVE_MASK_OP);
LinkedListNode expected = node2.clone();
RestUtils.trimRecordTemplate(node1, maskTree, false);
Assert.assertEquals(node1.getNext(), expected);
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class ProjectionUtil method validate.
private static Set<PathSpec> validate(DataMap filteredPathSpecs, Set<PathSpec> paths) {
final Set<PathSpec> result = new HashSet<>();
for (PathSpec p : paths) {
final List<String> components = p.getPathComponents();
DataMap currentMap = filteredPathSpecs;
boolean isPresent = true;
for (int i = 0; i < components.size(); ++i) {
final String currentComponent = components.get(i);
final Object currentValue = currentMap.get(currentComponent);
if (currentValue instanceof DataMap) {
@SuppressWarnings("unchecked") final DataMap valueMap = (DataMap) currentValue;
currentMap = valueMap;
} else {
isPresent = currentMap.containsKey(currentComponent);
break;
}
}
if (isPresent) {
result.add(p);
}
}
return result;
}
Aggregations