FileDocCategorySizeDatePackage
HomeMethodTest.javaAPI DocGlassfish v2 API7223Fri May 04 22:33:52 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.homeintf

HomeMethodTest

public abstract class HomeMethodTest extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest
Superclass for all Home methods tests.
author
Jerome Dochez
version

Fields Summary
Constructors Summary
Methods Summary
public com.sun.enterprise.tools.verifier.Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)

param
descriptor the Enterprise Java Bean deployment descriptor
return
Result the results for this assertion


 	Result result = getInitializedResult();
	ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();

	if(getHomeInterfaceName(descriptor) == null || "".equals(getHomeInterfaceName(descriptor))){
            addNaDetails(result, compName);
            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)) {
        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;                
        }
        boolean homeMethodFound = false;
        
	try {	  
	    // retrieve the remote interface methods
	    ClassLoader jcl = getVerifierContext().getClassLoader();
	    Class homeInterfaceClass = Class.forName(getClassName(descriptor), false, jcl);
            
            Vector<Method> v = new Vector<Method>(); 

            while (homeInterfaceClass != null && 
                    !homeInterfaceClass.getName().equals(getSuperInterface()) &&
                    !homeInterfaceClass.getName().equals("java.lang.Object")) {
	        Method [] homeInterfaceMethods = homeInterfaceClass.getDeclaredMethods();
                for (int i=0;i<homeInterfaceMethods.length;i++) {
                    v.add(homeInterfaceMethods[i]);
                }
                homeInterfaceClass = homeInterfaceClass.getSuperclass();
            }
                
            
	    Iterator iterator = v.iterator();
            while (iterator.hasNext()) {
                Method method = (Method) iterator.next();
                String methodName = method.getName();
                if (methodName.startsWith("create") || methodName.startsWith("find") || 
                    methodName.startsWith("remove")) 
                    continue;
                
                Method m = getMethod(javax.ejb.EJBHome.class, methodName, 
                                     method.getParameterTypes());
                if (m!=null) {
                    // this is an EJBHome method...
                    continue;
                } 
            
                homeMethodFound = true;
 
		// if (!runIndividualHomeMethodTest( method,descriptor, result)) 
		//  oneFailed = true;
		runIndividualHomeMethodTest( method,descriptor, result);
		if (result.getStatus() == Result.FAILED) 
		    break;
                
	    }
	} catch (ClassNotFoundException e) {
	    Verifier.debug(e);
	    addErrorDetails(result, compName);
		result.failed(smh.getLocalString
			  ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.failedException",
			   "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
			   new Object[] {getClassName(descriptor),descriptor.getName()}));
	}

        if (!homeMethodFound) {
	    addNaDetails(result, compName);
	    result.notApplicable(smh.getLocalString
			  ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable2",
			   "Home interface [ {0} ] does not define any home methods",
			   new Object[] {getClassName(descriptor)}));
        } //else {
    	  //  result.setStatus(oneFailed?result.FAILED:Result.PASSED);
	// }
	return result;
    
private java.lang.StringgetClassName(com.sun.enterprise.deployment.EjbDescriptor descriptor)

	return getHomeInterfaceName(descriptor);
    
protected abstract java.lang.StringgetHomeInterfaceName(com.sun.enterprise.deployment.EjbDescriptor descriptor)
Method tells the name of the home interface class that called this test

protected abstract java.lang.StringgetSuperInterface()

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

run an individual home method test

param
descriptor the deployment descriptor for the entity bean
param
result the result object
param
m the mehtod to test