use of org.apache.xbean.finder.ClassFinder in project tomee by apache.
the class TestClient method processSetterInjections.
protected final void processSetterInjections() {
Object home = null;
ClassFinder finder = null;
List<Method> methodList = null;
finder = new ClassFinder(getClassPath());
methodList = finder.findAnnotatedMethods(EJB.class);
for (final Iterator methods = methodList.iterator(); methods.hasNext(); ) {
final Method method = (Method) methods.next();
final EJB ejbAnnotation = method.getAnnotation(EJB.class);
if ((ejbAnnotation.name() != null) && (ejbAnnotation.name() != "") && (ejbAnnotation.beanInterface() != null)) {
try {
home = initialContext.lookup(ejbAnnotation.name());
// home = ejbAnnotation.beanInterface().cast(home;
home = cast(home, ejbAnnotation.beanInterface());
method.setAccessible(true);
method.invoke(this, new Object[] { home });
} catch (final Exception ex) {
// TODO - MNour : Needs better exception handling
ex.printStackTrace();
}
}
}
}
use of org.apache.xbean.finder.ClassFinder in project tomee by apache.
the class ApplicationComposers method validate.
private void validate() {
final List<Throwable> errors = new ArrayList<>();
if (isContainer()) {
final Map<Object, List<Method>> annotatedConfigurationMethods = findAnnotatedMethods(new HashMap<Object, List<Method>>(), Configuration.class);
{
int nbProp = 0;
int nbOpenejb = 0;
for (final List<Method> list : annotatedConfigurationMethods.values()) {
for (final Method m : list) {
final Class<?> type = m.getReturnType();
if (Openejb.class.isAssignableFrom(type) || String.class.equals(type)) {
nbOpenejb++;
} else if (Properties.class.isAssignableFrom(type)) {
nbProp++;
}
// else not supported?
}
}
if (nbProp > 1 || nbOpenejb > 1) {
final String gripe = "Test class should have no more than one @Configuration method by type (Openejb/String or Properties)";
errors.add(new Exception(gripe));
}
}
int injectorSize = 0;
for (final List<Method> m : findAnnotatedMethods(new HashMap<Object, List<Method>>(), org.apache.openejb.junit.MockInjector.class).values()) {
injectorSize += m.size();
}
for (final List<Method> m : findAnnotatedMethods(new HashMap<Object, List<Method>>(), MockInjector.class).values()) {
injectorSize += m.size();
}
if (injectorSize > 1) {
errors.add(new Exception("Test class should have no more than one @MockInjector method"));
}
final List<Method> components = new ArrayList<>();
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), Component.class).values()) {
components.addAll(l);
}
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), org.apache.openejb.junit.Component.class).values()) {
components.addAll(l);
}
for (final Method method : components) {
if (method.getParameterTypes().length > 0) {
errors.add(new Exception("@Component methods shouldn't take any parameters"));
}
}
for (final ClassFinder finder : testClassFinders.values()) {
for (final Field field : finder.findAnnotatedFields(RandomPort.class)) {
final Class<?> type = field.getType();
if (int.class != type && URL.class != type) {
throw new IllegalArgumentException("@RandomPort is only supported for int fields");
}
}
}
}
if (isApplication()) {
final List<Method> descriptors = new ArrayList<>();
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), Descriptors.class).values()) {
descriptors.addAll(l);
}
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), org.apache.openejb.junit.Descriptors.class).values()) {
descriptors.addAll(l);
}
for (final Method method : descriptors) {
final Class<?> returnType = method.getReturnType();
if (!returnType.equals(WebModule.class) && !returnType.equals(EjbModule.class) && !returnType.equals(WebApp.class) && !returnType.equals(EjbJar.class) && !returnType.equals(AppModule.class)) {
errors.add(new Exception("@Descriptors can't be used on " + returnType.getName()));
}
}
final List<Method> classes = new ArrayList<>();
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), Classes.class).values()) {
classes.addAll(l);
}
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), org.apache.openejb.junit.Classes.class).values()) {
classes.addAll(l);
}
for (final Method method : classes) {
final Class<?> returnType = method.getReturnType();
if (!returnType.equals(WebModule.class) && !returnType.equals(EjbModule.class) && !returnType.equals(WebApp.class) && !returnType.equals(EjbJar.class) && !EnterpriseBean.class.isAssignableFrom(returnType)) {
errors.add(new Exception("@Classes can't be used on a method returning " + returnType));
}
}
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), Jars.class).values()) {
for (final Method method : l) {
final Class<?> returnType = method.getReturnType();
if (!returnType.equals(WebModule.class) && !returnType.equals(EjbModule.class) && !returnType.equals(WebApp.class) && !returnType.equals(EjbJar.class) && !EnterpriseBean.class.isAssignableFrom(returnType)) {
errors.add(new Exception("@Classes can't be used on a method returning " + returnType));
}
}
}
int appModules = 0;
int modules = 0;
final List<Method> moduleMethods = new ArrayList<>();
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), Module.class).values()) {
moduleMethods.addAll(l);
}
for (final List<Method> l : findAnnotatedMethods(new HashMap<Object, List<Method>>(), org.apache.openejb.junit.Module.class).values()) {
moduleMethods.addAll(l);
}
for (final Method method : moduleMethods) {
modules++;
final Class<?> type = method.getReturnType();
if (Application.class.isAssignableFrom(type)) {
appModules++;
} else if (!isValidModuleType(type, MODULE_TYPES)) {
final String gripe = "@Module method must return " + Join.join(" or ", MODULE_TYPES).replaceAll("(class|interface) ", "");
errors.add(new Exception(gripe));
}
}
if (appModules > 1) {
final String gripe = "Test class should have no more than one @Module method that returns " + Application.class.getName();
errors.add(new Exception(gripe));
}
if (modules < 1 && testClass.getAnnotation(Classes.class) == null && testClass.getAnnotation(Default.class) == null) {
final String gripe = "Test class should have at least one @Module method";
errors.add(new Exception(gripe));
}
}
if (!errors.isEmpty()) {
throw new OpenEJBRuntimeException(errors.toString());
}
}
use of org.apache.xbean.finder.ClassFinder in project tomee by apache.
the class ApplicationComposers method fixFakeClassFinder.
private ClassFinder fixFakeClassFinder(final Object inputTestInstance) {
// test injections, we faked the instance before having it so ensuring we use the right finder
ClassFinder testClassFinder = testClassFinders.get(inputTestInstance);
if (testClassFinder == null) {
final ApplicationComposers self = this;
final ClassFinder remove = testClassFinders.remove(self);
if (remove != null) {
testClassFinders.put(inputTestInstance, remove);
testClassFinder = remove;
afterRunnables.add(new // reset state for next test
Runnable() {
@Override
public void run() {
final ClassFinder classFinder = testClassFinders.remove(inputTestInstance);
if (classFinder != null) {
testClassFinders.put(self, classFinder);
}
}
});
}
}
return testClassFinder;
}
use of org.apache.xbean.finder.ClassFinder in project tomee by apache.
the class AnnotationDeployerTest method testModule.
private EjbModule testModule() {
final EjbJar ejbJar = new EjbJar("test-classes");
final EjbModule ejbModule = new EjbModule(ejbJar);
ejbModule.setFinder(new ClassFinder(AnnotationDeployerTest.class, BusinessException.class, Exception.class, GenericInterface.class, InterceptedSLSBean.class, MyMainClass.class, TestLocalBean.class, ValueRequiredException.class));
return ejbModule;
}
use of org.apache.xbean.finder.ClassFinder in project tomee by apache.
the class AnnotationDeployerTest method testConnectorModule.
private ConnectorModule testConnectorModule() {
final Connector connector = new Connector();
final ConnectorModule connectorModule = new ConnectorModule(connector);
connectorModule.setFinder(new ClassFinder(TestConnector.class, TestManagedConnectionFactory.class, TestActivation.class, TestAdminObject.class));
return connectorModule;
}
Aggregations