@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",