use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testUnstructuredDataWriterParam.
@Test
public void testUnstructuredDataWriterParam() {
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
mockResourceContext.setResponseEntityStream(EasyMock.anyObject());
EasyMock.expectLastCall().once();
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
@SuppressWarnings({ "unchecked", "rawtypes" }) final Parameter<UnstructuredDataWriterParam> param = new Parameter("RestLi Unstructured Data Writer", UnstructuredDataWriter.class, null, false, null, Parameter.ParamType.UNSTRUCTURED_DATA_WRITER_PARAM, false, AnnotationSet.EMPTY);
List<Parameter<?>> parameters = Collections.singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
UnstructuredDataWriter result = (UnstructuredDataWriter) results[0];
Assert.assertNotNull(result);
Assert.assertTrue(result.getOutputStream() instanceof ByteArrayOutputStream);
EasyMock.verify(mockResourceContext);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testPositionalParameterType.
@Test(expectedExceptions = RoutingException.class, dataProvider = "positionalParameterData")
public void testPositionalParameterType(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.singletonList(param);
ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestBatchFinderResponseBuilder method getMockRoutingResult.
private static RoutingResult getMockRoutingResult(List<Criteria> criteria, ProtocolVersion protocolVersion) {
DataList param = new DataList();
for (int i = 0; i < criteria.size(); i++) {
param.add(criteria.get(i).criteria.data());
}
MaskTree mockMask = EasyMock.createMock(MaskTree.class);
EasyMock.expect(mockMask.getDataMap()).andStubReturn(new DataMap());
EasyMock.replay(mockMask);
ResourceContextImpl mockContext = EasyMock.createMock(ResourceContextImpl.class);
DataMap batch_method = new DataMap();
batch_method.put("bq", BATCH_METHOD);
EasyMock.expect(mockContext.getRestliProtocolVersion()).andStubReturn(protocolVersion);
EasyMock.expect(mockContext.getStructuredParameter(BATCH_PARAM)).andStubReturn(param);
EasyMock.expect(mockContext.getParameters()).andStubReturn(batch_method);
EasyMock.expect(mockContext.getParameter("start")).andStubReturn("0");
EasyMock.expect(mockContext.getParameter("count")).andStubReturn(Integer.toString(PAGE_COUNT));
EasyMock.expect(mockContext.getRequestHeaders()).andStubReturn(new HashMap<>());
EasyMock.expect(mockContext.getPagingProjectionMask()).andStubReturn(null);
EasyMock.expect(mockContext.getProjectionMode()).andStubReturn(ProjectionMode.MANUAL);
EasyMock.expect(mockContext.getProjectionMask()).andStubReturn(mockMask);
EasyMock.expect(mockContext.getMetadataProjectionMask()).andStubReturn(mockMask);
EasyMock.expect(mockContext.getMetadataProjectionMode()).andStubReturn(ProjectionMode.MANUAL);
EasyMock.expect(mockContext.getRawRequestContext()).andStubReturn(new RequestContext());
EasyMock.expect(mockContext.getAlwaysProjectedFields()).andReturn(Collections.emptySet()).anyTimes();
EasyMock.expect(mockContext.isFillInDefaultsRequested()).andStubReturn(false);
EasyMock.replay(mockContext);
List<Parameter<?>> parameterList = new ArrayList<>();
parameterList.add(new Parameter<>(BATCH_PARAM, String.class, null, false, null, Parameter.ParamType.QUERY, true, AnnotationSet.EMPTY));
ResourceMethodDescriptor mockDescriptor = EasyMock.createMock(ResourceMethodDescriptor.class);
EasyMock.expect(mockDescriptor.getAnnotation(BatchFinder.class)).andStubReturn(getInstanceOfAnnotation(BATCH_PARAM, BATCH_PARAM));
EasyMock.expect(mockDescriptor.getParametersWithType(Parameter.ParamType.PAGING_CONTEXT_PARAM)).andStubReturn(getPagingContextParam());
EasyMock.expect(mockDescriptor.getBatchFinderCriteriaParamIndex()).andStubReturn(0);
EasyMock.expect(mockDescriptor.getParameters()).andStubReturn(parameterList);
EasyMock.replay(mockDescriptor);
RoutingResult mockRoutingResult = EasyMock.createMock(RoutingResult.class);
EasyMock.expect(mockRoutingResult.getResourceMethod()).andStubReturn(mockDescriptor);
EasyMock.expect(mockRoutingResult.getContext()).andStubReturn(mockContext);
EasyMock.replay(mockRoutingResult);
return mockRoutingResult;
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testProjectionParams.
@Test
public void testProjectionParams() throws IOException {
List<Parameter<?>> finderWithProjectionParams = new ArrayList<>();
finderWithProjectionParams.add(new Parameter<>("key", String.class, new StringDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", PagingContext.class, null, false, new PagingContext(0, 10), Parameter.ParamType.PAGING_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", MaskTree.class, null, false, null, Parameter.ParamType.PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", MaskTree.class, null, false, null, Parameter.ParamType.METADATA_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", MaskTree.class, null, false, null, Parameter.ParamType.PAGING_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
Map<String, String> finderWithProjectionContextParams = new HashMap<>();
finderWithProjectionContextParams.put("start", "100");
finderWithProjectionContextParams.put("count", "15");
finderWithProjectionContextParams.put("key", "keyString");
Map<String, Integer> projectionMap = new HashMap<>();
projectionMap.put("a", 1);
Map<String, Integer> metadataMap = new HashMap<>();
metadataMap.put("intField", 1);
metadataMap.put("booleanField", 1);
Map<String, Integer> pagingMap = new HashMap<>();
pagingMap.put("total", 1);
MaskTree projectionMask = new MaskTree(new DataMap(projectionMap));
MaskTree metadataMask = new MaskTree(new DataMap(metadataMap));
MaskTree pagingMask = new MaskTree(new DataMap(pagingMap));
Object[] expectedArgs = new Object[] { "keyString", new PagingContext(100, 15), projectionMask, metadataMask, pagingMask };
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, 1, finderWithProjectionParams);
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(finderWithProjectionContextParams, projectionMask, metadataMask, pagingMask, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestGetArgumentBuilder method asyncArgumentData.
@DataProvider(name = "asyncArgumentData")
private Object[][] asyncArgumentData() {
List<Parameter<?>> callbackParams = new ArrayList<>();
callbackParams.add(getIntegerParam());
@SuppressWarnings("rawtypes") Parameter<Callback> cParam = new Parameter<>("", Callback.class, null, false, null, Parameter.ParamType.CALLBACK, false, new AnnotationSet(new Annotation[] {}));
callbackParams.add(cParam);
List<Parameter<?>> parSeqContextParams = new ArrayList<>();
parSeqContextParams.add(getIntegerParam());
parSeqContextParams.add(new Parameter<>("", Context.class, null, false, null, Parameter.ParamType.PARSEQ_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
List<Parameter<?>> deprecatedParSeqContextParams = new ArrayList<>();
deprecatedParSeqContextParams.add(getIntegerParam());
@SuppressWarnings("deprecation") Parameter<Context> contextParam = new Parameter<>("", Context.class, null, false, null, Parameter.ParamType.PARSEQ_CONTEXT, false, new AnnotationSet(new Annotation[] {}));
deprecatedParSeqContextParams.add(contextParam);
return new Object[][] { { callbackParams }, { parSeqContextParams }, { deprecatedParSeqContextParams } };
}
Aggregations