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[] {})));
}
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);
}
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);
}
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);
}
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);
}
Aggregations