Search in sources :

Example 6 with IntegerArray

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

the class TestRecord method testRecordTest.

@Test
public void testRecordTest() throws IOException {
    Object[][] inputs = { { "intField", 8 }, { "intOptionalField", 9 }, { "intDefaultField", 10 }, { "intDefaultOptionalField", 11 }, { "longField", 12L }, { "floatField", 13.0f }, { "doubleField", 14.0 }, { "booleanField", true }, { "stringField", "abc" }, { "bytesField", ByteString.copyAvroString("abcdef", true) }, { "enumField", EnumFruits.BANANA }, { "fixedField", new FixedMD5("0123456789abcdef") }, { "recordField", new RecordBar().setLocation("far") }, { "arrayField", new IntegerArray(Arrays.asList(1, 2, 3, 4, 5)) }, { "mapField", new StringMap(TestUtil.asMap("k1", "v1", "k2", "v2", "k3", "v3")) }, { "unionField", new RecordTest.UnionField(TestUtil.dataMapFromString("{ \"int\" : 3 }")) } };
    RecordTest record = new RecordTest();
    testRecord(record.getClass());
    for (Object[] row : inputs) {
        String fieldName = (String) row[0];
        Object value = row[1];
        testField(record, fieldName, value);
    }
}
Also used : StringMap(com.linkedin.data.template.StringMap) ByteString(com.linkedin.data.ByteString) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 7 with IntegerArray

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

the class TestArray method testIntegerArray.

@Test
public void testIntegerArray() {
    TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new ArrayTest(), "intArray");
    @SuppressWarnings("unchecked") Class<IntegerArray> templateClass = (Class<IntegerArray>) fieldInfo.getFieldClass();
    ArrayDataSchema schema = (ArrayDataSchema) fieldInfo.getField().getType();
    // must be unique
    List<Integer> input = Arrays.asList(1, 3, 5, 7, 9);
    List<Integer> adds = Arrays.asList(11, 13);
    TestArrayTemplate.testArray(templateClass, schema, input, adds);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) TestDataTemplateUtil(com.linkedin.data.template.TestDataTemplateUtil) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Example 8 with IntegerArray

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

the class RecordGeneratorTest method testWithComplexTypesDefaults.

@Test
public void testWithComplexTypesDefaults() {
    WithComplexTypeDefaults withDefaults = new WithComplexTypeDefaults();
    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(Collections.singletonList(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) WithComplexTypeDefaults(com.linkedin.pegasus.generator.test.idl.records.WithComplexTypeDefaults) 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 9 with IntegerArray

use of com.linkedin.data.template.IntegerArray 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(Collections.singletonList(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)

Example 10 with IntegerArray

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

the class TestTypeRefRecordTemplate method testArraySchema.

@Test
public void testArraySchema() {
    TyperefTest record = new TyperefTest();
    RecordDataSchema recordDataSchema = record.schema();
    record.setDoubleRefArray(new DoubleArray());
    DoubleArray doubleArray = record.getDoubleRefArray();
    assertEquals(doubleArray.schema(), DataTemplateUtil.getSchema(DoubleArray.class));
    assertNotEquals(recordDataSchema.getField("doubleRefArray").getType(), doubleArray.schema());
    record.setIntArray(new IntegerArray());
    IntegerArray intArray = record.getIntArray();
    assertEquals(intArray.schema(), DataTemplateUtil.getSchema(IntegerArray.class));
    assertNotEquals(recordDataSchema.getField("intArray").getType(), intArray.schema());
    record.setIntRefArray(intArray);
    intArray = record.getIntRefArray();
    assertEquals(intArray.schema(), DataTemplateUtil.getSchema(IntegerArray.class));
    assertNotEquals(recordDataSchema.getField("intRefArray").getType(), intArray.schema());
    assertNotEquals(recordDataSchema.getField("intArray").getType(), recordDataSchema.getField("intRefArray").getType());
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DoubleArray(com.linkedin.data.template.DoubleArray) IntegerArray(com.linkedin.data.template.IntegerArray) Test(org.testng.annotations.Test)

Aggregations

IntegerArray (com.linkedin.data.template.IntegerArray)11 Test (org.testng.annotations.Test)10 DoubleArray (com.linkedin.data.template.DoubleArray)3 IntegerMap (com.linkedin.data.template.IntegerMap)3 Simple (com.linkedin.pegasus.generator.test.idl.records.Simple)3 CustomInt (com.linkedin.pegasus.generator.test.pdl.fixtures.CustomInt)3 BooleanArray (com.linkedin.data.template.BooleanArray)2 BytesArray (com.linkedin.data.template.BytesArray)2 FloatArray (com.linkedin.data.template.FloatArray)2 LongArray (com.linkedin.data.template.LongArray)2 StringArray (com.linkedin.data.template.StringArray)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 StringMap (com.linkedin.data.template.StringMap)1 TestDataTemplateUtil (com.linkedin.data.template.TestDataTemplateUtil)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