use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor 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.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionCreate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionCreate")
public void testCustomCrudParamsCollectionCreate(ProtocolVersion version, String uri) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.CREATE);
CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
EasyMock.expect(resource.myCreate((CombinedTestDataModels.Foo) EasyMock.anyObject(), eq(1), eq("bar"))).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "POST", version, uri, "{}");
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor 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());
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionUpdate")
public void testCustomCrudParamsCollectionUpdate(ProtocolVersion version, String uri) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.UPDATE);
CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
EasyMock.expect(resource.myUpdate(eq("foo"), (CombinedTestDataModels.Foo) EasyMock.anyObject(), eq(1), eq("bar"))).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "PUT", version, uri, "{}", buildPathKeys("testId", "foo"));
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestUpdateResponseBuilder method testBuilderException.
@Test
public void testBuilderException() {
UpdateResponse updateResponse = new UpdateResponse(null);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
UpdateResponseBuilder updateResponseBuilder = new UpdateResponseBuilder();
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
try {
updateResponseBuilder.buildRestLiResponseData(null, routingResult, updateResponse, headers, Collections.<HttpCookie>emptyList());
Assert.fail("buildRestLiResponseData should have failed because of a null HTTP status!");
} catch (RestLiServiceException e) {
Assert.assertTrue(e.getMessage().contains("Unexpected null encountered. HttpStatus is null inside of a UpdateResponse returned by the resource method: "));
}
}
Aggregations