use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class RestLiArgumentBuilderTestHelper method getMockResourceContext.
public static ServerResourceContext getMockResourceContext(Map<String, String> parameters, boolean attachmentReaderGetExpected) {
ServerResourceContext context = createMock(ServerResourceContext.class);
for (String key : parameters.keySet()) {
expect(context.getParameter(key)).andReturn(parameters.get(key));
}
if (attachmentReaderGetExpected) {
expect(context.getRequestAttachmentReader()).andReturn(null);
}
replay(context);
return context;
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class RestLiArgumentBuilderTestHelper method getMockResourceContext.
public static ServerResourceContext getMockResourceContext(Map<String, String> parameters, MaskTree projectionMask, MaskTree metadataMask, MaskTree pagingMask, boolean attachmentReaderGetExpected) {
ServerResourceContext context = createMock(ServerResourceContext.class);
for (String key : parameters.keySet()) {
expect(context.getParameter(key)).andReturn(parameters.get(key));
}
expect(context.getProjectionMask()).andReturn(projectionMask);
expect(context.getMetadataProjectionMask()).andReturn(metadataMask);
expect(context.getPagingProjectionMask()).andReturn(pagingMask);
if (attachmentReaderGetExpected) {
expect(context.getRequestAttachmentReader()).andReturn(null);
}
replay(context);
return context;
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestRestUtils method testValidateRequestHeadersWithValidAcceptHeaderAndNoMatch.
@Test()
public void testValidateRequestHeadersWithValidAcceptHeaderAndNoMatch() throws Exception {
Map<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "text/html");
ServerResourceContext resourceContext = new ResourceContextImpl();
try {
RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, resourceContext);
Assert.fail();
} catch (RestLiServiceException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.S_406_NOT_ACCEPTABLE);
Assert.assertEquals(e.getMessage(), "None of the types in the request's 'Accept' header are supported. Supported MIME types are: [application/x-pson, application/json]");
Assert.assertEquals(resourceContext.getResponseMimeType(), null);
}
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchCreateResponseBuilder method getMockKVResourceContext.
private static ResourceContext getMockKVResourceContext(String altKeyName) {
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.hasParameter(RestConstants.ALT_KEY_PARAM)).andReturn(altKeyName != null).atLeastOnce();
if (altKeyName != null) {
EasyMock.expect(mockContext.getParameter(RestConstants.ALT_KEY_PARAM)).andReturn(altKeyName).atLeastOnce();
}
// not testing the diversity of options here.
EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.getDefault()).atLeastOnce();
EasyMock.expect(mockContext.getProjectionMask()).andReturn(null).atLeastOnce();
Map<String, String> protocolVersionOnlyHeaders = Collections.singletonMap(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion().toString());
EasyMock.expect(mockContext.getRequestHeaders()).andReturn(protocolVersionOnlyHeaders).atLeastOnce();
EasyMock.replay(mockContext);
return mockContext;
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchCreateResponseBuilder method testProjectionInBuildRestLiResponseData.
@Test
public void testProjectionInBuildRestLiResponseData() {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.hasParameter(RestConstants.ALT_KEY_PARAM)).andReturn(false);
EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
EasyMock.replay(mockContext);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
List<CreateKVResponse<Long, Foo>> createKVResponses = new ArrayList<CreateKVResponse<Long, Foo>>();
Foo foo = new Foo();
foo.setStringField("foo1");
foo.setFruitsField(Fruits.APPLE);
createKVResponses.add(new CreateKVResponse<Long, Foo>(1L, foo));
BatchCreateKVResult<Long, Foo> results = new BatchCreateKVResult<Long, Foo>(createKVResponses);
BatchCreateResponseBuilder responseBuilder = new BatchCreateResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(null, routingResult, results, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
Assert.assertTrue(responseData.getBatchCreateResponseEnvelope().isGetAfterCreate());
DataMap dataMap = responseData.getBatchCreateResponseEnvelope().getCreateResponses().get(0).getRecord().data().getDataMap("entity");
Assert.assertEquals(dataMap.size(), 1);
Assert.assertEquals(dataMap.get("fruitsField"), Fruits.APPLE.toString());
EasyMock.verify(mockContext);
}
Aggregations