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);
}
}
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());
}
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);
}
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);
}
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, "{}");
}
Aggregations