use of com.linkedin.restli.internal.server.RoutingResult 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);
}
use of com.linkedin.restli.internal.server.RoutingResult 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) 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<BatchUpdateRequest> param = new Parameter<>("", BatchUpdateRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 3, Collections.singletonList(param), CollectionResourceAsyncTemplate.class.getMethod("batchUpdate", BatchUpdateRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, version, true, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchUpdateArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(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);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchUpdateArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, String errorMessage) 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);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, null, null, CollectionResourceAsyncTemplate.class.getMethod("batchUpdate", BatchUpdateRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, version, false, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchUpdateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains(errorMessage));
assertEquals(HttpStatus.S_400_BAD_REQUEST.getCode(), e.getStatus());
}
verify(request, model, descriptor, context, routingResult);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestGetArgumentBuilder method testAsyncArguments.
@Test(dataProvider = "asyncArgumentData")
public void testAsyncArguments(List<Parameter<?>> paramList) throws IOException {
String keyName = "myComplexKeyCollectionId";
Object keyValue = Integer.valueOf(123);
DataSchema keySchema = new IntegerDataSchema();
Key key = new Key(keyName, keyValue.getClass(), keySchema);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, false);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, paramList);
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
Object[] expectedArgs = new Object[] { keyValue, null };
assertEquals(args, expectedArgs);
verify(model, descriptor, context, routingResult, request);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestGetArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(Parameter<?> param, String errorMessage) throws IOException {
String keyName = "myComplexKeyCollectionId";
Key key = new Key(keyName, Integer.class, new IntegerDataSchema());
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, true);
List<Parameter<?>> paramList = Collections.<Parameter<?>>singletonList(param);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, paramList);
ServerResourceContext context = EasyMock.createMock(ServerResourceContext.class);
MutablePathKeys mockPathKeys = EasyMock.createMock(MutablePathKeys.class);
EasyMock.expect(mockPathKeys.get(keyName)).andReturn(null).anyTimes();
EasyMock.expect(context.getPathKeys()).andReturn(mockPathKeys).anyTimes();
EasyMock.replay(context, mockPathKeys);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 2);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
try {
argumentBuilder.buildArguments(requestData, routingResult);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertEquals(e.getMessage(), errorMessage);
}
verify(descriptor, context, routingResult, request);
}
Aggregations