Search in sources :

Example 1 with FloatArray

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

the class ArrayGeneratorTest method testWithPrimitivesArray.

@Test
public void testWithPrimitivesArray() throws Throwable {
    String json = load("WithPrimitivesArray.json");
    WithPrimitivesArray original = new WithPrimitivesArray();
    IntegerArray ints = new IntegerArray();
    ints.add(1);
    ints.add(2);
    ints.add(3);
    original.setInts(ints);
    LongArray longs = new LongArray();
    longs.add(10L);
    longs.add(20L);
    longs.add(30L);
    original.setLongs(longs);
    FloatArray floats = new FloatArray();
    floats.add(1.1f);
    floats.add(2.2f);
    floats.add(3.3f);
    original.setFloats(floats);
    DoubleArray doubles = new DoubleArray();
    doubles.add(11.1d);
    doubles.add(22.2d);
    doubles.add(33.3d);
    original.setDoubles(doubles);
    BooleanArray booleans = new BooleanArray();
    booleans.add(false);
    booleans.add(true);
    original.setBooleans(booleans);
    StringArray strings = new StringArray();
    strings.add("a");
    strings.add("b");
    strings.add("c");
    original.setStrings(strings);
    BytesArray bytes = new BytesArray();
    bytes.add(SchemaFixtures.bytes1);
    bytes.add(SchemaFixtures.bytes2);
    original.setBytes(bytes);
    assertJson(original, json);
    WithPrimitivesArray roundTripped = new WithPrimitivesArray(roundTrip(original.data()));
    assertJson(roundTripped, json);
}
Also used : LongArray(com.linkedin.data.template.LongArray) BytesArray(com.linkedin.data.template.BytesArray) FloatArray(com.linkedin.data.template.FloatArray) StringArray(com.linkedin.data.template.StringArray) WithPrimitivesArray(com.linkedin.pegasus.generator.test.idl.arrays.WithPrimitivesArray) DoubleArray(com.linkedin.data.template.DoubleArray) IntegerArray(com.linkedin.data.template.IntegerArray) BooleanArray(com.linkedin.data.template.BooleanArray) Test(org.testng.annotations.Test)

Example 2 with FloatArray

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

the class TestParameterDefaultValue method testWrappedArray.

@Test
public void testWrappedArray() {
    Object result;
    result = test("[\"Hello\", \"World\"]", StringArray.class);
    Assert.assertEquals(result, new StringArray(Arrays.asList("Hello", "World")));
    Assert.assertSame(result.getClass(), StringArray.class);
    result = test("[false, true]", BooleanArray.class);
    Assert.assertEquals(result, new BooleanArray(Arrays.asList(false, true)));
    Assert.assertSame(result.getClass(), BooleanArray.class);
    result = test("[1, 2, 3]", IntegerArray.class);
    Assert.assertEquals(result, new IntegerArray(Arrays.asList(1, 2, 3)));
    Assert.assertSame(result.getClass(), IntegerArray.class);
    result = test("[1.1, 2.2, 3.3]", IntegerArray.class);
    Assert.assertEquals(result, new IntegerArray(Arrays.asList(1, 2, 3)));
    Assert.assertSame(result.getClass(), IntegerArray.class);
    result = test("[2, 3, 4]", LongArray.class);
    Assert.assertEquals(result, new LongArray(Arrays.asList(2L, 3L, 4L)));
    Assert.assertSame(result.getClass(), LongArray.class);
    result = test("[1.1, 2.2, 3.3]", FloatArray.class);
    Assert.assertEquals(result, new FloatArray(Arrays.asList(1.1F, 2.2F, 3.3F)));
    Assert.assertSame(result.getClass(), FloatArray.class);
    result = test("[2.2, 3.3, 4.4]", DoubleArray.class);
    Assert.assertEquals(result, new DoubleArray(Arrays.asList(2.2D, 3.3D, 4.4D)));
    Assert.assertSame(result.getClass(), DoubleArray.class);
    result = test("[\"APPLE\", \"BANANA\"]", EnumFruitsArray.class);
    Assert.assertEquals(result, new EnumFruitsArray(Arrays.asList(EnumFruits.APPLE, EnumFruits.BANANA)));
    Assert.assertSame(result.getClass(), EnumFruitsArray.class);
    result = test("[" + _bytes16Quoted + ", " + _bytes16Quoted + "]", BytesArray.class);
    Assert.assertEquals(result, new BytesArray(Arrays.asList(ByteString.copyAvroString(_bytes16, true), ByteString.copyAvroString(_bytes16, true))));
    Assert.assertSame(result.getClass(), BytesArray.class);
    result = test("[" + _bytes16Quoted + ", " + _bytes16Quoted + "]", FixedMD5Array.class);
    Assert.assertEquals(result, new FixedMD5Array(Arrays.asList(new FixedMD5(_bytes16), new FixedMD5(_bytes16))));
    Assert.assertSame(result.getClass(), FixedMD5Array.class);
    result = test("[{\"string\": \"String in union\"}, {\"int\": 1}]", ArrayTest.UnionArrayArray.class);
    final ArrayTest.UnionArray fixture1 = new ArrayTest.UnionArray();
    fixture1.setString("String in union");
    final ArrayTest.UnionArray fixture2 = new ArrayTest.UnionArray();
    fixture2.setInt(1);
    Assert.assertEquals(result, new ArrayTest.UnionArrayArray(Arrays.asList(fixture1, fixture2)));
    Assert.assertSame(result.getClass(), ArrayTest.UnionArrayArray.class);
    result = test("[{\"location\": \"Sunnyvale\"}, {\"location\": \"Mountain View\"}]", RecordBarArray.class);
    final DataMap dataFixture1 = new DataMap();
    final DataMap dataFixture2 = new DataMap();
    dataFixture1.put("location", "Sunnyvale");
    dataFixture2.put("location", "Mountain View");
    Assert.assertEquals(result, new RecordBarArray(Arrays.asList(new RecordBar(dataFixture1), new RecordBar(dataFixture2))));
    Assert.assertSame(result.getClass(), RecordBarArray.class);
}
Also used : BytesArray(com.linkedin.data.template.BytesArray) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) FixedMD5(com.linkedin.pegasus.generator.test.FixedMD5) BooleanArray(com.linkedin.data.template.BooleanArray) IntegerArray(com.linkedin.data.template.IntegerArray) DataMap(com.linkedin.data.DataMap) LongArray(com.linkedin.data.template.LongArray) FloatArray(com.linkedin.data.template.FloatArray) RecordBarArray(com.linkedin.pegasus.generator.test.RecordBarArray) StringArray(com.linkedin.data.template.StringArray) EnumFruitsArray(com.linkedin.pegasus.generator.test.EnumFruitsArray) FixedMD5Array(com.linkedin.pegasus.generator.test.FixedMD5Array) DoubleArray(com.linkedin.data.template.DoubleArray) Test(org.testng.annotations.Test) ArrayTest(com.linkedin.pegasus.generator.test.ArrayTest)

Aggregations

BooleanArray (com.linkedin.data.template.BooleanArray)2 BytesArray (com.linkedin.data.template.BytesArray)2 DoubleArray (com.linkedin.data.template.DoubleArray)2 FloatArray (com.linkedin.data.template.FloatArray)2 IntegerArray (com.linkedin.data.template.IntegerArray)2 LongArray (com.linkedin.data.template.LongArray)2 StringArray (com.linkedin.data.template.StringArray)2 Test (org.testng.annotations.Test)2 DataMap (com.linkedin.data.DataMap)1 ArrayTest (com.linkedin.pegasus.generator.test.ArrayTest)1 EnumFruitsArray (com.linkedin.pegasus.generator.test.EnumFruitsArray)1 FixedMD5 (com.linkedin.pegasus.generator.test.FixedMD5)1 FixedMD5Array (com.linkedin.pegasus.generator.test.FixedMD5Array)1 RecordBar (com.linkedin.pegasus.generator.test.RecordBar)1 RecordBarArray (com.linkedin.pegasus.generator.test.RecordBarArray)1 WithPrimitivesArray (com.linkedin.pegasus.generator.test.idl.arrays.WithPrimitivesArray)1