use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testNoOpParamType.
@Test(dataProvider = "noOpParameterData")
public void testNoOpParamType(Class<?> dataType, Parameter.ParamType paramType) {
String paramKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter(paramKey, dataType, null, false, null, paramType, false, AnnotationSet.EMPTY);
List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], null);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testRestLiAttachmentsParamResourceNotExpect.
@Test
public void testRestLiAttachmentsParamResourceNotExpect() {
//This test makes sure that if the resource method did not expect attachments but there were attachments present
//in the request, that an exception is thrown.
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
final RestLiAttachmentReader restLiAttachmentReader = new RestLiAttachmentReader(null);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(restLiAttachmentReader);
EasyMock.replay(mockResourceContext);
List<Parameter<?>> parameters = Collections.<Parameter<?>>emptyList();
try {
ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.fail();
} catch (RestLiServiceException restLiServiceException) {
Assert.assertEquals(restLiServiceException.getStatus(), HttpStatus.S_400_BAD_REQUEST);
Assert.assertEquals(restLiServiceException.getMessage(), "Resource method endpoint invoked does not accept any request attachments.");
}
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testRestLiAttachmentsParamResourceExpectNotPresent.
@Test
public void testRestLiAttachmentsParamResourceExpectNotPresent() {
//This test makes sure that a resource method that expects attachments, but none are present in the request,
//is given a null for the RestLiAttachmentReader.
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
@SuppressWarnings({ "unchecked", "rawtypes" }) final Parameter<RestLiAttachmentReader> param = new Parameter("RestLi Attachment Reader", RestLiAttachmentReader.class, null, false, null, Parameter.ParamType.RESTLI_ATTACHMENTS_PARAM, false, AnnotationSet.EMPTY);
List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], null);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestBatchUpdateResponseBuilder method testContextErrors.
@Test
public void testContextErrors() {
BatchUpdateResponseBuilder builder = new BatchUpdateResponseBuilder(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 envelope = builder.buildRestLiResponseData(null, routingResult, new BatchUpdateResult<Object, Integer>(Collections.<Object, UpdateResponse>emptyMap()), Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
Assert.assertEquals(envelope.getBatchResponseEnvelope().getBatchResponseMap().get("foo").getException(), exception);
Assert.assertEquals(envelope.getBatchResponseEnvelope().getBatchResponseMap().size(), 1);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestCreateResponseBuilder method getMockResourceContext.
private static ResourceContext getMockResourceContext(ProtocolVersion protocolVersion, String altKeyName) {
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.getRestliProtocolVersion()).andReturn(protocolVersion).once();
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;
}
Aggregations