Search in sources :

Example 6 with RecordBar

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

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

the class TestRestUtils method testFailFast.

@Test(expectedExceptions = IllegalArgumentException.class)
public void testFailFast() {
    RecordBar bar = new RecordBar();
    bar.setLocation("mountain view");
    bar.data().put("SF", "CA");
    RestUtils.trimRecordTemplate(bar, true);
}
Also used : 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 8 with RecordBar

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

the class TestRestUtils method testReadOnly.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testReadOnly() {
    RecordBar bar = new RecordBar();
    bar.setLocation("mountain view");
    bar.data().put("SF", "CA");
    bar.data().makeReadOnly();
    RestUtils.trimRecordTemplate(bar, false);
}
Also used : 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 9 with RecordBar

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

use of com.linkedin.pegasus.generator.test.RecordBar 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)

Aggregations

RecordBar (com.linkedin.pegasus.generator.test.RecordBar)11 Test (org.testng.annotations.Test)11 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)8 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)8 DataMap (com.linkedin.data.DataMap)4 ArrayTest (com.linkedin.pegasus.generator.test.ArrayTest)3 RecordBarMap (com.linkedin.pegasus.generator.test.RecordBarMap)3 ByteString (com.linkedin.data.ByteString)2 PathSpec (com.linkedin.data.schema.PathSpec)2 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)2 RecordBarArray (com.linkedin.pegasus.generator.test.RecordBarArray)2 DataList (com.linkedin.data.DataList)1 BooleanArray (com.linkedin.data.template.BooleanArray)1 BooleanMap (com.linkedin.data.template.BooleanMap)1 BytesArray (com.linkedin.data.template.BytesArray)1 BytesMap (com.linkedin.data.template.BytesMap)1 DoubleArray (com.linkedin.data.template.DoubleArray)1 DoubleMap (com.linkedin.data.template.DoubleMap)1 FloatArray (com.linkedin.data.template.FloatArray)1 FloatMap (com.linkedin.data.template.FloatMap)1