1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.createmethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import com.sun.enterprise.deployment.*; 27 import java.lang.ClassLoader ; 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.EjbCheck; 33 34 48 public class HomeInterfaceCreateMethodMatchArgs extends EjbTest implements EjbCheck { 49 Result result = null; 50 ComponentNameConstructor compName = null; 51 boolean foundAtLeastOneCreate = false; 52 68 public Result check(EjbDescriptor descriptor) { 69 70 result = getInitializedResult(); 71 compName = getVerifierContext().getComponentNameConstructor(); 72 73 if (descriptor instanceof EjbEntityDescriptor) { 74 boolean oneFailed = false; 75 76 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor.getLocalHomeClassName(),descriptor); 79 if (!foundAtLeastOneCreate) { 80 result.addNaDetails(smh.getLocalString 81 ("tests.componentNameConstructor", 82 "For [ {0} ]", 83 new Object [] {compName.toString()})); 84 result.addNaDetails(smh.getLocalString 85 (getClass().getName() + ".debug3", 86 "In Home Interface ", 87 new Object [] {})); 88 result.addNaDetails(smh.getLocalString 89 (getClass().getName() + ".notApplicable1", 90 "No create method was found, test not applicable." )); 91 result.setStatus(result.NOT_APPLICABLE); 92 } else { 93 if (oneFailed) { 94 result.setStatus(result.FAILED); 95 } else { 96 result.setStatus(result.PASSED); 97 } 98 } 99 100 return result; 101 102 } else { 103 result.addNaDetails(smh.getLocalString 104 ("tests.componentNameConstructor", 105 "For [ {0} ]", 106 new Object [] {compName.toString()})); 107 result.notApplicable(smh.getLocalString 108 (getClass().getName() + ".notApplicable", 109 "[ {0} ] expected {1} bean, but called with {2} bean.", 110 new Object [] {getClass(),"Entity","Session"})); 111 return result; 112 } 113 } 114 115 121 122 123 private boolean commonToBothInterfaces(String component, String local,EjbDescriptor descriptor) { 124 boolean oneFailed = false; 125 boolean found = false; 126 foundAtLeastOneCreate = false; 127 try { 128 Context context = getVerifierContext(); 129 ClassLoader jcl = context.getClassLoader(); 130 Class [] methodParameterTypes; 131 Class [] businessMethodParameterTypes; 132 boolean signaturesMatch = false; 133 Vector<Method> createMethodSuffix = new Vector<Method>(); 134 135 if (component != null) { 136 Class home = Class.forName(component, false, getVerifierContext().getClassLoader()); 137 Method [] homeMethods = home.getDeclaredMethods(); 138 139 for (int i = 0; i < homeMethods.length; i++) { 140 if (homeMethods[i].getName().startsWith("create")) { 142 foundAtLeastOneCreate = true; 143 createMethodSuffix.addElement( (Method)homeMethods[i]); 144 } 145 } 146 } 147 148 if (local != null) { 149 Class home = Class.forName(local, false, getVerifierContext().getClassLoader()); 150 Method [] homeMethods = home.getDeclaredMethods(); 151 152 for (int i = 0; i < homeMethods.length; i++) { 153 if (homeMethods[i].getName().startsWith("create")) { 155 foundAtLeastOneCreate = true; 156 createMethodSuffix.addElement( (Method)homeMethods[i]); 157 } 158 } 159 } 160 161 if (foundAtLeastOneCreate == false) 162 return false; 163 164 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 165 do { 167 Method [] methods = EJBClass.getDeclaredMethods(); 168 for (int j = 0; j < methods.length; j++) { 170 found = false; 171 if (methods[j].getName().startsWith("ejbCreate")) { 172 found = true; 173 String matchSuffix = methods[j].getName().substring(9); 174 for (int k = 0; k < createMethodSuffix.size(); k++) { 175 signaturesMatch = false; 176 177 if (matchSuffix.equals(((Method)(createMethodSuffix.elementAt(k))).getName().substring(6))) { 178 methodParameterTypes = ((Method)(createMethodSuffix.elementAt(k))).getParameterTypes(); 179 businessMethodParameterTypes = methods[j].getParameterTypes(); 180 if (Arrays.equals(methodParameterTypes,businessMethodParameterTypes)) { 181 signaturesMatch = true; 182 result.addGoodDetails(smh.getLocalString 185 ("tests.componentNameConstructor", 186 "For [ {0} ]", 187 new Object [] {compName.toString()})); 188 result.addGoodDetails(smh.getLocalString 189 (getClass().getName() + ".debug1", 190 "For Home Interface Method [ {0} ]", 191 new Object [] {((Method)(createMethodSuffix.elementAt(k))).getName()})); 192 result.addGoodDetails(smh.getLocalString 193 (getClass().getName() + ".passed", 194 "The corresponding ejbCreate method with matching parameters was found.")); 195 break; 196 } 197 } 198 } 199 if (signaturesMatch == false) { 200 oneFailed = true; 201 result.addErrorDetails(smh.getLocalString 202 ("tests.componentNameConstructor", 203 "For [ {0} ]", 204 new Object [] {compName.toString()})); 205 result.addErrorDetails(smh.getLocalString 206 (getClass().getName() + ".debug3", 207 "For Home Interface ", 208 new Object [] {})); 209 result.addErrorDetails(smh.getLocalString 210 (getClass().getName() + ".failed", 211 "Error: No corresponding ejbCreate<Method> method with matching parameters was found." )); 212 break; 213 214 } } 216 } 217 if (oneFailed == true) 218 break; 219 220 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!signaturesMatch)); 221 if (found == false && foundAtLeastOneCreate == true){ 222 result.addErrorDetails(smh.getLocalString 223 ("tests.componentNameConstructor", 224 "For [ {0} ]", 225 new Object [] {compName.toString()})); 226 result.failed(smh.getLocalString 227 (getClass().getName() + ".failedException1", 228 "Error: ejbPostCreate<Method> method corresponding to the ejbCreate<Method> method does not exist!", 229 new Object [] {})); 230 231 } 232 if (found == false && foundAtLeastOneCreate == false){ 233 result.addNaDetails(smh.getLocalString 234 ("tests.componentNameConstructor", 235 "For [ {0} ]", 236 new Object [] {compName.toString()})); 237 result.addNaDetails(smh.getLocalString 238 (getClass().getName() + ".notApplicable1", 239 "No create method was found, test not applicable." )); 240 } 241 return oneFailed; 242 } catch (ClassNotFoundException e) { 243 Verifier.debug(e); 244 result.addErrorDetails(smh.getLocalString 245 ("tests.componentNameConstructor", 246 "For [ {0} ]", 247 new Object [] {compName.toString()})); 248 result.failed(smh.getLocalString 249 (getClass().getName() + ".failedException", 250 "Error: Home interface (Remote/Local) or bean class [ {0} ] does not exist or is not loadable within bean [ {1} ]", 251 new Object [] {descriptor.getEjbClassName(),descriptor.getName()})); 252 return oneFailed; 253 } 254 } 255 } 256 | Popular Tags |