use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.
the class TestBatchPatchArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, PatchRequest<MyComplexKey>[] patches) {
Set<Object> batchKeys = new HashSet<Object>(Arrays.asList(keys));
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
@SuppressWarnings("rawtypes") Parameter<BatchPatchRequest> param = new Parameter<BatchPatchRequest>("", BatchPatchRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, Collections.singletonList(param));
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, true, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchPatchArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args.length, 1);
assertTrue(args[0] instanceof BatchPatchRequest);
Map<?, ?> data = ((BatchPatchRequest) args[0]).getData();
assertEquals(data.size(), keys.length);
for (int i = 0; i < keys.length; i++) {
assertEquals(data.get(keys[i]), patches[i]);
}
verify(request, descriptor, context, routingResult);
}
use of com.linkedin.restli.internal.server.model.AnnotationSet in project rest.li by linkedin.
the class Jsr330Adapter method scanInjectableConstructors.
private void scanInjectableConstructors(Class<?> beanClazz) {
int annotatedConstructors = 0;
for (Constructor<?> constructor : beanClazz.getConstructors()) {
Inject injectAnnotation = constructor.getAnnotation(Inject.class);
if (injectAnnotation != null) {
++annotatedConstructors;
if (annotatedConstructors > 1) {
throw new RestLiInternalException("Found multiple constructors annotated with @Inject in " + "class '" + beanClazz.getCanonicalName() + "'. At most one constructor can be annotated " + "with @Inject.");
}
Class<?>[] parameters = constructor.getParameterTypes();
Annotation[][] parameterAnnotations = constructor.getParameterAnnotations();
List<DependencyDecl> parameterDecls = new ArrayList<DependencyDecl>(parameters.length);
for (int i = 0; i < parameters.length; ++i) {
Class<?> parameter = parameters[i];
AnnotationSet annotations = new AnnotationSet(parameterAnnotations[i]);
Named namedAnno = annotations.get(Named.class);
parameterDecls.add(new DependencyDecl(parameter, namedAnno != null ? namedAnno.value() : null));
}
constructor.setAccessible(true);
_constructorParameterDependencies.put(beanClazz, new InjectableConstructor(constructor, parameterDecls));
}
}
if (annotatedConstructors == 0) {
try {
Constructor<?> defaultConstructor = beanClazz.getConstructor();
defaultConstructor.setAccessible(true);
_constructorParameterDependencies.put(beanClazz, new InjectableConstructor(defaultConstructor, Collections.<DependencyDecl>emptyList()));
} catch (NoSuchMethodException e) {
throw new RestLiInternalException(String.format("No injectable constructor defined for class %s. Classes must define" + " either a default constructor or a constructor annotated " + "with @Inject.", beanClazz.getName()), e);
}
}
}
Aggregations