use of com.linkedin.restli.server.twitter.PromiseStatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseDelete.
@Test
public void testPromiseDelete() 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 Delete on collection resource
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.DELETE);
statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.delete(eq(1L))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "DELETE", version, "/promisestatuses/1", buildPathKeys("statusID", 1L));
// #2 Delete on simple resource
methodDescriptor = locationResourceModel.findMethod(ResourceMethod.DELETE);
locationResource = getMockResource(PromiseLocationResource.class);
EasyMock.expect(locationResource.delete()).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(locationResource, methodDescriptor, "DELETE", version, "/promisestatuses/1/promiselocation", buildPathKeys("statusID", 1L));
// #3 Delete on complex key resource
methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.DELETE);
discoveredItemsResource = getMockResource(PromiseDiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> key = getDiscoveredItemComplexKey(1L, 2, 3L);
EasyMock.expect(discoveredItemsResource.delete(eq(key))).andReturn(Promises.<UpdateResponse>value(null)).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "DELETE", version, "/promisediscovereditems/(itemId:1,type:2,userId:3)", buildPathKeys("promiseDiscoveredItemId", key));
}
use of com.linkedin.restli.server.twitter.PromiseStatusCollectionResource 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.findNamedMethod("public_timeline");
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.getPublicTimeline(eq(buildPagingContext(5, null)))).andReturn(Promises.<List<Status>>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses" + query);
}
use of com.linkedin.restli.server.twitter.PromiseStatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseFinder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusFinder")
public void testPromiseFinder(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("search");
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.search(eq("linkedin"), eq(1L), eq(StatusType.REPLY))).andReturn(Promises.<List<Status>>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promiseStatuses" + query);
}
use of com.linkedin.restli.server.twitter.PromiseStatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testExecutionReport.
@Test
public void testExecutionReport() throws RestLiSyntaxException, URISyntaxException {
Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, AsyncStatusCollectionResource.class, PromiseStatusCollectionResource.class, TaskStatusCollectionResource.class);
ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
ResourceModel asyncStatusResourceModel = resourceModelMap.get("/asyncstatuses");
ResourceModel promiseStatusResourceModel = resourceModelMap.get("/promisestatuses");
ResourceModel taskStatusResourceModel = resourceModelMap.get("/taskstatuses");
ResourceMethodDescriptor methodDescriptor;
StatusCollectionResource statusResource;
AsyncStatusCollectionResource asyncStatusResource;
PromiseStatusCollectionResource promiseStatusResource;
TaskStatusCollectionResource taskStatusResource;
// #1: Sync Method Execution
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", null, buildPathKeys("statusID", 1L), new RequestExecutionCallback<RestResponse>() {
//A 404 is considered an error by rest.li
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
Assert.assertNull(executionReport.getParseqTrace(), "There should be no parseq trace!");
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
Assert.fail("Request failed unexpectedly.");
}
}, true, false);
// #2: Callback based Async Method Execution
Capture<RequestExecutionReport> requestExecutionReportCapture = new Capture<RequestExecutionReport>();
RestLiCallback<?> callback = getCallback(requestExecutionReportCapture);
methodDescriptor = asyncStatusResourceModel.findMethod(ResourceMethod.GET);
asyncStatusResource = getMockResource(AsyncStatusCollectionResource.class);
asyncStatusResource.get(eq(1L), EasyMock.<Callback<Status>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<Status> callback = (Callback<Status>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(asyncStatusResource);
checkAsyncInvocation(asyncStatusResource, callback, methodDescriptor, "GET", version, "/asyncstatuses/1", null, buildPathKeys("statusID", 1L), true);
Assert.assertNull(requestExecutionReportCapture.getValue().getParseqTrace());
// #3: Promise based Async Method Execution
methodDescriptor = promiseStatusResourceModel.findMethod(ResourceMethod.GET);
promiseStatusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(promiseStatusResource.get(eq(1L))).andReturn(Promises.<Status>value(null)).once();
checkInvocation(promiseStatusResource, methodDescriptor, "GET", version, "/promisestatuses/1", null, buildPathKeys("statusID", 1L), new RequestExecutionCallback<RestResponse>() {
//A 404 is considered an error by rest.li
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
Assert.assertNotNull(executionReport.getParseqTrace(), "There should be a valid parseq trace!");
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
Assert.fail("Request failed unexpectedly.");
}
}, true, false);
// #4: Task based Async Method Execution
methodDescriptor = taskStatusResourceModel.findMethod(ResourceMethod.GET);
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();
checkInvocation(taskStatusResource, methodDescriptor, "GET", version, "/taskstatuses/1", null, buildPathKeys("statusID", 1L), new RequestExecutionCallback<RestResponse>() {
@Override
public void onError(Throwable e, RequestExecutionReport executionReport, RestLiAttachmentReader requestAttachmentReader, RestLiResponseAttachments responseAttachments) {
Assert.fail("Request failed unexpectedly.");
}
@Override
public void onSuccess(RestResponse result, RequestExecutionReport executionReport, RestLiResponseAttachments responseAttachments) {
Assert.assertNotNull(executionReport.getParseqTrace());
}
}, true, false);
}
use of com.linkedin.restli.server.twitter.PromiseStatusCollectionResource in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromisePagingContextDefault.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusPagingContextDefault")
public void testPromisePagingContextDefault(ProtocolVersion version, String query) throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("public_timeline");
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
EasyMock.expect(statusResource.getPublicTimeline(eq(buildPagingContext(null, null)))).andReturn(Promises.<List<Status>>value(null)).once();
checkInvocation(statusResource, methodDescriptor, "GET", version, "/promisestatuses" + query);
}
Aggregations