Search in sources :

Example 11 with AnnotationSet

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

the class TestCreateArgumentBuilder method testArgumentBuilderSuccess.

@Test
public void testArgumentBuilderSuccess() {
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"a\":\"xyz\",\"b\":123}", 1);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
    Parameter<MyComplexKey> param = new Parameter<MyComplexKey>("", MyComplexKey.class, DataTemplateUtil.getSchema(MyComplexKey.class), false, null, Parameter.ParamType.POST, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 2, context, 1);
    RestLiArgumentBuilder argumentBuilder = new CreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof MyComplexKey);
    assertEquals(((MyComplexKey) args[0]).getA(), "xyz");
    assertEquals((long) ((MyComplexKey) args[0]).getB(), 123L);
    verify(request, model, descriptor, context, routingResult);
}
Also used : MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ResourceContext(com.linkedin.restli.server.ResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 12 with AnnotationSet

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

the class TestGetArgumentBuilder method asyncArgumentData.

@DataProvider(name = "asyncArgumentData")
private Object[][] asyncArgumentData() {
    List<Parameter<?>> callbackParams = new ArrayList<Parameter<?>>();
    callbackParams.add(getIntegerParam());
    @SuppressWarnings("rawtypes") Parameter<Callback> cParam = new Parameter<Callback>("", Callback.class, null, false, null, Parameter.ParamType.CALLBACK, false, new AnnotationSet(new Annotation[] {}));
    callbackParams.add(cParam);
    List<Parameter<?>> parSeqContextParams = new ArrayList<Parameter<?>>();
    parSeqContextParams.add(getIntegerParam());
    parSeqContextParams.add(new Parameter<Context>("", Context.class, null, false, null, Parameter.ParamType.PARSEQ_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
    List<Parameter<?>> deprecatedParSeqContextParams = new ArrayList<Parameter<?>>();
    deprecatedParSeqContextParams.add(getIntegerParam());
    @SuppressWarnings("deprecation") Parameter<Context> contextParam = new Parameter<Context>("", 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 : ResourceContext(com.linkedin.restli.server.ResourceContext) Context(com.linkedin.parseq.Context) 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)

Example 13 with AnnotationSet

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

the class TestGetArgumentBuilder method testHeaderArgument.

@Test
public void testHeaderArgument() {
    String keyName = "myComplexKeyCollectionId";
    Object keyValue = new Integer(123);
    DataSchema keySchema = new IntegerDataSchema();
    Key key = new Key(keyName, keyValue.getClass(), keySchema);
    Map<String, String> headers = new HashMap<String, String>();
    String headerString = "An extra string.";
    headers.put("extra", headerString);
    List<Parameter<?>> headerParams = new ArrayList<Parameter<?>>();
    headerParams.add(getIntegerParam());
    HeaderParam annotation = createMock(HeaderParam.class);
    expect(annotation.value()).andReturn("extra");
    AnnotationSet annotationSet = createMock(AnnotationSet.class);
    expect(annotationSet.getAll()).andReturn(new Annotation[] {});
    expect(annotationSet.get(HeaderParam.class)).andReturn(annotation);
    replay(annotation, annotationSet);
    Parameter<String> headerParam = new Parameter<String>("", String.class, null, false, null, Parameter.ParamType.HEADER, false, annotationSet);
    headerParams.add(headerParam);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, false);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, headerParams);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, headers, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
    RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs = new Object[] { keyValue, headerString };
    assertEquals(args, expectedArgs);
    verify(model, descriptor, context, routingResult, request, annotation, annotationSet);
}
Also used : HeaderParam(com.linkedin.restli.server.annotations.HeaderParam) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) ResourceContext(com.linkedin.restli.server.ResourceContext) HashMap(java.util.HashMap) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ArrayList(java.util.ArrayList) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) DataSchema(com.linkedin.data.schema.DataSchema) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) Parameter(com.linkedin.restli.internal.server.model.Parameter) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) 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) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 14 with AnnotationSet

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

the class TestPatchArgumentBuilder method argumentData.

@DataProvider(name = "argumentData")
private Object[][] argumentData() {
    @SuppressWarnings("rawtypes") Parameter<?> patchParam = new Parameter<PatchRequest>("", PatchRequest.class, null, 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(patchParam);
    List<Parameter<?>> simpleResourceParams = new ArrayList<Parameter<?>>();
    simpleResourceParams.add(patchParam);
    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(patchParam);
    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(patchParam);
    return new Object[][] { { collectionResourceParams, new Key("myComplexKeyCollectionId", Integer.class, new IntegerDataSchema()), "myComplexKeyCollectionId", 1234 }, { 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) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) 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 15 with AnnotationSet

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

the class TestBatchDeleteArgumentBuilder method testArgumentBuilderSuccess.

@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(Set<Object> batchKeys) {
    @SuppressWarnings("rawtypes") Parameter<Set> param = new Parameter<Set>("", Set.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, batchKeys, true);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 2);
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
    RestLiArgumentBuilder argumentBuilder = new BatchDeleteArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof BatchDeleteRequest);
    assertEquals(((BatchDeleteRequest) args[0]).getKeys(), batchKeys);
    verify(descriptor, context, routingResult, request);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) ResourceContext(com.linkedin.restli.server.ResourceContext) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Annotation(java.lang.annotation.Annotation) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) BatchDeleteRequest(com.linkedin.restli.server.BatchDeleteRequest) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

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