Search in sources :

Example 1 with PromiseFollowsAssociativeResource

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

the class TestRestLiMethodInvocation method testPromiseGetAssociativeResource.

@Test
public void testPromiseGetAssociativeResource() throws Exception {
    ResourceModel followsResourceModel = buildResourceModel(PromiseFollowsAssociativeResource.class);
    ResourceMethodDescriptor methodDescriptor;
    PromiseFollowsAssociativeResource resource;
    // #1: get
    methodDescriptor = followsResourceModel.findMethod(ResourceMethod.GET);
    resource = getMockResource(PromiseFollowsAssociativeResource.class);
    CompoundKey rawKey = new CompoundKey();
    rawKey.append("followerID", 1L);
    rawKey.append("followeeID", 2L);
    CompoundKey key = eq(rawKey);
    EasyMock.expect(resource.get(key)).andReturn(Promises.value(new Followed(new DataMap()))).once();
    checkInvocation(resource, methodDescriptor, "GET", version, "/promisefollows/(followerID:1,followeeID:2)", buildPathKeys("followerID", 1L, "followeeID", 2L, followsResourceModel.getKeyName(), rawKey));
}
Also used : PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Followed(com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with PromiseFollowsAssociativeResource

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

the class TestRestLiMethodInvocation method testPromisePut.

@Test
public void testPromisePut() throws Exception {
    Map<String, ResourceModel> resourceModelMap = buildResourceModels(PromiseStatusCollectionResource.class, PromiseLocationResource.class, PromiseDiscoveredItemsResource.class);
    ResourceModel statusResourceModel = resourceModelMap.get("/promisestatuses");
    ResourceModel locationResourceModel = statusResourceModel.getSubResource("promiselocation");
    ResourceModel followsAssociationResourceModel = buildResourceModel(PromiseFollowsAssociativeResource.class);
    ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/promisediscovereditems");
    ResourceMethodDescriptor methodDescriptor;
    PromiseStatusCollectionResource statusResource;
    PromiseFollowsAssociativeResource followsResource;
    PromiseLocationResource locationResource;
    PromiseDiscoveredItemsResource discoveredItemsResource;
    // #1 Update on collection resource
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.UPDATE);
    statusResource = getMockResource(PromiseStatusCollectionResource.class);
    long id = eq(1L);
    Status status = (Status) EasyMock.anyObject();
    EasyMock.expect(statusResource.update(id, status)).andReturn(Promises.<UpdateResponse>value(null)).once();
    checkInvocation(statusResource, methodDescriptor, "PUT", version, "/promisestatuses/1", "{}", buildPathKeys("statusID", 1L));
    // #2 Update on association resource
    methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.UPDATE);
    followsResource = getMockResource(PromiseFollowsAssociativeResource.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(Promises.<UpdateResponse>value(null)).once();
    checkInvocation(followsResource, methodDescriptor, "PUT", version, "/promisefollows/(followerID:1,followeeID:2)", "{}", buildPathKeys("followerID", 1L, "followeeID", 2L, followsAssociationResourceModel.getKeyName(), rawKey));
    // #3 Update on simple resource
    methodDescriptor = locationResourceModel.findMethod(ResourceMethod.UPDATE);
    locationResource = getMockResource(PromiseLocationResource.class);
    Location location = (Location) EasyMock.anyObject();
    EasyMock.expect(locationResource.update(location)).andReturn(Promises.<UpdateResponse>value(null)).once();
    checkInvocation(locationResource, methodDescriptor, "PUT", version, "/promisestatuses/1/promiselocation", "{}", buildPathKeys("statusID", 1L));
    // #4 Update on complex key resource
    methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.UPDATE);
    discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.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, "/promisediscovereditems/(itemId:1,type:2,userId:3)", "{}", buildPathKeys("promiseDiscoveredItemId", 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) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) 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) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) UpdateResponse(com.linkedin.restli.server.UpdateResponse) 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) PromiseLocationResource(com.linkedin.restli.server.twitter.PromiseLocationResource) 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)

Example 3 with PromiseFollowsAssociativeResource

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

the class TestRestLiMethodInvocation method testPromiseBatchGet.

@Test
public void testPromiseBatchGet() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
    ResourceModel followsAssociationResourceModel = buildResourceModel(PromiseFollowsAssociativeResource.class);
    ResourceModel discoveredItemsResourceModel = buildResourceModel(PromiseDiscoveredItemsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    PromiseStatusCollectionResource statusResource;
    PromiseFollowsAssociativeResource followsResource;
    PromiseDiscoveredItemsResource discoveredItemsResource;
    // #1 Batch get on collection resource
    methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_GET);
    statusResource = getMockResource(PromiseStatusCollectionResource.class);
    EasyMock.expect(statusResource.batchGet((Set<Long>) Matchers.eqCollectionUnordered(Sets.newHashSet(1L, 2L, 3L)))).andReturn(Promises.<Map<Long, Status>>value(null)).once();
    checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses?ids=List(1,2,3)", buildBatchPathKeys(1L, 2L, 3L));
    // #2 Batch get on association resource
    methodDescriptor = followsAssociationResourceModel.findMethod(ResourceMethod.BATCH_GET);
    followsResource = getMockResource(PromiseFollowsAssociativeResource.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(Promises.<Map<CompoundKey, Followed>>value(null)).once();
    checkInvocation(followsResource, methodDescriptor, "GET", version, "/promisefollows?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(PromiseDiscoveredItemsResource.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(Promises.<Map<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>value(null)).once();
    checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, "/promisediscovereditems?ids=List((itemId:1,type:2,userId:3),(itemId:4,type:5,userId:6))", buildBatchPathKeys(keyA, keyB));
}
Also used : PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) Set(java.util.Set) HashSet(java.util.HashSet) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) PromiseDiscoveredItemsResource(com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource) 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) Map(java.util.Map) DataMap(com.linkedin.data.DataMap) StringMap(com.linkedin.data.template.StringMap) 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)

Aggregations

CompoundKey (com.linkedin.restli.common.CompoundKey)3 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)3 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)3 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)3 PromiseFollowsAssociativeResource (com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource)3 AfterTest (org.testng.annotations.AfterTest)3 BeforeTest (org.testng.annotations.BeforeTest)3 Test (org.testng.annotations.Test)3 DataMap (com.linkedin.data.DataMap)2 PromiseDiscoveredItemsResource (com.linkedin.restli.server.twitter.PromiseDiscoveredItemsResource)2 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)2 DiscoveredItemKey (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKey)2 DiscoveredItemKeyParams (com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams)2 Followed (com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed)2 ByteString (com.linkedin.data.ByteString)1 StringMap (com.linkedin.data.template.StringMap)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1 HttpStatus (com.linkedin.restli.common.HttpStatus)1 UpdateResponse (com.linkedin.restli.server.UpdateResponse)1 CustomString (com.linkedin.restli.server.custom.types.CustomString)1