Search in sources :

Example 46 with ResourceContextImpl

use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.

the class TestRestLiRouting method testActionRootRouting.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "actionRootRouting")
public void testActionRootRouting(ProtocolVersion version, String uri, String actionName) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TwitterAccountsResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    RestRequest request = createRequest(uri, "POST", version);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    ResourceMethodDescriptor method = _router.process(context);
    assertNotNull(method);
    assertEquals(method.getActionName(), actionName);
    assertEquals(method.getType(), ResourceMethod.ACTION);
}
Also used : RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) 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) RequestContext(com.linkedin.r2.message.RequestContext) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) Test(org.testng.annotations.Test)

Example 47 with ResourceContextImpl

use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.

the class TestRestLiCallback method setUp.

@BeforeTest
protected void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    _filterResponseContextFactory = new RestLiFilterResponseContextFactory(_restRequest, _routingResult, _responseHandler);
    when(_routingResult.getContext()).thenReturn(new ResourceContextImpl());
    ErrorResponseBuilder errorResponseBuilder = new ErrorResponseBuilder();
    FilterChainDispatcher filterChainDispatcher = new FilterChainDispatcherImpl(_routingResult, _methodInvoker, _argumentBuilder);
    FilterChainCallback filterChainCallback = new FilterChainCallbackImpl(_routingResult, _responseHandler, _callback, errorResponseBuilder);
    _zeroFilterChain = new RestLiFilterChain(null, filterChainDispatcher, filterChainCallback);
    _oneFilterChain = new RestLiFilterChain(Arrays.asList(_filter), filterChainDispatcher, filterChainCallback);
    _twoFilterChain = new RestLiFilterChain(Arrays.asList(_filter, _filter), filterChainDispatcher, filterChainCallback);
    _noFilterRestLiCallback = new RestLiCallback(_filterRequestContext, _filterResponseContextFactory, _zeroFilterChain);
    _oneFilterRestLiCallback = new RestLiCallback(_filterRequestContext, _filterResponseContextFactory, _oneFilterChain);
    _twoFilterRestLiCallback = new RestLiCallback(_filterRequestContext, _filterResponseContextFactory, _twoFilterChain);
}
Also used : FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RestLiFilterResponseContextFactory(com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory) FilterChainDispatcher(com.linkedin.restli.internal.server.filter.FilterChainDispatcher) FilterChainDispatcherImpl(com.linkedin.restli.internal.server.filter.FilterChainDispatcherImpl) FilterChainCallbackImpl(com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) RestLiFilterChain(com.linkedin.restli.internal.server.filter.RestLiFilterChain) BeforeTest(org.testng.annotations.BeforeTest)

Example 48 with ResourceContextImpl

use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.

the class TestBatchFinderResponseBuilder method getMockRoutingResult.

private static RoutingResult getMockRoutingResult(List<Criteria> criteria, ProtocolVersion protocolVersion) {
    DataList param = new DataList();
    for (int i = 0; i < criteria.size(); i++) {
        param.add(criteria.get(i).criteria.data());
    }
    MaskTree mockMask = EasyMock.createMock(MaskTree.class);
    EasyMock.expect(mockMask.getDataMap()).andStubReturn(new DataMap());
    EasyMock.replay(mockMask);
    ResourceContextImpl mockContext = EasyMock.createMock(ResourceContextImpl.class);
    DataMap batch_method = new DataMap();
    batch_method.put("bq", BATCH_METHOD);
    EasyMock.expect(mockContext.getRestliProtocolVersion()).andStubReturn(protocolVersion);
    EasyMock.expect(mockContext.getStructuredParameter(BATCH_PARAM)).andStubReturn(param);
    EasyMock.expect(mockContext.getParameters()).andStubReturn(batch_method);
    EasyMock.expect(mockContext.getParameter("start")).andStubReturn("0");
    EasyMock.expect(mockContext.getParameter("count")).andStubReturn(Integer.toString(PAGE_COUNT));
    EasyMock.expect(mockContext.getRequestHeaders()).andStubReturn(new HashMap<>());
    EasyMock.expect(mockContext.getPagingProjectionMask()).andStubReturn(null);
    EasyMock.expect(mockContext.getProjectionMode()).andStubReturn(ProjectionMode.MANUAL);
    EasyMock.expect(mockContext.getProjectionMask()).andStubReturn(mockMask);
    EasyMock.expect(mockContext.getMetadataProjectionMask()).andStubReturn(mockMask);
    EasyMock.expect(mockContext.getMetadataProjectionMode()).andStubReturn(ProjectionMode.MANUAL);
    EasyMock.expect(mockContext.getRawRequestContext()).andStubReturn(new RequestContext());
    EasyMock.expect(mockContext.getAlwaysProjectedFields()).andReturn(Collections.emptySet()).anyTimes();
    EasyMock.expect(mockContext.isFillInDefaultsRequested()).andStubReturn(false);
    EasyMock.replay(mockContext);
    List<Parameter<?>> parameterList = new ArrayList<>();
    parameterList.add(new Parameter<>(BATCH_PARAM, String.class, null, false, null, Parameter.ParamType.QUERY, true, AnnotationSet.EMPTY));
    ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
    EasyMock.expect(mockDescriptor.getAnnotation(BatchFinder.class)).andStubReturn(getInstanceOfAnnotation(BATCH_PARAM, BATCH_PARAM));
    EasyMock.expect(mockDescriptor.getParametersWithType(Parameter.ParamType.PAGING_CONTEXT_PARAM)).andStubReturn(getPagingContextParam());
    EasyMock.expect(mockDescriptor.getBatchFinderCriteriaParamIndex()).andStubReturn(0);
    EasyMock.expect(mockDescriptor.getParameters()).andStubReturn(parameterList);
    EasyMock.replay(mockDescriptor);
    RoutingResult mockRoutingResult = EasyMock.createMock(RoutingResult.class);
    EasyMock.expect(mockRoutingResult.getResourceMethod()).andStubReturn(mockDescriptor);
    EasyMock.expect(mockRoutingResult.getContext()).andStubReturn(mockContext);
    EasyMock.replay(mockRoutingResult);
    return mockRoutingResult;
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ArrayList(java.util.ArrayList) DataMap(com.linkedin.data.DataMap) QueryParamsDataMap(com.linkedin.restli.internal.common.QueryParamsDataMap) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) DataList(com.linkedin.data.DataList) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) Parameter(com.linkedin.restli.internal.server.model.Parameter) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 49 with ResourceContextImpl

use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.

the class TestRestUtils method testValidateRequestHeadersForInProcessRequest.

@Test()
public void testValidateRequestHeadersForInProcessRequest() throws Exception {
    Map<String, String> headers = new AbstractMap<String, String>() {

        @Override
        public Set<Entry<String, String>> entrySet() {
            throw new IllegalStateException("Didn't expect headers to be accessed.");
        }
    };
    RequestContext requestContext = new RequestContext();
    requestContext.putLocalAttr(ServerResourceContext.CONTEXT_IN_PROCESS_RESOLUTION_KEY, true);
    ServerResourceContext resourceContext = new ResourceContextImpl();
    RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, Collections.emptySet(), resourceContext, requestContext);
    Assert.assertEquals(resourceContext.getResponseMimeType(), ContentType.JSON.getHeaderKey());
}
Also used : AbstractMap(java.util.AbstractMap) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 50 with ResourceContextImpl

use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.

the class TestRestUtils method testValidateRequestHeadersWithValidAcceptHeaderAndMatch.

@Test()
public void testValidateRequestHeadersWithValidAcceptHeaderAndMatch() throws Exception {
    Map<String, String> headers = new HashMap<>();
    headers.put("Accept", "application/json");
    ServerResourceContext resourceContext = new ResourceContextImpl();
    RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, Collections.emptySet(), resourceContext);
    Assert.assertEquals(resourceContext.getResponseMimeType(), "application/json");
}
Also used : HashMap(java.util.HashMap) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Aggregations

ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)52 RequestContext (com.linkedin.r2.message.RequestContext)41 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)40 PathKeysImpl (com.linkedin.restli.internal.server.PathKeysImpl)34 Test (org.testng.annotations.Test)31 RestRequest (com.linkedin.r2.message.rest.RestRequest)29 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)29 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)25 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)20 URI (java.net.URI)15 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)14 RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)14 RestLiConfig (com.linkedin.restli.server.RestLiConfig)14 ByteString (com.linkedin.data.ByteString)11 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)11 RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)10 PathKeys (com.linkedin.restli.server.PathKeys)10 RoutingException (com.linkedin.restli.server.RoutingException)9 DataMap (com.linkedin.data.DataMap)7 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)7