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));
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations