Search in sources :

Example 1 with AnnotationSet

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

the class TestActionArgumentBuilder method getEnumParams.

private List<Parameter<?>> getEnumParams() {
    EnumDataSchema simpleEnumSchema = new EnumDataSchema(new Name("com.linkedin.restli.common.test.SimpleEnum"));
    simpleEnumSchema.setSymbols(Arrays.asList("A", "B", "C"), null);
    return Collections.<Parameter<?>>singletonList(new Parameter<SimpleEnum>("simpleEnum", SimpleEnum.class, simpleEnumSchema, false, null, Parameter.ParamType.POST, true, new AnnotationSet(new Annotation[] {})));
}
Also used : EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) SimpleEnum(com.linkedin.restli.common.test.SimpleEnum) Parameter(com.linkedin.restli.internal.server.model.Parameter) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Name(com.linkedin.data.schema.Name)

Example 2 with AnnotationSet

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

the class TestArgumentBuilder method testHeaderParamType.

@Test
public void testHeaderParamType() {
    String testParamKey = "testParam";
    String expectedTestParamValue = "testParamValue";
    ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
    HeaderParam annotation = EasyMock.createMock(HeaderParam.class);
    EasyMock.expect(annotation.value()).andReturn(testParamKey);
    AnnotationSet annotationSet = EasyMock.createMock(AnnotationSet.class);
    EasyMock.expect(annotationSet.getAll()).andReturn(new Annotation[] {});
    EasyMock.expect(annotationSet.get(HeaderParam.class)).andReturn(annotation);
    Map<String, String> headers = new HashMap<String, String>();
    headers.put(testParamKey, expectedTestParamValue);
    EasyMock.expect(mockResourceContext.getRequestHeaders()).andReturn(headers);
    EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
    EasyMock.replay(mockResourceContext, annotation, annotationSet);
    Parameter<String> param = new Parameter<String>(testParamKey, String.class, DataSchemaConstants.STRING_DATA_SCHEMA, false, null, Parameter.ParamType.HEADER, false, annotationSet);
    List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
    Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
    Assert.assertEquals(results[0], expectedTestParamValue);
}
Also used : HeaderParam(com.linkedin.restli.server.annotations.HeaderParam) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) HashMap(java.util.HashMap) AnnotationSet(com.linkedin.restli.internal.server.model.AnnotationSet) Parameter(com.linkedin.restli.internal.server.model.Parameter) Test(org.testng.annotations.Test)

Example 3 with AnnotationSet

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

the class TestBatchCreateArgumentBuilder method testArgumentBuilderSuccess.

@Test
public void testArgumentBuilderSuccess() {
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"elements\":[{\"b\":123,\"a\":\"abc\"},{\"b\":5678,\"a\":\"xyzw\"}]}", 1);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
    @SuppressWarnings("rawtypes") Parameter<BatchCreateRequest> param = new Parameter<BatchCreateRequest>("", BatchCreateRequest.class, null, false, null, Parameter.ParamType.BATCH, 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 BatchCreateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof BatchCreateRequest);
    @SuppressWarnings("unchecked") List<MyComplexKey> entities = ((BatchCreateRequest<Integer, MyComplexKey>) args[0]).getInput();
    assertEquals(entities.size(), 2);
    assertEquals(entities.get(0).getA(), "abc");
    assertEquals((long) entities.get(0).getB(), 123L);
    assertEquals(entities.get(1).getA(), "xyzw");
    assertEquals((long) entities.get(1).getB(), 5678L);
    verify(request, model, descriptor, context, routingResult);
}
Also used : BatchCreateRequest(com.linkedin.restli.server.BatchCreateRequest) ResourceContext(com.linkedin.restli.server.ResourceContext) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) 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 4 with AnnotationSet

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

the class TestBatchGetArgumentBuilder 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 BatchGetArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    Object[] expectedArgs = new Object[] { batchKeys };
    assertEquals(args, expectedArgs);
    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) Parameter(com.linkedin.restli.internal.server.model.Parameter) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 5 with AnnotationSet

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

the class TestBatchUpdateArgumentBuilder method testArgumentBuilderSuccess.

@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys) {
    Set<Object> batchKeys = new HashSet<Object>(Arrays.asList(keys));
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
    @SuppressWarnings("rawtypes") Parameter<BatchUpdateRequest> param = new Parameter<BatchUpdateRequest>("", BatchUpdateRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 3, Collections.singletonList(param));
    ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, true, false);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
    RestLiArgumentBuilder argumentBuilder = new BatchUpdateArgumentBuilder();
    RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
    Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
    assertEquals(args.length, 1);
    assertTrue(args[0] instanceof BatchUpdateRequest);
    Map<?, ?> data = ((BatchUpdateRequest) args[0]).getData();
    assertEquals(data.size(), 2);
    MyComplexKey entity1 = (MyComplexKey) data.get(keys[0]);
    MyComplexKey entity2 = (MyComplexKey) data.get(keys[1]);
    assertEquals(entity1.getA(), "abc");
    assertEquals((long) entity1.getB(), 123L);
    assertEquals(entity2.getA(), "XY");
    assertEquals((long) entity2.getB(), 456L);
    verify(request, model, descriptor, context, routingResult);
}
Also used : ResourceContext(com.linkedin.restli.server.ResourceContext) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) BatchUpdateRequest(com.linkedin.restli.server.BatchUpdateRequest) 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) HashSet(java.util.HashSet) 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