FileDocCategorySizeDatePackage
HomeInterfaceFindByPrimaryKeyName.javaAPI DocGlassfish v2 API7106Fri May 04 22:33:48 BST 2007com.sun.enterprise.tools.verifier.tests.ejb.entity.findbyprimarykey

HomeInterfaceFindByPrimaryKeyName

public class HomeInterfaceFindByPrimaryKeyName extends com.sun.enterprise.tools.verifier.tests.ejb.EjbTest implements com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck
Define findByPrimaryKey method test. Every entity enterprise Bean class must define the findByPrimaryKey method.

Fields Summary
Result
result
ComponentNameConstructor
compName
Constructors Summary
Methods Summary
public Resultcheck(com.sun.enterprise.deployment.EjbDescriptor descriptor)
Define findByPrimaryKey method test. Every entity enterprise Bean class must define the findByPrimaryKey method.

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


                                                        
        

	result = getInitializedResult();
	boolean oneFailed = false;
	compName = getVerifierContext().getComponentNameConstructor();

	if (descriptor instanceof EjbEntityDescriptor) {
	    if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName()))
		oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor);	   
	    
	    if(oneFailed == false) {
		if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()))
		    oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor);	
	    }
	    if (oneFailed) {
		result.setStatus(result.FAILED);
	    } else {
		result.setStatus(result.PASSED);
	    }
	    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;
	}
    
private booleancommonToBothInterfaces(java.lang.String home, com.sun.enterprise.deployment.EjbDescriptor descriptor)
This method is responsible for the logic of the test. It is called for both local and remote interfaces.

param
descriptor the Enterprise Java Bean deployment descriptor
param
home for the Home interface of the Ejb.
return
boolean the results for this assertion i.e if a test has failed or not

	boolean findByPrimaryKeyMethodFound = false;
	boolean oneFailed = false;
	try {
	    // retrieve the home interface methods
	    Context context = getVerifierContext();
		ClassLoader jcl = context.getClassLoader();
	    Class homeInterfaceClass = Class.forName(home, false, getVerifierContext().getClassLoader());
	    Method [] ejbFinderMethods = homeInterfaceClass.getDeclaredMethods();
	    for (int j = 0; j < ejbFinderMethods.length; j++) {
		if (ejbFinderMethods[j].getName().equals("findByPrimaryKey")) {
		    // Every entity enterprise Bean class must define the 
		    // findByPrimaryKey method. 
	
		    findByPrimaryKeyMethodFound = true;
			    
		    // report for this particular findByPrimaryKey(...)
		    result.addGoodDetails(smh.getLocalString
					  ("tests.componentNameConstructor",
					   "For [ {0} ]",
					   new Object[] {compName.toString()}));
		    result.addGoodDetails(smh.getLocalString
					  (getClass().getName() + ".debug1",
					   "For Home interface [ {0} ] Finder Method [ {1} ]",
					   new Object[] {homeInterfaceClass.getName(),ejbFinderMethods[j].getName()}));
		    result.addGoodDetails(smh.getLocalString
					  (getClass().getName() + ".passed",
					   "A findByPrimaryKey method was found."));
		    return oneFailed;
		}
	    }
	    if (!findByPrimaryKeyMethodFound) {
		oneFailed = true;
		result.addErrorDetails(smh.getLocalString
				       ("tests.componentNameConstructor",
					"For [ {0} ]",
					new Object[] {compName.toString()}));
		result.addErrorDetails(smh.getLocalString
				       (getClass().getName() + ".debug3",
					"For Home interface [ {0} ] ",
					new Object[] {homeInterfaceClass.getName()}));
		result.addErrorDetails(smh.getLocalString
				       (getClass().getName() + ".failed",
					"Error: No findByPrimaryKey method was found in home interface class [ {0} ].",
					new Object[] {homeInterfaceClass.getName()}));
	    }
	    return oneFailed;
	} 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: Home interface [ {0} ] does not exist or is not loadable.",
			   new Object[] {home}));
	    oneFailed = true;
	    return oneFailed;
	}