use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsSimpleGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimpleGet(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request = createRequest(uri, "GET", version);
RoutingResult result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.GET);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "get");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] {});
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "trending");
assertNotNull(result.getContext());
PathKeys keys = result.getContext().getPathKeys();
assertNull(keys.getBatchIds());
}
use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsCollectionUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsCollectionEntity")
public void testRoutingDetailsCollectionUpdate(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request = createRequest(uri, "PUT", version);
RoutingResult result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.UPDATE);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), StatusCollectionResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "update");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Long.class, Status.class });
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "statuses");
assertNotNull(result.getContext());
PathKeys keys = result.getContext().getPathKeys();
assertEquals(keys.getAsLong("statusID"), new Long(1));
assertNull(keys.getAsString("foo"));
}
use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class TestGetArgumentBuilder method testFailure.
@Test(dataProvider = "failureData")
public void testFailure(Parameter<?> param, String errorMessage) {
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);
ResourceContext context = EasyMock.createMock(ResourceContext.class);
PathKeys mockPathKeys = EasyMock.createMock(PathKeys.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, 0);
RestLiArgumentBuilder argumentBuilder = new GetArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
try {
argumentBuilder.buildArguments(requestData, routingResult);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertEquals(e.getMessage(), errorMessage);
}
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class TestRestLiRouting method testDefaultPathKeyUniqueness.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "uniqueness")
public void testDefaultPathKeyUniqueness(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(CombinedResources.CombinedCollectionWithSubresources.class, CombinedResources.SubCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request;
RoutingResult result;
// #1 simple GET
request = createRequest(uri, "GET", version);
result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
PathKeys keys = result.getContext().getPathKeys();
assertEquals(keys.getAsString("testId"), "foo");
assertEquals(keys.getAsString("subId"), "bar");
}
use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsSimpleDelete.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimpleDelete(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request = createRequest(uri, "DELETE", version);
RoutingResult result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.DELETE);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "delete");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] {});
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "trending");
assertNotNull(result.getContext());
PathKeys keys = result.getContext().getPathKeys();
assertNull(keys.getBatchIds());
}
Aggregations