Search in sources :

Example 1 with AnnotationLiteral

use of jakarta.enterprise.util.AnnotationLiteral in project core by weld.

the class TransitiveResolutionTest method testDecoratorEnabledInWarButPackagedInEjbJar.

/*
    * WELD-507
    */
@Test
public void testDecoratorEnabledInWarButPackagedInEjbJar() {
    // Create the BDA in which we will deploy Foo. This is equivalent to a ejb
    // jar
    final BeanDeploymentArchiveImpl ejbJar = new BeanDeploymentArchiveImpl("ejb-jar", Blah.class, BlahDecorator.class, BlahImpl.class);
    // Create the BDA in which we will deploy Bar. This is equivalent to a war
    BeansXml beansXml = new BeansXmlImpl(null, null, Collections.singletonList(BlahDecorator.class.getName()), null);
    final BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war", beansXml, BlahImpl2.class);
    // The war can access the ejb jar
    war.getBeanDeploymentArchives().add(ejbJar);
    // Create a deployment, any other classes are put into the ejb-jar (not
    // relevant to test)
    Deployment deployment = new FlatDeployment(new BeanDeploymentArchive[] { war, ejbJar }) {

        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            return ejbJar;
        }
    };
    TestContainer container = new TestContainer(deployment);
    container.startContainer();
    container.ensureRequestActive();
    // Get the bean manager for war and ejb jar
    BeanManager warBeanManager = container.getBeanManager(war);
    BeanManager ejbJarBeanManager = container.getBeanManager(ejbJar);
    BasicInterceptor.reset();
    Blah blah = getReference(ejbJarBeanManager, Blah.class);
    blah.ping(10);
    assertEquals(10, blah.getI());
    BasicInterceptor.reset();
    blah = getReference(warBeanManager, Blah.class, new AnnotationLiteral<Baz>() {
    });
    blah.ping(10);
    assertEquals(11, blah.getI());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) AnnotationLiteral(jakarta.enterprise.util.AnnotationLiteral) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanManager(jakarta.enterprise.inject.spi.BeanManager) Test(org.testng.annotations.Test)

Example 2 with AnnotationLiteral

use of jakarta.enterprise.util.AnnotationLiteral in project cdi-tck by eclipse-ee4j.

the class GroceryWrapper method getMethods.

@SuppressWarnings({ "unchecked", "rawtypes", "serial" })
@Override
public Set<AnnotatedMethod<? super Grocery>> getMethods() {
    Set<AnnotatedMethod<? super Grocery>> methods = new HashSet<AnnotatedMethod<? super Grocery>>();
    for (AnnotatedMethod<? super Grocery> method : super.getMethods()) {
        if (method.getJavaMember().getName().equals("getMilk")) {
            AnnotatedMethodWrapper<? super Grocery> wrappedMethod = new AnnotatedMethodWrapper(method, this, false, new AnnotationLiteral<Produces>() {
            });
            methods.add(wrappedMethod);
        } else if (method.getJavaMember().getName().equals("getYogurt")) {
            // wrap the method and its parameters
            AnnotatedMethodWrapper<? super Grocery> wrappedMethod = new AnnotatedMethodWrapper(method, this, false, new ExpensiveLiteral(), new AnnotationLiteral<Produces>() {
            });
            methods.add(wrapMethodParameters(method.getParameters(), wrappedMethod, false, new CheapLiteral()));
        } else if (method.getJavaMember().getName().equals("nonInjectAnnotatedInitializer")) {
            AnnotatedMethodWrapper<? super Grocery> wrappedMethod = new AnnotatedMethodWrapper(method, this, true, new Annotation[] { new InjectLiteral() });
            methods.add(wrappedMethod);
        } else if (method.getJavaMember().getName().equals("initializer")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methodWrapper.replaceParameters(new AnnotatedParameterWrapper(method.getParameters().get(0), methodWrapper, false, new CheapLiteral()) {

                @Override
                public Type getBaseType() {
                    getBaseTypeOfInitializerTropicalFruitParameterUsed = true;
                    return TropicalFruit.class;
                }
            });
            methods.add(methodWrapper);
        } else if (method.getJavaMember().getName().equals("observer1")) {
            Annotation[] parameterAnnotations = new Annotation[] { new Observes() {

                public TransactionPhase during() {
                    return TransactionPhase.IN_PROGRESS;
                }

                public Reception notifyObserver() {
                    return Reception.ALWAYS;
                }

                public Class<? extends Annotation> annotationType() {
                    return Observes.class;
                }
            }, new CheapLiteral() };
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methods.add(wrapMethodParameters(method.getParameters(), methodWrapper, false, parameterAnnotations));
        } else if (method.getJavaMember().getName().equals("observer2")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methods.add(wrapMethodParameters(method.getParameters(), methodWrapper, true, new ExpensiveLiteral()));
        } else if (method.getJavaMember().getName().equals("observerMilk")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methodWrapper.replaceParameters(new AnnotatedParameterWrapper(methodWrapper.getParameter(0), methodWrapper, true), new AnnotatedParameterWrapper(methodWrapper.getParameter(1), methodWrapper, true) {

                @Override
                public Type getBaseType() {
                    getBaseTypeOfObserverInjectionPointUsed = true;
                    return TropicalFruit.class;
                }
            });
            methods.add(methodWrapper);
        } else if (method.getJavaMember().getName().equals("destroyBill")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            // replace the second parameter and keep the first one
            methodWrapper.replaceParameters(new AnnotatedParameterWrapper(methodWrapper.getParameter(0), methodWrapper, true), new AnnotatedParameterWrapper(methodWrapper.getParameter(1), methodWrapper, true, Any.Literal.INSTANCE) {

                @Override
                public Type getBaseType() {
                    getBaseTypeOfBillDisposerParameterUsed = true;
                    return TropicalFruit.class;
                }
            });
            methods.add(methodWrapper);
        } else if (method.getJavaMember().getName().equals("observesVegetable")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methodWrapper.replaceParameters(new AnnotatedParameterWrapper(methodWrapper.getParameter(0), methodWrapper, true) {

                @Override
                public Type getBaseType() {
                    getBaseTypeOfObserverParameterUsed = true;
                    return Carrot.class;
                }
            });
            methods.add(methodWrapper);
        } else if (method.getJavaMember().getName().equals("destroyVegetable")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methodWrapper.replaceParameters(new AnnotatedParameterWrapper(methodWrapper.getParameter(0), methodWrapper, true, new CheapLiteral()) {

                @Override
                public Type getBaseType() {
                    return Carrot.class;
                }
            });
            methods.add(methodWrapper);
        } else if (method.getJavaMember().getName().equals("destroyYogurt")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true);
            methodWrapper.replaceParameters(new AnnotatedParameterWrapper(methodWrapper.getParameter(0), methodWrapper, false, new Annotation[] { new ExpensiveLiteral(), new Disposes() {

                public Class<? extends Annotation> annotationType() {
                    return Disposes.class;
                }
            } }));
            methods.add(methodWrapper);
        } else if (method.getJavaMember().getName().equals("createVegetable")) {
            AnnotatedMethodWrapper<? super Grocery> methodWrapper = new AnnotatedMethodWrapper(method, this, true) {

                @Override
                public Set<Type> getTypeClosure() {
                    Set<Type> types = new HashSet<Type>();
                    types.add(Carrot.class);
                    getTypeClosureOfProducerMethodUsed = true;
                    return types;
                }
            };
            methods.add(methodWrapper);
        } else {
            methods.add(method);
        }
    }
    return methods;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AnnotatedMethod(jakarta.enterprise.inject.spi.AnnotatedMethod) InjectLiteral(jakarta.enterprise.inject.literal.InjectLiteral) Annotation(java.lang.annotation.Annotation) Disposes(jakarta.enterprise.inject.Disposes) Type(java.lang.reflect.Type) AnnotatedType(jakarta.enterprise.inject.spi.AnnotatedType) Produces(jakarta.enterprise.inject.Produces) AnnotationLiteral(jakarta.enterprise.util.AnnotationLiteral) Observes(jakarta.enterprise.event.Observes) AnnotatedParameterWrapper(org.jboss.cdi.tck.util.annotated.AnnotatedParameterWrapper) AnnotatedMethodWrapper(org.jboss.cdi.tck.util.annotated.AnnotatedMethodWrapper) HashSet(java.util.HashSet)

Example 3 with AnnotationLiteral

use of jakarta.enterprise.util.AnnotationLiteral in project cdi-tck by eclipse-ee4j.

the class DecoratorDefinitionTest method testEmptyTypeSetOnResolveDecoratorsFails.

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = BM_DECORATOR_RESOLUTION, id = "e")
public void testEmptyTypeSetOnResolveDecoratorsFails() {
    Annotation binding = new AnnotationLiteral<NonMeta>() {
    };
    getCurrentManager().resolveDecorators(new HashSet<Type>(), binding);
}
Also used : Type(java.lang.reflect.Type) AnnotationLiteral(jakarta.enterprise.util.AnnotationLiteral) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test) AbstractTest(org.jboss.cdi.tck.AbstractTest) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 4 with AnnotationLiteral

use of jakarta.enterprise.util.AnnotationLiteral in project cdi-tck by eclipse-ee4j.

the class DecoratorDefinitionTest method testDuplicateBindingsOnResolveDecoratorsFails.

@Test(expectedExceptions = IllegalArgumentException.class)
@SpecAssertion(section = BM_DECORATOR_RESOLUTION, id = "c")
public void testDuplicateBindingsOnResolveDecoratorsFails() {
    Annotation binding = new AnnotationLiteral<Meta>() {
    };
    getCurrentManager().resolveDecorators(FooBar.TYPES, binding, binding);
}
Also used : AnnotationLiteral(jakarta.enterprise.util.AnnotationLiteral) Annotation(java.lang.annotation.Annotation) Test(org.testng.annotations.Test) AbstractTest(org.jboss.cdi.tck.AbstractTest) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Example 5 with AnnotationLiteral

use of jakarta.enterprise.util.AnnotationLiteral in project cdi-tck by eclipse-ee4j.

the class EnterpriseBeanDefinitionTest method testBeanWithQualifiers.

@Test
@SpecAssertion(section = DECLARING_SESSION_BEAN, id = "be")
public void testBeanWithQualifiers() {
    Annotation tame = new AnnotationLiteral<Tame>() {
    };
    Bean<ApeLocal> apeBean = getBeans(ApeLocal.class, tame).iterator().next();
    assert apeBean.getQualifiers().contains(tame);
}
Also used : AnnotationLiteral(jakarta.enterprise.util.AnnotationLiteral) Annotation(java.lang.annotation.Annotation) AbstractTest(org.jboss.cdi.tck.AbstractTest) Test(org.testng.annotations.Test) SpecAssertion(org.jboss.test.audit.annotations.SpecAssertion)

Aggregations

AnnotationLiteral (jakarta.enterprise.util.AnnotationLiteral)8 Annotation (java.lang.annotation.Annotation)7 Test (org.testng.annotations.Test)6 AbstractTest (org.jboss.cdi.tck.AbstractTest)5 SpecAssertion (org.jboss.test.audit.annotations.SpecAssertion)4 Type (java.lang.reflect.Type)2 Observes (jakarta.enterprise.event.Observes)1 Disposes (jakarta.enterprise.inject.Disposes)1 Produces (jakarta.enterprise.inject.Produces)1 InjectLiteral (jakarta.enterprise.inject.literal.InjectLiteral)1 AnnotatedMethod (jakarta.enterprise.inject.spi.AnnotatedMethod)1 AnnotatedType (jakarta.enterprise.inject.spi.AnnotatedType)1 BeanManager (jakarta.enterprise.inject.spi.BeanManager)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)1 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)1 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)1 AnnotatedMethodWrapper (org.jboss.cdi.tck.util.annotated.AnnotatedMethodWrapper)1 AnnotatedParameterWrapper (org.jboss.cdi.tck.util.annotated.AnnotatedParameterWrapper)1