use of com.linkedin.restli.test.RecordTemplateWithDefaultValue in project rest.li by linkedin.
the class TestMockActionResponseFactory method testInference.
@Test
public void testInference() {
final RecordTemplateWithDefaultValue record = new RecordTemplateWithDefaultValue();
record.setId(42L);
record.setMessage("Lorem ipsum");
final ActionResponse<RecordTemplateWithDefaultValue> response = MockActionResponseFactory.create(RecordTemplateWithDefaultValue.class, record);
Assert.assertEquals(response.getValue(), record);
final RecordDataSchema schema = response.schema();
Assert.assertEquals(schema.getName(), ActionResponse.class.getSimpleName());
Assert.assertEquals(schema.getField(ActionResponse.VALUE_NAME).getType(), DataTemplateUtil.getSchema(RecordTemplateWithDefaultValue.class));
}
use of com.linkedin.restli.test.RecordTemplateWithDefaultValue in project rest.li by linkedin.
the class TestDataAssert method testRecordTemplatesAfterFixup.
@Test
public void testRecordTemplatesAfterFixup() {
RecordTemplateWithDefaultValue actual = new RecordTemplateWithDefaultValue().setId(1L);
RecordTemplateWithDefaultValue expected = new RecordTemplateWithDefaultValue().setId(1L).setMessage("message");
ValidationOptions validationOptions = new ValidationOptions(RequiredMode.FIXUP_ABSENT_WITH_DEFAULT, CoercionMode.STRING_TO_PRIMITIVE);
try {
DataAssert.assertRecordTemplateDataEqual(actual, expected, validationOptions);
Assert.fail("Assertion should have failed as the record templates are not equal w/o fix-up and coercion!");
} catch (Throwable t) {
// expected
}
DataAssert.assertRecordTemplateDataEqual(actual, expected, validationOptions);
}
use of com.linkedin.restli.test.RecordTemplateWithDefaultValue in project rest.li by linkedin.
the class TestDataAsserts method testAssertEqualsRecordTemplates.
@Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = ".*id(.|\n)*Expected: 1(.|\n)*got: 2.*")
public void testAssertEqualsRecordTemplates() {
RecordTemplateWithDefaultValue expected = new RecordTemplateWithDefaultValue().setId(1);
RecordTemplateWithDefaultValue actual = new RecordTemplateWithDefaultValue().setId(2);
assertEquals(actual, expected);
}
use of com.linkedin.restli.test.RecordTemplateWithDefaultValue in project rest.li by linkedin.
the class TestMockActionResponseFactory method testDynamicSchema.
@Test
public void testDynamicSchema() {
final RecordTemplateWithDefaultValue record = new RecordTemplateWithDefaultValue();
record.setId(42L);
record.setMessage("Lorem ipsum");
final CollectionResponse<RecordTemplateWithDefaultValue> collectionResponse = new CollectionResponse<>(RecordTemplateWithDefaultValue.class);
collectionResponse.getElements().add(record);
@SuppressWarnings("unchecked") final ActionResponse<CollectionResponse<RecordTemplateWithDefaultValue>> response = (ActionResponse<CollectionResponse<RecordTemplateWithDefaultValue>>) (Object) MockActionResponseFactory.create(CollectionResponse.class, collectionResponse.schema(), collectionResponse);
Assert.assertEquals(response.getValue(), collectionResponse);
final RecordDataSchema schema = response.schema();
Assert.assertEquals(schema.getName(), ActionResponse.class.getSimpleName());
Assert.assertEquals(schema.getField(ActionResponse.VALUE_NAME).getType(), collectionResponse.schema());
}
Aggregations