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