use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(List<Parameter<?>> params, Map<String, String> contextParams, String errorMessage) {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, 1, params);
//We cannot use RestLiArgumentBuilderTestHelper's getMockResourceContext since this is a failure scenario and
//getRequestAttachmentReader() will not be called.
ServerResourceContext context = createMock(ServerResourceContext.class);
for (String key : contextParams.keySet()) {
expect(context.getParameter(key)).andReturn(contextParams.get(key));
}
replay(context);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
try {
argumentBuilder.buildArguments(requestData, routingResult);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains(errorMessage));
}
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testComplexArrayArgument.
@Test(dataProvider = "complexArrayArgument")
public void testComplexArrayArgument(Parameter<?> param, String parameterKey, String parameterValue, Object structuredParameter, Object[] expectedArgs) {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContextWithStructuredParameter(parameterKey, parameterValue, structuredParameter, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testArrayArgumentFailure.
@Test(dataProvider = "arrayArgumentFailure")
public void testArrayArgumentFailure(Parameter<?> param, String parameterKey, List<String> parameterValues, String errorMessage) {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
//We cannot use RestLiArgumentBuilderTestHelper's getMockResourceContext since this is a failure scenario and
//getRequestAttachmentReader() will not be called.
ServerResourceContext context = createMock(ServerResourceContext.class);
expect(context.getParameter(parameterKey)).andReturn(parameterValues.get(0));
expect(context.getParameterValues(parameterKey)).andReturn(parameterValues);
replay(context);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null, 0);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
try {
argumentBuilder.buildArguments(requestData, routingResult);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains(errorMessage));
}
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestGetArgumentBuilder method testAsyncArguments.
@Test(dataProvider = "asyncArgumentData")
public void testAsyncArguments(List<Parameter<?>> paramList) {
String keyName = "myComplexKeyCollectionId";
Object keyValue = new Integer(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);
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, 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, null };
assertEquals(args, expectedArgs);
verify(model, descriptor, context, routingResult, request);
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestGetArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(Parameter<?> param, String errorMessage) {
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);
ResourceContext context = EasyMock.createMock(ResourceContext.class);
PathKeys mockPathKeys = EasyMock.createMock(PathKeys.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, 0);
RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
try {
argumentBuilder.buildArguments(requestData, routingResult);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertEquals(e.getMessage(), errorMessage);
}
verify(descriptor, context, routingResult, request);
}
Aggregations