use of com.linkedin.data.template.FloatMap 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.FloatMap 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<String, String>();
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<String, Boolean>();
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<String, Integer>();
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<String, Long>();
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<String, Float>();
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<String, Double>();
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<String, ByteString>();
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<String, RecordBar>();
recordFixture.put("key1", record1);
recordFixture.put("key2", record2);
Assert.assertEquals(result, new RecordBarMap(recordFixture));
Assert.assertSame(result.getClass(), RecordBarMap.class);
}
Aggregations