use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testProjectionParamType.
@Test(dataProvider = "projectionParameterData")
@SuppressWarnings("deprecation")
public void testProjectionParamType(Parameter.ParamType paramType) {
String testParamKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
MaskTree mockMask = EasyMock.createMock(MaskTree.class);
if (paramType == Parameter.ParamType.PROJECTION_PARAM || paramType == Parameter.ParamType.PROJECTION) {
EasyMock.expect(mockResourceContext.getProjectionMask()).andReturn(mockMask);
} else if (paramType == Parameter.ParamType.METADATA_PROJECTION_PARAM) {
EasyMock.expect(mockResourceContext.getMetadataProjectionMask()).andReturn(mockMask);
} else {
EasyMock.expect(mockResourceContext.getPagingProjectionMask()).andReturn(mockMask);
}
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
Parameter<MaskTree> param = new Parameter<MaskTree>(testParamKey, MaskTree.class, 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], mockMask);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testResourceContextParameterType.
@Test
@SuppressWarnings("deprecation")
public void testResourceContextParameterType() {
String testParamKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
List<Parameter<?>> parameters = new ArrayList<Parameter<?>>();
Parameter<ResourceContext> param1 = new Parameter<ResourceContext>(testParamKey, ResourceContext.class, null, false, null, Parameter.ParamType.RESOURCE_CONTEXT, false, AnnotationSet.EMPTY);
Parameter<ResourceContext> param2 = new Parameter<ResourceContext>(testParamKey, ResourceContext.class, null, false, null, Parameter.ParamType.RESOURCE_CONTEXT_PARAM, false, AnnotationSet.EMPTY);
parameters.add(param1);
parameters.add(param2);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], mockResourceContext);
Assert.assertEquals(results[1], mockResourceContext);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testHeaderParamType.
@Test
public void testHeaderParamType() {
String testParamKey = "testParam";
String expectedTestParamValue = "testParamValue";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
HeaderParam annotation = EasyMock.createMock(HeaderParam.class);
EasyMock.expect(annotation.value()).andReturn(testParamKey);
AnnotationSet annotationSet = EasyMock.createMock(AnnotationSet.class);
EasyMock.expect(annotationSet.getAll()).andReturn(new Annotation[] {});
EasyMock.expect(annotationSet.get(HeaderParam.class)).andReturn(annotation);
Map<String, String> headers = new HashMap<String, String>();
headers.put(testParamKey, expectedTestParamValue);
EasyMock.expect(mockResourceContext.getRequestHeaders()).andReturn(headers);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext, annotation, annotationSet);
Parameter<String> param = new Parameter<String>(testParamKey, String.class, DataSchemaConstants.STRING_DATA_SCHEMA, false, null, Parameter.ParamType.HEADER, false, annotationSet);
List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], expectedTestParamValue);
}
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.");
}
}
Aggregations