use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchCreateResponseBuilder method getMockResourceContext.
private static ResourceContext getMockResourceContext(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();
}
EasyMock.replay(mockContext);
return mockContext;
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchGetResponseBuilder method getMockResourceContext.
private static ResourceContext getMockResourceContext(ProtocolVersion protocolVersion, Map<Object, RestLiServiceException> exceptions, String altKeyName, MaskTree maskTree, ProjectionMode projectionMode) {
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.getBatchKeyErrors()).andReturn(exceptions).once();
EasyMock.expect(mockContext.getProjectionMode()).andReturn(projectionMode).times(2);
EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree).times(2);
EasyMock.expect(mockContext.getRestliProtocolVersion()).andReturn(protocolVersion).once();
EasyMock.expect(mockContext.hasParameter(RestConstants.ALT_KEY_PARAM)).andReturn(altKeyName != null).anyTimes();
if (altKeyName != null) {
EasyMock.expect(mockContext.getParameter(RestConstants.ALT_KEY_PARAM)).andReturn(altKeyName).atLeastOnce();
}
EasyMock.replay(mockContext);
return mockContext;
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchGetResponseBuilder 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.expect(mockContext.getBatchKeyErrors()).andReturn(Collections.<Object, RestLiServiceException>emptyMap()).once();
EasyMock.replay(mockContext);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
Map<Integer, Foo> results = new HashMap<Integer, Foo>();
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
results.put(1, value);
BatchGetResponseBuilder responseBuilder = new BatchGetResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(null, routingResult, results, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
RecordTemplate record = responseData.getBatchResponseEnvelope().getBatchResponseMap().get(1).getRecord();
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
EasyMock.verify(mockContext);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchGetResponseBuilder method testContextErrors.
@Test
public void testContextErrors() {
BatchGetResponseBuilder builder = new BatchGetResponseBuilder(new ErrorResponseBuilder());
ServerResourceContext context = EasyMock.createMock(ServerResourceContext.class);
Map<Object, RestLiServiceException> errors = new HashMap<Object, RestLiServiceException>();
RestLiServiceException exception = new RestLiServiceException(HttpStatus.S_402_PAYMENT_REQUIRED);
errors.put("foo", exception);
EasyMock.expect(context.hasParameter("altkey")).andReturn(false);
EasyMock.expect(context.getBatchKeyErrors()).andReturn(errors);
EasyMock.replay(context);
RoutingResult routingResult = new RoutingResult(context, null);
RestLiResponseData responseData = builder.buildRestLiResponseData(null, routingResult, new BatchResult<Object, EmptyRecord>(Collections.<Object, EmptyRecord>emptyMap(), Collections.<Object, RestLiServiceException>emptyMap()), Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
Assert.assertEquals(responseData.getBatchResponseEnvelope().getBatchResponseMap().get("foo").getException(), exception);
Assert.assertEquals(responseData.getBatchResponseEnvelope().getBatchResponseMap().size(), 1);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testBuildOptionalArg.
// utility method for reuse
private Object[] testBuildOptionalArg(Parameter<?> param) {
String paramKey = param.getName();
Class<?> dataType = param.getType();
Parameter.ParamType paramType = param.getParamType();
// mock resource context
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
DynamicRecordTemplate template = null;
if (paramType == Parameter.ParamType.POST) {
template = new DynamicRecordTemplate(new DataMap(), null);
} else {
MutablePathKeys mockPathKeys = EasyMock.createMock(MutablePathKeys.class);
EasyMock.expect(mockPathKeys.get(paramKey)).andReturn(null);
EasyMock.expect(mockResourceContext.getPathKeys()).andReturn(mockPathKeys);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
if (DataTemplate.class.isAssignableFrom(dataType)) {
EasyMock.expect(mockResourceContext.getStructuredParameter(paramKey)).andReturn(null);
} else {
EasyMock.expect(mockResourceContext.getParameter(paramKey)).andReturn(null);
}
EasyMock.replay(mockResourceContext);
}
// invoke buildArgs
List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
return ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, template);
}
Aggregations