1 23 package com.sun.enterprise.tools.verifier.tests.ejb.intf; 24 25 import com.sun.enterprise.deployment.EjbDescriptor; 26 import com.sun.enterprise.deployment.EjbEntityDescriptor; 27 import com.sun.enterprise.deployment.EjbSessionDescriptor; 28 import com.sun.enterprise.tools.verifier.Result; 29 import com.sun.enterprise.tools.verifier.Verifier; 30 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor; 31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 32 33 import java.lang.reflect.Method ; 34 import java.util.Arrays ; 35 36 40 abstract public class InterfaceMethodTest extends EjbTest { 41 42 static String [] EJBObjectMethods = 43 { "getEJBHome", "getHandle", "getPrimaryKey", 44 "isIdentical", "remove", "getEJBLocalHome", 45 }; 46 47 50 51 abstract protected String getInterfaceName(EjbDescriptor descriptor); 52 abstract protected String getInterfaceType(); 53 54 55 65 66 abstract protected boolean runIndividualMethodTest(EjbDescriptor descriptor, Method method, Result result); 67 68 77 public Result check(EjbDescriptor descriptor) { 78 79 Result result = getInitializedResult(); 80 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 81 82 if (!(descriptor instanceof EjbSessionDescriptor) && 83 !(descriptor instanceof EjbEntityDescriptor)) { 84 addNaDetails(result, compName); 85 result.notApplicable(smh.getLocalString 86 ("com.sun.enterprise.tools.verifier.tests.ejb.homeintf.HomeMethodTest.notApplicable1", 87 "Test apply only to session or entity beans.")); 88 return result; 89 } 90 91 if(getInterfaceName(descriptor) == null || "".equals(getInterfaceName(descriptor))){ 92 addNaDetails(result, compName); 93 result.notApplicable(smh.getLocalString 94 ("com.sun.enterprise.tools.verifier.tests.ejb.intf.InterfaceTest.notApplicable", 95 "Not Applicable because, EJB [ {0} ] does not have {1} Interface.", 96 new Object [] {descriptor.getEjbClassName(), getInterfaceType()})); 97 return result; 98 } 99 100 try { 101 102 Arrays.sort(EJBObjectMethods); 103 104 ClassLoader jcl = getVerifierContext().getClassLoader(); 106 Class interfaceClass = Class.forName(getClassName(descriptor), false, jcl); 107 108 if (studyInterface(descriptor, interfaceClass, result)) { 109 result.setStatus(Result.PASSED); 110 } else { 111 result.setStatus(Result.FAILED); 112 } 113 } catch (ClassNotFoundException e) { 114 Verifier.debug(e); 115 addErrorDetails(result, compName); 116 result.failed(smh.getLocalString 117 (getClass().getName() + ".failedException", 118 "Error: "+ getInterfaceType()+"interface [ {0} ] does not " + 119 "exist or is not loadable within bean [ {1} ]", 120 new Object [] {getClassName(descriptor),descriptor.getName()})); 121 } 122 123 return result; 124 } 125 126 137 private boolean studyInterface(EjbDescriptor descriptor, Class clazz, Result result) { 138 139 boolean allGood = true; 140 Method [] interfaceMethods = clazz.getDeclaredMethods(); 141 142 for (Method interfaceMethod : interfaceMethods) { 143 if (Arrays.binarySearch(EJBObjectMethods, interfaceMethod.getName()) < 0) { 144 145 if (!runIndividualMethodTest(descriptor, interfaceMethod,result)) 146 allGood = false; 147 148 } } 151 for (Class intf : clazz.getInterfaces()) { 153 if (!studyInterface(descriptor, intf, result)) 154 allGood = false; 155 } 156 return allGood; 157 } 158 159 private String getClassName(EjbDescriptor descriptor) { 160 return getInterfaceName(descriptor); 161 } 162 } 163 164 | Popular Tags |