Search in sources :

Example 21 with RestLiRouter

use of com.linkedin.restli.internal.server.RestLiRouter in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingSimbleSubResourceBatch.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingSimpleSubResourceBatch")
public void testRoutingSimbleSubResourceBatch(String uri, ProtocolVersion version, String httpMethod, String restliMethod, ResourceMethod method, String methodName, Set<String> keys) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class, TrendRegionsCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    checkResult(uri, version, httpMethod, restliMethod, method, TrendRegionsCollectionResource.class, methodName, true);
    checkBatchKeys(uri, version, httpMethod, keys);
}
Also used : RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiConfig(com.linkedin.restli.server.RestLiConfig) Test(org.testng.annotations.Test)

Example 22 with RestLiRouter

use of com.linkedin.restli.internal.server.RestLiRouter in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingDetailsSimpleUpdate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimpleUpdate(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    RestRequest request = createRequest(uri, "PUT", version);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    ResourceMethodDescriptor resourceMethodDescriptor = _router.process(context);
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.UPDATE);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "update");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Trending.class });
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "trending");
    PathKeys keys = context.getPathKeys();
    assertNull(keys.getBatchIds());
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) Test(org.testng.annotations.Test)

Example 23 with RestLiRouter

use of com.linkedin.restli.internal.server.RestLiRouter in project rest.li by linkedin.

the class TestRestLiRouting method testStreamingResourceContext.

// This test verifies that the router can create the correct resource context based on attachments being
// present in the request or an accept type indicating a desire to receive response attachments.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimpleStreaming")
public void testStreamingResourceContext(ProtocolVersion version, String uri, String acceptHeader, RestLiAttachmentReader requestAttachments) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    final RestRequestBuilder requestBuilder = new RestRequestBuilder(new URI(uri)).setMethod("GET").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
    if (acceptHeader != null) {
        requestBuilder.setHeader(RestConstants.HEADER_ACCEPT, acceptHeader);
    }
    final RestRequest request = requestBuilder.build();
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    context.setRequestAttachmentReader(requestAttachments);
    ResourceMethodDescriptor method = _router.process(context);
    assertNotNull(method);
    if (requestAttachments != null) {
        Assert.assertEquals(context.getRequestAttachmentReader(), requestAttachments);
    } else {
        Assert.assertNull(context.getRequestAttachmentReader());
    }
    if (acceptHeader != null && acceptHeader.contains("multipart/related")) {
        Assert.assertTrue(context.responseAttachmentsSupported());
    } else {
        Assert.assertFalse(context.responseAttachmentsSupported());
    }
}
Also used : PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) URI(java.net.URI) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) Test(org.testng.annotations.Test)

Example 24 with RestLiRouter

use of com.linkedin.restli.internal.server.RestLiRouter in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingDetailsAssociationGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsAssociationEntity")
public void testRoutingDetailsAssociationGet(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(FollowsAssociativeResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    RestRequest request = createRequest(uri, "GET", version);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    ResourceMethodDescriptor resourceMethodDescriptor = _router.process(context);
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.GET);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), FollowsAssociativeResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "get");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { CompoundKey.class });
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "follows");
    PathKeys keys = context.getPathKeys();
    assertEquals(keys.getAsLong("followerID"), Long.valueOf(1L));
    assertEquals(keys.getAsLong("followeeID"), Long.valueOf(2L));
}
Also used : PathKeys(com.linkedin.restli.server.PathKeys) RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RequestContext(com.linkedin.r2.message.RequestContext) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) Test(org.testng.annotations.Test)

Example 25 with RestLiRouter

use of com.linkedin.restli.internal.server.RestLiRouter in project rest.li by linkedin.

the class TestRestLiRouting method testRoutingSimpleResource.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingSimpleResource")
public void testRoutingSimpleResource(ProtocolVersion version, String httpMethod, String restliMethod, ResourceMethod method, String methodName) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    checkResult("/trending", version, httpMethod, restliMethod, method, TrendingResource.class, methodName, false);
}
Also used : RestLiRouter(com.linkedin.restli.internal.server.RestLiRouter) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiConfig(com.linkedin.restli.server.RestLiConfig) Test(org.testng.annotations.Test)

Aggregations

RestLiRouter (com.linkedin.restli.internal.server.RestLiRouter)32 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)32 RestLiConfig (com.linkedin.restli.server.RestLiConfig)32 Test (org.testng.annotations.Test)32 RequestContext (com.linkedin.r2.message.RequestContext)14 RestRequest (com.linkedin.r2.message.rest.RestRequest)14 PathKeysImpl (com.linkedin.restli.internal.server.PathKeysImpl)14 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)14 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)14 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)14 PathKeys (com.linkedin.restli.server.PathKeys)10 CombinedResources (com.linkedin.restli.server.combined.CombinedResources)4 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 CompoundKey (com.linkedin.restli.common.CompoundKey)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1