Search in sources :

Example 21 with RecordDataSchema

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

the class TestSchemaSampleDataGenerator method testTyperefSchema.

@Test
public void testTyperefSchema() {
    final RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.getSchema(TyperefTest.class);
    final DataMap value = SchemaSampleDataGenerator.buildRecordData(schema, _spec);
    for (RecordDataSchema.Field field : schema.getFields()) {
        final DataSchema fieldSchema = field.getType();
        if (!(fieldSchema instanceof TyperefDataSchema)) {
            continue;
        }
        final TyperefDataSchema fieldTyperefSchema = (TyperefDataSchema) field.getType();
        final Object fieldValue = value.get(field.getName());
        final Object rebuildValue = SchemaSampleDataGenerator.buildData(fieldTyperefSchema.getDereferencedDataSchema(), _spec);
        Assert.assertSame(fieldValue.getClass(), rebuildValue.getClass());
    }
}
Also used : UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataMap(com.linkedin.data.DataMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 22 with RecordDataSchema

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

the class TestSchemaSampleDataGenerator method testRecursivelyReferencedSchema.

@Test
public void testRecursivelyReferencedSchema() {
    try {
        final RecordDataSchema schema = (RecordDataSchema) DataTemplateUtil.getSchema(SelfReference.class);
        final DataMap data = SchemaSampleDataGenerator.buildRecordData(schema, _spec);
        Assert.assertTrue(data.getDataList("listRef").getDataMap(0).getDataList("listRef").isEmpty(), "Self referenced schema in list should not be embedded recursively");
        final String firstKey = data.getDataMap("mapRef").keySet().iterator().next();
        Assert.assertTrue(data.getDataMap("mapRef").getDataMap(firstKey).getDataMap("mapRef").isEmpty(), "Self referenced schema in map should not be embedded recursively");
        Assert.assertFalse(data.getDataMap("indirectRef").containsKey("ref"), "Self referenced schema (via indirect reference) should not be embedded recursively");
        Assert.assertFalse(data.getDataMap("unionRef").containsKey("com.linkedin.pegasus.generator.test.SelfReference"), "Self referenced schema in union should not be embedded recursively");
    } catch (StackOverflowError e) {
        Assert.fail("Self reference in schema should not cause stack overflow during doc gen.");
    }
}
Also used : SelfReference(com.linkedin.pegasus.generator.test.SelfReference) InvalidSelfReference(com.linkedin.pegasus.generator.test.InvalidSelfReference) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 23 with RecordDataSchema

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

the class TestCustomAnyRecord method testCustomAnyRecordSchema.

@Test
public void testCustomAnyRecordSchema() {
    RecordDataSchema schemaFromInstance = (new AnyRecord()).schema();
    DataSchema schemaFromClass = DataTemplateUtil.getSchema(AnyRecord.class);
    assertSame(schemaFromClass, schemaFromInstance);
    CustomAnyRecord custom = new CustomAnyRecord();
    RecordDataSchema customSchemaFromInstance = custom.schema();
    DataSchema customSchemaFromClass = DataTemplateUtil.getSchema(CustomAnyRecord.class);
    assertSame(customSchemaFromClass, customSchemaFromInstance);
    assertEquals(customSchemaFromClass, schemaFromClass);
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Example 24 with RecordDataSchema

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

the class TestTypeRefRecordTemplate method testMapSchema.

@Test
public void testMapSchema() {
    TyperefTest record = new TyperefTest();
    RecordDataSchema recordDataSchema = record.schema();
    DoubleMap doubleMap = new DoubleMap();
    record.setDoubleRefMap(doubleMap);
    doubleMap = record.getDoubleRefMap();
    assertEquals(doubleMap.schema(), DataTemplateUtil.getSchema(DoubleMap.class));
    assertNotEquals(recordDataSchema.getField("doubleRefMap").getType(), doubleMap.schema());
    IntegerMap intMap = new IntegerMap();
    record.setIntMap(intMap);
    intMap = record.getIntMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intMap").getType(), intMap.schema());
    record.setIntRefMap(intMap);
    intMap = record.getIntRefMap();
    assertEquals(intMap.schema(), DataTemplateUtil.getSchema(IntegerMap.class));
    assertNotEquals(recordDataSchema.getField("intRefMap").getType(), intMap.schema());
    assertNotEquals(recordDataSchema.getField("intMap").getType(), recordDataSchema.getField("intRefMap").getType());
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Example 25 with RecordDataSchema

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

the class TestLongStringLiteral method testSchema.

@Test
public void testSchema() {
    DataSchema schema = DataTemplateUtil.getSchema(LongStringLiteral.class);
    String schemaText = schema.toString();
    assertTrue(schemaText.length() > 65536);
    RecordDataSchema recordDataSchema = (RecordDataSchema) schema;
    RecordDataSchema.Field field = recordDataSchema.getField("text");
    DataList defaultValue = (DataList) field.getDefault();
    assertEquals(defaultValue.size(), 400);
    for (Object s : defaultValue) {
        assertEquals(s, LOREM);
    }
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) DataList(com.linkedin.data.DataList) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Aggregations

RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)63 DataMap (com.linkedin.data.DataMap)26 DataSchema (com.linkedin.data.schema.DataSchema)25 Test (org.testng.annotations.Test)24 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)15 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)14 MapDataSchema (com.linkedin.data.schema.MapDataSchema)12 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)12 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)10 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)8 Name (com.linkedin.data.schema.Name)8 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)7 ArrayList (java.util.ArrayList)7 FieldDef (com.linkedin.data.template.FieldDef)6 Schema (org.apache.avro.Schema)6 DataList (com.linkedin.data.DataList)5 ActionResponse (com.linkedin.restli.common.ActionResponse)5 GenericRecord (org.apache.avro.generic.GenericRecord)5 SchemaParser (com.linkedin.data.schema.SchemaParser)4 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)4