Search in sources :

Example 26 with RestLiRouter

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

the class TestRestLiRouting method testRoutingSubSimpleResource.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingSubSimpleResource")
public void testRoutingSubSimpleResource(String uri, ProtocolVersion version, String httpMethod, ResourceMethod method, String methodName, String[] pathKeys) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class, TrendRegionsCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    checkResult(uri, version, httpMethod, method, TrendRegionsCollectionResource.class, methodName, false, pathKeys);
}
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 27 with RestLiRouter

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

the class TestRestLiRouting method testRoutingDetailsAssociationBatchGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsAssociationBatch")
public void testRoutingDetailsAssociationBatchGet(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.BATCH_GET);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), FollowsAssociativeResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "batchGet");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Set.class });
    assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "follows");
    PathKeys keys = context.getPathKeys();
    assertNull(keys.getAsString("followerID"));
    assertNull(keys.getAsString("followeeID"));
    CompoundKey key1 = new CompoundKey();
    key1.append("followerID", 1L);
    key1.append("followeeID", 2L);
    CompoundKey key2 = new CompoundKey();
    key2.append("followerID", 3L);
    key2.append("followeeID", 4L);
    Set<CompoundKey> expectedBatchKeys = new HashSet<>();
    expectedBatchKeys.add(key1);
    expectedBatchKeys.add(key2);
    assertEquals(keys.getBatchIds().size(), 2);
    for (CompoundKey batchKey : keys.<CompoundKey>getBatchIds()) {
        assertTrue(expectedBatchKeys.contains(batchKey));
        expectedBatchKeys.remove(batchKey);
    }
    assertEquals(expectedBatchKeys.size(), 0);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) 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) 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) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 28 with RestLiRouter

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

the class TestRestLiRouting method testNKeyAssociationRoutingBasicBatch.

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

Example 29 with RestLiRouter

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

the class TestRestLiRouting method testRestliInvalidList.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "invalidList")
public void testRestliInvalidList(String uri, ProtocolVersion version, String httpMethod, String restliMethod) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, FollowsAssociativeResource.class, RepliesCollectionResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    expectRoutingExceptionWithStatus(uri, version, httpMethod, restliMethod, HttpStatus.S_400_BAD_REQUEST);
}
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 30 with RestLiRouter

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

the class TestRestLiRouting method testRoutingDetailsSimplePartialUpdate.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimplePartialUpdate(ProtocolVersion version, String uri) throws Exception {
    Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
    _router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
    RestRequest request = createRequest(uri, "POST", version);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    ResourceMethodDescriptor resourceMethodDescriptor = _router.process(context);
    assertNotNull(resourceMethodDescriptor);
    assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.PARTIAL_UPDATE);
    assertNull(resourceMethodDescriptor.getActionName());
    assertNull(resourceMethodDescriptor.getFinderName());
    assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
    assertEquals(resourceMethodDescriptor.getMethod().getName(), "update");
    assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { PatchRequest.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)

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