1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.deployment.EjbDescriptor; 27 import com.sun.enterprise.deployment.EjbEntityDescriptor; 28 import com.sun.enterprise.tools.verifier.tests.*; 29 import java.util.*; 30 import java.lang.reflect.*; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils; 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 34 35 48 public class HomeInterfacePostCreateMethodExceptionMatch extends EjbTest implements EjbCheck { 49 Result result = null; 50 ComponentNameConstructor compName = null; 51 boolean foundAtLeastOneCreate = false; 52 53 69 public Result check(EjbDescriptor descriptor) { 70 71 result = getInitializedResult(); 72 compName = getVerifierContext().getComponentNameConstructor(); 73 74 if (descriptor instanceof EjbEntityDescriptor) { 75 boolean oneFailed = false; 76 77 80 if(descriptor.getHomeClassName() != null) { 81 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor); 82 } 83 if(oneFailed == false) { 84 if(descriptor.getLocalHomeClassName() != null) { 85 oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor); 86 } 87 } 88 89 if (!foundAtLeastOneCreate) { 90 result.addNaDetails(smh.getLocalString 91 ("tests.componentNameConstructor", 92 "For [ {0} ]", 93 new Object [] {compName.toString()})); 94 result.addNaDetails(smh.getLocalString 95 (getClass().getName() + ".debug3", 96 "In Home Interface ", 97 new Object [] {})); 98 result.addNaDetails(smh.getLocalString 99 (getClass().getName() + ".notApplicable1", 100 "No create method was found, test not applicable." )); 101 result.setStatus(result.NOT_APPLICABLE); 102 } else { 103 if (oneFailed) { 104 result.setStatus(result.FAILED); 105 } else { 106 result.setStatus(result.PASSED); 107 } 108 } 109 return result; 110 111 } else { 112 result.addNaDetails(smh.getLocalString 113 ("tests.componentNameConstructor", 114 "For [ {0} ]", 115 new Object [] {compName.toString()})); 116 result.notApplicable(smh.getLocalString 117 (getClass().getName() + ".notApplicable", 118 "[ {0} ] expected {1} bean, but called with {2} bean.", 119 new Object [] {getClass(),"Entity","Session"})); 120 return result; 121 } 122 } 123 124 130 131 private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor) { 132 int ejbPostCreateMethodLoopCounter = 0; 133 boolean oneFailed = false; 134 foundAtLeastOneCreate = false; 135 try { 136 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 137 Class methodReturnType; 138 Class [] methodParameterTypes; 139 Class [] methodExceptionTypes; 140 Class [] ejbPostCreateMethodExceptionTypes; 141 Class [] ejbPostCreateMethodParameterTypes; 142 boolean ejbPostCreateFound = false; 143 boolean signaturesMatch = false; 144 boolean exceptionsMatch = false; 145 boolean createExists = false; 146 147 Method [] homeMethods = c.getDeclaredMethods(); 148 Vector<Method> createMethodSuffix = new Vector<Method>(); 149 for (int i = 0; i < homeMethods.length; i++) { 150 if (homeMethods[i].getName().startsWith("create")) { 152 foundAtLeastOneCreate = true; 153 createMethodSuffix.addElement( (Method)homeMethods[i]); 154 } 155 } 156 if(foundAtLeastOneCreate == false) 157 return false; 158 159 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 160 do { 161 Method [] methods = EJBClass.getDeclaredMethods(); 162 for (int i = 0; i < methods.length; i++) { 164 ejbPostCreateFound = false; 165 signaturesMatch = false; 166 exceptionsMatch = false; 167 Method [] ejbPostCreateMethods = EJBClass.getDeclaredMethods(); 168 ejbPostCreateMethodLoopCounter = 0; 171 if (methods[i].getName().startsWith("ejbPostCreate")) { 173 ejbPostCreateFound = true; 174 String matchSuffix = methods[i].getName().substring(13); 175 for (int k = 0; k < createMethodSuffix.size(); k++) { 176 if (matchSuffix.equals(((Method)(createMethodSuffix.elementAt(k))).getName().substring(6))) { 177 methodParameterTypes = ((Method)(createMethodSuffix.elementAt(k))).getParameterTypes(); 180 ejbPostCreateMethodParameterTypes = methods[i].getParameterTypes(); 181 if (Arrays.equals(methodParameterTypes,ejbPostCreateMethodParameterTypes)) { 182 signaturesMatch = true; 183 methodExceptionTypes = ((Method)(createMethodSuffix.elementAt(k))).getExceptionTypes(); 184 ejbPostCreateMethodExceptionTypes = methods[i].getExceptionTypes(); 185 if (RmiIIOPUtils.isEjbFindMethodExceptionsSubsetOfFindMethodExceptions(ejbPostCreateMethodExceptionTypes,methodExceptionTypes)) { 196 exceptionsMatch = true; 197 ejbPostCreateMethodLoopCounter = k; 199 break; 200 } 201 } } } 205 210 if (ejbPostCreateFound && signaturesMatch && exceptionsMatch) { 213 result.addGoodDetails(smh.getLocalString 214 ("tests.componentNameConstructor", 215 "For [ {0} ]", 216 new Object [] {compName.toString()})); 217 result.addGoodDetails(smh.getLocalString 218 (getClass().getName() + ".debug1", 219 "For Home Interface [ {0} ] Method [ {1} ]", 220 new Object [] {home,((Method)(createMethodSuffix.elementAt(ejbPostCreateMethodLoopCounter))).getName()})); 221 result.addGoodDetails(smh.getLocalString 222 (getClass().getName() + ".passed", 223 "The corresponding [ {0} ] method with matching exceptions was found in [ {1} ].", 224 new Object [] {methods[i].getName(), EJBClass.getName()})); 225 } else if (ejbPostCreateFound && signaturesMatch && !exceptionsMatch) { 226 result.addErrorDetails(smh.getLocalString 227 ("tests.componentNameConstructor", 228 "For [ {0} ]", 229 new Object [] {compName.toString()})); 230 result.addErrorDetails(smh.getLocalString 231 (getClass().getName() + ".debug1", 232 "For Home Interface [ {0} ] Method [ {1} ]", 233 new Object [] {home,((Method)(createMethodSuffix.elementAt(ejbPostCreateMethodLoopCounter))).getName()})); 234 result.failed(smh.getLocalString 235 (getClass().getName() + ".notApplicableDebug", 236 "A corresponding [ {0} ] method was found in [ {1} ], but the exceptions did not match.", 237 new Object [] {methods[i].getName(),EJBClass.getName()})); 238 oneFailed = true; 239 break; 240 } else if (ejbPostCreateFound && !signaturesMatch) { 241 result.addErrorDetails(smh.getLocalString 242 ("tests.componentNameConstructor", 243 "For [ {0} ]", 244 new Object [] {compName.toString()})); 245 result.addErrorDetails(smh.getLocalString 246 (getClass().getName() + ".debug3", 247 "For Home Interface ", 248 new Object [] {})); 249 result.failed(smh.getLocalString 250 (getClass().getName() + ".notApplicableDebug2", 251 "A corresponding [ {0} ] method was found in [ {1} ], but the parameters did not match.", 252 new Object [] {methods[i].getName(),EJBClass.getName()})); 253 oneFailed = true; 254 break; 255 } 256 } 257 } 258 if (oneFailed == true) 259 break; 260 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!(ejbPostCreateFound && signaturesMatch && exceptionsMatch))); 261 return oneFailed; 262 } catch (ClassNotFoundException e) { 263 Verifier.debug(e); 264 result.addErrorDetails(smh.getLocalString 265 ("tests.componentNameConstructor", 266 "For [ {0} ]", 267 new Object [] {compName.toString()})); 268 result.failed(smh.getLocalString 269 (getClass().getName() + ".failedException", 270 "Error: Home interface [ {0} ] or EJB class [ {1} ] does not exist or is not loadable within bean [ {2} ]", 271 new Object [] {home, descriptor.getEjbClassName(), descriptor.getName()})); 272 return oneFailed; 273 } 274 } 275 } 276 | Popular Tags |