Search in sources :

Example 1 with ActionResponseEnvelope

use of com.linkedin.restli.internal.server.response.ActionResponseEnvelope in project rest.li by linkedin.

the class TestRestLiValidationFilter method validateWithProjectionData.

@DataProvider(name = "validateWithProjectionData")
public Object[][] validateWithProjectionData() {
    RestLiResponseData<GetResponseEnvelope> getResponseData = ResponseDataBuilderUtil.buildGetResponseData(HttpStatus.S_200_OK, makeTestRecord());
    RestLiResponseData<CreateResponseEnvelope> createResponseData = ResponseDataBuilderUtil.buildCreateResponseData(HttpStatus.S_201_CREATED, new IdResponse<>(123L));
    RestLiResponseData<ActionResponseEnvelope> actionResponseData = ResponseDataBuilderUtil.buildActionResponseData(HttpStatus.S_200_OK, new EmptyRecord());
    return new Object[][] { // Resource model                                                     Response data         Projection mask                        Expect error?
    { RestLiAnnotationReader.processResource(ActionsResource.class), actionResponseData, null, false }, { RestLiAnnotationReader.processResource(ActionsResource.class), actionResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(ActionsResource.class), actionResponseData, makeMask("ignoreMePlease"), false }, { RestLiAnnotationReader.processResource(CollectionResource.class), getResponseData, null, false }, { RestLiAnnotationReader.processResource(CollectionResource.class), getResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(CollectionResource.class), getResponseData, makeMask("nonexistentField"), true }, { RestLiAnnotationReader.processResource(CollectionResource.class), getResponseData, makeMask("intField"), false }, { RestLiAnnotationReader.processResource(CollectionResource.class), actionResponseData, null, false }, { RestLiAnnotationReader.processResource(CollectionResource.class), actionResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(CollectionResource.class), actionResponseData, makeMask("ignoreMePlease"), false }, { RestLiAnnotationReader.processResource(SimpleResource.class), getResponseData, null, false }, { RestLiAnnotationReader.processResource(SimpleResource.class), getResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(SimpleResource.class), getResponseData, makeMask("nonexistentField"), true }, { RestLiAnnotationReader.processResource(SimpleResource.class), getResponseData, makeMask("intField"), false }, { RestLiAnnotationReader.processResource(SimpleResource.class), createResponseData, null, false }, { RestLiAnnotationReader.processResource(SimpleResource.class), createResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(SimpleResource.class), createResponseData, makeMask("nonexistentField"), true }, { RestLiAnnotationReader.processResource(SimpleResource.class), createResponseData, makeMask("intField"), false }, { RestLiAnnotationReader.processResource(SimpleResource.class), actionResponseData, null, false }, { RestLiAnnotationReader.processResource(SimpleResource.class), actionResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(SimpleResource.class), actionResponseData, makeMask("ignoreMePlease"), false }, { RestLiAnnotationReader.processResource(AssociationResource.class), getResponseData, null, false }, { RestLiAnnotationReader.processResource(AssociationResource.class), getResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(AssociationResource.class), getResponseData, makeMask("nonexistentField"), true }, { RestLiAnnotationReader.processResource(AssociationResource.class), getResponseData, makeMask("intField"), false }, { RestLiAnnotationReader.processResource(AssociationResource.class), actionResponseData, null, false }, { RestLiAnnotationReader.processResource(AssociationResource.class), actionResponseData, new MaskTree(), false }, { RestLiAnnotationReader.processResource(AssociationResource.class), actionResponseData, makeMask("ignoreMePlease"), false } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) BatchCreateResponseEnvelope(com.linkedin.restli.internal.server.response.BatchCreateResponseEnvelope) CreateResponseEnvelope(com.linkedin.restli.internal.server.response.CreateResponseEnvelope) GetResponseEnvelope(com.linkedin.restli.internal.server.response.GetResponseEnvelope) ActionResponseEnvelope(com.linkedin.restli.internal.server.response.ActionResponseEnvelope) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) RestLiSimpleResource(com.linkedin.restli.server.annotations.RestLiSimpleResource) DataProvider(org.testng.annotations.DataProvider)

Example 2 with ActionResponseEnvelope

use of com.linkedin.restli.internal.server.response.ActionResponseEnvelope in project rest.li by linkedin.

the class TestRestLiResponseHandler method testRestLiResponseData.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
@SuppressWarnings("unchecked")
public void testRestLiResponseData(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    RestLiResponseData<ActionResponseEnvelope> responseData;
    RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
    // #1 simple record template
    responseData = (RestLiResponseData<ActionResponseEnvelope>) _responseHandler.buildRestLiResponseData(request, routingResult1, buildStatusRecord());
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    assertEquals(responseData.getResponseEnvelope().getRecord().toString(), response1);
    // #2 DataTemplate response
    StringMap map = new StringMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
    responseData = (RestLiResponseData<ActionResponseEnvelope>) _responseHandler.buildRestLiResponseData(request, routingResult2, map);
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    // Obtain the maps necessary for comparison
    final DataMap actualMap;
    final DataMap expectedMap;
    actualMap = responseData.getResponseEnvelope().getRecord().data();
    expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
    assertEquals(actualMap, expectedMap);
    RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
    // #3 empty response
    responseData = (RestLiResponseData<ActionResponseEnvelope>) _responseHandler.buildRestLiResponseData(request, routingResult3, null);
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
    assertEquals(responseData.getResponseEnvelope().getRecord(), null);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) StringMap(com.linkedin.data.template.StringMap) RestRequest(com.linkedin.r2.message.rest.RestRequest) ActionResponseEnvelope(com.linkedin.restli.internal.server.response.ActionResponseEnvelope) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

ActionResponseEnvelope (com.linkedin.restli.internal.server.response.ActionResponseEnvelope)2 DataMap (com.linkedin.data.DataMap)1 StringMap (com.linkedin.data.template.StringMap)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)1 BatchCreateResponseEnvelope (com.linkedin.restli.internal.server.response.BatchCreateResponseEnvelope)1 CreateResponseEnvelope (com.linkedin.restli.internal.server.response.CreateResponseEnvelope)1 GetResponseEnvelope (com.linkedin.restli.internal.server.response.GetResponseEnvelope)1 RestLiSimpleResource (com.linkedin.restli.server.annotations.RestLiSimpleResource)1 DataProvider (org.testng.annotations.DataProvider)1 Test (org.testng.annotations.Test)1