Search in sources :

Example 46 with ResourceModel

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();
}
Also used : ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel)

Example 47 with ResourceModel

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);
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Method(java.lang.reflect.Method) Test(org.testng.annotations.Test)

Example 48 with ResourceModel

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;
}
Also used : HashMap(java.util.HashMap) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel)

Example 49 with ResourceModel

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));
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) CustomLong(com.linkedin.restli.server.custom.types.CustomLong) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 50 with ResourceModel

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);
}
Also used : Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) RestResponse(com.linkedin.r2.message.rest.RestResponse) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) RestException(com.linkedin.r2.message.rest.RestException) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RoutingException(com.linkedin.restli.server.RoutingException) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)223 Test (org.testng.annotations.Test)190 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)161 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)139 AfterTest (org.testng.annotations.AfterTest)114 BeforeTest (org.testng.annotations.BeforeTest)114 ByteString (com.linkedin.data.ByteString)50 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)50 CustomString (com.linkedin.restli.server.custom.types.CustomString)43 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)40 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)37 RestRequest (com.linkedin.r2.message.rest.RestRequest)36 Callback (com.linkedin.common.callback.Callback)34 RestLiConfig (com.linkedin.restli.server.RestLiConfig)34 RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)32 RequestContext (com.linkedin.r2.message.RequestContext)29 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)28 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)28 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)28 TaskStatusCollectionResource (com.linkedin.restli.server.twitter.TaskStatusCollectionResource)28