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