Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.RestLiRequestData


    RestLiArgumentBuilder mockBuilder = createMock(RestLiArgumentBuilder.class);
    RequestFilter mockFilter = createMock(RequestFilter.class);
    @SuppressWarnings("unchecked")
    RequestExecutionCallback<Object> mockCallback = createMock(RequestExecutionCallback.class);
    FilterRequestContextInternal mockFilterContext = createMock(FilterRequestContextInternal.class);
    RestLiRequestData requestData = new RestLiRequestDataImpl.Builder().key("Key").build();
    RestLiMethodInvoker invokerWithFilters =
        new RestLiMethodInvoker(_resourceFactory,
                                _engine,
                                new ErrorResponseBuilder(),
                                mockRegistry,
                                Arrays.asList(mockFilter, mockFilter));
    Map<String, ResourceModel> resourceModelMap =
        buildResourceModels(StatusCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
    ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
    ResourceMethodDescriptor resourceMethodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
    final StatusCollectionResource resource = getMockResource(StatusCollectionResource.class);
    RestRequestBuilder builder =
        new RestRequestBuilder(new URI("/statuses/1")).setMethod("GET")
                                                      .addHeaderValue("Accept", "application/json")
                                                      .setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION,
                                                                 AllProtocolVersions.LATEST_PROTOCOL_VERSION.toString());
    RestRequest request = builder.build();
    RoutingResult routingResult =
        new RoutingResult(new ResourceContextImpl(buildPathKeys("statusID", 1L), request, new RequestContext()),
                          resourceMethodDescriptor);
    expect(mockRegistry.getArgumentBuilder(resourceMethodDescriptor.getType())).andReturn(mockBuilder);
    expect(mockBuilder.extractRequestData(routingResult, request)).andReturn(requestData);
    mockFilterContext.setRequestData(requestData);
    final Exception exFromFilter = new RuntimeException("Exception from filter!");
    if (throwExceptionFromFirstFilter)
    {
      mockFilter.onRequest(mockFilterContext);
      expectLastCall().andThrow(exFromFilter);
      mockCallback.onError(eq(exFromFilter), anyObject(RequestExecutionReport.class));
    }
    else
    {
      expect(mockFilterContext.getRequestData()).andReturn(requestData).times(3);
      mockFilter.onRequest(mockFilterContext);
      expectLastCall().andAnswer(new IAnswer<Object>()
      {
        @Override
        public Object answer() throws Throwable
        {
          FilterRequestContext filterContext = (FilterRequestContext) getCurrentArguments()[0];
          RestLiRequestData data = filterContext.getRequestData();
          // Verify incoming data.
          assertEquals(data.getKey(), "Key");

          // Update data.
          data.setKey("Key-Filter1");
          return null;
        }
      }).andAnswer(new IAnswer<Object>()
      {
        @Override
        public Object answer() throws Throwable
        {
          FilterRequestContext filterContext = (FilterRequestContext) getCurrentArguments()[0];
          RestLiRequestData data = filterContext.getRequestData();
          // Verify incoming data.
          assertEquals(data.getKey(), "Key-Filter1");

          // Update data.
          data.setKey("Key-Filter2");
          return null;
        }
      });
      Long[] argsArray = { 1L };
      expect(mockBuilder.buildArguments(requestData, routingResult)).andReturn(argsArray);
View Full Code Here


    {
      routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 1);
    }

    RestLiArgumentBuilder argumentBuilder = new UpdateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);

    if (keyValue != null)
    {
      Assert.assertEquals(args.length, 2);
View Full Code Here

    {
      routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    }

    RestLiArgumentBuilder argumentBuilder = new PatchArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);

    if (keyValue != null)
    {
      Assert.assertEquals(args.length, 2);
View Full Code Here

    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);

    RestLiArgumentBuilder argumentBuilder = new CreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Assert.assertEquals(args.length, 1);
    Assert.assertTrue(args[0] instanceof MyComplexKey);
    Assert.assertEquals(((MyComplexKey)args[0]).getA(), "xyz");
    Assert.assertEquals((long) ((MyComplexKey)args[0]).getB(), 123L);
View Full Code Here

  }

  @Override
  public RestLiRequestData extractRequestData(RoutingResult routingResult, RestRequest request)
  {
    final RestLiRequestData reqData;
    if (ArgumentUtils.hasResourceKey(routingResult))
    {
      Object keyValue = ArgumentUtils.getResourceKey(routingResult);
      reqData = new RestLiRequestDataImpl.Builder().key(keyValue).build();
    }
View Full Code Here

    {
      throw new IllegalArgumentException("Unsupported method type: "
          + resourceMethodDescriptor.getType());
    }

    RestLiRequestData requestData = adapter.extractRequestData(invocableMethod, request);

    // First invoke all request filters.
    if (!_requestFilters.isEmpty())
    {
      try
View Full Code Here

    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, batchKeys);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);

    RestLiArgumentBuilder argumentBuilder = new BatchDeleteArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);

    Assert.assertEquals(args.length, 1);
    Assert.assertTrue(args[0] instanceof BatchDeleteRequest);
    Assert.assertEquals(((BatchDeleteRequest)args[0]).getKeys(), batchKeys);
View Full Code Here

    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, batchKeys);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 2);

    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
    RestLiArgumentBuilder argumentBuilder = new BatchGetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs = new Object[]{batchKeys};
    Assert.assertEquals(args, expectedArgs);

    EasyMock.verify(descriptor, context, routingResult, request);
View Full Code Here

      routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    }
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);

    RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs;
    if (keyValue == null)
    {
      expectedArgs = new Object[]{};
View Full Code Here

    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);

    RestLiArgumentBuilder argumentBuilder = new BatchCreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);

    Assert.assertEquals(args.length, 1);
    Assert.assertTrue(args[0] instanceof BatchCreateRequest);
    @SuppressWarnings("unchecked")
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.RestLiRequestData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.