Search in sources :

Example 26 with StatusCollectionResource

use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testDelete.

@Test
public void testDelete() throws Exception {
    Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
    ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
    ResourceModel locationResourceModel = statusResourceModel.getSubResource("location");
    ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/discovereditems");
    ResourceMethodDescriptor methodDescriptor;
    StatusCollectionResource statusResource;
    LocationResource locationResource;
    DiscoveredItemsResource discoveredItemsResource;
    // #1 Delete on collection resource
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.DELETE);
    statusResource = getMockResource(StatusCollectionResource.class);
    EasyMock.expect(statusResource.delete(eq(1L))).andReturn(null).once();
    checkInvocation(statusResource, methodDescriptor, "DELETE", version, "/statuses/1", buildPathKeys("statusID", 1L));
    // #2 Delete on simple resource
    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.DELETE);
    locationResource = getMockResource(LocationResource.class);
    EasyMock.expect(locationResource.delete()).andReturn(null).once();
    checkInvocation(locationResource, methodDescriptor, "DELETE", version, "/statuses/1/location", buildPathKeys("statusID", 1L));
    // #3 Delete on complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.DELETE);
    discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
    ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
    EasyMock.expect(discoveredItemsResource.delete(eq(key))).andReturn(null).once();
    checkInvocation(discoveredItemsResource, methodDescriptor, "DELETE", version, "/discovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("discoveredItemId", key));
}
Also used : DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) DiscoveredItemsResource(com.linkedin.restli.server.twitter.DiscoveredItemsResource) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) LocationResource(com.linkedin.restli.server.twitter.LocationResource) PromiseLocationResource(com.linkedin.restli.server.twitter.PromiseLocationResource) AsyncLocationResource(com.linkedin.restli.server.twitter.AsyncLocationResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 27 with StatusCollectionResource

use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testGet.

@Test
public void testGet() throws Exception {
    Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
    ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
    ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/discovereditems");
    ResourceMethodDescriptor methodDescriptor;
    StatusCollectionResource statusResource;
    DiscoveredItemsResource discoveredItemsResource;
    // #1: simple filter
    methodDescriptor = statusResourceModel.findNamedMethod("public_timeline");
    statusResource = getMockResource(StatusCollectionResource.class);
    EasyMock.expect(statusResource.getPublicTimeline((PagingContext) EasyMock.anyObject())).andReturn(null).once();
    checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses?q=public_timeline");
    // #2: get
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
    statusResource = getMockResource(StatusCollectionResource.class);
    EasyMock.expect(statusResource.get(eq(1L))).andReturn(null).once();
    checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses/1", buildPathKeys("statusID", 1L));
    // #3: get simple sub-resource
    ResourceModel locationResourceModel = statusResourceModel.getSubResource("location");
    LocationResource locationResource;
    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.GET);
    locationResource = getMockResource(LocationResource.class);
    EasyMock.expect(locationResource.get()).andReturn(null).once();
    checkInvocation(locationResource, methodDescriptor, "GET", version, "/statuses/1/location", buildPathKeys("statusID", 1L));
    // #4: get complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.GET);
    discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
    ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
    EasyMock.expect(discoveredItemsResource.get(eq(key))).andReturn(null).once();
    checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, "/discovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("discoveredItemId", key));
}
Also used : DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) PagingContext(com.linkedin.restli.server.PagingContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) DiscoveredItemsResource(com.linkedin.restli.server.twitter.DiscoveredItemsResource) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) LocationResource(com.linkedin.restli.server.twitter.LocationResource) PromiseLocationResource(com.linkedin.restli.server.twitter.PromiseLocationResource) AsyncLocationResource(com.linkedin.restli.server.twitter.AsyncLocationResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 28 with StatusCollectionResource

use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testFinder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinder")
public void testFinder(ProtocolVersion version, String query) throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("search");
    StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
    EasyMock.expect(statusResource.search(eq("linkedin"), eq(1L), eq(StatusType.REPLY))).andReturn(null).once();
    checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses" + query);
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 29 with StatusCollectionResource

use of com.linkedin.restli.server.twitter.StatusCollectionResource 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>();
    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));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) FollowsAssociativeResource(com.linkedin.restli.server.twitter.FollowsAssociativeResource) AsyncFollowsAssociativeResource(com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) DiscoveredItemsResource(com.linkedin.restli.server.twitter.DiscoveredItemsResource) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 30 with StatusCollectionResource

use of com.linkedin.restli.server.twitter.StatusCollectionResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testPut.

@Test
public void testPut() throws Exception {
    Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
    ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
    ResourceModel followsAssociationResourceModel = buildResourceModel(FollowsAssociativeResource.class);
    ResourceModel locationResourceModel = statusResourceModel.getSubResource("location");
    ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/discovereditems");
    ResourceMethodDescriptor methodDescriptor;
    StatusCollectionResource statusResource;
    FollowsAssociativeResource followsResource;
    LocationResource locationResource;
    DiscoveredItemsResource discoveredItemsResource;
    // #1 Update on collection resource
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.UPDATE);
    statusResource = getMockResource(StatusCollectionResource.class);
    long id = eq(1L);
    Status status = (Status) EasyMock.anyObject();
    EasyMock.expect(statusResource.update(id, status)).andReturn(null).once();
    checkInvocation(statusResource, methodDescriptor, "PUT", version, "/statuses/1", "{}", buildPathKeys("statusID", 1L));
    // #2 Update on association resource
    methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.UPDATE);
    followsResource = getMockResource(FollowsAssociativeResource.class);
    CompoundKey rawKey = new CompoundKey();
    rawKey.append("followerID", 1L);
    rawKey.append("followeeID", 2L);
    CompoundKey key = eq(rawKey);
    Followed followed = (Followed) EasyMock.anyObject();
    EasyMock.expect(followsResource.update(key, followed)).andReturn(null).once();
    checkInvocation(followsResource, methodDescriptor, "PUT", version, "/follows/(followerID:1,followeeID:2)", "{}", buildPathKeys("followerID", 1L, "followeeID", 2L, followsAssociationResourceModel.getKeyName(), rawKey));
    // #3 Update on simple resource
    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.UPDATE);
    locationResource = getMockResource(LocationResource.class);
    Location location = (Location) EasyMock.anyObject();
    EasyMock.expect(locationResource.update(location)).andReturn(null).once();
    checkInvocation(locationResource, methodDescriptor, "PUT", version, "/statuses/1/location", "{}", buildPathKeys("statusID", 1L));
    // #4 Update on complex-key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.UPDATE);
    discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
    ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> complexKey = getDiscoveredItemComplexKey(1L, 2, 3L);
    EasyMock.expect(discoveredItemsResource.update(eq(complexKey), (DiscoveredItem) EasyMock.anyObject())).andReturn(null).once();
    checkInvocation(discoveredItemsResource, methodDescriptor, "PUT", version, "/discovereditems/(itemId:1,type:2,userId:3)", "{}", buildPathKeys("discoveredItemId", complexKey));
// TODO would be nice to verify that posting an invalid record type fails
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) FollowsAssociativeResource(com.linkedin.restli.server.twitter.FollowsAssociativeResource) AsyncFollowsAssociativeResource(com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Followed(com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) LocationResource(com.linkedin.restli.server.twitter.LocationResource) PromiseLocationResource(com.linkedin.restli.server.twitter.PromiseLocationResource) AsyncLocationResource(com.linkedin.restli.server.twitter.AsyncLocationResource) DiscoveredItemKeyParams(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams) DiscoveredItem(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItem) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) AsyncDiscoveredItemsResource(com.linkedin.restli.server.twitter.AsyncDiscoveredItemsResource) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) DiscoveredItemsResource(com.linkedin.restli.server.twitter.DiscoveredItemsResource) DiscoveredItemKey(com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey) Location(com.linkedin.restli.server.twitter.TwitterTestDataModels.Location) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)34 StatusCollectionResource (com.linkedin.restli.server.twitter.StatusCollectionResource)34 AfterTest (org.testng.annotations.AfterTest)33 BeforeTest (org.testng.annotations.BeforeTest)33 Test (org.testng.annotations.Test)33 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)25 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)25 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)25 CustomStatusCollectionResource (com.linkedin.restli.server.twitter.CustomStatusCollectionResource)25 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)25 TaskStatusCollectionResource (com.linkedin.restli.server.twitter.TaskStatusCollectionResource)25 ByteString (com.linkedin.data.ByteString)13 CustomString (com.linkedin.restli.server.custom.types.CustomString)12 Callback (com.linkedin.common.callback.Callback)11 RequestContext (com.linkedin.r2.message.RequestContext)11 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)11 RestResponse (com.linkedin.r2.message.rest.RestResponse)11 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)11 RestException (com.linkedin.r2.message.rest.RestException)10 RestRequest (com.linkedin.r2.message.rest.RestRequest)10