Search in sources :

Example 1 with UnionTest

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

the class TestRestUtils method testUnionDataMap.

@Test
public void testUnionDataMap() throws CloneNotSupportedException {
    UnionTest foo = new UnionTest();
    foo.setUnionEmpty(new UnionTest.UnionEmpty());
    UnionTest expected = foo.copy();
    ((DataMap) foo.getUnionEmpty().data()).put("foo", "bar");
    RestUtils.trimRecordTemplate(foo, false);
    Assert.assertEquals(foo, expected);
    // Primitive case
    foo = new UnionTest();
    UnionTest.UnionWithNull bar = new UnionTest.UnionWithNull();
    bar.setBoolean(true);
    foo.setUnionWithNull(bar);
    expected = foo.copy();
    ((DataMap) foo.getUnionWithNull().data()).put("foo", "bar");
    Assert.assertEquals(((DataMap) foo.getUnionWithNull().data()).size(), 2);
    RestUtils.trimRecordTemplate(foo, false);
    Assert.assertEquals(foo, expected);
    // Complex case
    foo = new UnionTest();
    bar = new UnionTest.UnionWithNull();
    bar.setMap(new LongMap());
    foo.setUnionWithNull(bar);
    expected = foo.copy();
    expected.getUnionWithNull().getMap().put("foo", 1L);
    foo.getUnionWithNull().getMap().data().put("foo", 1L);
    foo.data().put("foo", "bar");
    Assert.assertEquals(((DataMap) foo.getUnionWithNull().data()).size(), 1);
    RestUtils.trimRecordTemplate(foo, false);
    Assert.assertEquals(foo, expected);
}
Also used : LongMap(com.linkedin.data.template.LongMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) 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

DataMap (com.linkedin.data.DataMap)1 LongMap (com.linkedin.data.template.LongMap)1 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)1 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)1 Test (org.testng.annotations.Test)1