Search in sources :

Example 1 with TwitterAccountsResource

use of com.linkedin.restli.server.twitter.TwitterAccountsResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testAction_SimpleParameters.

@Test
public void testAction_SimpleParameters() throws Exception {
    ResourceModel accountsResourceModel = buildResourceModel(TwitterAccountsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    TwitterAccountsResource accountsResource;
    // #1 no defaults provided
    methodDescriptor = accountsResourceModel.findActionMethod("register", ResourceLevel.COLLECTION);
    accountsResource = getMockResource(TwitterAccountsResource.class);
    accountsResource.register(eq("alfred"), eq("hitchcock"), eq("alfred@test.linkedin.com"), eq("genentech"), eq(false));
    EasyMock.expectLastCall().once();
    String jsonEntityBody = RestLiTestHelper.doubleQuote("{'first': 'alfred', 'last': 'hitchcock', 'email': 'alfred@test.linkedin.com', " + "'company': 'genentech', 'openToMarketingEmails': false}");
    checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=register", jsonEntityBody);
    // #2 defaults filled in
    methodDescriptor = accountsResourceModel.findActionMethod("register", ResourceLevel.COLLECTION);
    accountsResource = getMockResource(TwitterAccountsResource.class);
    accountsResource.register(eq("alfred"), eq("hitchcock"), eq("alfred@test.linkedin.com"), eq((String) null), eq(true));
    EasyMock.expectLastCall().once();
    jsonEntityBody = RestLiTestHelper.doubleQuote("{'first': 'alfred', 'last': 'hitchcock', 'email': 'alfred@test.linkedin.com'}");
    checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=register", jsonEntityBody);
    // #3 no-arg method
    methodDescriptor = accountsResourceModel.findActionMethod("noArgMethod", ResourceLevel.COLLECTION);
    accountsResource = getMockResource(TwitterAccountsResource.class);
    accountsResource.noArgMethod();
    EasyMock.expectLastCall().once();
    jsonEntityBody = RestLiTestHelper.doubleQuote("{}");
    checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=noArgMethod", jsonEntityBody);
    // #4 primitive response
    methodDescriptor = accountsResourceModel.findActionMethod("primitiveResponse", ResourceLevel.COLLECTION);
    accountsResource = getMockResource(TwitterAccountsResource.class);
    EasyMock.expect(accountsResource.primitiveResponse()).andReturn(1).once();
    jsonEntityBody = RestLiTestHelper.doubleQuote("{'value': 1}");
    checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=primitiveResponse", jsonEntityBody);
}
Also used : TwitterAccountsResource(com.linkedin.restli.server.twitter.TwitterAccountsResource) 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 2 with TwitterAccountsResource

use of com.linkedin.restli.server.twitter.TwitterAccountsResource in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testInvoke_testComplexParameters.

@Test
public void testInvoke_testComplexParameters() throws Exception {
    ResourceModel accountsResourceModel = buildResourceModel(TwitterAccountsResource.class);
    ResourceMethodDescriptor methodDescriptor;
    TwitterAccountsResource accountsResource;
    // #1 no defaults provided
    methodDescriptor = accountsResourceModel.findActionMethod("closeAccounts", ResourceLevel.COLLECTION);
    accountsResource = getMockResource(TwitterAccountsResource.class);
    StringArray emailAddresses = new StringArray("bob@test.linkedin.com", "joe@test.linkedin.com");
    EasyMock.expect(accountsResource.closeAccounts(eq(emailAddresses), eq(true), eq((StringMap) null))).andReturn((new StringMap())).once();
    String jsonEntityBody = RestLiTestHelper.doubleQuote("{'emailAddresses': ['bob@test.linkedin.com', 'joe@test.linkedin.com'], 'someFlag': true}");
    checkInvocation(accountsResource, methodDescriptor, "POST", version, "/accounts?action=closeAccounts", jsonEntityBody);
}
Also used : StringMap(com.linkedin.data.template.StringMap) StringArray(com.linkedin.data.template.StringArray) TwitterAccountsResource(com.linkedin.restli.server.twitter.TwitterAccountsResource) 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)

Aggregations

ByteString (com.linkedin.data.ByteString)2 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)2 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)2 CustomString (com.linkedin.restli.server.custom.types.CustomString)2 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)2 TwitterAccountsResource (com.linkedin.restli.server.twitter.TwitterAccountsResource)2 AfterTest (org.testng.annotations.AfterTest)2 BeforeTest (org.testng.annotations.BeforeTest)2 Test (org.testng.annotations.Test)2 StringArray (com.linkedin.data.template.StringArray)1 StringMap (com.linkedin.data.template.StringMap)1