Search in sources :

Example 1 with LinkedListNode

use of com.linkedin.restli.server.LinkedListNode in project rest.li by linkedin.

the class TestRestUtils method testRecursiveBasic.

@Test
public void testRecursiveBasic() throws CloneNotSupportedException {
    LinkedListNode node1 = new LinkedListNode();
    node1.setIntField(1);
    LinkedListNode node2 = new LinkedListNode();
    node2.setIntField(2);
    node1.setNext(node2);
    RecordTemplate expected = node1.copy();
    // Introduce bad elements.
    node1.data().put("foo", "bar");
    node2.data().put("foo", "bar");
    Assert.assertEquals(node1.getIntField().intValue(), 1);
    Assert.assertEquals(node1.getNext(), node2);
    Assert.assertEquals(node1.data().size(), 3);
    Assert.assertEquals(node2.getIntField().intValue(), 2);
    Assert.assertEquals(node2.getNext(), null);
    Assert.assertEquals(node2.data().size(), 2);
    RestUtils.trimRecordTemplate(node1, false);
    Assert.assertEquals(node1, expected);
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) LinkedListNode(com.linkedin.restli.server.LinkedListNode) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 2 with LinkedListNode

use of com.linkedin.restli.server.LinkedListNode 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)

Aggregations

TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)2 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)2 LinkedListNode (com.linkedin.restli.server.LinkedListNode)2 Test (org.testng.annotations.Test)2 PathSpec (com.linkedin.data.schema.PathSpec)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1