Search in sources :

Example 26 with Parameter

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);
}
Also used : ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) UnstructuredDataWriterParam(com.linkedin.restli.server.annotations.UnstructuredDataWriterParam) Parameter(com.linkedin.restli.internal.server.model.Parameter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnstructuredDataWriter(com.linkedin.restli.server.UnstructuredDataWriter) Test(org.testng.annotations.Test)

Example 27 with Parameter

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));
}
Also used : ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) Parameter(com.linkedin.restli.internal.server.model.Parameter) Test(org.testng.annotations.Test)

Example 28 with Parameter

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;
}
Also used : ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ArrayList(java.util.ArrayList) DataMap(com.linkedin.data.DataMap) QueryParamsDataMap(com.linkedin.restli.internal.common.QueryParamsDataMap) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) DataList(com.linkedin.data.DataList) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) Parameter(com.linkedin.restli.internal.server.model.Parameter) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 29 with Parameter

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);
}
Also used : HashMap(java.util.HashMap) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) DataMap(com.linkedin.data.DataMap) StringDataSchema(com.linkedin.data.schema.StringDataSchema) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PagingContext(com.linkedin.restli.server.PagingContext) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 30 with Parameter

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 } };
}
Also used : Context(com.linkedin.parseq.Context) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) Callback(com.linkedin.common.callback.Callback) ArrayList(java.util.ArrayList) Parameter(com.linkedin.restli.internal.server.model.Parameter) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) DataProvider(org.testng.annotations.DataProvider)

Aggregations

Parameter (com.linkedin.restli.internal.server.model.Parameter)42 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)29 Test (org.testng.annotations.Test)29 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)17 AnnotationSet (com.linkedin.restli.internal.server.model.AnnotationSet)14 ArrayList (java.util.ArrayList)13 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)12 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)11 RestRequest (com.linkedin.r2.message.rest.RestRequest)10 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)10 Annotation (java.lang.annotation.Annotation)10 DataMap (com.linkedin.data.DataMap)9 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)8 PagingContext (com.linkedin.restli.server.PagingContext)6 Callback (com.linkedin.common.callback.Callback)5 IntegerDataSchema (com.linkedin.data.schema.IntegerDataSchema)5 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)5 CompoundKey (com.linkedin.restli.common.CompoundKey)5 Key (com.linkedin.restli.server.Key)5 HashMap (java.util.HashMap)5