Search in sources :

Example 66 with ComponentNameConstructor

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

the class ExtendsRightInterface method check.

/**
 * local interfaces extend the EJBLocalObject interface and remote interfaces
 * extend the EJBObject interface test.
 * All enterprise beans remote interfaces must extend the EJBObject interface
 * and/or local interfaces must extend the EJBLocalObject 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 (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    if (getInterfaceName(descriptor) == null || "".equals(getInterfaceName(descriptor))) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", new Object[] { descriptor.getEjbClassName(), getInterfaceType() }));
        return result;
    }
    try {
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class c = Class.forName(getClassName(descriptor), false, jcl);
        str = getSuperInterface();
        if (isImplementorOf(c, str)) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] " + getInterfaceType() + " interface properly extends the" + str + " interface.", new Object[] { getClassName(descriptor) }));
        } else {
            addErrorDetails(result, compName);
            result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly extend the EJBObject interface. " + " All enterprise bean" + getInterfaceType() + " interfaces must extend the" + str + "  interface." + " [ {1} ] is not a valid " + getInterfaceType() + "interface within bean [ {2} ]", new Object[] { getClassName(descriptor), getClassName(descriptor), descriptor.getName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { getClassName(descriptor) }));
    }
    return result;
}
Also used : EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 67 with ComponentNameConstructor

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

the class InterfaceMatchMethodException method runIndividualMethodTest.

/**
 * <p>
 * run an individual verifier test against a declared method of the
 * local/remote interface.
 * </p>
 *
 * @param descriptor the deployment descriptor for the bean
 * @param method the method to run the test on
 * @return true if the test passes
 */
protected boolean runIndividualMethodTest(EjbDescriptor descriptor, Method method, Result result) {
    boolean businessMethodFound, exceptionsMatch;
    ComponentNameConstructor compName = null;
    try {
        compName = getVerifierContext().getComponentNameConstructor();
        // retrieve the EJB Class Methods
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, jcl);
        Class[] methodExceptionTypes = method.getExceptionTypes();
        // start do while loop here....
        do {
            Method[] businessMethods = EJBClass.getDeclaredMethods();
            // try and find the business method in the EJB Class Methods
            businessMethodFound = false;
            exceptionsMatch = false;
            for (Method businessMethod : businessMethods) {
                if (method.getName().equals(businessMethod.getName())) {
                    businessMethodFound = true;
                    // check the rest of the exceptions
                    Class[] businessMethodExceptionTypes = businessMethod.getExceptionTypes();
                    if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(businessMethodExceptionTypes, methodExceptionTypes)) {
                        exceptionsMatch = true;
                        break;
                    }
                // if the bean & local interface method exceptions match
                } else {
                    continue;
                }
            }
            // method
            if (businessMethodFound && exceptionsMatch) {
                addGoodDetails(result, compName);
                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "The corresponding business method with matching " + "exceptions was found."));
                return true;
            } else if (businessMethodFound && !exceptionsMatch) {
                logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { method.getDeclaringClass().getName(), method.getName() });
                logger.log(Level.FINE, getClass().getName() + ".debug3", new Object[] { method.getName() });
                logger.log(Level.FINE, getClass().getName() + ".debug2");
            }
        } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(businessMethodFound && exceptionsMatch)));
        if (!exceptionsMatch) {
            addErrorDetails(result, compName);
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No corresponding business method with matching exceptions was found for method [ {0} ].", new Object[] { method.getName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: " + getInterfaceType() + "interface [ {0} ] does not " + "exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
    }
    return false;
}
Also used : Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)

Example 68 with ComponentNameConstructor

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

the class InterfaceMethodTest method check.

/**
 * Run the verifier test against the local or remote interface, get all methods
 * and delegate actual testing for individual methods to the
 * runIndividualMethodTest
 *
 * @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.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    if (getInterfaceName(descriptor) == null || "".equals(getInterfaceName(descriptor))) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", new Object[] { descriptor.getEjbClassName(), getInterfaceType() }));
        return result;
    }
    try {
        Arrays.sort(EJBObjectMethods);
        // retrieve the local/remote interface methods
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class interfaceClass = Class.forName(getClassName(descriptor), false, jcl);
        if (studyInterface(descriptor, interfaceClass, result)) {
            result.setStatus(Result.PASSED);
        } else {
            result.setStatus(Result.FAILED);
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: " + getInterfaceType() + "interface [ {0} ] does not " + "exist or is not loadable within bean [ {1} ]", new Object[] { getClassName(descriptor), descriptor.getName() }));
    }
    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)

Example 69 with ComponentNameConstructor

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

the class RemoteInterfaceSuperInterface method check.

/**
 * Remote interface/business methods test.
 * Verify the following:
 *
 *   The remote interface is allowed to have superinterfaces. Use of interface
 *   inheritance is subject to the RMI-IIOP rules for the definition of remote
 *   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.homeintf.HomeMethodTest.notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    if (descriptor.getRemoteClassName() == null || "".equals(descriptor.getRemoteClassName())) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", new Object[] { descriptor.getEjbClassName(), "Remote" }));
        return result;
    }
    boolean oneFailed = false;
    try {
        ClassLoader jcl = getVerifierContext().getClassLoader();
        Class c = Class.forName(descriptor.getRemoteClassName(), false, jcl);
        Class remote = c;
        boolean validRemoteInterface = false;
        boolean ok = false;
        // walk up the class tree
        do {
            Class[] interfaces = c.getInterfaces();
            if (interfaces.length == 0) {
                ok = true;
            }
            for (Class intf : interfaces) {
                logger.log(Level.FINE, getClass().getName() + ".debug1", new Object[] { intf.getName() });
                // requirement is met if one superinterface complies.
                if (!ok) {
                    ok = RmiIIOPUtils.isValidRmiIIOPInterface(intf);
                }
                // check the methods now.
                if (RmiIIOPUtils.isValidRmiIIOPInterfaceMethods(intf)) {
                    // this interface is valid, continue
                    if (intf.getName().equals("javax.ejb.EJBObject")) {
                        validRemoteInterface = true;
                        break;
                    }
                } else {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to " + "rules of RMI-IIOP for superinterfaces.  All " + "enterprise beans remote interfaces are allowed " + "to have superinterfaces that conform to the " + "rules of RMI-IIOP for superinterfaces .  [ {1} ]" + " is not a valid remote interface.", new Object[] { intf.getName(), descriptor.getRemoteClassName() }));
                }
            }
        } while ((((c = c.getSuperclass()) != null) && (!validRemoteInterface)));
        if (!ok) {
            // check that one superinterface met rmiiiop requirement
            oneFailed = true;
            addErrorDetails(result, compName);
            result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: [ {0} ] does not properly conform to rules of " + "RMI-IIOP for superinterfaces.  All enterprise beans " + "remote interfaces are allowed to have superinterfaces " + "that conform to the rules of RMI-IIOP for superinterfaces. " + " [ {1} ] is not a valid remote interface.", new Object[] { remote.getName(), descriptor.getRemoteClassName() }));
        }
        if (validRemoteInterface) {
            addGoodDetails(result, compName);
            result.passed(smh.getLocalString(getClass().getName() + ".passed", "[ {0} ] properly conforms to rules of RMI-IIOP for superinterfaces.", new Object[] { descriptor.getRemoteClassName() }));
        }
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addGoodDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: Remote interface [ {0} ] does not exist or is not " + "loadable within bean [ {1} ]", new Object[] { descriptor.getRemoteClassName(), descriptor.getName() }));
        oneFailed = true;
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    } else {
        result.setStatus(Result.PASSED);
    }
    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)

Example 70 with ComponentNameConstructor

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

the class EjbCreateModifiers method check.

/**
 * Run a verifier test against an individual declared message
 * drive bean component
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbMessageBeanDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    Class mbc = loadMessageBeanClass(descriptor, result);
    if (mbc != null) {
        Method m = getMethod(mbc, getMethodName(), null);
        if (m != null) {
            int modifiers = m.getModifiers();
            if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) {
                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.passed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.messagebean.EjbCreateModifiers.passed", "Message-Drive bean [ {0} ] provide an {1} implementation declared public and not static or final", new Object[] { (descriptor).getEjbClassName(), getMethodName() }));
            } else {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.messagebean.EjbCreateModifiers.failed", "Error: Message-Drive bean [ {0} ] {1} implementation is either not public or is static or final", new Object[] { (descriptor).getEjbClassName(), getMethodName() }));
            }
        } else {
            result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.ejb.messagebean.EjbCreateExists.failed", "Error: Message-Drive bean [ {0} ] does not implement an {1} with no arguments", new Object[] { (descriptor).getEjbClassName(), getMethodName() }));
        }
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

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