use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromisePost.
@Test
public void testPromisePost() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(PromiseStatusCollectionResource.class, PromiseRepliesCollectionResource.class, PromiseLocationResource.class, PromiseDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/promisestatuses");
ResourceModel repliesResourceModel = statusResourceModel.getSubResource("promisereplies");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("promiselocation");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/promisediscovereditems");
ResourceMethodDescriptor methodDescriptor;
PromiseStatusCollectionResource statusResource;
PromiseRepliesCollectionResource repliesResource;
PromiseLocationResource locationResource;
PromiseDiscoveredItemsResource discoveredItemsResource;
// #1
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.CREATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.create((Status) EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses", "{}");
// #1.1: different endpoint
methodDescriptor = repliesResourceModel.findMethod(ResourceMethod.CREATE);
repliesResource = getMockResource(PromiseRepliesCollectionResource.class);
EasyMock.expect(repliesResource.create((Status) EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
checkInvocation(repliesResource, methodDescriptor, "POST", version, "/promisestatuses/1/replies", "{}", buildPathKeys("statusID", 1L));
// #1.2: invalid entity
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.CREATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.create((Status) EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
try {
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses", "{");
fail("Expected exception");
} catch (RoutingException e) {
// expected
EasyMock.reset(statusResource);
}
// #2: Collection Partial Update
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
PatchTree p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(42)));
PatchRequest<Status> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(statusResource.update(eq(1L), eq(expected))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses/1", "{\"patch\":{\"$set\":{\"foo\":42}}}", buildPathKeys("statusID", 1L));
// #3: Simple Resource Partial Update
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
locationResource = getMockResource(PromiseLocationResource.class);
p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(51)));
PatchRequest<Location> expectedLocation = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(locationResource.update(eq(expectedLocation))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(locationResource, methodDescriptor, "POST", version, "/promisestatuses/1/promiselocation", "{\"patch\":{\"$set\":{\"foo\":51}}}", buildPathKeys("statusID", 1L));
// #4 Complex key resource create
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.CREATE);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
EasyMock.expect(discoveredItemsResource.create((DiscoveredItem) EasyMock.anyObject())).andReturn(Promises.<CreateResponse>value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/promisediscovereditems", "{}");
// #5 Complex key resource partial update
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
p = new PatchTree();
p.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(Integer.valueOf(43)));
PatchRequest<DiscoveredItem> expectedDiscoveredItem = PatchRequest.createFromPatchDocument(p.getDataMap());
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
EasyMock.expect(discoveredItemsResource.update(eq(key), eq(expectedDiscoveredItem))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/promisediscovereditems/(itemId:1,type:2,userId:3)", "{\"patch\":{\"$set\":{\"foo\":43}}}", buildPathKeys("promiseDiscoveredItemId", key));
// TODO would be nice to verify that posting an invalid record type fails
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams 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));
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams 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));
}
use of com.linkedin.restli.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams 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 = (BatchUpdateRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
discoveredResource.batchUpdate(mockBatchUpdateReq, EasyMock.<Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>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.server.twitter.TwitterTestDataModels.DiscoveredItemKeyParams 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
}
Aggregations