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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations