Search in sources :

Example 11 with ArrayDataSchema

use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.

the class TestArrayTemplate method testBytesArray.

@Test
public void testBytesArray() {
    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"bytes\" }");
    List<ByteString> input = Arrays.asList(ByteString.copyAvroString("1", false), ByteString.copyAvroString("3", false), ByteString.copyAvroString("5", false), ByteString.copyAvroString("7", false), ByteString.copyAvroString("11", false));
    List<ByteString> adds = Arrays.asList(ByteString.copyAvroString("13", false), ByteString.copyAvroString("17", false), ByteString.copyAvroString("19", false));
    List<Object> badInput = asList(true, 99, 999L, 88.0f, 888.0, "Ā", new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, 99, 999L, 88.0f, 888.0, "Ā", new DataMap(), new DataList());
    testArray(BytesArray.class, schema, input, adds);
    testArrayBadInput(BytesArray.class, schema, input, badInput, badOutput);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 12 with ArrayDataSchema

use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.

the class TestArrayTemplate method testStringArray.

@Test
public void testStringArray() {
    ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"string\" }");
    // must be unique
    List<String> input = Arrays.asList("apple", "banana", "orange", "pineapple", "graphs");
    List<String> adds = Arrays.asList("foo", "bar", "baz");
    List<Object> badInput = asList(true, 1, 2L, 3.0f, 4.0, ByteString.empty(), new StringMap(), new StringArray(), null);
    List<Object> badOutput = asList(true, 1, 2L, 3.0f, 4.0, ByteString.empty(), new DataMap(), new DataList());
    testArray(StringArray.class, schema, input, adds);
    testArrayBadInput(StringArray.class, schema, input, badInput, badOutput);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 13 with ArrayDataSchema

use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.

the class TestSchemaSampleDataGenerator method testArraySchema.

@Test
public void testArraySchema() {
    for (Map.Entry<DataSchema.Type, Class<? extends DirectArrayTemplate<?>>> entry : _dataSchemaTypeToprimitiveArrayMap.entrySet()) {
        final PrimitiveDataSchema itemsSchema = DataSchemaUtil.dataSchemaTypeToPrimitiveDataSchema(entry.getKey());
        final ArrayDataSchema arraySchema = new ArrayDataSchema(itemsSchema);
        final DataList value = (DataList) SchemaSampleDataGenerator.buildData(arraySchema, _spec);
        final ParameterizedType arrayType = (ParameterizedType) entry.getValue().getGenericSuperclass();
        assert (arrayType.getRawType() == DirectArrayTemplate.class);
        Assert.assertSame(value.get(0).getClass(), arrayType.getActualTypeArguments()[0]);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) DirectArrayTemplate(com.linkedin.data.template.DirectArrayTemplate) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) DataList(com.linkedin.data.DataList) ParameterizedType(java.lang.reflect.ParameterizedType) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) BooleanMap(com.linkedin.data.template.BooleanMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) DoubleMap(com.linkedin.data.template.DoubleMap) BytesMap(com.linkedin.data.template.BytesMap) FloatMap(com.linkedin.data.template.FloatMap) IntegerMap(com.linkedin.data.template.IntegerMap) DataMap(com.linkedin.data.DataMap) StringMap(com.linkedin.data.template.StringMap) LongMap(com.linkedin.data.template.LongMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 14 with ArrayDataSchema

use of com.linkedin.data.schema.ArrayDataSchema in project rest.li by linkedin.

the class TestArray method testStringMapArray.

@Test
public void testStringMapArray() {
    TestDataTemplateUtil.FieldInfo fieldInfo = TestDataTemplateUtil.fieldInfo(new ArrayTest(), "stringMapArray");
    @SuppressWarnings("unchecked") Class<StringMapArray> templateClass = (Class<StringMapArray>) fieldInfo.getFieldClass();
    ArrayDataSchema schema = (ArrayDataSchema) fieldInfo.getField().getType();
    List<StringMap> input = new ArrayList<StringMap>();
    for (int i = 0; i < 5; ++i) {
        input.add(new StringMap());
        input.get(i).put("input key " + i, "value " + i);
    }
    List<StringMap> adds = new ArrayList<StringMap>();
    for (int i = 0; i < 5; ++i) {
        adds.add(new StringMap());
        input.get(i).put("add key " + i, "value " + i);
    }
    TestArrayTemplate.testArray(templateClass, schema, input, adds);
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 15 with ArrayDataSchema

use of com.linkedin.data.schema.ArrayDataSchema 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) Test(org.testng.annotations.Test)

Aggregations

ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)42 Test (org.testng.annotations.Test)20 DataList (com.linkedin.data.DataList)16 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)16 DataMap (com.linkedin.data.DataMap)15 DataSchema (com.linkedin.data.schema.DataSchema)15 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)11 MapDataSchema (com.linkedin.data.schema.MapDataSchema)10 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)8 ArrayList (java.util.ArrayList)7 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)6 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)6 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)5 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)5 TestDataTemplateUtil (com.linkedin.data.template.TestDataTemplateUtil)5 ByteString (com.linkedin.data.ByteString)3 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)3 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)2 Name (com.linkedin.data.schema.Name)2 StringArray (com.linkedin.data.template.StringArray)2