use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchPatch.
@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchPatch() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchPatchRequest batchPatchRequest = EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchPatchRequest)).andReturn(Promises.value(null)).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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"), EasyMock.anyObject(CombinedTestDataModels.Foo.class), eq(1), eq("bar"))).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "PUT", version, uri, "{}", buildPathKeys("testId", "foo"));
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchCreate.
@Test
@SuppressWarnings({ "unchecked" })
public void testBatchCreate() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceModel discoveredItemsResourceModel = buildResourceModel(DiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor;
StatusCollectionResource statusResource;
DiscoveredItemsResource discoveredItemsResource;
// #1 Batch create on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
statusResource = getMockResource(StatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchCreateRequest batchCreateRequest = EasyMock.anyObject();
EasyMock.expect(statusResource.batchCreate(batchCreateRequest)).andReturn(null).once();
String body = RestLiTestHelper.doubleQuote("{'elements':[{},{}]}");
checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses", body, buildBatchPathKeys());
// #2 Batch create on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_CREATE);
discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
batchCreateRequest = EasyMock.anyObject();
EasyMock.expect(discoveredItemsResource.batchCreate(batchCreateRequest)).andReturn(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/discovereditems", body, buildBatchPathKeys());
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromisePagingContextNegativeCount.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusPagingContextNegativeCount")
public void testPromisePagingContextNegativeCount(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findFinderMethod("public_timeline");
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
expectRoutingException(methodDescriptor, statusResource, "GET", "/promisestatuses" + query, version);
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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(EasyMock.anyObject())).andReturn(Promises.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(EasyMock.anyObject())).andReturn(Promises.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(EasyMock.anyObject())).andReturn(Promises.value(null)).once();
try {
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses", "{");
fail("Expected exception");
} catch (Exception 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(42));
PatchRequest<Status> expected = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(statusResource.update(eq(1L), eq(expected))).andReturn(Promises.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(51));
PatchRequest<Location> expectedLocation = PatchRequest.createFromPatchDocument(p.getDataMap());
EasyMock.expect(locationResource.update(eq(expectedLocation))).andReturn(Promises.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(EasyMock.anyObject())).andReturn(Promises.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(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.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
}
Aggregations