use of com.linkedin.restli.internal.server.model.Parameter 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<>();
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<>(testParamKey, String.class, DataSchemaConstants.STRING_DATA_SCHEMA, false, null, Parameter.ParamType.HEADER, false, annotationSet);
List<Parameter<?>> parameters = Collections.singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
Assert.assertEquals(results[0], expectedTestParamValue);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testNoOpParamType.
@Test(dataProvider = "noOpParameterData")
public void testNoOpParamType(Class<?> dataType, Parameter.ParamType paramType) {
String paramKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter(paramKey, dataType, null, false, null, paramType, false, AnnotationSet.EMPTY);
List<Parameter<?>> parameters = Collections.singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
Assert.assertEquals(results[0], null);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testBuildOptionalArg.
// utility method for reuse
private Object[] testBuildOptionalArg(Parameter<?> param) {
String paramKey = param.getName();
Class<?> dataType = param.getType();
Parameter.ParamType paramType = param.getParamType();
// mock resource context
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
DynamicRecordTemplate template = null;
if (paramType == Parameter.ParamType.POST) {
template = new DynamicRecordTemplate(new DataMap(), null);
} else {
MutablePathKeys mockPathKeys = EasyMock.createMock(MutablePathKeys.class);
EasyMock.expect(mockPathKeys.get(paramKey)).andReturn(null);
EasyMock.expect(mockResourceContext.getPathKeys()).andReturn(mockPathKeys);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.expect(mockResourceContext.hasParameter(paramKey)).andReturn(false);
if (DataTemplate.class.isAssignableFrom(dataType)) {
EasyMock.expect(mockResourceContext.getStructuredParameter(paramKey)).andReturn(null);
} else {
EasyMock.expect(mockResourceContext.getParameter(paramKey)).andReturn(null);
}
EasyMock.replay(mockResourceContext);
}
// invoke buildArgs
List<Parameter<?>> parameters = Collections.singletonList(param);
return ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, template, getMockResourceMethodConfig(false));
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestBatchCreateArgumentBuilder method testArgumentBuilderSuccess.
@Test
public void testArgumentBuilderSuccess() throws Exception {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"elements\":[{\"b\":123,\"a\":\"abc\"},{\"b\":5678,\"a\":\"xyzw\"}]}");
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
@SuppressWarnings("rawtypes") Parameter<BatchCreateRequest> param = new Parameter<>("", BatchCreateRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, param, CollectionResourceAsyncTemplate.class.getMethod("batchCreate", BatchCreateRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 1);
RestLiArgumentBuilder argumentBuilder = new BatchCreateArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(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.Parameter in project rest.li by linkedin.
the class TestBatchGetArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(Set<Object> batchKeys) throws IOException {
@SuppressWarnings("rawtypes") Parameter<Set> param = new Parameter<>("", Set.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, batchKeys, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 2);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new BatchGetArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
Object[] expectedArgs = new Object[] { batchKeys };
assertEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
Aggregations