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();
}
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;
}
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);
}
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);
}
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);
}
Aggregations