use of com.linkedin.restli.internal.server.ResponseType in project rest.li by linkedin.
the class TestRestLiResponseData method testSetNullStatus.
@Test(dataProvider = "envelopeResourceMethodDataProvider")
public void testSetNullStatus(RestLiResponseData responseData, ResourceMethod resourceMethod) {
ResponseType responseType = ResponseType.fromMethodType(resourceMethod);
try {
switch(responseType) {
case SINGLE_ENTITY:
responseData.getRecordResponseEnvelope().setRecord(new EmptyRecord(), null);
Assert.fail();
break;
case BATCH_ENTITIES:
responseData.getBatchResponseEnvelope().setBatchResponseMap(Collections.<Object, BatchResponseEnvelope.BatchResponseEntry>emptyMap(), null);
Assert.fail();
break;
case CREATE_COLLECTION:
responseData.getBatchCreateResponseEnvelope().setCreateResponse(Collections.<BatchCreateResponseEnvelope.CollectionCreateResponseItem>emptyList(), null);
Assert.fail();
break;
case GET_COLLECTION:
responseData.getCollectionResponseEnvelope().setCollectionResponse(Collections.<RecordTemplate>emptyList(), new CollectionMetadata(), new EmptyRecord(), null);
break;
case STATUS_ONLY:
responseData.getEmptyResponseEnvelope().setStatus(null);
break;
default:
Assert.fail();
}
Assert.fail();
} catch (UnsupportedOperationException e) {
// expected
}
}
use of com.linkedin.restli.internal.server.ResponseType in project rest.li by linkedin.
the class TestRestLiResponseData method testResponseType.
@Test(dataProvider = "envelopeResourceMethodDataProvider")
public void testResponseType(RestLiResponseData responseData, ResourceMethod resourceMethod) {
ResponseType responseType = ResponseType.fromMethodType(resourceMethod);
Assert.assertEquals(responseData.getResponseType(), responseType);
}
use of com.linkedin.restli.internal.server.ResponseType in project rest.li by linkedin.
the class TestRestLiResponseEnvelope method testEnvelopeSetDataNull.
@Test(dataProvider = "resourceMethodProvider")
public void testEnvelopeSetDataNull(ResourceMethod resourceMethod) {
// create an envelope and set all the data to null
RestLiResponseEnvelope responseEnvelope = EnvelopeBuilderUtil.buildBlankResponseEnvelope(resourceMethod, null);
responseEnvelope.clearData();
ResponseType responseType = ResponseType.fromMethodType(resourceMethod);
// extract the correct response envelope based on the data type and verify the data fields are all null
switch(responseType) {
case SINGLE_ENTITY:
RecordResponseEnvelope recordResponseEnvelope = (RecordResponseEnvelope) responseEnvelope;
Assert.assertNull(recordResponseEnvelope.getRecord());
break;
case GET_COLLECTION:
CollectionResponseEnvelope collectionResponseEnvelope = (CollectionResponseEnvelope) responseEnvelope;
Assert.assertNull(collectionResponseEnvelope.getCollectionResponse());
Assert.assertNull(collectionResponseEnvelope.getCollectionResponseCustomMetadata());
Assert.assertNull(collectionResponseEnvelope.getCollectionResponsePaging());
break;
case CREATE_COLLECTION:
BatchCreateResponseEnvelope batchCreateResponseEnvelope = (BatchCreateResponseEnvelope) responseEnvelope;
Assert.assertNull(batchCreateResponseEnvelope.getCreateResponses());
break;
case BATCH_ENTITIES:
BatchResponseEnvelope batchResponseEnvelope = (BatchResponseEnvelope) responseEnvelope;
Assert.assertNull(batchResponseEnvelope.getBatchResponseMap());
break;
case STATUS_ONLY:
// status only envelopes don't have data fields
break;
default:
throw new IllegalStateException();
}
}
use of com.linkedin.restli.internal.server.ResponseType in project rest.li by linkedin.
the class TestRestLiResponseEnvelope method testBuildBlankResponseEnvelope.
@Test(dataProvider = "resourceMethodProvider")
public void testBuildBlankResponseEnvelope(ResourceMethod resourceMethod) {
RestLiResponseEnvelope responseEnvelope = EnvelopeBuilderUtil.buildBlankResponseEnvelope(resourceMethod, null);
Assert.assertNotNull(responseEnvelope);
ResponseType responseType = ResponseType.fromMethodType(resourceMethod);
switch(responseType) {
case SINGLE_ENTITY:
RecordResponseEnvelope recordResponseEnvelope = (RecordResponseEnvelope) responseEnvelope;
Assert.assertNotNull(recordResponseEnvelope.getRecord());
Assert.assertTrue(recordResponseEnvelope.getRecord().getClass().isAssignableFrom(EmptyRecord.class));
break;
case GET_COLLECTION:
CollectionResponseEnvelope collectionResponseEnvelope = (CollectionResponseEnvelope) responseEnvelope;
Assert.assertNotNull(collectionResponseEnvelope.getCollectionResponse());
Assert.assertNotNull(collectionResponseEnvelope.getCollectionResponseCustomMetadata());
Assert.assertNull(collectionResponseEnvelope.getCollectionResponsePaging());
Assert.assertTrue(collectionResponseEnvelope.getCollectionResponse().isEmpty());
Assert.assertTrue(collectionResponseEnvelope.getCollectionResponseCustomMetadata().getClass().isAssignableFrom(EmptyRecord.class));
break;
case CREATE_COLLECTION:
BatchCreateResponseEnvelope batchCreateResponseEnvelope = (BatchCreateResponseEnvelope) responseEnvelope;
Assert.assertNotNull(batchCreateResponseEnvelope.getCreateResponses());
Assert.assertTrue(batchCreateResponseEnvelope.getCreateResponses().isEmpty());
break;
case BATCH_ENTITIES:
BatchResponseEnvelope batchResponseEnvelope = (BatchResponseEnvelope) responseEnvelope;
Assert.assertNotNull(batchResponseEnvelope.getBatchResponseMap());
Assert.assertTrue(batchResponseEnvelope.getBatchResponseMap().isEmpty());
break;
case STATUS_ONLY:
// status only envelopes are blank by default since they have no data fields
break;
default:
throw new IllegalStateException();
}
}
use of com.linkedin.restli.internal.server.ResponseType in project rest.li by linkedin.
the class TestRestLiResponseEnvelope method testEnvelopeResponseType.
@Test(dataProvider = "envelopeResourceMethodDataProvider")
public void testEnvelopeResponseType(RestLiResponseEnvelope responseEnvelope, ResourceMethod resourceMethod) {
ResponseType responseType = ResponseType.fromMethodType(resourceMethod);
Assert.assertEquals(responseEnvelope.getResponseType(), responseType);
}
Aggregations