use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchUpdateComplexKey.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchUpdateComplexKey")
public void testPromiseBatchUpdateComplexKey(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel discoveredItemsResourceModel = buildResourceModel(PromiseDiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
PromiseDiscoveredItemsResource discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyA = getDiscoveredItemComplexKey(1L, 2, 3L);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyB = getDiscoveredItemComplexKey(4L, 5, 6L);
BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> batchUpdateRequest = EasyMock.anyObject();
@SuppressWarnings("unchecked") Promise<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> batchUpdateResult = discoveredItemsResource.batchUpdate(batchUpdateRequest);
EasyMock.expect(batchUpdateResult).andReturn(Promises.value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys(keyA, keyB));
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchGet.
@Test
@SuppressWarnings("unchecked")
public void testBatchGet() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceModel followsAssociationResourceModel = buildResourceModel(FollowsAssociativeResource.class);
ResourceModel discoveredItemsResourceModel = buildResourceModel(DiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor;
StatusCollectionResource statusResource;
FollowsAssociativeResource followsResource;
DiscoveredItemsResource discoveredItemsResource;
// #1 Batch get on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_GET);
statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.batchGet((Set<Long>) Matchers.eqCollectionUnordered(Sets.newHashSet(1L, 2L, 3L)))).andReturn(null).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses?ids=List(1,2,3)", buildBatchPathKeys(1L, 2L, 3L));
// #2 Batch get on association resource
methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.BATCH_GET);
followsResource = getMockResource(FollowsAssociativeResource.class);
Set<CompoundKey> expectedKeys = new HashSet<>();
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);
EasyMock.expect(followsResource.batchGet((Set<CompoundKey>) Matchers.eqCollectionUnordered(expectedKeys))).andReturn(null).once();
String uri = "/follows?ids=List((followeeID:1,followerId:1),(followeeID:2,followerId:2))";
checkInvocation(followsResource, methodDescriptor, "GET", version, uri, buildBatchPathKeys(key1, key2));
// #3 Batch get on complex key resource.
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_GET);
discoveredItemsResource = getMockResource(DiscoveredItemsResource.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));
EasyMock.expect(discoveredItemsResource.batchGet(set)).andReturn(null).once();
uri = "/discovereditems?ids=List((itemId:1,type:2,userId:3),(itemId:4,type:5,userId:6))";
checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, uri, buildBatchPathKeys(keyA, keyB));
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchUpdateComplexKey.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchUpdateComplexKey")
public void testBatchUpdateComplexKey(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel discoveredItemsResourceModel = buildResourceModel(DiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_UPDATE);
DiscoveredItemsResource discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyA = getDiscoveredItemComplexKey(1L, 2, 3L);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyB = getDiscoveredItemComplexKey(4L, 5, 6L);
BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> batchUpdateRequest = EasyMock.anyObject();
@SuppressWarnings("unchecked") BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> batchUpdateResult = discoveredItemsResource.batchUpdate(batchUpdateRequest);
EasyMock.expect(batchUpdateResult).andReturn(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys(keyA, keyB));
}
use of com.linkedin.restli.common.ComplexResourceKey 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 = EasyMock.anyObject();
discoveredResource.batchUpdate(mockBatchUpdateReq, EasyMock.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.common.ComplexResourceKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchPatchComplexKey.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKeyWithBody")
public void testPromiseBatchPatchComplexKey(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel discoveredItemsResourceModel = buildResourceModel(PromiseDiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
PromiseDiscoveredItemsResource discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyA = getDiscoveredItemComplexKey(1L, 2, 3L);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyB = getDiscoveredItemComplexKey(4L, 5, 6L);
BatchPatchRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> batchPatchRequest = EasyMock.anyObject();
EasyMock.expect(discoveredItemsResource.batchUpdate(batchPatchRequest)).andReturn(Promises.value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, uri, body, buildBatchPathKeys(keyA, keyB));
}
Aggregations