Search in sources :

Example 1 with RecordTemplateWithDefaultValue

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));
}
Also used : RecordTemplateWithDefaultValue(com.linkedin.restli.test.RecordTemplateWithDefaultValue) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ActionResponse(com.linkedin.restli.common.ActionResponse) Test(org.testng.annotations.Test)

Example 2 with RecordTemplateWithDefaultValue

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);
}
Also used : RecordTemplateWithDefaultValue(com.linkedin.restli.test.RecordTemplateWithDefaultValue) ValidationOptions(com.linkedin.data.schema.validation.ValidationOptions) Test(org.testng.annotations.Test)

Example 3 with RecordTemplateWithDefaultValue

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);
}
Also used : RecordTemplateWithDefaultValue(com.linkedin.restli.test.RecordTemplateWithDefaultValue) Test(org.testng.annotations.Test)

Example 4 with RecordTemplateWithDefaultValue

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());
}
Also used : CollectionResponse(com.linkedin.restli.common.CollectionResponse) RecordTemplateWithDefaultValue(com.linkedin.restli.test.RecordTemplateWithDefaultValue) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ActionResponse(com.linkedin.restli.common.ActionResponse) Test(org.testng.annotations.Test)

Aggregations

RecordTemplateWithDefaultValue (com.linkedin.restli.test.RecordTemplateWithDefaultValue)4 Test (org.testng.annotations.Test)4 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)2 ActionResponse (com.linkedin.restli.common.ActionResponse)2 ValidationOptions (com.linkedin.data.schema.validation.ValidationOptions)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1