use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchPatchCollection.
@Test
@SuppressWarnings({ "unchecked" })
public void testBatchPatchCollection() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchPatchRequest batchPatchRequest = EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchPatchRequest)).andReturn(null).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "POST", version, "/statuses?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 testTimeoutParseqTraceTask.
@Test(dataProvider = "taskMethodConfigProviders")
public void testTimeoutParseqTraceTask(RestLiMethodConfig restliMethodConfig, String timeoutTaskName) throws Exception {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(TaskStatusCollectionResource.class);
ResourceModel taskStatusResourceModel = resourceModelMap.get("/taskstatuses");
// #4: Task based Async Method Execution
RequestContext taskRequestContext = new RequestContext();
ResourceMethodDescriptor methodDescriptor = taskStatusResourceModel.findMethod(ResourceMethod.GET);
TaskStatusCollectionResource taskStatusResource = getMockResource(TaskStatusCollectionResource.class);
EasyMock.expect(taskStatusResource.get(eq(1L))).andReturn(Task.callable("myTask", new Callable<Status>() {
@Override
public Status call() throws Exception {
return new Status();
}
})).once();
// configure method-level timeout
ResourceMethodConfigProvider methodConfigProvider = ResourceMethodConfigProvider.build(restliMethodConfig);
ResourceMethodConfig methodConfig = methodConfigProvider.apply(methodDescriptor);
checkInvocation(taskStatusResource, taskRequestContext, methodDescriptor, methodConfig, "GET", version, "/taskstatuses/1", null, buildPathKeys("statusID", 1L), new Callback<RestResponse>() {
@Override
public void onError(Throwable e) {
Assert.fail("Request failed unexpectedly.");
}
@Override
public void onSuccess(RestResponse result) {
Trace parseqTrace = (Trace) taskRequestContext.getLocalAttr(ATTRIBUTE_PARSEQ_TRACE);
Assert.assertNotNull(parseqTrace);
if (timeoutTaskName != null) {
Assert.assertTrue(hasTask(timeoutTaskName, parseqTrace));
}
}
}, true, false, null, null);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromisePagingContextNegativeStart.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusPagingContextNegativeStart")
public void testPromisePagingContextNegativeStart(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 testFinderOptionalParam.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinderOptionalParam")
public void testFinderOptionalParam(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findFinderMethod("search");
StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
EasyMock.expect(statusResource.search(eq("linkedin"), eq(-1L), eq((StatusType) null))).andReturn(null).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/statuses" + query);
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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.findFinderMethod("public_timeline");
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.getPublicTimeline(EasyMock.anyObject())).andReturn(Promises.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.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.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.value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, "/promisediscovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("promiseDiscoveredItemId", key));
}
Aggregations