Search in sources :

Example 86 with PathSpec

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();
}
Also used : ValidateEmptyUnion(com.linkedin.restli.examples.greetings.api.ValidateEmptyUnion) EmptyUnionRequestBuilders(com.linkedin.restli.examples.greetings.client.EmptyUnionRequestBuilders) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 87 with PathSpec

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);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) PathSpec(com.linkedin.data.schema.PathSpec) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 88 with PathSpec

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);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) PathSpec(com.linkedin.data.schema.PathSpec) RecordBarMap(com.linkedin.pegasus.generator.test.RecordBarMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 89 with PathSpec

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);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) LinkedListNode(com.linkedin.restli.server.LinkedListNode) PathSpec(com.linkedin.data.schema.PathSpec) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 90 with PathSpec

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;
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet) DataMap(com.linkedin.data.DataMap)

Aggregations

PathSpec (com.linkedin.data.schema.PathSpec)101 Test (org.testng.annotations.Test)74 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)40 DataMap (com.linkedin.data.DataMap)31 HashSet (java.util.HashSet)16 RecordTemplate (com.linkedin.data.template.RecordTemplate)11 Map (java.util.Map)10 Set (java.util.Set)10 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 HashMap (java.util.HashMap)8 DataList (com.linkedin.data.DataList)7 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)7 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)7 List (java.util.List)7 ByteString (com.linkedin.data.ByteString)6 DataSchema (com.linkedin.data.schema.DataSchema)5 MaskOperation (com.linkedin.data.transform.filter.request.MaskOperation)5 Foo (com.linkedin.pegasus.generator.examples.Foo)5 RequestContext (com.linkedin.r2.message.RequestContext)5 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)5