use of com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncFinderOnComplexKey.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "discoveredItemsFinder")
public void testAsyncFinderOnComplexKey(ProtocolVersion version, String query) throws Exception {
RestLiCallback<?> callback = getCallback();
ResourceModel discoveredItemsResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor = discoveredItemsResourceModel.findNamedMethod("user");
AsyncDiscoveredItemsResource discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
discoveredItemsResource.getDiscoveredItemsForUser((PagingContext) EasyMock.anyObject(), eq(1L), EasyMock.<Callback<List<DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<List<DiscoveredItem>> callback = (Callback<List<DiscoveredItem>>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredItemsResource);
checkAsyncInvocation(discoveredItemsResource, callback, methodDescriptor, "GET", version, "/asyncdiscovereditems" + query, null);
}
use of com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncGetAllComplexKeyResource.
@Test
public void testAsyncGetAllComplexKeyResource() throws Exception {
ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncDiscoveredItemsResource discoveredResource;
methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.GET_ALL);
discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
@SuppressWarnings("unchecked") PagingContext mockCtx = (PagingContext) EasyMock.anyObject();
discoveredResource.getAll(mockCtx, EasyMock.<Callback<List<DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<List<DiscoveredItem>> callback = (Callback<List<DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredResource);
checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "GET", version, "/asyncdiscovereditems", buildBatchPathKeys());
}
use of com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource 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.restli.server.twitter.AsyncDiscoveredItemsResource 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.restli.server.twitter.AsyncDiscoveredItemsResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncGet.
@SuppressWarnings("unchecked")
@Test
public void testAsyncGet() throws Exception {
AsyncStatusCollectionResource statusResource;
AsyncLocationResource locationResource;
AsyncDiscoveredItemsResource discoveredItemsResource;
Map<String, ResourceModel> resourceModelMap = buildResourceModels(AsyncStatusCollectionResource.class, AsyncLocationResource.class, AsyncDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/asyncstatuses");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("asynclocation");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/asyncdiscovereditems");
ResourceMethodDescriptor methodDescriptor;
RestLiCallback<?> callback = getCallback();
methodDescriptor = statusResourceModel.findNamedMethod("public_timeline");
statusResource = getMockResource(AsyncStatusCollectionResource.class);
statusResource.getPublicTimeline((PagingContext) EasyMock.anyObject(), EasyMock.<Callback<List<Status>>>anyObject());
// the goal of below lines is that to make sure that we are getting callback in the resource
//an callback is called without any problem
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
Callback<List<Status>> callback = (Callback<List<Status>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses?q=public_timeline", null);
// #3: get
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
statusResource.get(eq(1L), EasyMock.<Callback<Status>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Status> callback = (Callback<Status>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses/1", buildPathKeys("statusID", 1L));
// #4: get on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.GET);
locationResource = getMockResource(AsyncLocationResource.class);
locationResource.get(EasyMock.<Callback<Location>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Location> callback = (Callback<Location>) EasyMock.getCurrentArguments()[0];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(locationResource);
checkAsyncInvocation(locationResource, callback, methodDescriptor, "GET", version, "/asyncstatuses/1/asynclocation", buildPathKeys("statusID", 1L));
// #5: get on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.GET);
discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
discoveredItemsResource.get(eq(key), EasyMock.<Callback<DiscoveredItem>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<List<DiscoveredItem>> callback = (Callback<List<DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredItemsResource);
checkAsyncInvocation(discoveredItemsResource, callback, methodDescriptor, "GET", version, "/asyncdiscovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("asyncDiscoveredItemId", key));
}
Aggregations