use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testPagingContextParamType.
@Test
@SuppressWarnings("deprecation")
public void testPagingContextParamType() {
String testParamKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
PagingContext pagingContext = new PagingContext(RestConstants.DEFAULT_START, RestConstants.DEFAULT_COUNT, false, false);
EasyMock.expect(mockResourceContext.getParameter(RestConstants.START_PARAM)).andReturn(null).anyTimes();
EasyMock.expect(mockResourceContext.getParameter(RestConstants.COUNT_PARAM)).andReturn(null).anyTimes();
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
List<Parameter<?>> parameters = new ArrayList<>();
Parameter<PagingContext> param1 = new Parameter<>(testParamKey, PagingContext.class, null, false, null, Parameter.ParamType.PAGING_CONTEXT_PARAM, false, AnnotationSet.EMPTY);
Parameter<PagingContext> param2 = new Parameter<>(testParamKey, PagingContext.class, null, false, null, Parameter.ParamType.CONTEXT, false, AnnotationSet.EMPTY);
parameters.add(param1);
parameters.add(param2);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
Assert.assertEquals(results[0], pagingContext);
Assert.assertEquals(results[1], pagingContext);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testResourceContextParameterType.
@Test
@SuppressWarnings("deprecation")
public void testResourceContextParameterType() {
String testParamKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
List<Parameter<?>> parameters = new ArrayList<>();
Parameter<ResourceContext> param1 = new Parameter<>(testParamKey, ResourceContext.class, null, false, null, Parameter.ParamType.RESOURCE_CONTEXT, false, AnnotationSet.EMPTY);
Parameter<ResourceContext> param2 = new Parameter<>(testParamKey, ResourceContext.class, null, false, null, Parameter.ParamType.RESOURCE_CONTEXT_PARAM, false, AnnotationSet.EMPTY);
parameters.add(param1);
parameters.add(param2);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
Assert.assertEquals(results[0], mockResourceContext);
Assert.assertEquals(results[1], mockResourceContext);
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestArgumentBuilder method testRestLiAttachmentsParamResourceNotExpect.
@Test
public void testRestLiAttachmentsParamResourceNotExpect() {
// This test makes sure that if the resource method did not expect attachments but there were attachments present
// in the request, that an exception is thrown.
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
final RestLiAttachmentReader restLiAttachmentReader = new RestLiAttachmentReader(null);
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(restLiAttachmentReader);
EasyMock.replay(mockResourceContext);
List<Parameter<?>> parameters = Collections.emptyList();
try {
ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null, getMockResourceMethodConfig(false));
Assert.fail();
} catch (RestLiServiceException restLiServiceException) {
Assert.assertEquals(restLiServiceException.getStatus(), HttpStatus.S_400_BAD_REQUEST);
Assert.assertEquals(restLiServiceException.getMessage(), "Resource method endpoint invoked does not accept any request attachments.");
}
}
use of com.linkedin.restli.internal.server.model.Parameter in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method argumentData.
@DataProvider(name = "argumentData")
private Object[][] argumentData() {
List<Parameter<?>> getAllParams = new ArrayList<>();
getAllParams.add(getPagingContextParam());
Map<String, String> getAllContextParams = new HashMap<>();
getAllContextParams.put("start", "33");
getAllContextParams.put("count", "444");
Map<String, String> finderContextParams = new HashMap<>();
finderContextParams.put("start", "33");
finderContextParams.put("count", "444");
finderContextParams.put("required", "777");
finderContextParams.put("optional", null);
Map<String, String> finderContextParamsWithOptionalString = new HashMap<>(finderContextParams);
finderContextParamsWithOptionalString.put("optional", "someString");
List<Parameter<?>> finderWithAssocKeyParams = new ArrayList<>();
finderWithAssocKeyParams.add(new Parameter<>("string1", String.class, new StringDataSchema(), false, null, Parameter.ParamType.ASSOC_KEY_PARAM, true, new AnnotationSet(new Annotation[] {})));
return new Object[][] { { getAllParams, getAllContextParams, null, new Object[] { new PagingContext(33, 444) } }, { getFinderParams(), finderContextParams, null, new Object[] { new PagingContext(33, 444), Integer.valueOf(777), null } }, { getFinderParams(), finderContextParamsWithOptionalString, null, new Object[] { new PagingContext(33, 444), Integer.valueOf(777), "someString" } }, { finderWithAssocKeyParams, null, new PathKeysImpl().append("string1", "testString"), new Object[] { "testString" } } };
}
use of com.linkedin.restli.internal.server.model.Parameter 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