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