1 23 package com.sun.enterprise.tools.verifier.tests.ejb.session.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.EjbSessionDescriptor; 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 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils; 35 36 46 public class HomeInterfaceCreateMethodExceptionCreate extends EjbTest implements EjbCheck { 47 Result result = null; 48 ComponentNameConstructor compName = null; 49 50 64 public Result check(EjbDescriptor descriptor) { 65 66 result = getInitializedResult(); 67 compName = getVerifierContext().getComponentNameConstructor(); 68 69 if (descriptor instanceof EjbSessionDescriptor) { 70 boolean oneFailed = false; 71 if (descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) 72 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),(EjbSessionDescriptor)descriptor); 73 if (oneFailed == false) { 74 if (descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) 75 oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),(EjbSessionDescriptor)descriptor); 76 } 77 if ((oneFailed == false) && (implementsEndpoints(descriptor))) { 78 result.addNaDetails(smh.getLocalString 79 ("tests.componentNameConstructor", 80 "For [ {0} ]", 81 new Object [] {compName.toString()})); 82 result.notApplicable(smh.getLocalString 83 ("com.sun.enterprise.tools.verifier.tests.ejb.webservice.notapp", 84 "Not Applicable because, EJB [ {0} ] implements a Service Endpoint Interface.", 85 new Object [] {compName.toString()})); 86 result.setStatus(result.NOT_APPLICABLE); 87 return result; 88 } 89 90 if (oneFailed) { 91 result.setStatus(result.FAILED); 92 } else { 93 result.setStatus(result.PASSED); 94 } 95 return result; 96 97 } else { 98 result.addNaDetails(smh.getLocalString 99 ("tests.componentNameConstructor", 100 "For [ {0} ]", 101 new Object [] {compName.toString()})); 102 result.notApplicable(smh.getLocalString 103 (getClass().getName() + ".notApplicable", 104 "[ {0} ] expected {1} bean, but called with {2} bean.", 105 new Object [] {getClass(),"Session","Entity"})); 106 return result; 107 } 108 } 109 110 116 117 118 private boolean commonToBothInterfaces(String home, EjbSessionDescriptor descriptor) { 119 boolean oneFailed = false; 120 try { 124 Context context = getVerifierContext(); 125 ClassLoader jcl = context.getClassLoader(); 126 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 127 Method methods[] = c.getDeclaredMethods(); 128 Class [] methodExceptionTypes; 129 boolean throwsCreateException = false; 130 131 for (int i=0; i< methods.length; i++) { 132 throwsCreateException = false; 134 if (methods[i].getName().startsWith("create")) { 135 methodExceptionTypes = methods[i].getExceptionTypes(); 136 137 if (EjbUtils.isValidCreateException(methodExceptionTypes)) { 139 throwsCreateException = true; 140 } 141 142 if (throwsCreateException ) { 146 result.addGoodDetails(smh.getLocalString 147 ("tests.componentNameConstructor", 148 "For [ {0} ]", 149 new Object [] {compName.toString()})); 150 result.addGoodDetails(smh.getLocalString 151 (getClass().getName() + ".debug1", 152 "For Home Interface [ {0} ] Method [ {1} ]", 153 new Object [] {c.getName(),methods[i].getName()})); 154 result.addGoodDetails(smh.getLocalString 155 (getClass().getName() + ".passed", 156 "The create method which must throw javax.ejb.CreateException was found..")); 157 } else if (!throwsCreateException) { 158 oneFailed = true; 159 result.addErrorDetails(smh.getLocalString 160 ("tests.componentNameConstructor", 161 "For [ {0} ]", 162 new Object [] {compName.toString()})); 163 result.addErrorDetails(smh.getLocalString 164 (getClass().getName() + ".debug1", 165 "For Home Interface [ {0} ] Method [ {1} ]", 166 new Object [] {c.getName(),methods[i].getName()})); 167 result.addErrorDetails(smh.getLocalString 168 (getClass().getName() + ".failed", 169 "Error: A create method was found, but did not throw javax.ejb.CreateException." )); 170 } } } 174 return oneFailed; 175 } catch (ClassNotFoundException e) { 176 Verifier.debug(e); 177 result.addErrorDetails(smh.getLocalString 178 ("tests.componentNameConstructor", 179 "For [ {0} ]", 180 new Object [] {compName.toString()})); 181 result.failed(smh.getLocalString 182 (getClass().getName() + ".failedException", 183 "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 184 new Object [] {home, descriptor.getName()})); 185 return oneFailed; 186 187 } 188 } 189 } 190 | Popular Tags |