use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestMultiplexedCallback method testMixed.
@Test
public void testMixed() throws Exception {
FutureCallback<RestResponse> callback1 = new FutureCallback<RestResponse>();
FutureCallback<RestResponse> callback2 = new FutureCallback<RestResponse>();
ImmutableMap<Integer, Callback<RestResponse>> individualCallbacks = ImmutableMap.<Integer, Callback<RestResponse>>of(ID1, callback1, ID2, callback2);
FutureCallback<MultiplexedResponse> aggregatedCallback = new FutureCallback<MultiplexedResponse>();
TestRecord entity1 = fakeEntity(ID1);
IndividualResponse ir1 = fakeIndividualResponse(entity1);
IndividualResponse ir2 = fakeIndividualErrorResponse();
MultiplexedResponseContent responseContent = new MultiplexedResponseContent().setResponses(new IndividualResponseMap(ImmutableMap.of(Integer.toString(ID1), ir1, Integer.toString(ID2), ir2)));
MultiplexedCallback multiplexedCallback = new MultiplexedCallback(individualCallbacks, aggregatedCallback);
multiplexedCallback.onSuccess(fakeRestResponse(responseContent));
assertRestResponseEquals(callback1.get(), fakeRestResponse(entity1));
RestException actualError = (RestException) getError(callback2);
assertRestResponseEquals(actualError.getResponse(), fakeRestErrorResponse());
MultiplexedResponse multiplexedResponse = aggregatedCallback.get();
Assert.assertEquals(multiplexedResponse.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(multiplexedResponse.getHeaders(), HEADERS);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testBody.
@Test
public void testBody() throws IOException {
TestRecord entity = fakeEntity(0);
CreateRequest<TestRecord> request = fakeCreateRequest(entity);
NoOpCallback<EmptyRecord> callback = new NoOpCallback<EmptyRecord>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request, callback).build();
IndividualRequest individualRequest = new IndividualRequest().setMethod(HttpMethod.POST.name()).setHeaders(new StringMap(HEADERS)).setRelativeUrl(BASE_URI).setBody(new IndividualBody(entity.data()));
MultiplexedRequestContent expectedRequests = new MultiplexedRequestContent();
expectedRequests.setRequests(new IndividualRequestMap(ImmutableMap.of("0", individualRequest)));
assertMultiplexedRequestContentEquals(multiplexedRequest.getContent(), expectedRequests);
}
use of com.linkedin.restli.client.test.TestRecord in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testCookies.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testCookies() throws RestLiEncodingException {
final HttpCookie cookie1 = new HttpCookie("testCookie1", "testCookieValue1");
final HttpCookie cookie2 = new HttpCookie("testCookie2", "testCookieValue2");
// create a request with two cookies
Request<TestRecord> requestWithCookie = new GetRequestBuilder<Integer, TestRecord>(BASE_URI, TestRecord.class, RESOURCE_SPEC, RestliRequestOptions.DEFAULT_OPTIONS).id(ID1).setHeaders(HEADERS).addCookie(cookie1).addCookie(cookie2).build();
// Adding cookies to individual request should cause builder to throw an IllegalArgumentException exception.
// For security reason, cookies should be passed in the envelope request.
MultiplexedRequestBuilder.createSequentialRequest().addRequest(requestWithCookie, callback2).build();
}
use of com.linkedin.restli.client.test.TestRecord 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.client.test.TestRecord 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);
}
Aggregations