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);
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResultAction.
/**
* Creates a RoutingResult for an Action with the given returnType.
*
* @param actionReturnType the return type of the action.
* @return a RoutingResult
*/
private final RoutingResult buildRoutingResultAction(Class<?> actionReturnType, RestRequest request, Map<String, String> headers) throws NoSuchMethodException, RestLiSyntaxException, URISyntaxException {
if (actionReturnType == Void.class) {
actionReturnType = Void.TYPE;
}
// actual method passed in is irrelevant, since we are constructing a ResourceMethodDescriptor by hand.
Method method = ProjectionTestFixture.class.getMethod("batchGet", Set.class);
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
String actionName = "return" + actionReturnType.getSimpleName();
List<Parameter<?>> parameters = Collections.<Parameter<?>>emptyList();
RecordDataSchema actionReturnRecordDataSchema;
FieldDef<?> returnFieldDef;
if (actionReturnType != Void.TYPE) {
@SuppressWarnings({ "unchecked", "rawtypes" }) FieldDef<?> nonVoidFieldDef = new FieldDef(ActionResponse.VALUE_NAME, actionReturnType, DataTemplateUtil.getSchema(actionReturnType));
returnFieldDef = nonVoidFieldDef;
actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(actionName, Collections.singleton(returnFieldDef));
} else {
returnFieldDef = null;
actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(actionName, Collections.<FieldDef<?>>emptyList());
}
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForAction(method, parameters, actionName, ResourceLevel.COLLECTION, returnFieldDef, actionReturnRecordDataSchema, DynamicRecordMetadata.buildSchema(actionName, parameters), InterfaceType.SYNC, new DataMap());
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext resourceContext = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, resourceContext);
return new RoutingResult(resourceContext, methodDescriptor);
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResultFinder.
private final RoutingResult buildRoutingResultFinder(RestRequest request, Map<String, String> acceptHeaders) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
Method method = ProjectionTestFixture.class.getMethod("find");
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(ResourceMethod.FINDER, method, InterfaceType.SYNC);
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testPromiseBatchPatch.
@Test
@SuppressWarnings({ "unchecked" })
public void testPromiseBatchPatch() throws Exception {
ResourceModel statusResourceModel = buildResourceModel(PromiseStatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = statusResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
PromiseStatusCollectionResource statusResource = getMockResource(PromiseStatusCollectionResource.class);
@SuppressWarnings("rawtypes") BatchPatchRequest batchPatchRequest = (BatchPatchRequest) EasyMock.anyObject();
EasyMock.expect(statusResource.batchUpdate(batchPatchRequest)).andReturn(Promises.<BatchUpdateResult<Long, Status>>value(null)).once();
String body = RestLiTestHelper.doubleQuote("{'entities':{'1':{},'2':{}}}");
checkInvocation(statusResource, methodDescriptor, "POST", version, "/promisestatuses?ids=List(1,2)", body, buildBatchPathKeys(1L, 2L));
}
use of com.linkedin.restli.internal.server.model.ResourceMethodDescriptor in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testFinderOnComplexKey.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "discoveredItemsFinder")
public void testFinderOnComplexKey(ProtocolVersion version, String query) throws Exception {
ResourceModel discoveredItemsResourceModel = buildResourceModel(DiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor = discoveredItemsResourceModel.findNamedMethod("user");
DiscoveredItemsResource discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
EasyMock.expect(discoveredItemsResource.findByUser(eq(1L))).andReturn(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "GET", version, "/discoveredItems" + query);
}
Aggregations