Search in sources :

Example 51 with Result

use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.

the class EjbFinderMethodObjectNotFoundException method check.

/**
 * Single-object ejbFind<METHOD>(...) methods throws ObjectNotFoundException
 *  test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     The ObjectNotFoundException is a subclass of FinderException. It is
 *     thrown by the ejbFind<METHOD>(...) methods to indicate that the
 *     requested entity object does not exist.
 *
 *     Only single-object finders (see Subsection 9.1.8) may throw this
 *     exception.   Multi-object finders must not throw this exception.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean okayToThrowObjectNotFoundException = false;
            boolean throwsObjectNotFoundException = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    String primaryKeyType = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            okayToThrowObjectNotFoundException = false;
                            throwsObjectNotFoundException = false;
                            Class returnByPrimaryKeyValue = ejbFinderMethods[j].getReturnType();
                            foundAtLeastOne++;
                            // exception.   Multi-object finders must not throw this exception.
                            if (returnByPrimaryKeyValue.getName().equals(primaryKeyType)) {
                                okayToThrowObjectNotFoundException = true;
                            } else if ((returnByPrimaryKeyValue.getName().equals("java.util.Collection")) || (returnByPrimaryKeyValue.getName().equals("java.util.Enumeration"))) {
                                okayToThrowObjectNotFoundException = false;
                            }
                            // test passes or is not applicable
                            if (!okayToThrowObjectNotFoundException) {
                                // get the exceptions and see if this method throw
                                // ObjectNotFoundException when it was not allowed to
                                Class[] exceptions = ejbFinderMethods[j].getExceptionTypes();
                                if (EjbUtils.isValidObjectNotFoundExceptionException(exceptions)) {
                                    throwsObjectNotFoundException = true;
                                }
                            }
                            if ((okayToThrowObjectNotFoundException) || ((!okayToThrowObjectNotFoundException) && (!throwsObjectNotFoundException))) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "An [ {0} ] method was found with valid exception types declared in throws clause.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if ((!okayToThrowObjectNotFoundException) && throwsObjectNotFoundException) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but [ {1} ] throws ObjectNotFoundException.  Multi-object finder methods must not throw this exception.", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", new Object[] { descriptor.getEjbClassName() }));
                }
            } catch (ClassNotFoundException e) {
                Verifier.debug(e);
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 52 with Result

use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.

the class EjbFinderMethodFinal method check.

/**
 * ejbFind<METHOD>(...) methods test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     The method must not be declared as final.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean ejbFindMethodFound = false;
            boolean isFinal = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        isFinal = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            foundAtLeastOne++;
                            ejbFindMethodFound = true;
                            // The method must not be declared as final.
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isFinal(findMethodModifiers)) {
                                isFinal = true;
                            }
                            if (ejbFindMethodFound && !isFinal) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A non-final [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && isFinal) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A final [ {0} ] method was found, but [ {1} ] cannot be declared as final.", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", new Object[] { descriptor.getEjbClassName() }));
                }
            } catch (ClassNotFoundException e) {
                Verifier.debug(e);
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 53 with Result

use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.

the class EjbFinderMethodPublic method check.

/**
 * ejbFind<METHOD>(...) methods test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     A finder method must be declared as public.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean ejbFindMethodFound = false;
            boolean isPublic = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        isPublic = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            ejbFindMethodFound = true;
                            foundAtLeastOne++;
                            // A finder method must be declared as public. check the modifier
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isPublic(findMethodModifiers)) {
                                isPublic = true;
                            }
                            if (ejbFindMethodFound && isPublic) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A public [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && !isPublic) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but was not public.", new Object[] { ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "No ejbFind<METHOD> method was found in [ {0} ] class.", new Object[] { descriptor.getEjbClassName() }));
                }
            } catch (ClassNotFoundException e) {
                Verifier.debug(e);
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 54 with Result

use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.

the class EjbFinderMethodStatic method check.

/**
 * ejbFind<METHOD>(...) methods test.
 *
 *   EJB class contains all ejbFind<METHOD>(...) methods declared in the bean
 *   class.
 *
 *   The signatures of the finder methods must follow the following rules:
 *
 *     A finder method name must start with the prefix ``ejbFind''
 *     (e.g. ejbFindByPrimaryKey, ejbFindLargeAccounts, ejbFindLateShipments).
 *
 *     The method must not be declared as static.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            boolean ejbFindMethodFound = false;
            boolean isStatic = false;
            boolean oneFailed = false;
            int findMethodModifiers = 0;
            int foundAtLeastOne = 0;
            try {
                // retrieve the EJB Class Methods
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                // start do while loop here....
                do {
                    Method[] ejbFinderMethods = EJBClass.getDeclaredMethods();
                    for (int j = 0; j < ejbFinderMethods.length; ++j) {
                        isStatic = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            ejbFindMethodFound = true;
                            foundAtLeastOne++;
                            // The method must not be declared as static.
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isStatic(findMethodModifiers)) {
                                isStatic = true;
                            }
                            if (ejbFindMethodFound && !isStatic) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "A non-static [ {0} ] method was found.", new Object[] { ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && isStatic) {
                                oneFailed = true;
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: A static [ {0} ] method was found, but [ {1} ] cannot be declared as static.", new Object[] { ejbFinderMethods[j].getName(), ejbFinderMethods[j].getName() }));
                            }
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (foundAtLeastOne == 0));
                if (foundAtLeastOne == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbFind<METHOD>(...) methods.", new Object[] { descriptor.getEjbClassName() }));
                }
            } catch (ClassNotFoundException e) {
                Verifier.debug(e);
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: EJB Class [ {1} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundAtLeastOne == 0) {
                result.setStatus(result.NOT_APPLICABLE);
            } else {
                result.setStatus(result.PASSED);
            }
            return result;
        } else {
            // if (CONTAINER_PERSISTENCE.equals(persistence))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistence }));
            return result;
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 55 with Result

use of com.sun.enterprise.tools.verifier.Result in project Payara by payara.

the class EjbPostCreateMethodArgs method check.

/**
 * Entity Bean's ejbPostCreate(...) methods test.
 * Each entity Bean class may define zero or more ejbPostCreate(...) methods.
 * The number and signatures of a entity Bean's create methods are specific
 * to each EJB class. The method signatures must follow these rules:
 *
 * The method name must be ejbPostCreate.
 *
 * The methods arguments must be the same as the arguments of the
 * matching ejbCreate(...) method.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor instanceof EjbEntityDescriptor) {
        boolean oneFailed = false;
        int foundAtLeastOne = 0;
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
            Class[] ejbPostCreateMethodParameterTypes;
            Class[] ejbCreateMethodParameterTypes;
            boolean signaturesMatch = false;
            boolean ejbCreateExists = false;
            Method[] methods = c.getDeclaredMethods();
            Vector<Method> createMethodSuffix = new Vector<Method>();
            for (int i = 0; i < methods.length; i++) {
                // The method name must start with create.
                if (methods[i].getName().startsWith("ejbCreate")) {
                    createMethodSuffix.addElement((Method) methods[i]);
                    ejbCreateExists = true;
                }
            }
            // start do while loop here....
            do {
                for (int i = 0; i < methods.length; i++) {
                    // reset flags from last time thru loop
                    signaturesMatch = false;
                    // The method name must be ejbPostCreate.
                    if (methods[i].getName().startsWith("ejbPostCreate")) {
                        foundAtLeastOne++;
                        String matchSuffix = methods[i].getName().substring(13);
                        for (int k = 0; k < createMethodSuffix.size(); k++) {
                            if (matchSuffix.equals(((Method) createMethodSuffix.elementAt(k)).getName().substring(9))) {
                                ejbCreateMethodParameterTypes = ((Method) createMethodSuffix.elementAt(k)).getParameterTypes();
                                ejbPostCreateMethodParameterTypes = methods[i].getParameterTypes();
                                if (Arrays.equals(ejbCreateMethodParameterTypes, ejbPostCreateMethodParameterTypes)) {
                                    signaturesMatch = true;
                                    break;
                                }
                            }
                        }
                        if (signaturesMatch) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                            result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] declares [ {1} ] method with parameters that match corresponding [ {2} ] method.", new Object[] { descriptor.getEjbClassName(), methods[i].getName(), "ejbCreate<method>" }));
                        } else if (!signaturesMatch) {
                            oneFailed = true;
                            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: An [ {0} ] method was found, but [ {1} ] method parameters did not match any corresponding [ {2} ] method parameters.", new Object[] { methods[i].getName(), methods[i].getName(), "ejbCreate<method>" }));
                            break;
                        }
                    }
                }
                if (oneFailed == true)
                    break;
            } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
            if (ejbCreateExists == false) {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "[ {0} ] does not declare any ejbPostCreate(...) methods.", new Object[] { descriptor.getEjbClassName() }));
            }
            if (foundAtLeastOne == 0 && ejbCreateExists == true) {
                oneFailed = true;
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException1", "Error: ejbPostCreate<Method> method corresponding to the ejbCreate<Method> method does not exist!", new Object[] {}));
            }
        } catch (ClassNotFoundException e) {
            Verifier.debug(e);
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getEjbClassName() }));
            oneFailed = true;
        }
        if (oneFailed) {
            result.setStatus(result.FAILED);
        } else if (foundAtLeastOne == 0) {
            result.setStatus(result.NOT_APPLICABLE);
        } else {
            result.setStatus(result.PASSED);
        }
        return result;
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "[ {0} ] expected {1} bean, but called with {2} bean.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Method(java.lang.reflect.Method) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Vector(java.util.Vector) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Aggregations

Result (com.sun.enterprise.tools.verifier.Result)288 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)88 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Method (java.lang.reflect.Method)66 Iterator (java.util.Iterator)50 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)26 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)17 Enumeration (java.util.Enumeration)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)14 Field (java.lang.reflect.Field)13 EnvironmentProperty (com.sun.enterprise.deployment.EnvironmentProperty)10 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)9 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)9 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 ConnectionDefDescriptor (com.sun.enterprise.deployment.ConnectionDefDescriptor)6 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6