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