Search in sources :

Example 81 with RecordDataSchema

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

the class TestSchemaAnnotationProcessor method testHandlerResolveException.

@Test
public void testHandlerResolveException() throws Exception {
    String failureMessage = "Intentional failure";
    SchemaAnnotationHandler testHandler = new SchemaAnnotationHandler() {

        @Override
        public ResolutionResult resolve(List<Pair<String, Object>> propertiesOverrides, ResolutionMetaData resolutionMetadata) {
            throw new RuntimeException(failureMessage);
        }

        @Override
        public String getAnnotationNamespace() {
            return TEST_ANNOTATION_LABEL;
        }

        @Override
        public AnnotationValidationResult validate(Map<String, Object> resolvedProperties, ValidationMetaData metaData) {
            return new AnnotationValidationResult();
        }
    };
    RecordDataSchema testSchema = (RecordDataSchema) TestUtil.dataSchemaFromPdlString(simpleTestSchema);
    try {
        SchemaAnnotationProcessor.SchemaAnnotationProcessResult result = SchemaAnnotationProcessor.process(Arrays.asList(testHandler), testSchema, new SchemaAnnotationProcessor.AnnotationProcessOption());
    } catch (IllegalStateException e) {
        e.getMessage().equals(String.format("Annotation processing failed when resolving annotations in the schema using the handler for " + "annotation namespace \"%s\"", TEST_ANNOTATION_LABEL));
    }
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) List(java.util.List) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 82 with RecordDataSchema

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

the class TestCopySchemaUtil method testCopyField.

@Test
public void testCopyField() throws Exception {
    RecordDataSchema fooSchema = (RecordDataSchema) TestUtil.dataSchemaFromString(fooSchemaText);
    RecordDataSchema.Field field = fooSchema.getField("intField");
    // Use old field to do the exact copy
    RecordDataSchema.Field newField = CopySchemaUtil.copyField(field, field.getType());
    newField.setRecord(field.getRecord());
    // Copy result should appear to be the same
    Assert.assertEquals(field, newField);
}
Also used : RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Example 83 with RecordDataSchema

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

the class TestCopySchemaUtil method testCopyUnionMember.

@Test
public void testCopyUnionMember() throws Exception {
    RecordDataSchema fooSchema = (RecordDataSchema) TestUtil.dataSchemaFromString(fooSchemaText);
    UnionDataSchema unionDataSchema = (UnionDataSchema) fooSchema.getField("unionField").getType();
    UnionDataSchema.Member firstMember = unionDataSchema.getMembers().get(0);
    UnionDataSchema.Member newMember = CopySchemaUtil.copyUnionMember(firstMember, firstMember.getType());
    Assert.assertEquals(firstMember, newMember);
}
Also used : UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) Test(org.testng.annotations.Test)

Example 84 with RecordDataSchema

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

the class TestCopySchemaUtil method testBuildSkeletonSchema.

@Test
public void testBuildSkeletonSchema() throws Exception {
    DataSchema oldSchema = null;
    RecordDataSchema fooSchema = (RecordDataSchema) TestUtil.dataSchemaFromString(fooSchemaText);
    // Test Record
    RecordDataSchema newRecordSchema = (RecordDataSchema) CopySchemaUtil.buildSkeletonSchema(fooSchema);
    assert ((newRecordSchema.getFields().size() == 0) && Objects.equals(newRecordSchema.getDoc(), fooSchema.getDoc()) && Objects.equals(newRecordSchema.getProperties(), fooSchema.getProperties()) && Objects.equals(newRecordSchema.getAliases(), fooSchema.getAliases()));
    // Test TypeRef
    oldSchema = fooSchema.getField("typeRefField").getType();
    TyperefDataSchema newTypeRefDataSchema = (TyperefDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    assert (Objects.equals(newTypeRefDataSchema.getDoc(), ((TyperefDataSchema) oldSchema).getDoc()) && Objects.equals(newTypeRefDataSchema.getProperties(), oldSchema.getProperties()) && Objects.equals(newTypeRefDataSchema.getAliases(), ((TyperefDataSchema) oldSchema).getAliases()));
    // Test Union
    oldSchema = fooSchema.getField("unionField").getType();
    UnionDataSchema newUnionDataSchema = (UnionDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    assert (newUnionDataSchema.getMembers().size() == 0 && Objects.equals(newUnionDataSchema.getProperties(), oldSchema.getProperties()));
    // Test map
    oldSchema = fooSchema.getField("mapField").getType();
    MapDataSchema mapDataSchema = (MapDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    assert (Objects.equals(mapDataSchema.getProperties(), oldSchema.getProperties()) && Objects.equals(mapDataSchema.getValues(), DataSchemaConstants.NULL_DATA_SCHEMA));
    // Test array
    oldSchema = fooSchema.getField("arrayField").getType();
    ArrayDataSchema arrayDataSchema = (ArrayDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    assert (Objects.equals(arrayDataSchema.getProperties(), oldSchema.getProperties()) && Objects.equals(arrayDataSchema.getItems(), DataSchemaConstants.NULL_DATA_SCHEMA));
    // Test ENUM
    oldSchema = fooSchema.getField("enumField").getType();
    EnumDataSchema enumDataSchema = (EnumDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    Assert.assertEquals(enumDataSchema, oldSchema);
    // Test FIXED
    oldSchema = fooSchema.getField("fixedField").getType();
    FixedDataSchema fixedDataSchema = (FixedDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    Assert.assertEquals(fixedDataSchema, oldSchema);
    // Test primitive
    oldSchema = fooSchema.getField("intField").getType();
    PrimitiveDataSchema primitiveDataSchema = (PrimitiveDataSchema) CopySchemaUtil.buildSkeletonSchema(oldSchema);
    Assert.assertEquals(primitiveDataSchema, oldSchema);
}
Also used : EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) Test(org.testng.annotations.Test)

Example 85 with RecordDataSchema

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

the class TestActionArgumentBuilder method testExtractRequestDataFailure.

@Test(dataProvider = "failureData")
public void testExtractRequestDataFailure(String entity, List<Parameter<?>> params, String errorRegEx) throws IOException {
    RecordDataSchema dataSchema = DynamicRecordMetadata.buildSchema("testAction", params);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, null, "testAction", dataSchema);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, null, 1);
    RestLiArgumentBuilder argumentBuilder = new ActionArgumentBuilder();
    try {
        argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
        fail("Expected RoutingException");
    } catch (RoutingException e) {
        assertTrue(e.getMessage().matches(errorRegEx));
    }
    verify(request, descriptor, routingResult);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Test(org.testng.annotations.Test)

Aggregations

RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)106 DataMap (com.linkedin.data.DataMap)43 Test (org.testng.annotations.Test)43 DataSchema (com.linkedin.data.schema.DataSchema)40 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)32 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)28 MapDataSchema (com.linkedin.data.schema.MapDataSchema)26 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)25 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)20 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)19 ArrayList (java.util.ArrayList)18 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)14 Name (com.linkedin.data.schema.Name)14 Map (java.util.Map)10 Schema (org.apache.avro.Schema)10 DataList (com.linkedin.data.DataList)9 GenericRecord (org.apache.avro.generic.GenericRecord)9 ValidateDataAgainstSchema (com.linkedin.data.schema.validation.ValidateDataAgainstSchema)8 HashMap (java.util.HashMap)8 FieldDef (com.linkedin.data.template.FieldDef)7