use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsCollectionGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsCollectionEntity")
public void testRoutingDetailsCollectionGet(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap);
// #1 simple GET
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(), StatusCollectionResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "get");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Long.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 RestLiAnnotationReader method buildPathKeysParam.
private static Parameter<?> buildPathKeysParam(final AnnotationSet annotations, final Class<?> paramType, final Class<?> paramAnnotationType) {
if (!paramType.equals(PathKeys.class)) {
throw new ResourceConfigException("Incorrect data type for param: @" + PathKeysParam.class.getSimpleName() + " or @" + Keys.class.getSimpleName() + " parameter annotation must be of type " + PathKeys.class.getName());
}
Optional optional = annotations.get(Optional.class);
Parameter.ParamType parameter = null;
if (paramAnnotationType.equals(Keys.class)) {
parameter = Parameter.ParamType.PATH_KEYS;
} else if (paramAnnotationType.equals(PathKeysParam.class)) {
parameter = Parameter.ParamType.PATH_KEYS_PARAM;
} else {
throw new ResourceConfigException("Param Annotation type must be 'PathKeysParam' or the deprecated 'Keys' for PathKeys");
}
@SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter("", paramType, null, optional != null, new PathKeysImpl(), parameter, false, annotations);
return param;
}
use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class ComplexKeysSubResource method get.
@RestMethod.Get
public TwoPartKey get(String key) {
PathKeys pathKeys = getContext().getPathKeys();
ComplexResourceKey<TwoPartKey, TwoPartKey> keys = pathKeys.get("keys");
return convert(keys);
}
use of com.linkedin.restli.server.PathKeys in project rest.li by linkedin.
the class AssociationsSubResource method get.
public Message get(String key) {
PathKeys pathKeys = getContext().getPathKeys();
String srcKey = pathKeys.getAsString("src");
String destKey = pathKeys.getAsString("dest");
Message message = new Message();
message.setId(srcKey);
message.setTone(Tone.FRIENDLY);
message.setMessage(destKey);
return message;
}
use of com.linkedin.restli.server.PathKeys 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);
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.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");
assertNotNull(result.getContext());
PathKeys keys = result.getContext().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<CompoundKey>();
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);
}
Aggregations