Search in sources :

Example 6 with AnnotationSet

use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.

the class TestCollectionArgumentBuilder method complexArrayArgument.

@DataProvider(name = "complexArrayArgument")
private Object[][] complexArrayArgument() {
    Map<String, String> map1 = new HashMap<String, String>();
    map1.put("a", "A1");
    map1.put("b", "111");
    Map<String, String> map2 = new HashMap<String, String>();
    map2.put("a", "A2");
    map2.put("b", "222");
    Map<String, String> map3 = new HashMap<String, String>();
    map3.put("a", "A3");
    map3.put("b", "333");
    DataList data = new DataList();
    data.add(new DataMap(map1));
    data.add(new DataMap(map2));
    data.add(new DataMap(map3));
    return new Object[][] { { new Parameter<MyComplexKey[]>("myComplexKeys", MyComplexKey[].class, new ArrayDataSchema(DataTemplateUtil.getSchema(MyComplexKey.class)), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {})), "myComplexKeys", "{b=111, a=A1}", data, new Object[] { new MyComplexKey[] { new MyComplexKey().setA("A1").setB(111L), new MyComplexKey().setA("A2").setB(222L), new MyComplexKey().setA("A3").setB(333L) } } } };
}
Also used : DataList(com.linkedin.data.DataList) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) HashMap(java.util.HashMap) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) DataMap(com.linkedin.data.DataMap) DataProvider(org.testng.annotations.DataProvider)

Example 7 with AnnotationSet

use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.

the class TestCollectionArgumentBuilder method argumentData.

@DataProvider(name = "argumentData")
private Object[][] argumentData() {
    List<Parameter<?>> getAllParams = new ArrayList<Parameter<?>>();
    getAllParams.add(getPagingContextParam());
    Map<String, String> getAllContextParams = new HashMap<String, String>();
    getAllContextParams.put("start", "33");
    getAllContextParams.put("count", "444");
    Map<String, String> finderContextParams = new HashMap<String, String>();
    finderContextParams.put("start", "33");
    finderContextParams.put("count", "444");
    finderContextParams.put("required", "777");
    finderContextParams.put("optional", null);
    Map<String, String> finderContextParamsWithOptionalString = new HashMap<String, String>(finderContextParams);
    finderContextParamsWithOptionalString.put("optional", "someString");
    List<Parameter<?>> finderWithAssocKeyParams = new ArrayList<Parameter<?>>();
    finderWithAssocKeyParams.add(new Parameter<String>("string1", String.class, new StringDataSchema(), false, null, Parameter.ParamType.ASSOC_KEY_PARAM, true, new AnnotationSet(new Annotation[] {})));
    return new Object[][] { { getAllParams, getAllContextParams, null, new Object[] { new PagingContext(33, 444) } }, { getFinderParams(), finderContextParams, null, new Object[] { new PagingContext(33, 444), new Integer(777), null } }, { getFinderParams(), finderContextParamsWithOptionalString, null, new Object[] { new PagingContext(33, 444), new Integer(777), "someString" } }, { finderWithAssocKeyParams, null, new PathKeysImpl().append("string1", "testString"), new Object[] { "testString" } } };
}
Also used : HashMap(java.util.HashMap) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) StringDataSchema(com.linkedin.data.schema.StringDataSchema) PagingContext(com.linkedin.restli.server.PagingContext) Parameter(com.linkedin.restli.internal.server.model.Parameter) DataProvider(org.testng.annotations.DataProvider)

Example 8 with AnnotationSet

use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.

the class TestUpdateArgumentBuilder method argumentData.

@DataProvider(name = "argumentData")
private Object[][] argumentData() {
    Parameter<?> myComplexKeyParam = new Parameter<MyComplexKey>("", MyComplexKey.class, DataTemplateUtil.getSchema(MyComplexKey.class), false, null, Parameter.ParamType.POST, false, new AnnotationSet(new Annotation[] {}));
    List<Parameter<?>> collectionResourceParams = new ArrayList<Parameter<?>>();
    collectionResourceParams.add(new Parameter<Integer>("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
    collectionResourceParams.add(myComplexKeyParam);
    List<Parameter<?>> simpleResourceParams = new ArrayList<Parameter<?>>();
    simpleResourceParams.add(myComplexKeyParam);
    List<Parameter<?>> associationResourceParams = new ArrayList<Parameter<?>>();
    associationResourceParams.add(new Parameter<CompoundKey>("myComplexKeyAssociationId", CompoundKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {})));
    associationResourceParams.add(myComplexKeyParam);
    List<Parameter<?>> complexResourceKeyParams = new ArrayList<Parameter<?>>();
    @SuppressWarnings("rawtypes") Parameter<ComplexResourceKey> complexResourceKeyParam = new Parameter<ComplexResourceKey>("complexKeyTestId", ComplexResourceKey.class, null, false, null, Parameter.ParamType.RESOURCE_KEY, false, new AnnotationSet(new Annotation[] {}));
    complexResourceKeyParams.add(complexResourceKeyParam);
    complexResourceKeyParams.add(myComplexKeyParam);
    return new Object[][] { { collectionResourceParams, new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()), "myComplexKeyCollectionId", 4545 }, { simpleResourceParams, null, null, null }, { associationResourceParams, new Key("myComplexKeyAssociationId", CompoundKey.class, null), "myComplexKeyAssociationId", new CompoundKey().append("string1", "apples").append("string2", "oranges") }, { complexResourceKeyParams, new Key("complexKeyTestId", ComplexResourceKey.class, null), "complexKeyTestId", new ComplexResourceKey<MyComplexKey, EmptyRecord>(new MyComplexKey().setA("keyString").setB(1234L), new EmptyRecord()) } };
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) CompoundKey(com.linkedin.restli.common.CompoundKey) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Parameter(com.linkedin.restli.internal.server.model.Parameter) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) DataProvider(org.testng.annotations.DataProvider)

Example 9 with AnnotationSet

use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.

the class TestCollectionArgumentBuilder method testProjectionParams.

@Test
public void testProjectionParams() {
    List<Parameter<?>> finderWithProjectionParams = new ArrayList<Parameter<?>>();
    finderWithProjectionParams.add(new Parameter<String>("key", String.class, new StringDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<PagingContext>("", PagingContext.class, null, false, new PagingContext(0, 10), Parameter.ParamType.PAGING_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<MaskTree>("", MaskTree.class, null, false, null, Parameter.ParamType.PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<MaskTree>("", MaskTree.class, null, false, null, Parameter.ParamType.METADATA_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
    finderWithProjectionParams.add(new Parameter<MaskTree>("", MaskTree.class, null, false, null, Parameter.ParamType.PAGING_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
    Map<String, String> finderWithProjectionContextParams = new HashMap<String, String>();
    finderWithProjectionContextParams.put("start", "100");
    finderWithProjectionContextParams.put("count", "15");
    finderWithProjectionContextParams.put("key", "keyString");
    Map<String, Integer> projectionMap = new HashMap<String, Integer>();
    projectionMap.put("a", 1);
    Map<String, Integer> metadataMap = new HashMap<String, Integer>();
    metadataMap.put("intField", 1);
    metadataMap.put("booleanField", 1);
    Map<String, Integer> pagingMap = new HashMap<String, Integer>();
    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);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(finderWithProjectionContextParams, projectionMask, metadataMask, pagingMask, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
    RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args, expectedArgs);
    verify(descriptor, context, routingResult, request);
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) 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) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) StringDataSchema(com.linkedin.data.schema.StringDataSchema) RestRequest(com.linkedin.r2.message.rest.RestRequest) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) 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 10 with AnnotationSet

use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.

the class TestCollectionArgumentBuilder method getFinderParams.

private List<Parameter<?>> getFinderParams() {
    List<Parameter<?>> finderParams = new ArrayList<Parameter<?>>();
    finderParams.add(getPagingContextParam());
    Parameter<Integer> requiredIntParam = new Parameter<Integer>("required", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {}));
    finderParams.add(requiredIntParam);
    Parameter<String> optionalStringParam = new Parameter<String>("optional", String.class, new StringDataSchema(), true, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {}));
    finderParams.add(optionalStringParam);
    return finderParams;
}
Also used : StringDataSchema(com.linkedin.data.schema.StringDataSchema) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) 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)

Aggregations

AnnotationSet (com.linkedin.restli.internal.server.model.AnnotationSet)17 Parameter (com.linkedin.restli.internal.server.model.Parameter)15 Annotation (java.lang.annotation.Annotation)10 ResourceContext (com.linkedin.restli.server.ResourceContext)9 Test (org.testng.annotations.Test)9 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)8 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)8 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)8 ArrayList (java.util.ArrayList)8 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)7 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)5 HashMap (java.util.HashMap)5 DataProvider (org.testng.annotations.DataProvider)5 IntegerDataSchema (com.linkedin.data.schema.IntegerDataSchema)4 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)4 HashSet (java.util.HashSet)4 StringDataSchema (com.linkedin.data.schema.StringDataSchema)3 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)3 CompoundKey (com.linkedin.restli.common.CompoundKey)3