Search in sources :

Example 6 with ActionResponse

use of com.linkedin.restli.common.ActionResponse 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)

Example 7 with ActionResponse

use of com.linkedin.restli.common.ActionResponse in project rest.li by linkedin.

the class TestActionResponseBuilder method getActionResponse.

private static ActionResponse<Long> getActionResponse(long returnValue) {
    DataMap dataMap = new DataMap();
    dataMap.put(LONG_RETURN.getName(), returnValue);
    return new ActionResponse<>(dataMap, LONG_RETURN, LONG_RETURN.getField().getRecord());
}
Also used : ActionResponse(com.linkedin.restli.common.ActionResponse) DataMap(com.linkedin.data.DataMap)

Aggregations

ActionResponse (com.linkedin.restli.common.ActionResponse)7 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)6 FieldDef (com.linkedin.data.template.FieldDef)4 DataMap (com.linkedin.data.DataMap)3 HttpStatus (com.linkedin.restli.common.HttpStatus)2 ActionResult (com.linkedin.restli.server.ActionResult)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 RecordTemplateWithDefaultValue (com.linkedin.restli.test.RecordTemplateWithDefaultValue)2 Test (org.testng.annotations.Test)2 DataSchema (com.linkedin.data.schema.DataSchema)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1