use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class TestBatchKVResponse method testDeserialization.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchKVResponseDataProvider")
public <K> void testDeserialization(List<K> keys, Class<K> keyClass, Class<? extends RecordTemplate> keyKeyClass, Class<? extends RecordTemplate> keyParamsClass, ProtocolVersion protocolVersion) {
final K resultKey = keys.get(0);
final K errorKey = keys.get(1);
final String resultKeyString = URIParamUtils.encodeKeyForBody(resultKey, false, protocolVersion);
final String errorKeyString = URIParamUtils.encodeKeyForBody(errorKey, false, protocolVersion);
final DataMap inputResults = new DataMap();
inputResults.put(resultKeyString, _record.data());
final DataMap inputErrors = new DataMap();
inputErrors.put(errorKeyString, _error.data());
final DataMap testData = new DataMap();
testData.put(BatchKVResponse.RESULTS, inputResults);
testData.put(BatchKVResponse.ERRORS, inputErrors);
final BatchKVResponse<K, TestRecord> response = new BatchKVResponse<K, TestRecord>(testData, keyClass, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap(), keyKeyClass, keyParamsClass, protocolVersion);
final Map<K, TestRecord> outputResults = response.getResults();
final TestRecord outRecord = outputResults.get(resultKey);
Assert.assertEquals(outRecord, outRecord);
final Map<K, ErrorResponse> outputErrors = response.getErrors();
final ErrorResponse outError = outputErrors.get(errorKey);
Assert.assertEquals(outError, _error);
}
use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class TestBatchEntityResponseDecoder method testDecoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchEntityResponseDataProvider")
public void testDecoding(List<String> keys, ProtocolVersion protocolVersion) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
final String resultKey = keys.get(0);
final String statusKey = keys.get(1);
final String errorKey = keys.get(2);
final DataMap resultData = new DataMap();
resultData.put(resultKey, _record.data());
final DataMap statusData = new DataMap();
statusData.put(statusKey, _status.getCode());
final DataMap errorData = new DataMap();
errorData.put(errorKey, _error.data());
final DataMap data = new DataMap();
data.put(BatchResponse.RESULTS, resultData);
data.put(BatchResponse.STATUSES, statusData);
data.put(BatchResponse.ERRORS, errorData);
final BatchEntityResponseDecoder<String, TestRecord> decoder = new BatchEntityResponseDecoder<String, TestRecord>(new TypeSpec<TestRecord>(TestRecord.class), new TypeSpec<String>(String.class), Collections.<String, CompoundKey.TypeInfo>emptyMap(), null);
final BatchKVResponse<String, EntityResponse<TestRecord>> response = decoder.wrapResponse(data, Collections.<String, String>emptyMap(), protocolVersion);
final Map<String, EntityResponse<TestRecord>> results = response.getResults();
final Map<String, ErrorResponse> errors = response.getErrors();
final Collection<String> uniqueKeys = new HashSet<String>(keys);
Assert.assertEquals(results.size(), uniqueKeys.size());
Assert.assertEquals(errors.size(), 1);
Assert.assertEquals(results.get(resultKey).getEntity(), _record);
Assert.assertEquals(results.get(statusKey).getStatus(), _status);
Assert.assertEquals(results.get(errorKey).getError(), _error);
Assert.assertEquals(errors.get(errorKey), _error);
}
use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class TestNullGreetingsClient method testBatchUpdateUnsupportedNullKeyMap.
/*
* This test is one of the few areas in this test suite where we don't expect an exception.
* The purpose of this test is to make sure Rest.li can handle java.util.concurrent.ConcurrentHashMap(s) sent
* back by resource methods.
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchUpdateUnsupportedNullKeyMap(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(7l, someGreeting).build();
Response<BatchKVResponse<Long, UpdateStatus>> response = getClient().sendRequest(writeRequest).getResponse();
Map<Long, ErrorResponse> actualErrors = response.getEntity().getErrors();
Assert.assertEquals(actualErrors.size(), 0, "Errors map should be empty");
Map<Long, UpdateStatus> actualResults = response.getEntity().getResults();
Map<Long, UpdateStatus> expectedResults = new HashMap<Long, UpdateStatus>();
UpdateStatus updateStatus = new UpdateStatus().setStatus(201);
expectedResults.put(3l, updateStatus);
Assert.assertEquals(actualResults, expectedResults, "The results map should be correct");
}
use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class IndividualResponseException method createErrorResponse.
private static ErrorResponse createErrorResponse(HttpStatus status, String message) {
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setStatus(status.getCode());
errorResponse.setMessage(message);
return errorResponse;
}
use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class ErrorResponseBuilder method buildErrorResponse.
private ErrorResponse buildErrorResponse(RestLiServiceException result, ErrorResponseFormat errorResponseFormat) {
ErrorResponse er = new ErrorResponse();
if (errorResponseFormat.showStatusCodeInBody()) {
er.setStatus(result.getStatus().getCode());
}
if (errorResponseFormat.showMessage() && result.getMessage() != null) {
er.setMessage(result.getMessage());
}
if (errorResponseFormat.showServiceErrorCode() && result.hasServiceErrorCode()) {
er.setServiceErrorCode(result.getServiceErrorCode());
}
if (errorResponseFormat.showDetails() && result.hasErrorDetails()) {
er.setErrorDetails(new ErrorDetails(result.getErrorDetails()));
}
if (errorResponseFormat.showStacktrace()) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
result.printStackTrace(pw);
er.setStackTrace(sw.toString());
er.setExceptionClass(result.getClass().getName());
}
if (errorResponseFormat.showExceptionClass()) {
er.setExceptionClass(result.getClass().getName());
}
return er;
}
Aggregations