use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncPut.
@SuppressWarnings("unchecked")
@Test
public void testAsyncPut() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(AsyncStatusCollectionResource.class, AsyncLocationResource.class, AsyncDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/asyncstatuses");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("asynclocation");
ResourceModel followsAssociationResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/asyncdiscovereditems");
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncStatusCollectionResource statusResource;
AsyncFollowsAssociativeResource followsResource;
AsyncLocationResource locationResource;
AsyncDiscoveredItemsResource discoveredItemsResource;
// #1 Update on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.UPDATE);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
long id = eq(1L);
Status status = (Status) EasyMock.anyObject();
statusResource.update(id, status, EasyMock.<Callback<UpdateResponse>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "PUT", version, "/asyncstatuses/1", "{}", buildPathKeys("statusID", 1L));
// #2 Update on association resource
methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.UPDATE);
followsResource = getMockResource(AsyncFollowsAssociativeResource.class);
CompoundKey rawKey = new CompoundKey();
rawKey.append("followerID", 1L);
rawKey.append("followeeID", 2L);
CompoundKey key = eq(rawKey);
Followed followed = (Followed) EasyMock.anyObject();
followsResource.update(key, followed, (Callback<UpdateResponse>) EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(followsResource);
checkAsyncInvocation(followsResource, callback, methodDescriptor, "PUT", version, "/asyncfollows/(followerID:1,followeeID:2)", "{}", buildPathKeys("followerID", 1L, "followeeID", 2L, followsAssociationResourceModel.getKeyName(), rawKey));
// #3 Update on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.UPDATE);
locationResource = getMockResource(AsyncLocationResource.class);
Location location = (Location) EasyMock.anyObject();
locationResource.update(location, EasyMock.<Callback<UpdateResponse>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(locationResource);
checkAsyncInvocation(locationResource, callback, methodDescriptor, "PUT", version, "/asyncstatuses/1/asynclocation", "{}", buildPathKeys("statusID", 1L));
// #4 Update on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.UPDATE);
discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> complexKey = getDiscoveredItemComplexKey(1L, 2, 3L);
discoveredItemsResource.update(eq(complexKey), (DiscoveredItem) EasyMock.anyObject(), EasyMock.<Callback<UpdateResponse>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<UpdateResponse> callback = (Callback<UpdateResponse>) EasyMock.getCurrentArguments()[2];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredItemsResource);
checkAsyncInvocation(discoveredItemsResource, callback, methodDescriptor, "PUT", version, "/asyncdiscovereditems/(itemId:1,type:2,userId:3)", "{}", buildPathKeys("asyncDiscoveredItemId", complexKey));
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchCreate.
@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchCreate() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceModel discoveredItemsResourceModel = buildResourceModel(PromiseDiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor;
PromiseStatusCollectionResource statusResource;
PromiseDiscoveredItemsResource discoveredItemsResource;
// #1 Batch create on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchCreateRequest batchCreateRequest = (BatchCreateRequest) EasyMock.anyObject();
EasyMock.expect(statusResource.batchCreate(batchCreateRequest)).andReturn(Promises.<BatchCreateResult<Long, Status>>value(null)).once();
String body = RestLiTestHelper.doubleQuote("{'elements':[{},{}]}");
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses", body, buildBatchPathKeys());
// #2 Batch create on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
batchCreateRequest = (BatchCreateRequest) EasyMock.anyObject();
EasyMock.expect(discoveredItemsResource.batchCreate(batchCreateRequest)).andReturn(Promises.<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/promisediscovereditems", body, buildBatchPathKeys());
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseGet.
@Test
public void testPromiseGet() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(PromiseStatusCollectionResource.class, PromiseLocationResource.class, PromiseDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/promisestatuses");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("promiselocation");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/promisediscovereditems");
ResourceMethodDescriptor methodDescriptor;
PromiseStatusCollectionResource statusResource;
PromiseLocationResource locationResource;
PromiseDiscoveredItemsResource discoveredItemsResource;
// #1: simple filter
methodDescriptor = statusResourceModel.findNamedMethod("public_timeline");
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.getPublicTimeline((PagingContext) EasyMock.anyObject())).andReturn(Promises.<List<Status>>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses?q=public_timeline");
// #2: get
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.get(eq(1L))).andReturn(Promises.<Status>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses/1", buildPathKeys("statusID", 1L));
// #3: get on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.GET);
locationResource = getMockResource(PromiseLocationResource.class);
EasyMock.expect(locationResource.get()).andReturn(Promises.<Location>value(null)).once();
checkInvocation(locationResource, methodDescriptor, "GET", version, "/promisestatuses/1/promiselocation", buildPathKeys("statusID", 1L));
// #4 get on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.GET);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
EasyMock.expect(discoveredItemsResource.get(eq(key))).andReturn(Promises.<DiscoveredItem>value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, "/promisediscovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("promiseDiscoveredItemId", key));
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchGet.
@SuppressWarnings("unchecked")
@Test
public void testAsyncBatchGet() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
ResourceModel followsAssociationResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
ResourceModel discoveredItemsResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncStatusCollectionResource statusResource;
AsyncFollowsAssociativeResource followsResource;
AsyncDiscoveredItemsResource discoveredItemsResource;
// #1 Batch get on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_GET);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
statusResource.batchGet((Set<Long>) Matchers.eqCollectionUnordered(Sets.newHashSet(1L, 2L, 3L)), EasyMock.<Callback<Map<Long, Status>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Map<Long, Status>> callback = (Callback<Map<Long, Status>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses?ids=List(1,2,3)", buildBatchPathKeys(1L, 2L, 3L));
// #2 Batch get on association resource
methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.BATCH_GET);
followsResource = getMockResource(AsyncFollowsAssociativeResource.class);
Set<CompoundKey> expectedKeys = new HashSet<CompoundKey>();
CompoundKey key1 = new CompoundKey();
key1.append("followeeID", 1L);
key1.append("followerID", 1L);
expectedKeys.add(key1);
CompoundKey key2 = new CompoundKey();
key2.append("followeeID", 2L);
key2.append("followerID", 2L);
expectedKeys.add(key2);
followsResource.batchGet((Set<CompoundKey>) Matchers.eqCollectionUnordered(expectedKeys), (Callback<Map<CompoundKey, Followed>>) EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Map<CompoundKey, Followed>> callback = (Callback<Map<CompoundKey, Followed>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(followsResource);
checkAsyncInvocation(followsResource, callback, methodDescriptor, "GET", version, "/asyncfollows?ids=List((followeeID:1,followerID:1),(followeeID:2,followerID:2))", buildBatchPathKeys(key1, key2));
// #3 Batch get on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_GET);
discoveredItemsResource = getMockResource(AsyncDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyA = getDiscoveredItemComplexKey(1L, 2, 3L);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyB = getDiscoveredItemComplexKey(4L, 5, 6L);
@SuppressWarnings("unchecked") Set<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>> set = (Set<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>>) Matchers.eqCollectionUnordered(Sets.newHashSet(keyA, keyB));
discoveredItemsResource.batchGet(set, EasyMock.<Callback<Map<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Map<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<Map<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredItemsResource);
checkAsyncInvocation(discoveredItemsResource, callback, methodDescriptor, "GET", version, "/asyncdiscovereditems?ids=List((userId:3,type:2,itemId:1),(itemId:4,type:5,userId:6))", buildBatchPathKeys(keyA, keyB));
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchCreateComplexKeyResource.
@Test
public void testAsyncBatchCreateComplexKeyResource() throws Exception {
ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncDiscoveredItemsResource discoveredResource;
methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
@SuppressWarnings("unchecked") BatchCreateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchCreateReq = (BatchCreateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
discoveredResource.batchCreate(mockBatchCreateReq, EasyMock.<Callback<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchCreateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredResource);
String uri = "/asyncdiscovereditems";
String entityBody = "{}";
checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "POST", version, uri, entityBody, buildBatchPathKeys());
}
Aggregations