Search in sources :

Example 61 with Result

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

the class PrimaryKeyClassElement method check.

/**
 * Entity bean's Primary Key Class test.
 * If the enterprise bean is a Entity Bean, the Bean provider specifies
 * the fully qualified name of the Entity bean's primary key class in the
 * "primary-class" element. The Bean provider 'must' specify the primary key
 * class for an Entity with bean managed persistence, and 'may' (but is not
 * required to) specify the primary key class for an Entity with
 * Container-managed persistence.
 *
 * @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)) {
            logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { descriptor.getName(), "bean" });
            String primkey = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
            if (!primkey.equals("java.lang.String")) {
                try {
                    Class c = Class.forName(primkey, false, getVerifierContext().getClassLoader());
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "Primary Key Class [ {0} ] exist and is loadable", new Object[] { primkey }));
                } catch (Exception e) {
                    Verifier.debug(e);
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Loading Primary Key Class [ {0} ]", new Object[] { primkey }));
                    return result;
                }
            } else {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Primary Key Class is [ {0} ]", new Object[] { primkey }));
            }
            return result;
        } else if (EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence)) {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Entity Bean [ {0} ] with [ {1} ] managed persistence, primkey optional.", new Object[] { descriptor.getName(), persistence }));
            return result;
        } else {
            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 : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 62 with Result

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

the class PrimaryKeyClassMethodEqual method check.

/**
 * Primary key class provide implementation of equals() methods test.
 *
 * Enterprise Bean's primary key class
 * The class must provide suitable implementation of the equals(Object other)
 * methods to simplify the management of the primary keys by client code.
 *
 * @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 transactionType = descriptor.getTransactionType();
        if (EjbDescriptor.CONTAINER_TRANSACTION_TYPE.equals(transactionType)) {
            boolean hasDefinedEqaulsMethod = false;
            boolean oneFailed = false;
            int lc = 0;
            // RULE: Primary key class must defined equals(Object other) method
            try {
                VerifierTestContext context = getVerifierContext();
                ClassLoader jcl = context.getClassLoader();
                // retrieve the EJB primary key class
                Class c = Class.forName(((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), false, getVerifierContext().getClassLoader());
                Method[] methods = c.getDeclaredMethods();
                for (int i = 0; i < methods.length; i++) {
                    if (methods[i].getName().equals("equals")) {
                        // this is the right primary key class method equals()
                        hasDefinedEqaulsMethod = true;
                        // used in output below
                        lc = i;
                        break;
                    }
                }
                if (hasDefinedEqaulsMethod) {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB primary key class [ {0} ]", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                    result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Primary key class method [ {0} ] was defined in the primary key class.", new Object[] { methods[lc].getName() }));
                } else if (!hasDefinedEqaulsMethod) {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".debug1", "For EJB primary key class [ {0} ]", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: Primary key class method equal() was not defined in the primary key 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: Primary Key Class [ {0} ] not found within bean [ {1} ]", new Object[] { ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName(), descriptor.getName() }));
            }
            if (oneFailed) {
                result.setStatus(result.FAILED);
            } else {
                result.setStatus(result.PASSED);
            }
        } else {
            // not container managed, but is a entity bean
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Bean [ {0} ] is not [ {1} ] managed, it is [ {2} ]  managed.", new Object[] { descriptor.getName(), EjbDescriptor.CONTAINER_TRANSACTION_TYPE, transactionType }));
        }
        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 63 with Result

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

the class PrimaryKeyClassOptReturn method check.

/**
 * Entity bean's Primary Key Class return test.
 * If the enterprise bean is a Entity Bean, the Bean provider specifies
 * the fully qualified name of the Entity bean's primary key class in the
 * "primary-class" element. The Bean provider 'must' specify the primary key
 * class for an Entity with bean managed persistence, and 'may' (but is not
 * required to) specify the primary key class for an Entity with
 * Container-managed persistence.
 *
 * Special case: Unknown primary key class
 * In special situations, the Bean Provider may choose not to specify the
 * primary key class for an entity bean with container-managed persistence. This
 * case happens if the Bean Provider wants to allow the Deployer to select the
 * primary key fields at deployment time. The Deployer uses instructions
 * supplied by the Bean Provider (these instructions are beyond the scope of
 * the EJB spec.) to define a suitable primary key class.
 *
 * In this special case, the type of the argument of the findByPrimaryKey method
 * must be declared as java.lang.Object, and the return value of ejbCreate()
 * must be declared as java.lang.Object. The Bean Provider must specify the
 * primary key class in the deployment descriptor as of the type
 * java.lang.Object.
 *
 * The primary key class is specified at deployment time when the Bean Provider
 * develops enterprise beans that is intended to be used with multiple back-ends
 * that provide persistence, and when these multiple back-ends require different
 * primary key structures.
 *
 * @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)) {
            String primkey = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
            // <prim-key-class> to "java.lang.Object"
            if (primkey.equals("java.lang.Object")) {
                try {
                    VerifierTestContext context = getVerifierContext();
                    ClassLoader jcl = context.getClassLoader();
                    Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
                    boolean returnsJLO = false;
                    // start do while loop here....
                    do {
                        Method[] methods = c.getDeclaredMethods();
                        returnsJLO = false;
                        for (int j = 0; j < methods.length; ++j) {
                            if (methods[j].getName().equals("ejbCreate")) {
                                // The return type must be java.lang.Object.
                                Class rt = methods[j].getReturnType();
                                if (rt.getName().equals("java.lang.Object")) {
                                    returnsJLO = true;
                                    break;
                                }
                            }
                        }
                    } while (((c = c.getSuperclass()) != null) && (!returnsJLO));
                    if (returnsJLO) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed", "ejbCreate() method properly defines method return type [ {0} ]", new Object[] { "java.lang.Object" }));
                    } else {
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "ejbCreate() method does not properly define method return type [ {0} ]", new Object[] { "java.lang.Object" }));
                    }
                } catch (Exception e) {
                    Verifier.debug(e);
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Loading bean class [ {0} ]", new Object[] { descriptor.getEjbClassName() }));
                    return result;
                }
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Primary Key Class is [ {0} ]", new Object[] { primkey }));
            }
            return result;
        } else if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity bean with [ {0} ] managed persistence, primkey mandatory.", new Object[] { persistence }));
            return result;
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable3", "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} 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 64 with Result

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

the class PrimaryKeyClassOptType method check.

/**
 * Entity bean's Primary Key Class type test.
 * If the enterprise bean is a Entity Bean, the Bean provider specifies
 * the fully qualified name of the Entity bean's primary key class in the
 * "primary-class" element. The Bean provider 'must' specify the primary key
 * class for an Entity with bean managed persistence, and 'may' (but is not
 * required to) specify the primary key class for an Entity with
 * Container-managed persistence.
 *
 * Special case: Unknown primary key class
 * In special situations, the Bean Provider may choose not to specify the
 * primary key class for an entity bean with container-managed persistence. This
 * case happens if the Bean Provider wants to allow the Deployer to select the
 * primary key fields at deployment time. The Deployer uses instructions
 * supplied by the Bean Provider (these instructions are beyond the scope of
 * the EJB spec.) to define a suitable primary key class.
 *
 * In this special case, the type of the argument of the findByPrimaryKey method
 * must be declared as java.lang.Object, and the return value of ejbCreate()
 * must be declared as java.lang.Object. The Bean Provider must specify the
 * primary key class in the deployment descriptor as of the type
 * java.lang.Object.
 *
 * The primary key class is specified at deployment time when the Bean Provider
 * develops enterprise beans that is intended to be used with multiple back-ends
 * that provide persistence, and when these multiple back-ends require different
 * primary key structures.
 *
 * @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)) {
            String primkey = ((EjbEntityDescriptor) descriptor).getPrimaryKeyClassName();
            // <prim-key-class> to "java.lang.Object"
            if (primkey.equals("java.lang.Object")) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "Properly defined primary key class type [ {0} ]", new Object[] { "java.lang.Object" }));
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Primary Key Class is [ {0} ]", new Object[] { primkey }));
            }
            return result;
        } else if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "Entity Bean with [ {0} ] managed persistence, primkey mandatory.", new Object[] { persistence }));
            return result;
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable3", "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} bean.", new Object[] { getClass(), "Entity", "Session" }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 65 with Result

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

the class HomeInterfaceExtendsRightInterface method check.

/**
 * Extends the EJBHome Interface test.
 * All enterprise beans home interface's must extend the EJBHome interface.
 *
 * @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();
    String str = null;
    if (getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))) {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.localinterfaceonly.notapp", "Not Applicable because, EJB [ {0} ] has Local Interfaces only.", new Object[] { descriptor.getEjbClassName() }));
        return result;
    }
    if ((descriptor instanceof EjbSessionDescriptor) || (descriptor instanceof EjbEntityDescriptor)) {
        try {
            VerifierTestContext context = getVerifierContext();
            ClassLoader jcl = context.getClassLoader();
            Class c = Class.forName(getClassName(descriptor), false, jcl);
            str = getSuperInterface();
            if (isImplementorOf(c, str)) {
                // it extends the proper EJBHome
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly extends the " + str + "interface.", new Object[] { getClassName(descriptor) }));
            } else {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly extend the  " + str + " interface.  All enterprise beans home interfaces must extend the  " + str + " interface.  [ {1} ] is not a valid home interface.", new Object[] { getClassName(descriptor), getClassName(descriptor) }));
            }
        } 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[] { getClassName(descriptor) }));
        }
        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 or {2} bean, but called with {3}.", new Object[] { getClass(), "Session", "Entity", descriptor.getName() }));
        return result;
    }
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) VerifierTestContext(com.sun.enterprise.tools.verifier.VerifierTestContext) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

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