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<>();
elements.add(new CreateIdStatus<>(HttpStatus.S_201_CREATED.getCode(), keys[0], null, version));
elements.add(new CreateIdStatus<>(HttpStatus.S_201_CREATED.getCode(), keys[1], null, version));
ErrorResponse error = new ErrorResponse().setMessage("3");
elements.add(new CreateIdStatus<>(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 TestMockRestliResponseExceptionBuilder method testOverwriteStatus.
@Test
public void testOverwriteStatus() {
ErrorResponse noStatusErrorResponse = new ErrorResponse();
RestLiResponseException exception = new MockRestliResponseExceptionBuilder().setErrorResponse(noStatusErrorResponse).build();
assertEquals(exception.getStatus(), 500);
}
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 TestMockBatchKVResponseFactory method complexKeyData.
@DataProvider(name = "complexKey")
public Object[][] complexKeyData() {
Map<ComplexResourceKey<Greeting, Greeting>, Greeting> recordTemplates = new HashMap<>();
Map<ComplexResourceKey<Greeting, Greeting>, ErrorResponse> errorResponses = new HashMap<>();
Greeting g1 = buildGreeting(1L);
Greeting g2 = buildGreeting(2L);
Greeting g3 = buildGreeting(3L);
recordTemplates.put(new ComplexResourceKey<>(g1, g1), g1);
recordTemplates.put(new ComplexResourceKey<>(g2, g2), g2);
errorResponses.put(new ComplexResourceKey<>(g3, g3), new ErrorResponse().setMessage("3"));
Map<ComplexResourceKey<Greeting, Greeting>, HttpStatus> statuses = new HashMap<>();
statuses.put(new ComplexResourceKey<>(g1, g1), HttpStatus.S_200_OK);
statuses.put(new ComplexResourceKey<>(g2, g2), HttpStatus.S_200_OK);
statuses.put(new ComplexResourceKey<>(g3, g3), HttpStatus.S_500_INTERNAL_SERVER_ERROR);
// Strip the parameters from complex keys in expected results and expected errors.
Map<ComplexResourceKey<Greeting, Greeting>, Greeting> expectedRecordTemplates = new HashMap<>();
expectedRecordTemplates.put(new ComplexResourceKey<>(g1, new Greeting()), recordTemplates.get(new ComplexResourceKey<>(g1, g1)));
expectedRecordTemplates.put(new ComplexResourceKey<>(g2, new Greeting()), recordTemplates.get(new ComplexResourceKey<>(g2, g2)));
Map<ComplexResourceKey<Greeting, Greeting>, EntityResponse<Greeting>> expectedResults = new HashMap<>();
expectedResults.put(new ComplexResourceKey<>(g1, new Greeting()), buildEntityResponse(recordTemplates.get(new ComplexResourceKey<>(g1, g1)), HttpStatus.S_200_OK, null));
expectedResults.put(new ComplexResourceKey<>(g2, new Greeting()), buildEntityResponse(recordTemplates.get(new ComplexResourceKey<>(g2, g2)), HttpStatus.S_200_OK, null));
expectedResults.put(new ComplexResourceKey<>(g3, new Greeting()), buildEntityResponse(null, HttpStatus.S_500_INTERNAL_SERVER_ERROR, errorResponses.get(new ComplexResourceKey<>(g3, g3))));
Map<ComplexResourceKey<Greeting, Greeting>, ErrorResponse> expectedErrors = new HashMap<>();
expectedErrors.put(new ComplexResourceKey<>(g3, new Greeting()), errorResponses.get(new ComplexResourceKey<>(g3, g3)));
return new Object[][] { { recordTemplates, statuses, errorResponses, expectedRecordTemplates, expectedResults, expectedErrors } };
}
use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class DefaultScatterGatherStrategy method gatherException.
/**
* Gather an incoming scattered request error and merge it into currently accumulated batch response.
* @param accumulatedDataMap currently accumulated response data map.
* @param keys keys which result in the error.
* @param e error exception.
* @param version protocol version.
* @param <K> request key type
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private <K> void gatherException(DataMap accumulatedDataMap, Set<K> keys, Throwable e, ProtocolVersion version) {
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setMessage(e.getMessage());
errorResponse.setStatus(HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
errorResponse.setExceptionClass(e.getClass().getName());
keys.forEach(key -> {
String keyString = BatchResponse.keyToString(key, version);
accumulatedDataMap.getDataMap(BatchResponse.ERRORS).put(keyString, errorResponse.data());
});
}
Aggregations