use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionBatchUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionBatchUpdate")
public void testCustomCrudParamsCollectionBatchUpdate(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.BATCH_UPDATE);
CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
@SuppressWarnings("rawtypes") BatchUpdateRequest batchUpdateRequest = EasyMock.anyObject();
@SuppressWarnings("unchecked") BatchUpdateResult<String, CombinedTestDataModels.Foo> batchUpdateResult = resource.myBatchUpdate(batchUpdateRequest, eq(1), eq("baz"));
EasyMock.expect(batchUpdateResult).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys("foo", "bar"));
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomTypeParametersCustomLongArrayWithDefault.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "customLongArrayDefault")
public void testCustomTypeParametersCustomLongArrayWithDefault(ProtocolVersion version, String uri) throws Exception {
ResourceModel repliesResourceModel = buildResourceModel(RepliesCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = repliesResourceModel.findFinderMethod("customLongArrayDefault");
RepliesCollectionResource repliesResource = getMockResource(RepliesCollectionResource.class);
CustomLong[] longs = { new CustomLong(100L), new CustomLong(200L) };
CustomLong[] longsFromDefault = { new CustomLong(1235L), new CustomLong(6789L) };
repliesResource.customLongArrayDefault(EasyMock.aryEq(longs), EasyMock.aryEq(longsFromDefault));
EasyMock.expectLastCall().andReturn(null).once();
checkInvocation(repliesResource, methodDescriptor, "GET", version, uri);
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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.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 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.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.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsSimpleUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramSimple")
public void testCustomCrudParamsSimpleUpdate(ProtocolVersion version, String uri) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.SimpleResourceWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.UPDATE);
CombinedResources.SimpleResourceWithCustomCrudParams resource = getMockResource(CombinedResources.SimpleResourceWithCustomCrudParams.class);
EasyMock.expect(resource.myUpdate(EasyMock.anyObject(), eq(1), eq("bar"))).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "PUT", version, uri, "{}", buildBatchPathKeys());
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAltKeyGet.
// keys are already parsed by this point, so in path keys alternative keys are in canonical format.
// tests for ensuring keys are parsed into pathKeys correctly can be found in TestRestliRouting.
// this test is primarily for ensuring that alternate keys to not cause parameter parsing to fail.
@Test
public void testAltKeyGet() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor getMethodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.get(eq(1L))).andReturn(null).once();
checkInvocation(statusResource, getMethodDescriptor, "GET", version, "/statuses/Alt1?altkey=alt", buildPathKeys("statusID", 1L));
ResourceMethodDescriptor batchGetMethodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_GET);
statusResource = getMockResource(StatusCollectionResource.class);
Set<Long> batchKeys = new HashSet<>(3);
batchKeys.add(1L);
batchKeys.add(2L);
batchKeys.add(3L);
EasyMock.expect(statusResource.batchGet(eq(batchKeys))).andReturn(null).once();
checkInvocation(statusResource, batchGetMethodDescriptor, "GET", version, "/statuses?ids=List(Alt1,Alt2,Alt3)&altkey=alt", buildBatchPathKeys(1L, 2L, 3L));
}
Aggregations