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.EjbDescriptor; 27 import com.sun.enterprise.deployment.EjbEntityDescriptor; 28 import java.lang.ClassLoader ; 29 import com.sun.enterprise.tools.verifier.tests.*; 30 import java.util.*; 31 import java.lang.reflect.*; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 34 35 48 public class HomeInterfaceCreateMethodReturn extends EjbTest implements EjbCheck { 49 boolean foundAtLeastOneCreate = false; 50 Result result = null; 51 ComponentNameConstructor compName = null; 52 boolean remote_exists = false; 53 boolean local_exists = false; 54 69 public Result check(EjbDescriptor descriptor) { 70 71 result = getInitializedResult(); 72 compName = getVerifierContext().getComponentNameConstructor(); 73 String local = null; 74 String localHome = null; 75 String remote = null; 76 String home = null; 77 if (descriptor instanceof EjbEntityDescriptor) { 78 boolean oneFailed = false; 79 80 84 if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName()) && 85 descriptor.getRemoteClassName() != null && !"".equals(descriptor.getRemoteClassName()) ) { 86 remote_exists = true; 87 home = descriptor.getHomeClassName(); 88 remote = descriptor.getRemoteClassName(); 89 } 90 if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())&& 91 descriptor.getLocalClassName() != null && !"".equals(descriptor.getLocalClassName())) { 92 local_exists = true; 93 localHome = descriptor.getLocalHomeClassName(); 94 local = descriptor.getLocalClassName(); 95 } 96 oneFailed = commonToBothInterfaces(remote,home,local,localHome,(EjbEntityDescriptor)descriptor); 97 98 if (!foundAtLeastOneCreate) { 99 result.addNaDetails(smh.getLocalString 100 ("tests.componentNameConstructor", 101 "For [ {0} ]", 102 new Object [] {compName.toString()})); 103 result.addNaDetails(smh.getLocalString 104 (getClass().getName() + ".debug3", 105 "In Home Interface ", 106 new Object [] {})); 107 result.addNaDetails(smh.getLocalString 108 (getClass().getName() + ".notApplicable1", 109 "No create method was found, test not applicable." )); 110 result.setStatus(result.NOT_APPLICABLE); 111 } else { 112 if (oneFailed) { 113 result.setStatus(result.FAILED); 114 } else { 115 result.setStatus(result.PASSED); 116 } 117 } 118 119 return result; 120 121 } else { 122 result.addNaDetails(smh.getLocalString 123 ("tests.componentNameConstructor", 124 "For [ {0} ]", 125 new Object [] {compName.toString()})); 126 result.notApplicable(smh.getLocalString 127 (getClass().getName() + ".notApplicable", 128 "[ {0} ] expected {1} bean, but called with {2} bean.", 129 new Object [] {getClass(),"Entity","Session"})); 130 return result; 131 } 132 } 133 134 141 142 private boolean commonToBothInterfaces(String remote, String home, String local, String localHome, EjbEntityDescriptor descriptor) { 143 boolean oneFailed = false; 144 Class c,rc,lc,hc; 145 Method localMethods[],methods[]; 146 try { 147 Context context = getVerifierContext(); 148 ClassLoader jcl = context.getClassLoader(); 149 if (remote_exists) { 150 c = Class.forName(home, false, getVerifierContext().getClassLoader()); 151 rc = Class.forName(remote, false, getVerifierContext().getClassLoader()); 152 methods = c.getDeclaredMethods(); 153 oneFailed = findReturnType(methods,home,local,remote); 154 } 155 if (oneFailed == false) { 156 if (local_exists) { 157 hc = Class.forName(localHome, false, getVerifierContext().getClassLoader()); 158 lc = Class.forName(local, false, getVerifierContext().getClassLoader()); 159 localMethods = hc.getDeclaredMethods(); 160 oneFailed = findReturnType(localMethods,localHome,local,remote); 161 } 162 } 163 return oneFailed; 164 165 } catch (ClassNotFoundException e) { 166 Verifier.debug(e); 167 result.addErrorDetails(smh.getLocalString 168 ("tests.componentNameConstructor", 169 "For [ {0} ]", 170 new Object [] {compName.toString()})); 171 result.failed(smh.getLocalString 172 (getClass().getName() + ".failedException", 173 "Error: Home interface [ {0} ] or [ {1} ]or Component interface [ {2} ] or [ {3} ] does not exist or is not loadable within bean [ {4} ]", 174 new Object [] {home, localHome, remote, local, descriptor.getName()})); 175 return false; 176 } 177 } 178 179 180 private boolean findReturnType(Method[] methods, String home, String local, String remote) { 181 Class methodReturnType; 182 boolean validReturn, oneFailed = false; 183 184 for (int i=0; i< methods.length; i++) { 185 validReturn = false; 187 if (methods[i].getName().startsWith("create")) { 188 foundAtLeastOneCreate=true; 189 methodReturnType = methods[i].getReturnType(); 191 if (remote_exists) { 192 if (methodReturnType.getName().equals(remote)) { 193 validReturn = true; 195 result.addGoodDetails(smh.getLocalString 196 ("tests.componentNameConstructor", 197 "For [ {0} ]", 198 new Object [] {compName.toString()})); 199 result.addGoodDetails(smh.getLocalString 200 (getClass().getName() + ".debug1", 201 "For Home Interface [ {0} ] Method [ {1} ]", 202 new Object [] {home ,methods[i].getName()})); 203 result.addGoodDetails(smh.getLocalString 204 (getClass().getName() + ".passed", 205 "The create method which returns [ {0} ] interface was found.", 206 new Object [] {"remote"})); 207 } 208 } 209 if (local_exists) { 210 if (methodReturnType.getName().equals(local)) { 211 validReturn = true; 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 ,methods[i].getName()})); 221 result.addGoodDetails(smh.getLocalString 222 (getClass().getName() + ".passed", 223 "The create method which returns [ {0} ] interface was found.", 224 new Object [] {"local"})); 225 } 226 } 227 228 if (!validReturn) { 232 oneFailed = true; 233 result.addErrorDetails(smh.getLocalString 234 ("tests.componentNameConstructor", 235 "For [ {0} ]", 236 new Object [] {compName.toString()})); 237 result.addErrorDetails(smh.getLocalString 238 (getClass().getName() + ".debug1", 239 "For Home Interface [ {0} ] Method [ {1} ]", 240 new Object [] {home,methods[i].getName()})); 241 result.addErrorDetails(smh.getLocalString 242 (getClass().getName() + ".failed", 243 "Error: A Create method was found, but the return type [ {0} ] was not the Remote/Local interface" , 244 new Object [] {methodReturnType.getName()})); 245 return oneFailed; 246 } } } 250 return oneFailed; 251 252 } 253 } 254 | Popular Tags |