use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionBatchGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionBatchGet")
public void testCustomCrudParamsCollectionBatchGet(ProtocolVersion version, String uri) throws Exception {
ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.BATCH_GET);
CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
EasyMock.expect(resource.myBatchGet((Set<String>) Matchers.eqCollectionUnordered(Sets.newHashSet("foo", "bar", "baz")), eq(1), eq("qux"))).andReturn(null).once();
checkInvocation(resource, methodDescriptor, "GET", version, uri, buildBatchPathKeys("foo", "bar", "baz"));
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testCustomTypeParametersCustomLong.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "customLongParam")
public void testCustomTypeParametersCustomLong(ProtocolVersion version, String uri) throws Exception {
ResourceModel repliesResourceModel = buildResourceModel(RepliesCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = repliesResourceModel.findFinderMethod("customLong");
RepliesCollectionResource repliesResource = getMockResource(RepliesCollectionResource.class);
repliesResource.customLong(new CustomLong(100L));
EasyMock.expectLastCall().andReturn(null).once();
checkInvocation(repliesResource, methodDescriptor, "GET", version, uri);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPost.
@Test
public void testPost() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, RepliesCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
ResourceModel repliesResourceModel = statusResourceModel.getSubResource("replies");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("location");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/discovereditems");
ResourceMethodDescriptor methodDescriptor;
StatusCollectionResource statusResource;
RepliesCollectionResource repliesResource;
LocationResource locationResource;
DiscoveredItemsResource discoveredItemsResource;
// #1
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.CREATE);
statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.create(EasyMock.anyObject())).andReturn(null).once();
checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses", "{}");
// #1.1: different endpoint
methodDescriptor = repliesResourceModel.findMethod(ResourceMethod.CREATE);
repliesResource = getMockResource(RepliesCollectionResource.class);
EasyMock.expect(repliesResource.create(EasyMock.anyObject())).andReturn(null).once();
checkInvocation(repliesResource, methodDescriptor, "POST", version, "/statuses/1/replies", "{}", buildPathKeys("statusID", 1L));
// #1.2: invalid entity
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.CREATE);
statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.create(EasyMock.anyObject())).andReturn(null).once();
try {
checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses", "{");
fail("Expected exception");
} catch (Exception e) {
// expected
EasyMock.reset(statusResource);
}
// #2 Collection Partial Update
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
statusResource = getMockResource(StatusCollectionResource.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(null).once();
checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses/1", "{\"patch\":{\"$set\":{\"foo\":42}}}", buildPathKeys("statusID", 1L));
// #3 Simple Resource Partial Update
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
locationResource = getMockResource(LocationResource.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(null).once();
checkInvocation(locationResource, methodDescriptor, "POST", version, "/statuses/1/location", "{\"patch\":{\"$set\":{\"foo\":51}}}", buildPathKeys("statusID", 1L));
// #4 Complex-key resource create
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.CREATE);
discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
EasyMock.expect(discoveredItemsResource.create(EasyMock.anyObject())).andReturn(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/discovereditems", "{}");
// #5 Partial update on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE);
discoveredItemsResource = getMockResource(DiscoveredItemsResource.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(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, "/discovereditems/(itemId:1,type:2,userId:3)", "{\"patch\":{\"$set\":{\"foo\":43}}}", buildPathKeys("discoveredItemId", key));
// TODO would be nice to verify that posting an invalid record type fails
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromisePagingContextStartOnly.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusPagingContextStartOnly")
public void testPromisePagingContextStartOnly(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findFinderMethod("public_timeline");
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.getPublicTimeline(eq(buildPagingContext(5, null)))).andReturn(Promises.value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses" + query);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testFinderOptionalBooleanParam.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinderOptionalBooleanParam")
public void testFinderOptionalBooleanParam(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findFinderMethod("user_timeline");
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.getUserTimeline(eq(false), EasyMock.anyObject())).andReturn(null).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses" + query);
}
Aggregations