private void validate()

in container/openejb-core/src/main/java/org/apache/openejb/testing/ApplicationComposers.java [207:347]


    private void validate() {
        final List<Throwable> errors = new ArrayList<>();

        if (isContainer()) {
            final Map<Object, List<Method>> annotatedConfigurationMethods = findAnnotatedMethods(new HashMap<>(), 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<>(), org.apache.openejb.junit.MockInjector.class).values()) {
                injectorSize += m.size();
            }
            for (final List<Method> m : findAnnotatedMethods(new HashMap<>(), 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<>(), Component.class).values()) {
                components.addAll(l);
            }
            for (final List<Method> l : findAnnotatedMethods(new HashMap<>(), 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<>(), Descriptors.class).values()) {
                descriptors.addAll(l);
            }
            for (final List<Method> l : findAnnotatedMethods(new HashMap<>(), 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<>(), Classes.class).values()) {
                classes.addAll(l);
            }
            for (final List<Method> l : findAnnotatedMethods(new HashMap<>(), 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<>(), 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<>(), Module.class).values()) {
                moduleMethods.addAll(l);
            }
            for (final List<Method> l : findAnnotatedMethods(new HashMap<>(), 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());
        }
    }