Search in sources :

Example 1 with IntegerMap

use of com.linkedin.data.template.IntegerMap in project rest.li by linkedin.

the class TestTypeRefRecordTemplate method testMapSchema.

@Test
public void testMapSchema() {
    TyperefTest record = new TyperefTest();
    RecordDataSchema recordDataSchema = record.schema();
    DoubleMap doubleMap = new DoubleMap();
    record.setDoubleRefMap(doubleMap);
    doubleMap = record.getDoubleRefMap();
    assertEquals(doubleMap.schema(), DataTemplateUtil.getSchema(DoubleMap.class));
    assertNotEquals(recordDataSchema.getField("doubleRefMap").getType(), doubleMap.schema());
    IntegerMap intMap = new IntegerMap();
    record.setIntMap(intMap);
    intMap = record.getIntMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intMap").getType(), intMap.schema());
    record.setIntRefMap(intMap);
    intMap = record.getIntRefMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intRefMap").getType(), intMap.schema());
    assertNotEquals(recordDataSchema.getField("intMap").getType(), recordDataSchema.getField("intRefMap").getType());
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DoubleMap(com.linkedin.data.template.DoubleMap) Test(org.testng.annotations.Test)

Example 2 with IntegerMap

use of com.linkedin.data.template.IntegerMap in project rest.li by linkedin.

the class MapGeneratorTest method testWithPrimitivesMap.

@Test
public void testWithPrimitivesMap() throws Throwable {
    String json = load("WithPrimitivesMap.json");
    WithPrimitivesMap original = new WithPrimitivesMap();
    IntegerMap ints = new IntegerMap();
    ints.put("a", 1);
    ints.put("b", 2);
    ints.put("c", 3);
    original.setInts(ints);
    LongMap longs = new LongMap();
    longs.put("a", 10L);
    longs.put("b", 20L);
    longs.put("c", 30L);
    original.setLongs(longs);
    FloatMap floats = new FloatMap();
    floats.put("a", 1.1f);
    floats.put("b", 2.2f);
    floats.put("c", 3.3f);
    original.setFloats(floats);
    DoubleMap doubles = new DoubleMap();
    doubles.put("a", 11.1d);
    doubles.put("b", 22.2d);
    doubles.put("c", 33.3d);
    original.setDoubles(doubles);
    BooleanMap booleans = new BooleanMap();
    booleans.put("a", true);
    booleans.put("b", false);
    booleans.put("c", true);
    original.setBooleans(booleans);
    StringMap strings = new StringMap();
    strings.put("a", "string1");
    strings.put("b", "string2");
    strings.put("c", "string3");
    original.setStrings(strings);
    BytesMap bytes = new BytesMap();
    bytes.put("a", SchemaFixtures.bytes1);
    bytes.put("b", SchemaFixtures.bytes2);
    bytes.put("c", SchemaFixtures.bytes3);
    original.setBytes(bytes);
    assertJson(original, json);
    WithPrimitivesMap roundTripped = new WithPrimitivesMap(roundTrip(original.data()));
    assertJson(roundTripped, json);
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) LongMap(com.linkedin.data.template.LongMap) StringMap(com.linkedin.data.template.StringMap) BooleanMap(com.linkedin.data.template.BooleanMap) WithPrimitivesMap(com.linkedin.pegasus.generator.test.idl.maps.WithPrimitivesMap) BytesMap(com.linkedin.data.template.BytesMap) FloatMap(com.linkedin.data.template.FloatMap) DoubleMap(com.linkedin.data.template.DoubleMap) Test(org.testng.annotations.Test)

Example 3 with IntegerMap

use of com.linkedin.data.template.IntegerMap in project rest.li by linkedin.

the class RecordGeneratorTest method testWithComplexTypes.

@Test
public void testWithComplexTypes() throws Throwable {
    WithComplexTypes original = new WithComplexTypes();
    Simple simple = new Simple();
    simple.setMessage("message");
    original.setRecord(simple);
    original.setEnum(Fruits.APPLE);
    original.setUnion(WithComplexTypes.Union.create(1));
    IntegerArray intArray = new IntegerArray();
    intArray.add(1);
    original.setArray(intArray);
    IntegerMap intMap = new IntegerMap();
    intMap.put("a", 1);
    original.setMap(intMap);
    SimpleMap simpleMap = new SimpleMap();
    simpleMap.put("a", simple);
    original.setComplexMap(simpleMap);
    original.setCustom(new CustomInt(1));
    WithComplexTypes roundTripped = new WithComplexTypes(roundTrip(original.data()));
    assertEquals(roundTripped.getRecord(), simple);
    assertEquals(roundTripped.getEnum(), Fruits.APPLE);
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) WithComplexTypes(com.linkedin.pegasus.generator.test.idl.records.WithComplexTypes) SimpleMap(com.linkedin.pegasus.generator.test.idl.records.SimpleMap) CustomInt(com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 4 with IntegerMap

use of com.linkedin.data.template.IntegerMap in project rest.li by linkedin.

the class TestMap method testIntegerMap.

@Test
public void testIntegerMap() {
    TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new MapTest(), "intMap");
    @SuppressWarnings("unchecked") Class<IntegerMap> templateClass = (Class<IntegerMap>) fieldInfo.getFieldClass();
    MapDataSchema schema = (MapDataSchema) fieldInfo.getField().getType();
    Map<String, Integer> input = asMap("one", 1, "three", 3, "five", 5, "seven", 7, "eleven", 11);
    Map<String, Integer> adds = asMap("thirteen", 13, "seventeen", 17, "nineteen", 19);
    TestMapTemplate.testMap(templateClass, schema, input, adds);
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) TestDataTemplateUtil(com.linkedin.data.template.TestDataTemplateUtil) MapDataSchema(com.linkedin.data.schema.MapDataSchema) Test(org.testng.annotations.Test)

Example 5 with IntegerMap

use of com.linkedin.data.template.IntegerMap in project rest.li by linkedin.

the class RecordGeneratorTest method testWithOptionalComplexTypesDefaults.

@Test
public void testWithOptionalComplexTypesDefaults() {
    WithOptionalComplexTypeDefaults withDefaults = new WithOptionalComplexTypeDefaults();
    Simple simple = new Simple();
    simple.setMessage("defaults!");
    assertEquals(withDefaults.getRecord(), simple);
    assertEquals(withDefaults.getEnum(), Fruits.APPLE);
    assertEquals(withDefaults.getUnion(), WithComplexTypeDefaults.Union.create(1));
    IntegerArray intArray = new IntegerArray();
    intArray.add(1);
    assertEquals(withDefaults.getArray(), intArray);
    IntegerMap intMap = new IntegerMap();
    intMap.put("a", 1);
    assertEquals(withDefaults.getMap(), intMap);
    assertEquals(withDefaults.getCustom(), new CustomInt(1));
}
Also used : IntegerMap(com.linkedin.data.template.IntegerMap) WithOptionalComplexTypeDefaults(com.linkedin.pegasus.generator.test.idl.records.WithOptionalComplexTypeDefaults) CustomInt(com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt) Simple(com.linkedin.pegasus.generator.test.idl.records.Simple) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Aggregations

IntegerMap (com.linkedin.data.template.IntegerMap)7 Test (org.testng.annotations.Test)7 DoubleMap (com.linkedin.data.template.DoubleMap)3 IntegerArray (com.linkedin.data.template.IntegerArray)3 Simple (com.linkedin.pegasus.generator.test.idl.records.Simple)3 CustomInt (com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt)3 BooleanMap (com.linkedin.data.template.BooleanMap)2 BytesMap (com.linkedin.data.template.BytesMap)2 FloatMap (com.linkedin.data.template.FloatMap)2 LongMap (com.linkedin.data.template.LongMap)2 StringMap (com.linkedin.data.template.StringMap)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 MapDataSchema (com.linkedin.data.schema.MapDataSchema)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 TestDataTemplateUtil (com.linkedin.data.template.TestDataTemplateUtil)1 ArrayTest (com.linkedin.pegasus.generator.test.ArrayTest)1 RecordBar (com.linkedin.pegasus.generator.test.RecordBar)1 RecordBarMap (com.linkedin.pegasus.generator.test.RecordBarMap)1 WithPrimitivesMap (com.linkedin.pegasus.generator.test.idl.maps.WithPrimitivesMap)1