FileDocCategorySizeDatePackage
InterfaceMethodTest.javaAPI DocGlassfish v2 API7420Fri May 04 22:33:54 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.intf

InterfaceMethodTest

public abstract class InterfaceMethodTest extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest
Superclass for all local/remote interfaces method testing.

Fields Summary
static String[]
EJBObjectMethods
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)
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
Result the results for this assertion

    
                       
    
        
       
    
    
                                                   
    
            
    
                                                     
        
        
        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;
    
private java.lang.StringgetClassName(com.sun.enterprise.deployment.EjbDescriptor descriptor)

        return getInterfaceName(descriptor);
    
protected abstract java.lang.StringgetInterfaceName(com.sun.enterprise.deployment.EjbDescriptor descriptor)
Methods to get the type of interface: local/remote and the name of the class

protected abstract java.lang.StringgetInterfaceType()

protected abstract booleanrunIndividualMethodTest(com.sun.enterprise.deployment.EjbDescriptor descriptor, java.lang.reflect.Method method, com.sun.enterprise.tools.verifier.Result result)

run an individual verifier test against a declared method of the local or remote interface.

param
descriptor the deployment descriptor for the bean
param
method the method to run the test on
return
true if the test passes

private booleanstudyInterface(com.sun.enterprise.deployment.EjbDescriptor descriptor, java.lang.Class clazz, com.sun.enterprise.tools.verifier.Result result)

study an interface by running an individual test on each method of the inteface then recursively study all the interfaces this interface extends

param
descriptor the bean deployment descriptor
param
clazz the interface to study
param
result to place the results of the tests in
return
true if all tests passed

        
        boolean allGood = true;
        Method [] interfaceMethods = clazz.getDeclaredMethods();
        
        for (Method interfaceMethod : interfaceMethods) {
            if (Arrays.binarySearch(EJBObjectMethods, interfaceMethod.getName()) < 0) {
                
                if (!runIndividualMethodTest(descriptor, interfaceMethod,result))
                    allGood = false;
                
            } // if you found a business method
        } // for all local or remote interface methods for the current class
        
        // now all superinterfaces....
        for (Class intf : clazz.getInterfaces()) {
            if (!studyInterface(descriptor, intf, result)) 
                allGood = false;
        }
        return allGood;