Search in sources :

Example 26 with ErrorResponse

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

the class MockBatchKVResponseFactory method buildDataMap.

private static <K, V extends RecordTemplate> DataMap buildDataMap(Map<K, V> recordTemplates, Map<K, ErrorResponse> errorResponses, ProtocolVersion version) {
    DataMap batchResponseDataMap = new DataMap();
    DataMap rawBatchData = new DataMap();
    for (Map.Entry<K, V> entry : recordTemplates.entrySet()) {
        String stringKey = URIParamUtils.encodeKeyForBody(entry.getKey(), false, version);
        rawBatchData.put(stringKey, entry.getValue().data());
    }
    batchResponseDataMap.put(BatchResponse.RESULTS, rawBatchData);
    DataMap rawErrorData = new DataMap();
    for (Map.Entry<K, ErrorResponse> errorResponse : errorResponses.entrySet()) {
        rawErrorData.put(URIParamUtils.encodeKeyForBody(errorResponse.getKey(), false, version), errorResponse.getValue().data());
    }
    batchResponseDataMap.put(BatchResponse.ERRORS, rawErrorData);
    return batchResponseDataMap;
}
Also used : DataMap(com.linkedin.data.DataMap) Map(java.util.Map) DataMap(com.linkedin.data.DataMap) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 27 with ErrorResponse

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

the class MockFailedResponseFutureBuilder method buildWithEntity.

private ResponseFuture<V> buildWithEntity() {
    int status = getStatus();
    byte[] entity = mapToBytes(getEntity().data());
    Response<V> decodedResponse = new MockResponseBuilder<K, V>().setEntity(getEntity()).setStatus(status).setHeaders(getHeaders()).setCookies(getCookies()).setProtocolVersion(getProtocolVersion()).build();
    RestResponse restResponse = new RestResponseBuilder().setEntity(entity).setStatus(status).setHeaders(decodedResponse.getHeaders()).setCookies(CookieUtil.encodeCookies(decodedResponse.getCookies())).build();
    RestLiResponseException restLiResponseException = new RestLiResponseException(restResponse, decodedResponse, new ErrorResponse());
    ExecutionException executionException = new ExecutionException(restLiResponseException);
    Future<Response<V>> responseFuture = buildFuture(null, executionException);
    return new ResponseFutureImpl<V>(responseFuture, _errorHandlingBehavior);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) ErrorResponse(com.linkedin.restli.common.ErrorResponse) RestResponse(com.linkedin.r2.message.rest.RestResponse) Response(com.linkedin.restli.client.Response) ErrorResponse(com.linkedin.restli.common.ErrorResponse) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) ResponseFutureImpl(com.linkedin.restli.internal.client.ResponseFutureImpl)

Example 28 with ErrorResponse

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

the class TestMockBatchCreateIdResponseFactory method testCreate.

@Test(dataProvider = "provideKeys")
public <K> void testCreate(K[] keys) {
    ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
    List<CreateIdStatus<K>> elements = new ArrayList<CreateIdStatus<K>>();
    elements.add(new CreateIdStatus<K>(HttpStatus.S_201_CREATED.getCode(), keys[0], null, version));
    elements.add(new CreateIdStatus<K>(HttpStatus.S_201_CREATED.getCode(), keys[1], null, version));
    ErrorResponse error = new ErrorResponse().setMessage("3");
    elements.add(new CreateIdStatus<K>(HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode(), keys[2], error, version));
    BatchCreateIdResponse<K> batchResp = MockBatchCreateIdResponseFactory.create(elements);
    Assert.assertEquals(batchResp.getElements(), elements);
}
Also used : ArrayList(java.util.ArrayList) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 29 with ErrorResponse

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

the class TestMockBatchKVResponseFactory method compoundKeyData.

@DataProvider(name = "compoundKey")
public Object[][] compoundKeyData() {
    CompoundKey c1 = buildCompoundKey("c1", 1);
    CompoundKey c2 = buildCompoundKey("c2", 2);
    CompoundKey c3 = buildCompoundKey("c3", 3);
    Map<CompoundKey, Greeting> recordTemplates = new HashMap<CompoundKey, Greeting>();
    recordTemplates.put(c1, buildGreeting(1L));
    recordTemplates.put(c2, buildGreeting(2L));
    Map<CompoundKey, ErrorResponse> errorResponses = new HashMap<CompoundKey, ErrorResponse>();
    errorResponses.put(c3, new ErrorResponse().setMessage("3"));
    Map<CompoundKey, HttpStatus> statuses = new HashMap<CompoundKey, HttpStatus>();
    statuses.put(c1, HttpStatus.S_200_OK);
    statuses.put(c2, HttpStatus.S_200_OK);
    statuses.put(c3, HttpStatus.S_500_INTERNAL_SERVER_ERROR);
    Map<String, CompoundKey.TypeInfo> keyParts = new HashMap<String, CompoundKey.TypeInfo>();
    keyParts.put("part1", new CompoundKey.TypeInfo(String.class, String.class));
    keyParts.put("part2", new CompoundKey.TypeInfo(Integer.class, Integer.class));
    Map<CompoundKey, EntityResponse<Greeting>> expectedResults = new HashMap<CompoundKey, EntityResponse<Greeting>>();
    expectedResults.put(c1, buildEntityResponse(recordTemplates.get(c1), HttpStatus.S_200_OK, null));
    expectedResults.put(c2, buildEntityResponse(recordTemplates.get(c2), HttpStatus.S_200_OK, null));
    expectedResults.put(c3, buildEntityResponse(null, HttpStatus.S_500_INTERNAL_SERVER_ERROR, errorResponses.get(c3)));
    return new Object[][] { { keyParts, recordTemplates, statuses, errorResponses, expectedResults } };
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CompoundKey(com.linkedin.restli.common.CompoundKey) HashMap(java.util.HashMap) HttpStatus(com.linkedin.restli.common.HttpStatus) MyCustomString(com.linkedin.restli.common.MyCustomString) ErrorResponse(com.linkedin.restli.common.ErrorResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) DataProvider(org.testng.annotations.DataProvider)

Example 30 with ErrorResponse

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

the class TestMockBatchKVResponseFactory method customPrimitiveTyperefKeyData.

@DataProvider(name = "customPrimitiveTyperefKey")
public Object[][] customPrimitiveTyperefKeyData() {
    MyCustomString m1 = new MyCustomString("1");
    MyCustomString m2 = new MyCustomString("2");
    MyCustomString m3 = new MyCustomString("3");
    Map<MyCustomString, Greeting> recordTemplates = new HashMap<MyCustomString, Greeting>();
    Map<MyCustomString, ErrorResponse> errorResponses = new HashMap<MyCustomString, ErrorResponse>();
    recordTemplates.put(m1, buildGreeting(1L));
    recordTemplates.put(m2, buildGreeting(2L));
    errorResponses.put(m3, new ErrorResponse().setMessage("3"));
    Map<MyCustomString, HttpStatus> statuses = new HashMap<MyCustomString, HttpStatus>();
    statuses.put(m1, HttpStatus.S_200_OK);
    statuses.put(m2, HttpStatus.S_200_OK);
    statuses.put(m3, HttpStatus.S_500_INTERNAL_SERVER_ERROR);
    Map<MyCustomString, EntityResponse<Greeting>> expectedResults = new HashMap<MyCustomString, EntityResponse<Greeting>>();
    expectedResults.put(m1, buildEntityResponse(recordTemplates.get(m1), HttpStatus.S_200_OK, null));
    expectedResults.put(m2, buildEntityResponse(recordTemplates.get(m2), HttpStatus.S_200_OK, null));
    expectedResults.put(m3, buildEntityResponse(null, HttpStatus.S_500_INTERNAL_SERVER_ERROR, errorResponses.get(m3)));
    return new Object[][] { { recordTemplates, statuses, errorResponses, expectedResults } };
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) MyCustomString(com.linkedin.restli.common.MyCustomString) HashMap(java.util.HashMap) HttpStatus(com.linkedin.restli.common.HttpStatus) EntityResponse(com.linkedin.restli.common.EntityResponse) ErrorResponse(com.linkedin.restli.common.ErrorResponse) DataProvider(org.testng.annotations.DataProvider)

Aggregations

ErrorResponse (com.linkedin.restli.common.ErrorResponse)41 Test (org.testng.annotations.Test)20 DataMap (com.linkedin.data.DataMap)12 HashMap (java.util.HashMap)12 RestResponse (com.linkedin.r2.message.rest.RestResponse)8 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)8 RestException (com.linkedin.r2.message.rest.RestException)6 RestRequest (com.linkedin.r2.message.rest.RestRequest)6 IOException (java.io.IOException)6 CompoundKey (com.linkedin.restli.common.CompoundKey)5 Map (java.util.Map)5 Callback (com.linkedin.common.callback.Callback)4 MultiPartMIMEFullReaderCallback (com.linkedin.multipart.utils.MIMETestUtils.MultiPartMIMEFullReaderCallback)4 SinglePartMIMEFullReaderCallback (com.linkedin.multipart.utils.MIMETestUtils.SinglePartMIMEFullReaderCallback)4 RequestContext (com.linkedin.r2.message.RequestContext)4 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)4 StreamException (com.linkedin.r2.message.stream.StreamException)4 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)4 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)4 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)4