Search in sources :

Example 91 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testPromiseFinderError.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "promiseFinderError")
public void testPromiseFinderError(ProtocolVersion version, String uri) throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = statusResourceModel.findNamedMethod("search");
    PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
    expectRoutingException(methodDescriptor, statusResource, "GET", uri, version);
}
Also used : PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 92 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionBatchUpdate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionBatchUpdate")
public void testCustomCrudParamsCollectionBatchUpdate(ProtocolVersion version, String uri, String body) throws Exception {
    ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
    ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.BATCH_UPDATE);
    CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
    @SuppressWarnings("rawtypes") BatchUpdateRequest batchUpdateRequest = (BatchUpdateRequest) EasyMock.anyObject();
    @SuppressWarnings("unchecked") BatchUpdateResult<String, CombinedTestDataModels.Foo> batchUpdateResult = resource.myBatchUpdate(batchUpdateRequest, eq(1), eq("baz"));
    EasyMock.expect(batchUpdateResult).andReturn(null).once();
    checkInvocation(resource, methodDescriptor, "PUT", version, uri, body, buildBatchPathKeys("foo", "bar"));
}
Also used : CombinedResources(com.linkedin.restli.server.combined.CombinedResources) BatchUpdateRequest(com.linkedin.restli.server.BatchUpdateRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 93 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestRestLiResourceModels method testTwitterAsyncStatusModel.

@Test
public void testTwitterAsyncStatusModel() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(AsyncStatusCollectionResource.class);
    checkCollectionModel(statusResourceModel, "asyncstatuses", Long.class, "statusID", Status.class, false, AsyncStatusCollectionResource.class);
    assertHasMethods(statusResourceModel, ResourceMethod.CREATE, ResourceMethod.FINDER, ResourceMethod.BATCH_GET);
    ResourceMethodDescriptor methodDescriptor;
    methodDescriptor = checkFinderMethod(statusResourceModel, "public_timeline", 2);
    methodDescriptor = checkFinderMethod(statusResourceModel, "user_timeline", 3);
    methodDescriptor = checkFinderMethod(statusResourceModel, "search", 5);
    checkParam(methodDescriptor, "keywords", String.class, null);
    checkParam(methodDescriptor, "since", long.class, -1L);
    checkParam(methodDescriptor, "type", StatusType.class, null);
    assertNull(methodDescriptor.getParameter("foo"));
    assertNull(statusResourceModel.findActionMethod("foo", ResourceLevel.COLLECTION));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_GET));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.CREATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_DELETE));
    checkEntityModel(statusResourceModel, Long.class, "statusID", Status.class, Collections.<String, Class<?>>emptyMap());
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.GET));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.FINDER));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_UPDATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.GET_ALL));
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) Test(org.testng.annotations.Test)

Example 94 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestRestLiResourceModels method testTwitterStatusModel.

@Test
public void testTwitterStatusModel() throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
    checkCollectionModel(statusResourceModel, "statuses", Long.class, "statusID", Status.class, false, StatusCollectionResource.class);
    assertHasMethods(statusResourceModel, ResourceMethod.CREATE, ResourceMethod.FINDER, ResourceMethod.BATCH_GET);
    ResourceMethodDescriptor methodDescriptor;
    methodDescriptor = checkFinderMethod(statusResourceModel, "public_timeline", 1);
    methodDescriptor = checkFinderMethod(statusResourceModel, "user_timeline", 2);
    methodDescriptor = checkFinderMethod(statusResourceModel, "search", 3);
    checkParam(methodDescriptor, "keywords", String.class, null);
    checkParam(methodDescriptor, "since", long.class, -1L);
    checkParam(methodDescriptor, "type", StatusType.class, null);
    assertNull(methodDescriptor.getParameter("foo"));
    assertNull(statusResourceModel.findActionMethod("foo", ResourceLevel.COLLECTION));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_GET));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.CREATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_CREATE));
    checkEntityModel(statusResourceModel, Long.class, "statusID", Status.class, Collections.<String, Class<?>>emptyMap());
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.GET));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.PARTIAL_UPDATE));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.FINDER));
    assertNotNull(statusResourceModel.findMethod(ResourceMethod.BATCH_UPDATE));
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) Test(org.testng.annotations.Test)

Example 95 with ResourceMethodDescriptor

use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.

the class TestRestLiResourceModels method testExceptionMethods.

@Test
public void testExceptionMethods() throws Exception {
    final ResourceModel resourceModel = buildResourceModel(ExceptionsResource.class);
    assertEquals(resourceModel.getResourceType(), ResourceType.COLLECTION);
    assertEquals(resourceModel.getResourceMethodDescriptors().size(), 2);
    final ResourceMethodDescriptor getMethod = resourceModel.findMethod(ResourceMethod.GET);
    assertNotNull(getMethod);
    final ResourceMethodDescriptor actionMethod = resourceModel.findActionMethod("exception", ResourceLevel.COLLECTION);
    assertNotNull(actionMethod);
    final Class<?> returnClass = actionMethod.getActionReturnType();
    assertSame(returnClass, Integer.class);
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) Test(org.testng.annotations.Test)

Aggregations

ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)195 Test (org.testng.annotations.Test)171 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)140 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)116 AfterTest (org.testng.annotations.AfterTest)105 BeforeTest (org.testng.annotations.BeforeTest)105 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)66 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)47 RestRequest (com.linkedin.r2.message.rest.RestRequest)41 ByteString (com.linkedin.data.ByteString)40 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)38 ResourceContext (com.linkedin.restli.server.ResourceContext)37 CustomString (com.linkedin.restli.server.custom.types.CustomString)37 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)31 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)27 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)27 EasyMock.anyObject (org.easymock.EasyMock.anyObject)27 Callback (com.linkedin.common.callback.Callback)26 RequestExecutionCallback (com.linkedin.restli.server.RequestExecutionCallback)26 CustomStatusCollectionResource (com.linkedin.restli.server.twitter.CustomStatusCollectionResource)26