use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testQueryParameterType.
@Test
public void testQueryParameterType() {
String testParamKey = "testParam";
String expectedTestParamValue = "testParamValue";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockResourceContext.hasParameter(testParamKey)).andReturn(true).times(1);
EasyMock.expect(mockResourceContext.getParameter(testParamKey)).andReturn(expectedTestParamValue).anyTimes();
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
Parameter<String> param = new Parameter<>(testParamKey, String.class, DataSchemaConstants.STRING_DATA_SCHEMA, false, null, Parameter.ParamType.QUERY, 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], expectedTestParamValue);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestBatchDeleteArgumentBuilder 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 BatchDeleteArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
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);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestBatchPatchArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, PatchRequest<MyComplexKey>[] patches) throws Exception {
Set<Object> batchKeys = new HashSet<>(Arrays.asList(keys));
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
@SuppressWarnings("rawtypes") Parameter<BatchPatchRequest> param = new Parameter<>("", BatchPatchRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, Collections.singletonList(param), CollectionResourceAsyncTemplate.class.getMethod("batchUpdate", BatchPatchRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, version, true, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchPatchArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args.length, 1);
assertTrue(args[0] instanceof BatchPatchRequest);
Map<?, ?> data = ((BatchPatchRequest) args[0]).getData();
assertEquals(data.size(), keys.length);
for (int i = 0; i < keys.length; i++) {
assertEquals(data.get(keys[i]), patches[i]);
}
verify(request, descriptor, context, routingResult);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method getFinderParams.
private List<Parameter<?>> getFinderParams() {
List<Parameter<?>> finderParams = new ArrayList<>();
finderParams.add(getPagingContextParam());
Parameter<Integer> requiredIntParam = new Parameter<>("required", Integer.class, new IntegerDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {}));
finderParams.add(requiredIntParam);
Parameter<String> optionalStringParam = new Parameter<>("optional", String.class, new StringDataSchema(), true, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {}));
finderParams.add(optionalStringParam);
return finderParams;
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestCreateArgumentBuilder method testArgumentBuilderSuccess.
@Test
public void testArgumentBuilderSuccess() throws IOException, NoSuchMethodException {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"a\":\"xyz\",\"b\":123}");
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
Parameter<MyComplexKey> param = new Parameter<>("", MyComplexKey.class, DataTemplateUtil.getSchema(MyComplexKey.class), false, null, Parameter.ParamType.POST, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = getMockResourceMethodDescriptor(model, param, CollectionResourceAsyncTemplate.class.getMethod("create", RecordTemplate.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(null, null, null, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 1);
RestLiArgumentBuilder argumentBuilder = new CreateArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(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);
}
Aggregations