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);
}
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 } };
}
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);
}
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()) } };
}
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);
}
Aggregations