use of com.linkedin.restli.server.PagingContext in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseGet.
@Test
public void testPromiseGet() throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(PromiseStatusCollectionResource.class, PromiseLocationResource.class, PromiseDiscoveredItemsResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/promisestatuses");
ResourceModel locationResourceModel = statusResourceModel.getSubResource("promiselocation");
ResourceModel discoveredItemsResourceModel = resourceModelMap.get("/promisediscovereditems");
ResourceMethodDescriptor methodDescriptor;
PromiseStatusCollectionResource statusResource;
PromiseLocationResource locationResource;
PromiseDiscoveredItemsResource discoveredItemsResource;
// #1: simple filter
methodDescriptor = statusResourceModel.findNamedMethod("public_timeline");
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.getPublicTimeline((PagingContext) EasyMock.anyObject())).andReturn(Promises.<List<Status>>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses?q=public_timeline");
// #2: get
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.get(eq(1L))).andReturn(Promises.<Status>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses/1", buildPathKeys("statusID", 1L));
// #3: get on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.GET);
locationResource = getMockResource(PromiseLocationResource.class);
EasyMock.expect(locationResource.get()).andReturn(Promises.<Location>value(null)).once();
checkInvocation(locationResource, methodDescriptor, "GET", version, "/promisestatuses/1/promiselocation", buildPathKeys("statusID", 1L));
// #4 get on complex-key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.GET);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
EasyMock.expect(discoveredItemsResource.get(eq(key))).andReturn(Promises.<DiscoveredItem>value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, "/promisediscovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("promiseDiscoveredItemId", key));
}
use of com.linkedin.restli.server.PagingContext in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPagingContextUserTimelineDefault.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusUserTimelineDefault")
public void testPagingContextUserTimelineDefault(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("user_timeline");
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.getUserTimeline(eq(true), eq(new PagingContext(10, 100, false, false)))).andReturn(null).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses" + query);
}
use of com.linkedin.restli.server.PagingContext in project rest.li by linkedin.
the class TestPhotoResource method testResourceFind.
@Test
public void testResourceFind() {
_res.purge();
createPhoto("InEdible");
createPhoto("InEdible");
createPhoto("InEdible", PhotoFormats.BMP);
final PagingContext pc = new PagingContext(0, 4);
final PagingContext pc2 = new PagingContext(0, 2);
final List<Photo> foundByTitle = _res.find(pc, "InEdible", null);
Assert.assertEquals(foundByTitle.size(), 3);
final List<Photo> foundByFormat = _res.find(pc, null, PhotoFormats.BMP);
Assert.assertEquals(foundByFormat.size(), 1);
final List<Photo> foundByTitleAndFormat = _res.find(pc, "InEdible", PhotoFormats.PNG);
Assert.assertEquals(foundByTitleAndFormat.size(), 2);
final List<Photo> foundTwo = _res.find(pc2, null, null);
Assert.assertEquals(foundTwo.size(), 2);
// testResourcePurge() assumes there is at least one photo
createPhoto();
}
use of com.linkedin.restli.server.PagingContext in project rest.li by linkedin.
the class TestArgumentBuilder method testPagingContextParamType.
@Test
@SuppressWarnings("deprecation")
public void testPagingContextParamType() {
String testParamKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
PagingContext pagingContext = new PagingContext(RestConstants.DEFAULT_START, RestConstants.DEFAULT_COUNT, false, false);
EasyMock.expect(mockResourceContext.getParameter(RestConstants.START_PARAM)).andReturn(null).anyTimes();
EasyMock.expect(mockResourceContext.getParameter(RestConstants.COUNT_PARAM)).andReturn(null).anyTimes();
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
List<Parameter<?>> parameters = new ArrayList<Parameter<?>>();
Parameter<PagingContext> param1 = new Parameter<PagingContext>(testParamKey, PagingContext.class, null, false, null, Parameter.ParamType.PAGING_CONTEXT_PARAM, false, AnnotationSet.EMPTY);
Parameter<PagingContext> param2 = new Parameter<PagingContext>(testParamKey, PagingContext.class, null, false, null, Parameter.ParamType.CONTEXT, false, AnnotationSet.EMPTY);
parameters.add(param1);
parameters.add(param2);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], pagingContext);
Assert.assertEquals(results[1], pagingContext);
}
use of com.linkedin.restli.server.PagingContext in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method argumentData.
@DataProvider(name = "argumentData")
private Object[][] argumentData() {
List<Parameter<?>> getAllParams = new ArrayList<Parameter<?>>();
getAllParams.add(getPagingContextParam());
Map<String, String> getAllContextParams = new HashMap<String, String>();
getAllContextParams.put("start", "33");
getAllContextParams.put("count", "444");
Map<String, String> finderContextParams = new HashMap<String, String>();
finderContextParams.put("start", "33");
finderContextParams.put("count", "444");
finderContextParams.put("required", "777");
finderContextParams.put("optional", null);
Map<String, String> finderContextParamsWithOptionalString = new HashMap<String, String>(finderContextParams);
finderContextParamsWithOptionalString.put("optional", "someString");
List<Parameter<?>> finderWithAssocKeyParams = new ArrayList<Parameter<?>>();
finderWithAssocKeyParams.add(new Parameter<String>("string1", String.class, new StringDataSchema(), false, null, Parameter.ParamType.ASSOC_KEY_PARAM, true, new AnnotationSet(new Annotation[] {})));
return new Object[][] { { getAllParams, getAllContextParams, null, new Object[] { new PagingContext(33, 444) } }, { getFinderParams(), finderContextParams, null, new Object[] { new PagingContext(33, 444), new Integer(777), null } }, { getFinderParams(), finderContextParamsWithOptionalString, null, new Object[] { new PagingContext(33, 444), new Integer(777), "someString" } }, { finderWithAssocKeyParams, null, new PathKeysImpl().append("string1", "testString"), new Object[] { "testString" } } };
}
Aggregations