Search in sources :

Example 1 with RestLiTestHelper.buildResourceModel

use of com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel 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);
}
Also used : PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Method(java.lang.reflect.Method) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) FieldDef(com.linkedin.data.template.FieldDef) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) Parameter(com.linkedin.restli.internal.server.model.Parameter) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 2 with RestLiTestHelper.buildResourceModel

use of com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel 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);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) 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) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Method(java.lang.reflect.Method) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 3 with RestLiTestHelper.buildResourceModel

use of com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel in project rest.li by linkedin.

the class TestRestLiResponseHandler method buildRoutingResult.

private final RoutingResult buildRoutingResult(ResourceMethod resourceMethod, RestRequest request, Map<String, String> acceptHeaders) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
    Method method = ProjectionTestFixture.class.getMethod("batchGet", Set.class);
    ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(resourceMethod, method, InterfaceType.SYNC);
    model.addResourceMethodDescriptor(methodDescriptor);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, context);
    return new RoutingResult(context, methodDescriptor);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) 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) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Method(java.lang.reflect.Method) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Aggregations

RequestContext (com.linkedin.r2.message.RequestContext)3 ResourceMethod (com.linkedin.restli.common.ResourceMethod)3 PathKeysImpl (com.linkedin.restli.internal.server.PathKeysImpl)3 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)3 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)3 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)3 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)3 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)3 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)3 Method (java.lang.reflect.Method)3 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)1 FieldDef (com.linkedin.data.template.FieldDef)1 Parameter (com.linkedin.restli.internal.server.model.Parameter)1