use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiServer method testPostProcessingException.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "protocolVersions")
public void testPostProcessingException(final ProtocolVersion protocolVersion, final String errorResponseHeaderName, final RestOrStream restOrStream) throws Exception {
//request for nested projection within string field will generate error
final StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.get(eq(1L))).andReturn(buildStatusRecord()).once();
EasyMock.replay(statusResource);
Callback<RestResponse> restResponseCallback = 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();
try {
assertEquals(restResponse.getStatus(), 500);
assertTrue(restResponse.getEntity().length() > 0);
assertEquals(restResponse.getHeader(errorResponseHeaderName), RestConstants.HEADER_VALUE_ERROR);
EasyMock.verify(statusResource);
EasyMock.reset(statusResource);
} catch (Exception e2) {
fail(e2.toString());
}
}
};
if (restOrStream == RestOrStream.REST) {
RestRequest request = new RestRequestBuilder(new URI("/statuses/1?fields=text:(invalid)")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString()).build();
_server.handleRequest(request, new RequestContext(), restResponseCallback);
} else {
StreamRequest streamRequest = new StreamRequestBuilder(new URI("/statuses/1?fields=text:(invalid)")).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString()).build(EntityStreams.emptyStream());
Callback<StreamResponse> callback = new Callback<StreamResponse>() {
@Override
public void onSuccess(StreamResponse streamResponse) {
fail();
}
@Override
public void onError(Throwable e) {
Messages.toRestException((StreamException) e, new Callback<RestException>() {
@Override
public void onError(Throwable e) {
Assert.fail();
}
@Override
public void onSuccess(RestException result) {
restResponseCallback.onError(result);
}
});
}
};
_server.handleRequest(streamRequest, new RequestContext(), callback);
}
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchUpdateComplexKeyResource.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "asyncBatchUpdateComplexKey")
public void testAsyncBatchUpdateComplexKeyResource(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncDiscoveredItemsResource discoveredResource;
methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
@SuppressWarnings("unchecked") BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchUpdateReq = (BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
discoveredResource.batchUpdate(mockBatchUpdateReq, EasyMock.<Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredResource);
checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys(getDiscoveredItemComplexKey(1, 1, 1), getDiscoveredItemComplexKey(2, 2, 2), getDiscoveredItemComplexKey(3, 3, 3)));
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchDeleteComplexResource.
@Test
public void testAsyncBatchDeleteComplexResource() throws Exception {
ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncDiscoveredItemsResource discoveredResource;
methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_DELETE);
discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
@SuppressWarnings("unchecked") BatchDeleteRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchDeleteReq = (BatchDeleteRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
discoveredResource.batchDelete(mockBatchDeleteReq, EasyMock.<Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredResource);
String uri = "/asyncdiscovereditems?ids=List((itemId:1,type:1,userId:1),(itemId:2,type:2,userId:2),(itemId:3,type:3,userId:3))";
checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "DELETE", version, uri, buildBatchPathKeys(getDiscoveredItemComplexKey(1, 1, 1), getDiscoveredItemComplexKey(2, 2, 2), getDiscoveredItemComplexKey(3, 3, 3)));
}
use of com.linkedin.common.callback.Callback in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncFinderOptionalBooleanParam.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinderOptionalBooleanParam")
@SuppressWarnings("unchecked")
public void testAsyncFinderOptionalBooleanParam(ProtocolVersion version, String query) throws Exception {
RestLiCallback<?> callback = getCallback();
ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("user_timeline");
AsyncStatusCollectionResource statusResource = getMockResource(AsyncStatusCollectionResource.class);
statusResource.getUserTimeline((PagingContext) EasyMock.anyObject(), eq(false), (Callback<List<Status>>) EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<List<Status>> callback = (Callback<List<Status>>) EasyMock.getCurrentArguments()[2];
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 testAsyncFinder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinder")
@SuppressWarnings("unchecked")
public void testAsyncFinder(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.REPLY), (Callback<List<Status>>) EasyMock.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);
}
Aggregations