use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class ResourceMethodConfigCacheKey method getResourceName.
private static String getResourceName(ResourceMethodDescriptor requestMethod) {
ResourceModel currentModel = requestMethod.getResourceModel();
StringBuffer resourceName = new StringBuffer(currentModel.getName());
while ((currentModel = currentModel.getParentResourceModel()) != null) {
resourceName.insert(0, ":" + currentModel.getName());
}
return resourceName.toString();
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestResourceMethodConfigProvider method testMethodConfigPriority.
@Test(dataProvider = "methodConfigs")
public void testMethodConfigPriority(RestLiMethodConfigBuilder configBuilder, Long timeout) throws NoSuchMethodException {
ResourceMethodConfigProvider provider = ResourceMethodConfigProvider.build(configBuilder.build());
Method method = StatusCollectionResource.class.getMethod("getPublicTimeline", PagingContext.class);
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForFinder(method, Collections.emptyList(), "public_timeline", null, ResourceMethodDescriptor.InterfaceType.SYNC, null);
model.addResourceMethodDescriptor(methodDescriptor);
ResourceMethodConfig rmc = provider.apply(methodDescriptor);
assertEquals(rmc.getTimeoutMs().getValue(), timeout);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class RestLiTestHelper method buildResourceModels.
public static Map<String, ResourceModel> buildResourceModels(Class<?>... rootResourceClasses) {
Map<String, ResourceModel> map = new HashMap<>();
for (Class<?> rootResourceClass : rootResourceClasses) {
ResourceModel model = RestLiAnnotationReader.processResource(rootResourceClass);
map.put("/" + model.getName(), model);
}
return map;
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchPatch.
@Test
public void testAsyncBatchPatch() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
RestLiCallback callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncStatusCollectionResource statusResource;
methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
statusResource = getMockResource(AsyncStatusCollectionResource.class);
@SuppressWarnings("unchecked") BatchPatchRequest<Long, Status> mockBatchPatchReq = EasyMock.anyObject();
statusResource.batchUpdate(mockBatchPatchReq, EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchCreateResult<Long, Status>> callback = (Callback<BatchCreateResult<Long, Status>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(statusResource);
checkAsyncInvocation(statusResource, callback, methodDescriptor, "POST", version, "/asyncstatuses?ids=List(1,2,3)", "{\"entities\": {\"1\": {}, \"2\": {}, \"3\": {}}}", buildBatchPathKeys(1L, 2L, 3L));
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testParseqTraceTask.
@Test
public void testParseqTraceTask() 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();
checkInvocation(taskStatusResource, taskRequestContext, methodDescriptor, "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) {
Assert.assertNotNull(taskRequestContext.getLocalAttr(ATTRIBUTE_PARSEQ_TRACE));
}
}, true, false);
}
Aggregations