Search in sources :

Example 1 with Annotation

use of org.jboss.jca.common.spi.annotations.repository.Annotation in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnectorFailNoConnector.

/**
 * Process: Connector -- verification of the processConnector method
 *
 * @throws Throwable throwable exception
 */
@Ignore("JBJCA-1435: The current validation in IronJacamar is not correct, the testcase here is.")
@Test(expected = ValidateException.class)
public void testProcessConnectorFailNoConnector() throws Throwable {
    // Test prep
    AnnotationRepository ar = null;
    try {
        File srcRars = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars");
        File srcRa16 = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno");
        final String destRars = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars";
        final String destRa16 = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno";
        for (File srcFile : srcRars.listFiles()) {
            if (!srcFile.isDirectory() && !"BaseResourceAdapter.class".equals(srcFile.getName())) {
                Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
            }
        }
        for (File srcFile : srcRa16.listFiles()) {
            if (!srcFile.isDirectory() && !"TestResourceAdapter.class".equals(srcFile.getName())) {
                Files.copy(srcFile, new File(destRa16 + "/" + srcFile.getName()));
            }
        }
        URI uri = getURI("/ra16inoutmultianno.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            System.out.println("testProcessConnectorFailNoConnector: adding " + classFile.getPathName());
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Test preparation error " + e.getMessage());
    }
    Collection<Annotation> values = ar.getAnnotation(javax.resource.spi.Connector.class);
    assertNull(values);
    // Test run
    annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) URI(java.net.URI) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Indexer(org.jboss.jandex.Indexer) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with Annotation

use of org.jboss.jca.common.spi.annotations.repository.Annotation in project wildfly by wildfly.

the class JandexAnnotationRepositoryImpl method getAnnotation.

@Override
public Collection<Annotation> getAnnotation(Class<?> annotationClass) {
    List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName()));
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size());
    for (AnnotationInstance instance : instances) {
        AnnotationTarget target = instance.target();
        Annotation annotation = null;
        if (target instanceof MethodInfo) {
            MethodInfo m = (MethodInfo) target;
            List<String> parameterTypes = new ArrayList<String>(m.args().length);
            for (Type type : m.args()) {
                parameterTypes.add(type.toString());
            }
            String declaringClass = m.declaringClass().name().toString();
            annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
        }
        if (target instanceof FieldInfo) {
            FieldInfo f = (FieldInfo) target;
            String declaringClass = f.declaringClass().name().toString();
            annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass);
        }
        if (target instanceof ClassInfo) {
            ClassInfo c = (ClassInfo) target;
            annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
        }
        if (annotation != null) {
            annotations.add(annotation);
        }
    }
    annotations.trimToSize();
    if (annotations.isEmpty()) {
        return null;
    } else {
        return Collections.unmodifiableList(annotations);
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) ArrayList(java.util.ArrayList) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Type(org.jboss.jandex.Type) MethodInfo(org.jboss.jandex.MethodInfo) AnnotationInstance(org.jboss.jandex.AnnotationInstance) FieldInfo(org.jboss.jandex.FieldInfo) ClassInfo(org.jboss.jandex.ClassInfo)

Example 3 with Annotation

use of org.jboss.jca.common.spi.annotations.repository.Annotation in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnectorManualSpecConnector.

/**
 * Process: Connector -- verification of the processConnector method
 *
 * @throws Throwable throwable exception
 */
public void testProcessConnectorManualSpecConnector() throws Throwable {
    // Test prep
    AnnotationRepository ar = null;
    try {
        File srcRars = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars");
        File srcRa16 = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno");
        final String destRars = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars";
        final String destRa16 = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno";
        for (File srcFile : srcRars.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
            }
        }
        for (File srcFile : srcRa16.listFiles()) {
            if (!srcFile.isDirectory() && !"TestResourceAdapter.class".equals(srcFile.getName())) {
                Files.copy(srcFile, new File(destRa16 + "/" + srcFile.getName()));
            }
        }
        URI uri = getURI("/ra16inoutmultianno.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            System.out.println("testProcessConnectorFailNoConnector: adding " + classFile.getPathName());
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Test preparation error " + e.getMessage());
    }
    Collection<Annotation> values = ar.getAnnotation(javax.resource.spi.Connector.class);
    assertNull(values);
    // Test run
    annotations.process(ar, "org.jboss.as.connector.deployers.spec.rars.BaseResourceAdapter", Thread.currentThread().getContextClassLoader());
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) URI(java.net.URI) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Indexer(org.jboss.jandex.Indexer) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File)

Example 4 with Annotation

use of org.jboss.jca.common.spi.annotations.repository.Annotation in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnectorFailTooManyConnectors.

/**
 * Process: Connector -- verification of the processConnector method
 *
 * @throws Throwable throwable exception
 */
@Test(expected = ValidateException.class)
public void testProcessConnectorFailTooManyConnectors() throws Throwable {
    // Test prep
    AnnotationRepository ar = null;
    try {
        File srcRars = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars");
        File srcRa16 = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno");
        File srcStandalone = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/rastandalone");
        final String destRars = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars";
        final String destRa16 = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno";
        final String destStandalone = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/rastandalone";
        Files.createParentDirs(new File(destStandalone + "/sample.file"));
        for (File srcFile : srcRars.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
            }
        }
        for (File srcFile : srcRa16.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destRa16 + "/" + srcFile.getName()));
            }
        }
        for (File srcFile : srcStandalone.listFiles()) {
            if (!srcFile.isDirectory()) {
                Files.copy(srcFile, new File(destStandalone + "/" + srcFile.getName()));
            }
        }
        URI uri = getURI("/ra16inoutmultianno.rar");
        final VirtualFile virtualFile = VFS.getChild(uri);
        final Indexer indexer = new Indexer();
        final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
        for (VirtualFile classFile : classChildren) {
            System.out.println("testProcessConnectorFailTooManyConnectors: adding " + classFile.getPathName());
            InputStream inputStream = null;
            try {
                inputStream = classFile.openStream();
                indexer.index(inputStream);
            } finally {
                VFSUtils.safeClose(inputStream);
            }
        }
        final Index index = indexer.complete();
        ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
    } catch (Throwable e) {
        e.printStackTrace();
        fail("Test preparation error " + e.getMessage());
    }
    Collection<Annotation> values = ar.getAnnotation(javax.resource.spi.Connector.class);
    assertNotNull(values);
    assertEquals(2, values.size());
    // Test run
    annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) URI(java.net.URI) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Indexer(org.jboss.jandex.Indexer) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Example 5 with Annotation

use of org.jboss.jca.common.spi.annotations.repository.Annotation in project wildfly by wildfly.

the class AnnotationsTestCase method testProcessConnector.

/**
 * Process: Connector -- verification of the processConnector method
 *
 * @throws Throwable throwable exception
 */
@Test
public void testProcessConnector() throws Throwable {
    // Test prep
    File srcRars = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars");
    File srcRa16 = new File("./target/test-classes/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno");
    final String destRars = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars";
    final String destRa16 = MULTIANNO_TARGET + "/org/jboss/as/connector/deployers/spec/rars/ra16inoutmultianno";
    for (File srcFile : srcRars.listFiles()) {
        if (!srcFile.isDirectory()) {
            Files.copy(srcFile, new File(destRars + "/" + srcFile.getName()));
        }
    }
    for (File srcFile : srcRa16.listFiles()) {
        if (!srcFile.isDirectory()) {
            Files.copy(srcFile, new File(destRa16 + "/" + srcFile.getName()));
        }
    }
    URI uri = getURI("/ra16inoutmultianno.rar");
    final VirtualFile virtualFile = VFS.getChild(uri);
    final Indexer indexer = new Indexer();
    final List<VirtualFile> classChildren = virtualFile.getChildren(new SuffixMatchFilter(".class", VisitorAttributes.RECURSE_LEAVES_ONLY));
    for (VirtualFile classFile : classChildren) {
        System.out.println("testProcessConnector: adding " + classFile.getPathName());
        InputStream inputStream = null;
        try {
            inputStream = classFile.openStream();
            indexer.index(inputStream);
        } finally {
            VFSUtils.safeClose(inputStream);
        }
    }
    final Index index = indexer.complete();
    AnnotationRepository ar = new JandexAnnotationRepositoryImpl(index, Thread.currentThread().getContextClassLoader());
    Collection<Annotation> values = ar.getAnnotation(javax.resource.spi.Connector.class);
    assertNotNull(values);
    assertEquals(1, values.size());
    // Test run
    try {
        annotations.process(ar, null, Thread.currentThread().getContextClassLoader());
    } catch (Throwable t) {
        t.printStackTrace();
        fail(t.getMessage());
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) InputStream(java.io.InputStream) Index(org.jboss.jandex.Index) URI(java.net.URI) Annotation(org.jboss.jca.common.spi.annotations.repository.Annotation) Indexer(org.jboss.jandex.Indexer) SuffixMatchFilter(org.jboss.vfs.util.SuffixMatchFilter) AnnotationRepository(org.jboss.jca.common.spi.annotations.repository.AnnotationRepository) VirtualFile(org.jboss.vfs.VirtualFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Annotation (org.jboss.jca.common.spi.annotations.repository.Annotation)5 File (java.io.File)4 InputStream (java.io.InputStream)4 URI (java.net.URI)4 Index (org.jboss.jandex.Index)4 Indexer (org.jboss.jandex.Indexer)4 AnnotationRepository (org.jboss.jca.common.spi.annotations.repository.AnnotationRepository)4 VirtualFile (org.jboss.vfs.VirtualFile)4 SuffixMatchFilter (org.jboss.vfs.util.SuffixMatchFilter)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 AnnotationInstance (org.jboss.jandex.AnnotationInstance)1 AnnotationTarget (org.jboss.jandex.AnnotationTarget)1 ClassInfo (org.jboss.jandex.ClassInfo)1 FieldInfo (org.jboss.jandex.FieldInfo)1 MethodInfo (org.jboss.jandex.MethodInfo)1 Type (org.jboss.jandex.Type)1 Ignore (org.junit.Ignore)1