Search in sources :

Example 11 with ClassesArchive

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;
}
Also used : StatelessBean(org.apache.openejb.jee.StatelessBean) EjbModule(org.apache.openejb.config.EjbModule) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) EjbJar(org.apache.openejb.jee.EjbJar)

Example 12 with ClassesArchive

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));
}
Also used : Field(java.lang.reflect.Field) ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 13 with ClassesArchive

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());
}
Also used : Field(java.lang.reflect.Field) ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 14 with ClassesArchive

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());
}
Also used : ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) ClassAnnotatedClass(org.acme.ClassAnnotatedClass) ClassMultipleAnnotatedClass(org.acme.ClassMultipleAnnotatedClass) NotAnnotated(org.acme.NotAnnotated) Test(org.junit.Test)

Example 15 with ClassesArchive

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()));
    }
}
Also used : ClassesArchive(org.apache.xbean.finder.archive.ClassesArchive) List(java.util.List)

Aggregations

ClassesArchive (org.apache.xbean.finder.archive.ClassesArchive)33 Test (org.junit.Test)14 AnnotationFinder (org.apache.xbean.finder.AnnotationFinder)12 NotAnnotated (org.acme.NotAnnotated)10 ClassAnnotatedClass (org.acme.ClassAnnotatedClass)8 Method (java.lang.reflect.Method)7 URL (java.net.URL)7 CompositeArchive (org.apache.xbean.finder.archive.CompositeArchive)7 FilteredArchive (org.apache.xbean.finder.archive.FilteredArchive)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 EjbModule (org.apache.openejb.config.EjbModule)6 EjbJar (org.apache.openejb.jee.EjbJar)6 Archive (org.apache.xbean.finder.archive.Archive)6 MalformedURLException (java.net.MalformedURLException)5 AppModule (org.apache.openejb.config.AppModule)5 File (java.io.File)4 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4