use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncFinderOptionalParam.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinderOptionalParam")
public void testAsyncFinderOptionalParam(ProtocolVersion version, String query) throws Exception {
RestLiCallback<?> callback = getCallback();
ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("search");
AsyncStatusCollectionResource statusResource = getMockResource(AsyncStatusCollectionResource.class);
statusResource.search((PagingContext) EasyMock.anyObject(), eq("linkedin"), eq(-1L), eq((StatusType) null), EasyMock.<Callback<List<Status>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<List<Status>> callback = (Callback<List<Status>>) EasyMock.getCurrentArguments()[4];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses" + query, null);
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchPatchAssociativeResource.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchUpdateCompoundKey")
public void testAsyncBatchPatchAssociativeResource(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel followsResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncFollowsAssociativeResource resource;
methodDescriptor = followsResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
resource = getMockResource(AsyncFollowsAssociativeResource.class);
@SuppressWarnings("unchecked") BatchPatchRequest<CompoundKey, Followed> mockBatchPatchReq = (BatchPatchRequest<CompoundKey, Followed>) EasyMock.anyObject();
resource.batchUpdate(mockBatchPatchReq, EasyMock.<Callback<BatchUpdateResult<CompoundKey, Followed>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchUpdateResult<CompoundKey, Followed>> callback = (Callback<BatchUpdateResult<CompoundKey, Followed>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(resource);
checkAsyncInvocation(resource, callback, methodDescriptor, "POST", version, uri, body, buildBatchPathKeys(buildFollowsCompoundKey(1L, 2L), buildFollowsCompoundKey(3L, 4L), buildFollowsCompoundKey(5L, 6L)));
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestMultiplexedCallback method testSuccess.
@Test
public void testSuccess() 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);
TestRecord entity2 = fakeEntity(ID2);
IndividualResponse ir2 = fakeIndividualResponse(entity2);
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));
assertRestResponseEquals(callback2.get(), fakeRestResponse(entity2));
MultiplexedResponse multiplexedResponse = aggregatedCallback.get();
Assert.assertEquals(multiplexedResponse.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals(multiplexedResponse.getHeaders(), HEADERS);
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestGetArgumentBuilder method asyncArgumentData.
@DataProvider(name = "asyncArgumentData")
private Object[][] asyncArgumentData() {
List<Parameter<?>> callbackParams = new ArrayList<Parameter<?>>();
callbackParams.add(getIntegerParam());
@SuppressWarnings("rawtypes") Parameter<Callback> cParam = new Parameter<Callback>("", Callback.class, null, false, null, Parameter.ParamType.CALLBACK, false, new AnnotationSet(new Annotation[] {}));
callbackParams.add(cParam);
List<Parameter<?>> parSeqContextParams = new ArrayList<Parameter<?>>();
parSeqContextParams.add(getIntegerParam());
parSeqContextParams.add(new Parameter<Context>("", Context.class, null, false, null, Parameter.ParamType.PARSEQ_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
List<Parameter<?>> deprecatedParSeqContextParams = new ArrayList<Parameter<?>>();
deprecatedParSeqContextParams.add(getIntegerParam());
@SuppressWarnings("deprecation") Parameter<Context> contextParam = new Parameter<Context>("", Context.class, null, false, null, Parameter.ParamType.PARSEQ_CONTEXT, false, new AnnotationSet(new Annotation[] {}));
deprecatedParSeqContextParams.add(contextParam);
return new Object[][] { { callbackParams }, { parSeqContextParams }, { deprecatedParSeqContextParams } };
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiServer method testRestRequestAttachmentsPresent.
@Test
public void testRestRequestAttachmentsPresent() throws Exception {
//This test verifies that a RestRequest sent to the RestLiServer throws an exception if the content type is multipart/related
RestRequest contentTypeMultiPartRelated = new RestRequestBuilder(new URI("/statuses/abcd")).setHeader(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_MULTIPART_RELATED).build();
Callback<RestResponse> callback = new Callback<RestResponse>() {
@Override
public void onSuccess(RestResponse restResponse) {
fail();
}
@Override
public void onError(Throwable e) {
assertTrue(e instanceof RestException);
RestException restException = (RestException) e;
RestResponse restResponse = restException.getResponse();
assertEquals(restResponse.getStatus(), 415);
assertTrue(restResponse.getEntity().length() > 0);
assertEquals(restResponse.getEntity().asString(Charset.defaultCharset()), "This server cannot handle requests with a content type of multipart/related");
}
};
_server.handleRequest(contentTypeMultiPartRelated, new RequestContext(), callback);
}
Aggregations