Search in sources :

Example 86 with EjbEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.

the class EjbCreateMethodReturn method check.

/**
 * Entity Bean's ejbCreate(...) methods return test.
 * Each entity Bean class may define zero or more ejbCreate(...) 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 ejbCreate.
 *
 * The return type must be primary key type.
 *
 * @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 oneFailed = false;
            boolean oneWarning = false;
            int foundAtLeastOne = 0;
            try {
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                String primaryKeyType = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
                boolean ejbCreateFound = false;
                boolean returnsPrimaryKeyType = false;
                // start do while loop here....
                do {
                    Method[] methods = c.getDeclaredMethods();
                    for (int i = 0; i < methods.length; i++) {
                        // reset flags from last time thru loop
                        ejbCreateFound = false;
                        returnsPrimaryKeyType = false;
                        // The method name must be ejbCreate.
                        if (methods[i].getName().startsWith("ejbCreate")) {
                            foundAtLeastOne++;
                            ejbCreateFound = true;
                            // The return type must be primary key type.
                            Class rt = methods[i].getReturnType();
                            if (rt.getName().equals(primaryKeyType)) {
                                returnsPrimaryKeyType = true;
                            }
                            // method
                            if (ejbCreateFound && !returnsPrimaryKeyType) {
                                if (primaryKeyType.equals("java.lang.Object")) {
                                    oneWarning = true;
                                    result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                    result.addWarningDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] method [ {1} ]", new Object[] { descriptor.getEjbClassName(), methods[i].getName() }));
                                    result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Warning: An [ {0} ] method was found, but [ {1} ] method has [ {2} ] return type.   Deployment descriptor primary key type [ {3} ]. Definition of the primary key type is deferred to deployment time ?", new Object[] { methods[i].getName(), methods[i].getName(), methods[i].getReturnType().getName(), primaryKeyType }));
                                } else {
                                    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 has illegal return value.   [ {2} ] methods must return primary key type [ {3} ].", new Object[] { methods[i].getName(), methods[i].getName(), methods[i].getName(), primaryKeyType }));
                                    break;
                                }
                            }
                        }
                    }
                    if (oneFailed == true)
                        break;
                } while (((c = c.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() + ".notApplicable0", "[ {0} ] does not declare any ejbCreate(...) methods.", new Object[] { descriptor.getEjbClassName() }));
                }
                if (oneFailed == false && foundAtLeastOne > 0) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ]", new Object[] { descriptor.getEjbClassName() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly declares ejbCreate<method> method to return primary key type [ {1} ].", new Object[] { descriptor.getEjbClassName(), primaryKeyType }));
                }
            } 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 {
                if (oneWarning) {
                    result.setStatus(result.WARNING);
                } 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() + ".notApplicable1", "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 87 with EjbEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.

the class EjbFindByPrimaryKeyException method check.

/**
 * Define ejbFindByPrimaryKey method exception test.
 *
 *     Every entity enterprise Bean class must define the ejbFindByPrimaryKey
 *     method.
 *
 *     Compatibility Note: EJB 1.0 allowed the finder methods to throw the
 *     java.rmi.RemoteException to indicate a non-application exception. This
 *     practice is deprecated in EJB 1.1---an EJB 1.1 compliant enterprise
 *     bean should throw the javax.ejb.EJBException or another
 *     java.lang.RuntimeException to indicate non-application exceptions to
 *     the Container.
 *
 * @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 persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) {
            boolean ejbFindByPrimaryKeyMethodFound = false;
            boolean throwsRemoteException = false;
            boolean oneFailed = false;
            int foundWarning = 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) {
                        if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) {
                            // Every entity enterprise Bean class must define the
                            // ejbFindByPrimaryKey method.
                            ejbFindByPrimaryKeyMethodFound = true;
                            // Compatibility Note: EJB 1.0 allowed the ejbFindByPrimaryKey to
                            // throw the java.rmi.RemoteException to indicate a non-application
                            // exception. This practice is deprecated in EJB 1.1---an EJB 1.1
                            // compliant enterprise bean should throw the javax.ejb.EJBException
                            // or another RuntimeException to indicate non-application
                            // exceptions to the Container (see Section 12.2.2).
                            // Note: Treat as a warning to user in this instance.
                            Class[] exceptions = ejbFinderMethods[j].getExceptionTypes();
                            for (int z = 0; z < exceptions.length; ++z) {
                                if (exceptions[z].getName().equals("java.rmi.RemoteException")) {
                                    throwsRemoteException = true;
                                    break;
                                }
                            }
                            if (ejbFindByPrimaryKeyMethodFound && (!throwsRemoteException)) {
                                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", "[ {0} ] declares [ {1} ] method, which properly does not throw java.rmi.RemoteException", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                            } else if (ejbFindByPrimaryKeyMethodFound && throwsRemoteException) {
                                result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addWarningDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder Method [ {1} ]", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                                result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Error: Compatibility Note:" + "\n An [ {0} ] method was found, but" + "\n EJB 1.0 allowed the ejbFindByPrimaryKey method to throw " + "\n the java.rmi.RemoteException to indicate a non-application" + "\n exception. This practice is deprecated in EJB 1.1" + "\n ---an EJB 1.1 compliant enterprise bean should" + "\n throw the javax.ejb.EJBException or another " + "\n RuntimeException to indicate non-application exceptions" + "\n to the Container. ", new Object[] { ejbFinderMethods[j].getName() }));
                                foundWarning++;
                            }
                            // found one, and there should only be one, break out
                            break;
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound));
                if (!ejbFindByPrimaryKeyMethodFound) {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug3", "For EJB Class [ {0} ]", new Object[] { descriptor.getEjbClassName() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No ejbFindByPrimaryKey method was found in bean class."));
                }
            } 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 [ {0} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else if (foundWarning > 0) {
                result.setStatus(result.WARNING);
            } else {
                result.setStatus(result.PASSED);
            }
        } else {
            // (CONTAINER_PERSISTENCE.equals(persistentType))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistentType }));
        }
        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 88 with EjbEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.

the class EjbFindByPrimaryKeyFinal method check.

/**
 * Define ejbFindByPrimaryKey method final test.
 *
 *     Every entity enterprise Bean class must define the ejbFindByPrimaryKey
 *     method.
 *
 *     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 persistentType = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) {
            boolean ejbFindByPrimaryKeyMethodFound = false;
            boolean isFinal = false;
            boolean oneFailed = false;
            int findMethodModifiers = 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) {
                        if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) {
                            // Every entity enterprise Bean class must define the
                            // ejbFindByPrimaryKey method.
                            ejbFindByPrimaryKeyMethodFound = true;
                            // The method must not be declared as final.
                            findMethodModifiers = ejbFinderMethods[j].getModifiers();
                            if (Modifier.isFinal(findMethodModifiers)) {
                                isFinal = true;
                            }
                            if (ejbFindByPrimaryKeyMethodFound && !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 (ejbFindByPrimaryKeyMethodFound && 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() }));
                            }
                            // found one, and there should only be one, break out
                            break;
                        }
                    }
                } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound));
                if (!ejbFindByPrimaryKeyMethodFound) {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug3", "For EJB Class [ {0} ]", new Object[] { descriptor.getEjbClassName() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed1", "Error: No ejbFindByPrimaryKey method was found in bean class."));
                }
            } 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 [ {0} ] does not exist or is not loadable.", new Object[] { descriptor.getEjbClassName() }));
                oneFailed = true;
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else {
                result.setStatus(result.PASSED);
            }
        } else {
            // (CONTAINER_PERSISTENCE.equals(persistentType))
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", new Object[] { EjbEntityDescriptor.BEAN_PERSISTENCE, descriptor.getName(), persistentType }));
        }
        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 89 with EjbEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.

the class EjbFinderMethodException 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).
 *
 *     Compatibility Note: EJB 1.0 allowed the finder methods to throw the
 *     java.rmi.RemoteException to indicate a non-application exception. This
 *     practice is deprecated in EJB 1.1---an EJB 1.1 compliant enterprise
 *     bean should throw the javax.ejb.EJBException or another
 *     java.lang.RuntimeException to indicate non-application exceptions to
 *     the Container.
 *
 * @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 throwsRemoteException = false;
            boolean throwsFinderException = false;
            boolean isValidFinderException = false;
            boolean oneFailed = false;
            int foundWarning = 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) {
                        throwsRemoteException = false;
                        throwsFinderException = false;
                        ejbFindMethodFound = false;
                        if (ejbFinderMethods[j].getName().startsWith("ejbFind")) {
                            ejbFindMethodFound = true;
                            foundAtLeastOne++;
                            // Compatibility Note: EJB 1.0 allowed the ejbFind<METHOD> to
                            // throw the java.rmi.RemoteException to indicate a non-application
                            // exception. This practice is deprecated in EJB 1.1---an EJB 1.1
                            // compliant enterprise bean should throw the javax.ejb.EJBException
                            // or another RuntimeException to indicate non-application
                            // exceptions to the Container (see Section 12.2.2).
                            // Note: Treat as a warning to user in this instance.
                            Class[] exceptions = ejbFinderMethods[j].getExceptionTypes();
                            if (EjbUtils.isValidRemoteException(exceptions)) {
                                throwsRemoteException = true;
                            }
                            if (EjbUtils.isValidFinderException(exceptions)) {
                                throwsFinderException = true;
                            }
                            if (ejbFindMethodFound && throwsRemoteException == false && throwsFinderException == true) {
                                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", "[ {0} ] declares [ {1} ] method, which properly does not throw java.rmi.RemoteException, but throws FinderException", new Object[] { EJBClass.getName(), ejbFinderMethods[j].getName() }));
                            } else if (ejbFindMethodFound && throwsRemoteException == true) {
                                if (descriptor instanceof EjbCMPEntityDescriptor) {
                                    if (((EjbCMPEntityDescriptor) descriptor).getCMPVersion() == EjbCMPEntityDescriptor.CMP_2_x) {
                                        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[] { descriptor.getEjbClassName(), ejbFinderMethods[j].getName() }));
                                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".error", "Error: Compatibility Note:" + "\n An [ {0} ] method was found, but" + "\n EJB 1.0 allowed the ejbFind<METHOD> method to throw the " + "\n java.rmi.RemoteException to indicate a non-application" + "\n exception. This practice was deprecated in EJB 1.1" + "\n ---an EJB 2.0 compliant enterprise bean must" + "\n throw the javax.ejb.EJBException or another " + "\n RuntimeException to indicate non-application exceptions" + "\n to the Container. ", new Object[] { ejbFinderMethods[j].getName() }));
                                        oneFailed = true;
                                    } else {
                                        // warning for 1.1
                                        foundWarning++;
                                        result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                        result.addWarningDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB Class [ {0} ] Finder method [ {1} ]", new Object[] { descriptor.getEjbClassName(), ejbFinderMethods[j].getName() }));
                                        result.addWarningDetails(smh.getLocalString(getClass().getName() + ".warning", "Error: Compatibility Note:" + "\n An [ {0} ] method was found, but" + "\n EJB 1.0 allowed the ejbFind<METHOD> method to throw the " + "\n java.rmi.RemoteException to indicate a non-application" + "\n exception. This practice is deprecated in EJB 1.1" + "\n ---an EJB 1.1 compliant enterprise bean should" + "\n throw the javax.ejb.EJBException or another " + "\n RuntimeException to indicate non-application exceptions" + "\n to the Container. ", new Object[] { ejbFinderMethods[j].getName() }));
                                    }
                                } else {
                                    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() }));
                                }
                            } else if (ejbFindMethodFound && throwsFinderException == false) {
                                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[] { descriptor.getEjbClassName(), ejbFinderMethods[j].getName() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".error1", "Error: ejbFind[Method] [ {0} ] does not throw FinderException", new Object[] { ejbFinderMethods[j].getName() }));
                                oneFailed = true;
                            }
                        }
                    }
                } 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 if (foundWarning > 0) {
                result.setStatus(result.WARNING);
            } 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) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 90 with EjbEntityDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor in project Payara by payara.

the class EjbHasLocalorRemoteorBothInterfaces method check.

/**
 * Bean interface type test.
 * The bean provider must provide either Local or Remote or Both interfaces
 *
 * @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 EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceClassExist.notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    if ((descriptor.getRemoteClassName() == null || "".equals(descriptor.getRemoteClassName())) && (descriptor.getLocalClassName() == null || "".equals(descriptor.getLocalClassName()))) {
        if (implementsEndpoints(descriptor)) {
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", new Object[] { compName.toString() }));
            return result;
        } else {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Ejb [ {0} ] does not have local or remote interfaces", new Object[] { descriptor.getEjbClassName() }));
            return result;
        }
    } else {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Ejb [ {0} ] does have valid local and/or remote interfaces", new Object[] { descriptor.getEjbClassName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)101 Result (com.sun.enterprise.tools.verifier.Result)88 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)87 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)49 Method (java.lang.reflect.Method)42 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)18 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)12 Iterator (java.util.Iterator)12 Field (java.lang.reflect.Field)10 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 Set (java.util.Set)8 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)7 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)7 Vector (java.util.Vector)5 Descriptor (org.glassfish.deployment.common.Descriptor)3 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)3 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)3 IASEjbExtraDescriptors (org.glassfish.ejb.deployment.descriptor.runtime.IASEjbExtraDescriptors)3 EjbMessageBeanDescriptor (com.sun.enterprise.deployment.EjbMessageBeanDescriptor)2