use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestRestLiRouting method testStreamingResourceContext.
//This test verifies that the router can create the correct resource context based on attachments being
//present in the request or an accept type indicating a desire to receive response attachments.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimpleStreaming")
public void testStreamingResourceContext(ProtocolVersion version, String uri, String acceptHeader, RestLiAttachmentReader requestAttachments) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
_router = new RestLiRouter(pathRootResourceMap);
final RestRequestBuilder requestBuilder = new RestRequestBuilder(new URI(uri)).setMethod("GET").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
if (acceptHeader != null) {
requestBuilder.setHeader(RestConstants.HEADER_ACCEPT, acceptHeader);
}
final RestRequest request = requestBuilder.build();
RoutingResult result = _router.process(request, new RequestContext(), requestAttachments);
assertNotNull(result);
final ServerResourceContext resourceContext = (ServerResourceContext) result.getContext();
if (requestAttachments != null) {
Assert.assertEquals(resourceContext.getRequestAttachmentReader(), requestAttachments);
} else {
Assert.assertNull(resourceContext.getRequestAttachmentReader());
}
if (acceptHeader != null && acceptHeader.contains("multipart/related")) {
Assert.assertTrue(resourceContext.responseAttachmentsSupported());
} else {
Assert.assertFalse(resourceContext.responseAttachmentsSupported());
}
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testQueryParameterType.
@Test
public void testQueryParameterType() {
String testParamKey = "testParam";
String expectedTestParamValue = "testParamValue";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockResourceContext.getParameter(testParamKey)).andReturn(expectedTestParamValue).anyTimes();
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
Parameter<String> param = new Parameter<String>(testParamKey, String.class, DataSchemaConstants.STRING_DATA_SCHEMA, false, null, Parameter.ParamType.QUERY, 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], expectedTestParamValue);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testPostParameterType.
@Test
public void testPostParameterType() {
String testParamKey = "testParam";
String expectedTestParamValue = "testParamValue";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
DataMap entityBody = new DataMap();
entityBody.put(testParamKey, expectedTestParamValue);
DynamicRecordTemplate template = new DynamicRecordTemplate(entityBody, null);
Parameter<String> param = new Parameter<String>(testParamKey, String.class, DataSchemaConstants.STRING_DATA_SCHEMA, false, null, Parameter.ParamType.POST, false, AnnotationSet.EMPTY);
List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, template);
Assert.assertEquals(results[0], expectedTestParamValue);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testRestLiAttachmentsParam.
@Test
public void testRestLiAttachmentsParam() {
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
final RestLiAttachmentReader restLiAttachmentReader = new RestLiAttachmentReader(null);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(restLiAttachmentReader);
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], restLiAttachmentReader);
}
use of com.linkedin.restli.internal.server.ServerResourceContext in project rest.li by linkedin.
the class TestArgumentBuilder method testPathKeyParameterType.
@Test
@SuppressWarnings("deprecation")
public void testPathKeyParameterType() {
String testParamKey = "testParam";
String expectedTestParamValue = "testParamValue";
// mock setup
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
MutablePathKeys mockPathKeys = EasyMock.createMock(MutablePathKeys.class);
EasyMock.expect(mockPathKeys.get(testParamKey)).andReturn(expectedTestParamValue).anyTimes();
EasyMock.expect(mockResourceContext.getPathKeys()).andReturn(mockPathKeys).anyTimes();
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext, mockPathKeys);
List<Parameter<?>> parameters = new ArrayList<Parameter<?>>();
Parameter<String> param1 = new Parameter<String>(testParamKey, String.class, null, false, null, Parameter.ParamType.KEY, false, AnnotationSet.EMPTY);
Parameter<String> param2 = new Parameter<String>(testParamKey, String.class, null, false, null, Parameter.ParamType.ASSOC_KEY_PARAM, false, AnnotationSet.EMPTY);
Parameter<PathKeys> param3 = new Parameter<PathKeys>(testParamKey, PathKeys.class, null, false, null, Parameter.ParamType.PATH_KEYS, false, AnnotationSet.EMPTY);
Parameter<PathKeys> param4 = new Parameter<PathKeys>(testParamKey, PathKeys.class, null, false, null, Parameter.ParamType.PATH_KEYS_PARAM, false, AnnotationSet.EMPTY);
parameters.add(param1);
parameters.add(param2);
parameters.add(param3);
parameters.add(param4);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], expectedTestParamValue);
Assert.assertEquals(results[1], expectedTestParamValue);
Assert.assertEquals(results[2], mockPathKeys);
Assert.assertEquals(results[3], mockPathKeys);
}
Aggregations