Search in sources :

Example 1 with ResponseType

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
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) ResponseType(com.linkedin.restli.internal.server.ResponseType) Test(org.testng.annotations.Test)

Example 2 with ResponseType

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

Example 3 with 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();
    }
}
Also used : ResponseType(com.linkedin.restli.internal.server.ResponseType) Test(org.testng.annotations.Test)

Example 4 with ResponseType

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();
    }
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) ResponseType(com.linkedin.restli.internal.server.ResponseType) Test(org.testng.annotations.Test)

Example 5 with ResponseType

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

Aggregations

ResponseType (com.linkedin.restli.internal.server.ResponseType)6 Test (org.testng.annotations.Test)6 EmptyRecord (com.linkedin.restli.common.EmptyRecord)3 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)2 DataMap (com.linkedin.data.DataMap)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)1 AnyRecord (com.linkedin.restli.internal.server.methods.AnyRecord)1 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)1 HashMap (java.util.HashMap)1