use of org.apache.xbean.finder.archive.ClassesArchive in project tomee by apache.
the class CheckAnnotationTest method shouldWarnForLocalAnnotationOnBeanWithNoInterface.
@Keys({ @Key(value = "ann.local.forLocalBean", type = KeyType.WARNING) })
public EjbModule shouldWarnForLocalAnnotationOnBeanWithNoInterface() {
final EjbJar ejbJar = new EjbJar();
ejbJar.addEnterpriseBean(new StatelessBean(EjbWithoutInterface.class));
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(EjbWithoutInterface.class)).link());
return ejbModule;
}
use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.
the class ClassAnnotationFinderTest method checkClassAnnotationOnField.
@Test
public void checkClassAnnotationOnField() throws Exception {
final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class), false);
final List<Field> annotations = finder.findAnnotatedFields(ClassAnnotation.class);
assertEquals(1, annotations.size());
assertEquals(ClassAnnotatedClass.class.getDeclaredField("green"), annotations.get(0));
}
use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.
the class ClassAnnotationFinderTest method checkClassAnnotationOnFieldDefaults.
@Test
public void checkClassAnnotationOnFieldDefaults() {
final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class));
final List<Field> annotations = finder.findAnnotatedFields(ClassAnnotation.class);
assertEquals(0, annotations.size());
}
use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.
the class ClassAnnotationFinderTest method checkClassAnnotationIsFound.
@Test
public void checkClassAnnotationIsFound() {
final AnnotationFinder finder = new AnnotationFinder(new ClassesArchive(ClassAnnotatedClass.class, NotAnnotated.class), false);
final List<Class<?>> annotations = finder.findAnnotatedClasses(ClassAnnotation.class);
assertEquals(1, annotations.size());
assertEquals(ClassAnnotatedClass.class, annotations.iterator().next());
}
use of org.apache.xbean.finder.archive.ClassesArchive in project geronimo-xbean by apache.
the class SelectMetaAnnotatedClassTest method test.
public void test() throws Exception {
finder = new AnnotationFinder(new ClassesArchive(Square.class, Circle.class, Triangle.class, Fake.class, Store.class, Farm.class, None.class)).link();
// MetaAnnotation classes themselves are not included
assertNull(get(Red.class));
assertNull(get(Crimson.class));
assertNull(get(None.class));
// Check the positive scenarios
{
// Circle
Annotated<Class<?>> target = get(Circle.class);
assertNotNull(target);
assertTrue(target.isAnnotationPresent(Color.class));
assertTrue(target.getAnnotation(Color.class) != null);
assertTrue(contains(Color.class, target.getDeclaredAnnotations()));
assertTrue(contains(Color.class, target.getAnnotations()));
assertEquals("white", target.getAnnotation(Color.class).value());
}
{
// Square
Annotated<Class<?>> target = get(Square.class);
assertNotNull(target);
assertTrue(target.isAnnotationPresent(Color.class));
assertTrue(target.getAnnotation(Color.class) != null);
assertTrue(!contains(Color.class, target.getDeclaredAnnotations()));
assertTrue(contains(Color.class, target.getAnnotations()));
assertEquals("red", target.getAnnotation(Color.class).value());
assertTrue(target.isAnnotationPresent(Red.class));
assertTrue(target.getAnnotation(Red.class) != null);
assertTrue(contains(Red.class, target.getDeclaredAnnotations()));
assertTrue(contains(Red.class, target.getAnnotations()));
}
{
// Triangle
Annotated<Class<?>> target = get(Triangle.class);
assertNotNull(target);
assertTrue(target.isAnnotationPresent(Color.class));
assertTrue(target.getAnnotation(Color.class) != null);
assertTrue(!contains(Color.class, target.getDeclaredAnnotations()));
assertTrue(contains(Color.class, target.getAnnotations()));
assertEquals("red", target.getAnnotation(Color.class).value());
assertTrue(target.isAnnotationPresent(Red.class));
assertTrue(target.getAnnotation(Red.class) != null);
assertTrue(!contains(Red.class, target.getDeclaredAnnotations()));
assertTrue(contains(Red.class, target.getAnnotations()));
assertTrue(target.isAnnotationPresent(Crimson.class));
assertTrue(target.getAnnotation(Crimson.class) != null);
assertTrue(contains(Crimson.class, target.getDeclaredAnnotations()));
assertTrue(contains(Crimson.class, target.getAnnotations()));
}
{
// Fake -- should not get more than we asked for
Annotated<Class<?>> target = get(Fake.class);
assertNull(target);
List<Annotated<Class<?>>> list = finder.findMetaAnnotatedClasses(NotMeta.class);
assertEquals(1, list.size());
target = list.get(0);
assertNotNull(target);
assertTrue(!target.isAnnotationPresent(Color.class));
assertTrue(target.getAnnotation(Color.class) == null);
assertTrue(!contains(Color.class, target.getDeclaredAnnotations()));
assertTrue(!contains(Color.class, target.getAnnotations()));
}
{
// Circular - Egg wins
Annotated<Class<?>> target = get(Store.class);
assertNotNull(target);
assertTrue(target.isAnnotationPresent(Color.class));
assertTrue(target.getAnnotation(Color.class) != null);
assertTrue(!contains(Color.class, target.getDeclaredAnnotations()));
assertTrue(contains(Color.class, target.getAnnotations()));
assertEquals("egg", target.getAnnotation(Color.class).value());
assertTrue(target.isAnnotationPresent(Egg.class));
assertTrue(target.getAnnotation(Egg.class) != null);
assertTrue(contains(Egg.class, target.getDeclaredAnnotations()));
assertTrue(contains(Egg.class, target.getAnnotations()));
assertTrue(target.isAnnotationPresent(Chicken.class));
assertTrue(target.getAnnotation(Chicken.class) != null);
assertTrue(!contains(Chicken.class, target.getDeclaredAnnotations()));
assertTrue(contains(Chicken.class, target.getAnnotations()));
}
{
// Circular - Chicken wins
Annotated<Class<?>> target = get(Farm.class);
assertNotNull(target);
assertTrue(target.isAnnotationPresent(Color.class));
assertTrue(target.getAnnotation(Color.class) != null);
assertTrue(!contains(Color.class, target.getDeclaredAnnotations()));
assertTrue(contains(Color.class, target.getAnnotations()));
assertEquals("chicken", target.getAnnotation(Color.class).value());
assertTrue(target.isAnnotationPresent(Egg.class));
assertTrue(target.getAnnotation(Egg.class) != null);
assertTrue(!contains(Egg.class, target.getDeclaredAnnotations()));
assertTrue(contains(Egg.class, target.getAnnotations()));
assertTrue(target.isAnnotationPresent(Chicken.class));
assertTrue(target.getAnnotation(Chicken.class) != null);
assertTrue(contains(Chicken.class, target.getDeclaredAnnotations()));
assertTrue(contains(Chicken.class, target.getAnnotations()));
}
}
Aggregations