All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.oneandone.iocunit.validate.ValidateTestExtension Maven / Gradle / Ivy

package com.oneandone.iocunit.validate;

import java.lang.annotation.Annotation;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import javax.enterprise.util.AnnotationLiteral;

import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;

/**
 * @author aschoerk
 */
@ApplicationScoped
public class ValidateTestExtension implements Extension {

    private static AnnotationLiteral createApplicationScopedAnnotation() {
        return new AnnotationLiteral() {
            private static final long serialVersionUID = 1L;
        };
    }

    public  void processAnnotatedType(@Observes ProcessAnnotatedType pat) {
        AnnotatedType annotatedType = pat.getAnnotatedType();
        AnnotatedTypeBuilder builder = new AnnotatedTypeBuilder().readFromType(annotatedType);

        final Class aClass = annotatedType.getJavaClass();
        if(TestExtensionServices.testExtensionServiceData.get().contains(aClass)) {
            if (ValidationClassFinder.getMethodValidatedAnnotation() != null) {
                builder.addToClass(new AnnotationLiteral() {
                    private static final long serialVersionUID = 4280858811908223334L;

                    @Override
                    public Class annotationType() {
                        return ValidationClassFinder.getMethodValidatedAnnotation();
                    }
                });
                pat.setAnnotatedType(builder.create());
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy