use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class InjectResourceFactory method setRootResources.
@Override
public void setRootResources(final Map<String, ResourceModel> rootResources) {
log.debug("Setting root resources");
_rootResources = rootResources;
Collection<Class<?>> allResourceClasses = new HashSet<>();
for (ResourceModel resourceModel : _rootResources.values()) {
processChildResource(resourceModel, allResourceClasses);
}
_jsr330Adapter = new Jsr330Adapter(allResourceClasses, _beanProvider);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class InjectResourceFactory method processChildResource.
protected void processChildResource(final ResourceModel resourceModel, final Collection<Class<?>> allResourceClasses) {
if (resourceModel == null) {
return;
}
log.debug("Adding resource class for DI: " + resourceModel.getResourceClass());
allResourceClasses.add(resourceModel.getResourceClass());
for (ResourceModel child : resourceModel.getSubResources()) {
processChildResource(child, allResourceClasses);
}
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestBatchPatchArgumentBuilder 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, 2, null, CollectionResourceAsyncTemplate.class.getMethod("batchUpdate", BatchPatchRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, version, false, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchPatchArgumentBuilder();
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, context, routingResult);
}
use of com.linkedin.restli.internal.server.model.ResourceModel in project rest.li by linkedin.
the class TestBatchGetResponseBuilder method getMockResourceModel.
private static ResourceModel getMockResourceModel(Map<String, AlternativeKey<?, ?>> alternativeKeyMap) {
ResourceModel mockResourceModel = EasyMock.createMock(ResourceModel.class);
EasyMock.expect(mockResourceModel.getAlternativeKeys()).andReturn(alternativeKeyMap).anyTimes();
EasyMock.replay(mockResourceModel);
return mockResourceModel;
}
use of com.linkedin.restli.internal.server.model.ResourceModel 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);
}
Aggregations