Search in sources :

Example 56 with ComponentNameConstructor

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

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

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

Example 59 with ComponentNameConstructor

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

the class HomeMethodModifiers method runIndividualHomeMethodTest.

/**
 * <p>
 * run an individual home method test
 * </p>
 *
 * @param method the home method to test
 * @param descriptor the deployment descriptor for the entity bean
 * @param result the result object
 */
protected void runIndividualHomeMethodTest(Method method, EjbDescriptor descriptor, Result result) {
    Method m;
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    try {
        // retrieve the remote interface methods
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class ejbClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
        // Bug: 4952890. first character of this name should be converted to UpperCase.
        String methodName = method.getName().replaceFirst(method.getName().substring(0, 1), method.getName().substring(0, 1).toUpperCase());
        String expectedMethodName = "ejbHome" + methodName;
        do {
            // retrieve the EJB Class Methods
            m = getMethod(ejbClass, expectedMethodName, method.getParameterTypes());
        } while (((ejbClass = ejbClass.getSuperclass()) != null) && (m == null));
        if (m != null) {
            int modifiers = m.getModifiers();
            if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
                addGoodDetails(result, compName);
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "For method [ {1} ] in Home Interface [ {0} ], ejbHome method is public and not static", new Object[] { method.getDeclaringClass().getName(), method.getName() }));
                result.setStatus(Result.PASSED);
            // return true;
            } else {
                addErrorDetails(result, compName);
                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".notApplicable", "Error : For method [ {1} ] defined in Home Interface [ {0} ], the ejbHome method is either static or not public", new Object[] { method.getDeclaringClass().getName(), method.getName() }));
                result.setStatus(Result.FAILED);
            // return false;
            }
        } else {
            addErrorDetails(result, compName);
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error : For method [ {1} ] defined in Home Interface [ {0} ], no ejbHome name matching method was found", new Object[] { method.getDeclaringClass().getName(), method.getName() }));
            result.setStatus(Result.FAILED);
        // return true;
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
        // return false;
        result.setStatus(Result.FAILED);
    }
}
Also used : Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 60 with ComponentNameConstructor

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

the class HomeMethodNameMatch method runIndividualHomeMethodTest.

/**
 * <p>
 * run an individual home method test
 * </p>
 *
 * @param method the home method to test
 * @param descriptor the deployment descriptor for the entity bean
 * @param result the result object
 */
protected void runIndividualHomeMethodTest(Method method, EjbDescriptor descriptor, Result result) {
    Method m;
    ComponentNameConstructor compName = null;
    try {
        compName = getVerifierContext().getComponentNameConstructor();
        // retrieve the remote interface methods
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class ejbClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
        // Bug: 4952890. first character of this name should be converted to UpperCase.
        String methodName = method.getName().replaceFirst(method.getName().substring(0, 1), method.getName().substring(0, 1).toUpperCase());
        String expectedMethodName = "ejbHome" + methodName;
        do {
            // retrieve the EJB Class Methods
            m = getMethod(ejbClass, expectedMethodName, method.getParameterTypes());
        } while (((ejbClass = ejbClass.getSuperclass()) != null) && (m == null));
        if (m != null) {
            // now display the appropriate results for this particular business
            // method
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "For method [ {1} ] in Home Interface [ {0} ], a ejbHome<METHOD> name matching method was found", new Object[] { method.getDeclaringClass().getName(), method.getName() }));
        } else {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error : For method [ {1} ] defined in Home Interface [ {0} ], no ejbHome<METHOD> name matching method was found", new Object[] { method.getDeclaringClass().getName(), method.getName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
    }
}
Also used : Method(java.lang.reflect.Method) 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