Search in sources :

Example 6 with ResourceModel

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);
}
Also used : ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) HashSet(java.util.HashSet)

Example 7 with ResourceModel

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);
    }
}
Also used : ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel)

Example 8 with ResourceModel

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);
}
Also used : RoutingException(com.linkedin.restli.server.RoutingException) BatchPatchRequest(com.linkedin.restli.server.BatchPatchRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) CollectionResourceAsyncTemplate(com.linkedin.restli.server.resources.CollectionResourceAsyncTemplate) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) Callback(com.linkedin.common.callback.Callback) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 9 with ResourceModel

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;
}
Also used : ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel)

Example 10 with ResourceModel

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);
}
Also used : IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) DataSchema(com.linkedin.data.schema.DataSchema) IntegerDataSchema(com.linkedin.data.schema.IntegerDataSchema) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Key(com.linkedin.restli.server.Key) CompoundKey(com.linkedin.restli.common.CompoundKey) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Aggregations

ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)223 Test (org.testng.annotations.Test)190 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)161 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)139 AfterTest (org.testng.annotations.AfterTest)114 BeforeTest (org.testng.annotations.BeforeTest)114 ByteString (com.linkedin.data.ByteString)50 PromiseStatusCollectionResource (com.linkedin.restli.server.twitter.PromiseStatusCollectionResource)50 CustomString (com.linkedin.restli.server.custom.types.CustomString)43 AsyncStatusCollectionResource (com.linkedin.restli.server.twitter.AsyncStatusCollectionResource)40 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)37 RestRequest (com.linkedin.r2.message.rest.RestRequest)36 Callback (com.linkedin.common.callback.Callback)34 RestLiConfig (com.linkedin.restli.server.RestLiConfig)34 RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)32 RequestContext (com.linkedin.r2.message.RequestContext)29 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)28 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)28 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)28 TaskStatusCollectionResource (com.linkedin.restli.server.twitter.TaskStatusCollectionResource)28