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;
}
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);
}
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);
}
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 } };
}
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 } };
}
Aggregations