Search in sources :

Example 1 with RecordBarMap

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

the class TestParameterDefaultValue method testWrappedMap.

@Test
public void testWrappedMap() {
    Object result;
    result = test("{\"key1\": \"Hello\", \"key2\": \"World\"}", StringMap.class);
    final Map<String, String> stringFixture = new HashMap<>();
    stringFixture.put("key1", "Hello");
    stringFixture.put("key2", "World");
    Assert.assertEquals(result, new StringMap(stringFixture));
    Assert.assertSame(result.getClass(), StringMap.class);
    result = test("{\"key1\": true, \"key2\": false}", BooleanMap.class);
    final Map<String, Boolean> booleanFixture = new HashMap<>();
    booleanFixture.put("key1", true);
    booleanFixture.put("key2", false);
    Assert.assertEquals(result, new BooleanMap(booleanFixture));
    Assert.assertSame(result.getClass(), BooleanMap.class);
    result = test("{\"key1\": 1, \"key2\": 2}", IntegerMap.class);
    final Map<String, Integer> integerFixture = new HashMap<>();
    integerFixture.put("key1", 1);
    integerFixture.put("key2", 2);
    Assert.assertEquals(result, new IntegerMap(integerFixture));
    Assert.assertSame(result.getClass(), IntegerMap.class);
    result = test("{\"key1\": 2, \"key2\": 3}", LongMap.class);
    final Map<String, Long> longFixture = new HashMap<>();
    longFixture.put("key1", 2L);
    longFixture.put("key2", 3L);
    Assert.assertEquals(result, new LongMap(longFixture));
    Assert.assertSame(result.getClass(), LongMap.class);
    result = test("{\"key1\": 1.1, \"key2\": 2.2}", FloatMap.class);
    final Map<String, Float> floatFixture = new HashMap<>();
    floatFixture.put("key1", 1.1F);
    floatFixture.put("key2", 2.2F);
    Assert.assertEquals(result, new FloatMap(floatFixture));
    Assert.assertSame(result.getClass(), FloatMap.class);
    result = test("{\"key1\": 2.2, \"key2\": 3.3}", DoubleMap.class);
    final Map<String, Double> doubleFixture = new HashMap<>();
    doubleFixture.put("key1", 2.2D);
    doubleFixture.put("key2", 3.3D);
    Assert.assertEquals(result, new DoubleMap(doubleFixture));
    Assert.assertSame(result.getClass(), DoubleMap.class);
    result = test("{\"key1\": " + _bytes16Quoted + ", \"key2\": " + _bytes16Quoted + "}", BytesMap.class);
    final Map<String, ByteString> bytesFixture = new HashMap<>();
    bytesFixture.put("key1", ByteString.copyAvroString(_bytes16, true));
    bytesFixture.put("key2", ByteString.copyAvroString(_bytes16, true));
    Assert.assertEquals(result, new BytesMap(new DataMap(bytesFixture)));
    Assert.assertSame(result.getClass(), BytesMap.class);
    result = test("{\"key1\": {\"location\": \"Sunnyvale\"}, \"key2\": {\"location\": \"MTV\"}}", RecordBarMap.class);
    final DataMap dataFixture1 = new DataMap();
    final DataMap dataFixture2 = new DataMap();
    dataFixture1.put("location", "Sunnyvale");
    dataFixture2.put("location", "MTV");
    final RecordBar record1 = new RecordBar(dataFixture1);
    final RecordBar record2 = new RecordBar(dataFixture2);
    final Map<String, RecordBar> recordFixture = new HashMap<>();
    recordFixture.put("key1", record1);
    recordFixture.put("key2", record2);
    Assert.assertEquals(result, new RecordBarMap(recordFixture));
    Assert.assertSame(result.getClass(), RecordBarMap.class);
}
Also used : StringMap(com.linkedin.data.template.StringMap) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) BytesMap(com.linkedin.data.template.BytesMap) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) DoubleMap(com.linkedin.data.template.DoubleMap) DataMap(com.linkedin.data.DataMap) RecordBarMap(com.linkedin.pegasus.generator.test.RecordBarMap) IntegerMap(com.linkedin.data.template.IntegerMap) LongMap(com.linkedin.data.template.LongMap) FloatMap(com.linkedin.data.template.FloatMap) BooleanMap(com.linkedin.data.template.BooleanMap) CustomLong(com.linkedin.restli.server.custom.types.CustomLong) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Example 2 with RecordBarMap

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

Example 3 with RecordBarMap

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

Aggregations

RecordBar (com.linkedin.pegasus.generator.test.RecordBar)3 RecordBarMap (com.linkedin.pegasus.generator.test.RecordBarMap)3 Test (org.testng.annotations.Test)3 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)2 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 PathSpec (com.linkedin.data.schema.PathSpec)1 BooleanMap (com.linkedin.data.template.BooleanMap)1 BytesMap (com.linkedin.data.template.BytesMap)1 DoubleMap (com.linkedin.data.template.DoubleMap)1 FloatMap (com.linkedin.data.template.FloatMap)1 IntegerMap (com.linkedin.data.template.IntegerMap)1 LongMap (com.linkedin.data.template.LongMap)1 StringMap (com.linkedin.data.template.StringMap)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 ArrayTest (com.linkedin.pegasus.generator.test.ArrayTest)1 CustomLong (com.linkedin.restli.server.custom.types.CustomLong)1 CustomString (com.linkedin.restli.server.custom.types.CustomString)1 HashMap (java.util.HashMap)1