Search in sources :

Example 46 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor 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 47 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor 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 48 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor 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)

Example 49 with ComponentNameConstructor

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

the class PrimaryKeyClassConstructor method check.

/**
 * Enterprise Java Bean primary key class constuctor test.
 * The primary key class must have a public constructor that takes no
 * parameters.
 *
 * @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.CONTAINER_PERSISTENCE.equals(persistence)) {
            // field in entity bean class and this test in notApplicable
            try {
                FieldDescriptor fd = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
                if (fd != null) {
                    String pkf = fd.getName();
                    if (pkf.length() > 0) {
                        // N/A case
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", new Object[] { descriptor.getEjbClassName() }));
                    }
                } else {
                    try {
                        VerifierTestContext context = getVerifierContext();
                        ClassLoader jcl = context.getClassLoader();
                        Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
                        boolean foundOne = false;
                        Constructor[] constructors = c.getConstructors();
                        for (int i = 0; i < constructors.length; i++) {
                            int modifiers = constructors[i].getModifiers();
                            if (Modifier.isPublic(modifiers)) {
                                Class[] constructorParameterTypes;
                                constructorParameterTypes = constructors[i].getParameterTypes();
                                if (constructorParameterTypes.length > 0) {
                                    continue;
                                } else {
                                    foundOne = true;
                                    break;
                                }
                            }
                        }
                        if (foundOne) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "This primary key class [ {0} ] has a public constructor method with no parameters.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                        } else {
                            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: A public constructor method with no parameters was not found in the primary key class [ {0} ].", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                        }
                    } 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[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                    }
                }
            } catch (NullPointerException e) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
            }
            return result;
        } else {
            // if (BEAN_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.CONTAINER_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}.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Constructor(java.lang.reflect.Constructor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) Result(com.sun.enterprise.tools.verifier.Result) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 50 with ComponentNameConstructor

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

the class PrimaryKeyClassFieldsMatchBeanFields method check.

/**
 * Enterprise Java Bean primary key maps to multiple fields in the Entity bean
 * class test.
 *
 * The primkey-field element is not used if the primary key maps to multiple
 * container-managed fields (i.e. the key is a compound key). In this case, the
 * fields of the primary key class must be public, and their names must
 * correspond to the field names of the entity bean class that comprise the key.
 *
 * @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();
    // field names of the entity bean class that comprise the key.
    if (descriptor instanceof EjbEntityDescriptor) {
        String persistence = ((EjbEntityDescriptor) descriptor).getPersistenceType();
        if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
            // field in entity bean class and this test in notApplicable
            try {
                FieldDescriptor fd = ((EjbCMPEntityDescriptor) descriptor).getPrimaryKeyFieldDesc();
                if (fd != null) {
                    String pkf = fd.getName();
                    if (pkf.length() > 0) {
                        // N/A case
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean [ {0} ] with primekey-field non-blank, test not applicable.", new Object[] { descriptor.getEjbClassName() }));
                    }
                } else {
                    try {
                        VerifierTestContext context = getVerifierContext();
                        ClassLoader jcl = context.getClassLoader();
                        Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
                        Field[] fields = c.getDeclaredFields();
                        Vector beanFields = ((EjbDescriptor) descriptor).getFieldDescriptors();
                        boolean oneFailed = false;
                        boolean badField = false;
                        for (int i = 0; i < fields.length; i++) {
                            badField = false;
                            if (EjbUtils.isPKFieldMatchingBeanFields(fields[i], beanFields)) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed1", "Valid: Field [ {0} ] defined within primary key class [ {1} ] does correspond to the field names of the entity bean class [ {2} ] that comprise the key.", new Object[] { fields[i].getName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), descriptor.getEjbClassName() }));
                                continue;
                            } else {
                                if (!oneFailed) {
                                    oneFailed = true;
                                }
                                badField = true;
                            }
                            if (badField == true) {
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: Field [ {0} ] defined within primary key class [ {1} ] does not correspond to the field names of the entity bean class [ {2} ] that comprise the key.", new Object[] { fields[i].getName(), ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), descriptor.getEjbClassName() }));
                            }
                        }
                        if (!oneFailed) {
                            result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "This primary key class [ {0} ] has defined all fields which correspond to the field names of the entity bean class [ {1} ] that comprise the key.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), 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: [ {0} ] class or [ {1} ] class not found.", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), ((EjbEntityDescriptor) descriptor).getEjbClassName() }));
                    } catch (Throwable t) {
                        result.addWarningDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.warning(smh.getLocalString(getClass().getName() + ".warningException", "Warning: [ {0} ] class encountered [ {1} ]. Cannot access fields of class [ {2} ] which is external to [ {3} ].", new Object[] { (descriptor).getEjbClassName(), t.toString(), t.getMessage(), descriptor.getEjbBundleDescriptor().getModuleDescriptor().getArchiveUri() }));
                    }
                }
            } catch (NullPointerException e) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failedException2", "Error: Primkey field not defined within [ {0} ] bean.", new Object[] { descriptor.getName() }));
            }
            return result;
        } else {
            // if (BEAN_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.CONTAINER_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}.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) FieldDescriptor(org.glassfish.ejb.deployment.descriptor.FieldDescriptor) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Field(java.lang.reflect.Field) EjbCMPEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor) Vector(java.util.Vector) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Aggregations

ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)237 Result (com.sun.enterprise.tools.verifier.Result)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)87 Method (java.lang.reflect.Method)70 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Iterator (java.util.Iterator)40 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)19 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)16 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 Field (java.lang.reflect.Field)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)12 Enumeration (java.util.Enumeration)11 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)11 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)6 Vector (java.util.Vector)6