Search in sources :

Example 1 with TyperefTest

use of com.linkedin.pegasus.generator.test.TyperefTest in project rest.li by linkedin.

the class TestRestUtils method testArrayTrim.

@Test
public void testArrayTrim() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    RecordBarArray array = new RecordBarArray();
    RecordBar recordBar = new RecordBar();
    recordBar.setLocation("mountain view");
    array.add(recordBar);
    RecordBar recordBar2 = new RecordBar();
    recordBar2.setLocation("palo alto");
    array.add(recordBar2);
    test.setRecordArray(array);
    // Generate expected copy.
    TyperefTest expected = test.copy();
    // Introduce bad elements.
    test.getRecordArray().get(0).data().put("troublemaker", "foo");
    test.getRecordArray().get(0).data().put("troublemaker2", "foo");
    test.getRecordArray().get(1).data().put("troublemaker", "foo");
    test.getRecordArray().get(1).data().put("troublemaker2", "foo");
    Assert.assertEquals(test.getRecordArray().get(0).data().size(), 3);
    Assert.assertEquals(test.getRecordArray().get(1).data().size(), 3);
    RestUtils.trimRecordTemplate(test, false);
    Assert.assertEquals(test, expected);
}
Also used : RecordBarArray(com.linkedin.pegasus.generator.test.RecordBarArray) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 2 with TyperefTest

use of com.linkedin.pegasus.generator.test.TyperefTest in project rest.li by linkedin.

the class TestRestUtils method testRefTrim.

@Test
public void testRefTrim() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    test.setImportRef(1.0);
    test.setImportRef2(2.0);
    RecordTemplate expected = test.copy();
    // Introduce bad elements
    test.data().put("troublemaker", "boo");
    Assert.assertEquals(test.data().size(), 3);
    RestUtils.trimRecordTemplate(test, false);
    Assert.assertEquals(test, expected);
}
Also used : TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordTemplate(com.linkedin.data.template.RecordTemplate) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 3 with TyperefTest

use of com.linkedin.pegasus.generator.test.TyperefTest 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 4 with TyperefTest

use of com.linkedin.pegasus.generator.test.TyperefTest in project rest.li by linkedin.

the class TestRestUtils method testTrimmerWithPrimitivesRecordsUnionsMix.

@Test
public void testTrimmerWithPrimitivesRecordsUnionsMix() throws CloneNotSupportedException {
    TyperefTest recordTemplate = new TyperefTest();
    recordTemplate.setBoolean(true);
    RecordBar foo = new RecordBar();
    foo.setLocation("foo");
    recordTemplate.setBar1(foo);
    TyperefTest.Union5 union = new TyperefTest.Union5();
    union.setIntRef(5);
    recordTemplate.setUnion5(union);
    RecordTemplate expected = recordTemplate.copy();
    // Introduce bad elements
    recordTemplate.getBar1().data().put("troublemaker", "foo");
    ((DataMap) recordTemplate.getUnion5().data()).put("troublemaker", "foo");
    recordTemplate.data().put("foo", "bar");
    DataList list = new DataList();
    list.add(1);
    DataMap map = new DataMap();
    map.put("foo", 666);
    recordTemplate.data().put("keyFoo", list);
    recordTemplate.data().put("keyBar", map);
    // Pre filtering
    Assert.assertEquals(recordTemplate.data().size(), 6);
    Assert.assertEquals(recordTemplate.getBar1().data().size(), 2);
    RestUtils.trimRecordTemplate(recordTemplate, false);
    // Post filtering
    Assert.assertEquals(recordTemplate, expected);
}
Also used : DataList(com.linkedin.data.DataList) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordTemplate(com.linkedin.data.template.RecordTemplate) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) DataMap(com.linkedin.data.DataMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 5 with TyperefTest

use of com.linkedin.pegasus.generator.test.TyperefTest in project rest.li by linkedin.

the class TestRestUtils method testMapTrim.

@Test
public void testMapTrim() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    RecordBarMap map = new RecordBarMap();
    RecordBar recordBar = new RecordBar();
    recordBar.setLocation("foo");
    map.put("map", recordBar);
    test.setBarRefMap(map);
    TyperefTest expected = test.copy();
    test.getBarRefMap().get("map").data().put("troublemaker", "data filth");
    Assert.assertEquals(recordBar.data().size(), 2);
    Assert.assertEquals(test.getBarRefMap().get("map").data().size(), 2);
    RestUtils.trimRecordTemplate(test, false);
    Assert.assertEquals(expected, test);
}
Also used : TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) 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)

Aggregations

TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)5 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)5 Test (org.testng.annotations.Test)5 RecordBar (com.linkedin.pegasus.generator.test.RecordBar)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 RecordBarMap (com.linkedin.pegasus.generator.test.RecordBarMap)2 DataList (com.linkedin.data.DataList)1 DataMap (com.linkedin.data.DataMap)1 PathSpec (com.linkedin.data.schema.PathSpec)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 RecordBarArray (com.linkedin.pegasus.generator.test.RecordBarArray)1