Search in sources :

Example 1 with RecordBarArray

use of com.linkedin.pegasus.generator.test.RecordBarArray 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("Hello", "World"));
    Assert.assertSame(result.getClass(), StringArray.class);
    result = test("[false, true]", BooleanArray.class);
    Assert.assertEquals(result, new BooleanArray(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(2L, 3L, 4L));
    Assert.assertSame(result.getClass(), LongArray.class);
    result = test("[1.1, 2.2, 3.3]", FloatArray.class);
    Assert.assertEquals(result, new FloatArray(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(2.2D, 3.3D, 4.4D));
    Assert.assertSame(result.getClass(), DoubleArray.class);
    result = test("[\"APPLE\", \"BANANA\"]", EnumFruitsArray.class);
    Assert.assertEquals(result, new EnumFruitsArray(EnumFruits.APPLE, EnumFruits.BANANA));
    Assert.assertSame(result.getClass(), EnumFruitsArray.class);
    result = test("[" + _bytes16Quoted + ", " + _bytes16Quoted + "]", BytesArray.class);
    Assert.assertEquals(result, new BytesArray(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(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 = ArrayTest.UnionArray.create("String in union");
    final ArrayTest.UnionArray fixture2 = ArrayTest.UnionArray.create(1);
    Assert.assertEquals(result, new ArrayTest.UnionArrayArray(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(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)

Example 2 with RecordBarArray

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

the class TestRestUtils method testRecordRefArrayTrim.

@Test
public void testRecordRefArrayTrim() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    RecordBarArrayArray recordBarArrayArray = new RecordBarArrayArray();
    RecordBarArray recordBarArray = new RecordBarArray();
    RecordBar recordBar = new RecordBar();
    recordBar.setLocation("mountain view");
    recordBarArray.add(recordBar);
    RecordBar recordBar2 = new RecordBar();
    recordBar2.setLocation("palo alto");
    recordBarArray.add(recordBar2);
    recordBarArrayArray.add(recordBarArray);
    test.setRecordRefArray(recordBarArrayArray);
    // Generate expected copy.
    TyperefTest expected = test.copy();
    // Introduce bad elements.
    test.getRecordRefArray().get(0).get(0).data().put("evil", "bar");
    test.getRecordRefArray().get(0).get(0).data().put("evil2", "bar");
    test.getRecordRefArray().get(0).get(1).data().put("evil", "foo");
    test.getRecordRefArray().get(0).get(1).data().put("evil2", "foo");
    Assert.assertEquals(test.getRecordRefArray().get(0).get(0).data().size(), 3);
    Assert.assertEquals(test.getRecordRefArray().get(0).get(1).data().size(), 3);
    RestUtils.trimRecordTemplate(test, false);
    Assert.assertEquals(test, expected);
}
Also used : RecordBarArray(com.linkedin.pegasus.generator.test.RecordBarArray) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) RecordBarArrayArray(com.linkedin.pegasus.generator.test.RecordBarArrayArray) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 3 with RecordBarArray

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

the class TestRestUtils method testArrayTrim.

@Test
public void testArrayTrim() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    RecordBarArray array = new RecordBarArray();
    RecordBar recordBar = new RecordBar();
    recordBar.setLocation("mountain view");
    array.add(recordBar);
    RecordBar recordBar2 = new RecordBar();
    recordBar2.setLocation("palo alto");
    array.add(recordBar2);
    test.setRecordArray(array);
    // Generate expected copy.
    TyperefTest expected = test.copy();
    // Introduce bad elements.
    test.getRecordArray().get(0).data().put("troublemaker", "foo");
    test.getRecordArray().get(0).data().put("troublemaker2", "foo");
    test.getRecordArray().get(1).data().put("troublemaker", "foo");
    test.getRecordArray().get(1).data().put("troublemaker2", "foo");
    Assert.assertEquals(test.getRecordArray().get(0).data().size(), 3);
    Assert.assertEquals(test.getRecordArray().get(1).data().size(), 3);
    RestUtils.trimRecordTemplate(test, false);
    Assert.assertEquals(test, expected);
}
Also used : RecordBarArray(com.linkedin.pegasus.generator.test.RecordBarArray) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 4 with RecordBarArray

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

the class TestRestUtils method testNestedArrayRefRecord.

@Test
public void testNestedArrayRefRecord() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    NestedArrayRefRecord nestedArrayRefRecord = new NestedArrayRefRecord();
    RecordBarArray recordBarArray = new RecordBarArray();
    RecordBar recordBar = new RecordBar();
    recordBar.setLocation("mountain view");
    recordBarArray.add(recordBar);
    RecordBar recordBar2 = new RecordBar();
    recordBar2.setLocation("palo alto");
    recordBarArray.add(recordBar2);
    RecordBarArrayArray recordBarArrayArray = new RecordBarArrayArray();
    recordBarArrayArray.add(recordBarArray);
    nestedArrayRefRecord.setNestedRecordRefArray(recordBarArrayArray);
    test.setNestedArrayRefRecord(nestedArrayRefRecord);
    // Generate expected copy.
    TyperefTest expected = test.copy();
    // Introduce bad elements.
    test.getNestedArrayRefRecord().getNestedRecordRefArray().get(0).get(0).data().put("evil", "bar");
    test.getNestedArrayRefRecord().getNestedRecordRefArray().get(0).get(0).data().put("evil2", "bar");
    test.getNestedArrayRefRecord().getNestedRecordRefArray().get(0).get(1).data().put("evil", "foo");
    test.getNestedArrayRefRecord().getNestedRecordRefArray().get(0).get(1).data().put("evil2", "foo");
    Assert.assertEquals(test.getNestedArrayRefRecord().getNestedRecordRefArray().get(0).get(0).data().size(), 3);
    Assert.assertEquals(test.getNestedArrayRefRecord().getNestedRecordRefArray().get(0).get(1).data().size(), 3);
    RestUtils.trimRecordTemplate(test, false);
    Assert.assertEquals(test, expected);
}
Also used : RecordBarArray(com.linkedin.pegasus.generator.test.RecordBarArray) NestedArrayRefRecord(com.linkedin.pegasus.generator.test.NestedArrayRefRecord) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) RecordBarArrayArray(com.linkedin.pegasus.generator.test.RecordBarArrayArray) 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)4 RecordBarArray (com.linkedin.pegasus.generator.test.RecordBarArray)4 Test (org.testng.annotations.Test)4 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)3 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)3 RecordBarArrayArray (com.linkedin.pegasus.generator.test.RecordBarArrayArray)2 DataMap (com.linkedin.data.DataMap)1 BooleanArray (com.linkedin.data.template.BooleanArray)1 BytesArray (com.linkedin.data.template.BytesArray)1 DoubleArray (com.linkedin.data.template.DoubleArray)1 FloatArray (com.linkedin.data.template.FloatArray)1 IntegerArray (com.linkedin.data.template.IntegerArray)1 LongArray (com.linkedin.data.template.LongArray)1 StringArray (com.linkedin.data.template.StringArray)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 NestedArrayRefRecord (com.linkedin.pegasus.generator.test.NestedArrayRefRecord)1