Search in sources :

Example 56 with ResourceModel

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

the class TestRestLiMethodInvocation method testAction_BadParameterTypes.

@Test
public void testAction_BadParameterTypes() throws Exception {
    ResourceModel accountsResourceModel = buildResourceModel(TwitterAccountsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    // #1 no defaults provided
    methodDescriptor = accountsResourceModel.findActionMethod("register", ResourceLevel.COLLECTION);
    String jsonEntityBody = RestLiTestHelper.doubleQuote("{'first': 42, 'last': 42, 'email': 42, " + "'company': 42, 'openToMarketingEmails': 'false'}");
    RestRequest request = new RestRequestBuilder(new URI("/accounts?action=register")).setMethod("POST").setEntity(jsonEntityBody.getBytes(Data.UTF_8_CHARSET)).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString()).build();
    RoutingResult routingResult = new RoutingResult(new ResourceContextImpl(null, request, new RequestContext()), methodDescriptor);
    try {
        RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), Collections.emptySet(), routingResult.getContext());
        _methodAdapterProvider.getArgumentBuilder(methodDescriptor.getMethodType()).extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
        _invoker.invoke(null, routingResult, _methodAdapterProvider.getArgumentBuilder(methodDescriptor.getMethodType()), null);
        Assert.fail("expected routing exception");
    } catch (RoutingException e) {
        Assert.assertEquals(e.getStatus(), 400);
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) 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) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 57 with ResourceModel

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

the class TestRestLiMethodInvocation method testAsyncGetAllAssociativeResource.

@Test
public void testAsyncGetAllAssociativeResource() throws Exception {
    ResourceModel followsResourceModel = buildResourceModel(AsyncFollowsAssociativeResource.class);
    RestLiCallback callback = getCallback();
    ResourceMethodDescriptor methodDescriptor;
    AsyncFollowsAssociativeResource resource;
    methodDescriptor = followsResourceModel.findMethod(ResourceMethod.GET_ALL);
    resource = getMockResource(AsyncFollowsAssociativeResource.class);
    resource.getAll(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            @SuppressWarnings("unchecked") Callback<List<Followed>> callback = (Callback<List<Followed>>) EasyMock.getCurrentArguments()[1];
            callback.onSuccess(null);
            return null;
        }
    });
    EasyMock.replay(resource);
    checkAsyncInvocation(resource, callback, methodDescriptor, "GET", version, "/asyncfollows", buildBatchPathKeys());
}
Also used : 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) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Followed(com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) List(java.util.List) AsyncFollowsAssociativeResource(com.linkedin.restli.server.twitter.AsyncFollowsAssociativeResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 58 with ResourceModel

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

the class TestRestLiMethodInvocation method testPagingContextNegativeStart.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusPagingContextNegativeStart")
public void testPagingContextNegativeStart(ProtocolVersion version, String query) throws Exception {
    ResourceModel statusResourceModel = buildResourceModel(StatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = statusResourceModel.findFinderMethod("public_timeline");
    StatusCollectionResource statusResource = getMockResource(StatusCollectionResource.class);
    expectRoutingException(methodDescriptor, statusResource, "GET", "/statuses" + query, version);
}
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) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 59 with ResourceModel

use of com.linkedin.restli.internal.server.model.ResourceModel 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.findFinderMethod("search");
    PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
    EasyMock.expect(statusResource.search(eq("linkedin"), eq(1L), eq(StatusType.REPLY))).andReturn(Promises.value(null)).once();
    checkInvocation(statusResource, methodDescriptor, "GET", version, "/promiseStatuses" + query);
}
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 60 with ResourceModel

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

the class TestRestLiMethodInvocation method testCustomCrudParamsCollectionCreate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "paramCollectionCreate")
public void testCustomCrudParamsCollectionCreate(ProtocolVersion version, String uri) throws Exception {
    ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
    ResourceMethodDescriptor methodDescriptor = model.findMethod(ResourceMethod.CREATE);
    CombinedResources.CollectionWithCustomCrudParams resource = getMockResource(CombinedResources.CollectionWithCustomCrudParams.class);
    EasyMock.expect(resource.myCreate((CombinedTestDataModels.Foo) EasyMock.anyObject(), eq(1), eq("bar"))).andReturn(null).once();
    checkInvocation(resource, methodDescriptor, "POST", version, uri, "{}");
}
Also used : CombinedResources(com.linkedin.restli.server.combined.CombinedResources) 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)

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