use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.
the class TestMockFailedResponseFutureBuilder method testOnlyOneOfErrorResponseOrEntityIsSet.
@Test
public void testOnlyOneOfErrorResponseOrEntityIsSet() {
MockFailedResponseFutureBuilder<Long, Greeting> builder = new MockFailedResponseFutureBuilder<Long, Greeting>();
builder.setEntity(new Greeting());
try {
builder.setErrorResponse(new ErrorResponse());
Assert.fail();
} catch (IllegalStateException e) {
// expected
}
builder = new MockFailedResponseFutureBuilder<Long, Greeting>();
builder.setErrorResponse(new ErrorResponse());
try {
builder.setEntity(new Greeting());
Assert.fail();
} catch (IllegalStateException e) {
// expected
}
}
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 ParSeqRestClientTest method mockClient.
/**
* @return a mock ParSeqRestClient that gives an error
*/
private ParSeqRestClient mockClient(final String errKey, final String errValue, final String errMsg, final int httpCode, final int appCode, final ProtocolVersion protocolVersion, final String errorResponseHeaderName) {
final ErrorResponse er = new ErrorResponse();
final DataMap errMap = new DataMap();
errMap.put(errKey, errValue);
er.setErrorDetails(new ErrorDetails(errMap));
er.setStatus(httpCode);
er.setMessage(errMsg);
er.setServiceErrorCode(appCode);
final byte[] mapBytes;
try {
mapBytes = new JacksonDataCodec().mapToBytes(er.data());
} catch (final IOException e) {
throw new RuntimeException(e);
}
final Map<String, String> headers = new HashMap<>();
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
headers.put(errorResponseHeaderName, RestConstants.HEADER_VALUE_ERROR);
return new ParSeqRestClient(new RestClient(new MockClient(httpCode, headers, mapBytes), "http://localhost"), RequestConfigProvider.build(new ParSeqRestliClientConfigBuilder().build(), () -> Optional.empty()));
}
Aggregations