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 46 public class HomeInterfaceCreateMethodExceptionCreate extends EjbTest implements EjbCheck { 47 boolean foundAtLeastOneCreate = false; 48 Result result = null; 49 ComponentNameConstructor compName = null; 50 64 public Result check(EjbDescriptor descriptor) { 65 66 result = getInitializedResult(); 67 compName = getVerifierContext().getComponentNameConstructor(); 68 boolean oneFailed = false; 69 70 if (descriptor instanceof EjbEntityDescriptor) { 71 if(descriptor.getHomeClassName() != null && !"".equals(descriptor.getHomeClassName())) 72 oneFailed = commonToBothInterfaces(descriptor.getHomeClassName(),descriptor); 73 if(oneFailed == false) { 74 if(descriptor.getLocalHomeClassName() != null && !"".equals(descriptor.getLocalHomeClassName())) 75 oneFailed = commonToBothInterfaces(descriptor.getLocalHomeClassName(),descriptor); 76 } 77 78 if (!foundAtLeastOneCreate) { 79 result.addGoodDetails(smh.getLocalString 80 ("tests.componentNameConstructor", 81 "For [ {0} ]", 82 new Object [] {compName.toString()})); 83 result.addGoodDetails(smh.getLocalString 84 (getClass().getName() + ".debug3", 85 "For Home Interface [ {0} ]", 86 new Object [] {descriptor.getHomeClassName()})); 87 result.addGoodDetails(smh.getLocalString 88 (getClass().getName() + ".notApplicable1", 89 "No create method was found, test not applicable." )); 90 result.setStatus(result.PASSED); 91 } else { 92 if (oneFailed) { 93 result.setStatus(result.FAILED); 94 } else { 95 result.setStatus(result.PASSED); 96 } 97 } 98 99 return result; 100 101 } else { 102 result.addNaDetails(smh.getLocalString 103 ("tests.componentNameConstructor", 104 "For [ {0} ]", 105 new Object [] {compName.toString()})); 106 result.notApplicable(smh.getLocalString 107 (getClass().getName() + ".notApplicable", 108 "[ {0} ] expected {1} bean, but called with {2} bean.", 109 new Object [] {getClass(),"Entity","Session"})); 110 return result; 111 } 112 } 113 119 120 121 private boolean commonToBothInterfaces(String home, EjbDescriptor descriptor) { 122 boolean oneFailed = false; 123 124 try { 127 Context context = getVerifierContext(); 128 ClassLoader jcl = context.getClassLoader(); 129 Class c = Class.forName(home, false, getVerifierContext().getClassLoader()); 130 Method methods[] = c.getDeclaredMethods(); 131 Class [] methodExceptionTypes; 132 boolean throwsCreateException = false; 133 134 for (int i=0; i< methods.length; i++) { 135 throwsCreateException = false; 137 if (methods[i].getName().startsWith("create")) { 138 if (!foundAtLeastOneCreate) { 143 foundAtLeastOneCreate = true; 144 } 145 146 methodExceptionTypes = methods[i].getExceptionTypes(); 147 148 for (int kk = 0; kk < methodExceptionTypes.length; ++kk) { 150 if (methodExceptionTypes[kk].getName().equals("javax.ejb.CreateException")) { 151 throwsCreateException = true; 152 break; 153 } 154 } 155 156 if (throwsCreateException ) { 160 result.addGoodDetails(smh.getLocalString 161 ("tests.componentNameConstructor", 162 "For [ {0} ]", 163 new Object [] {compName.toString()})); 164 result.addGoodDetails(smh.getLocalString 165 (getClass().getName() + ".debug1", 166 "For Home Interface [ {0} ] Method [ {1} ]", 167 new Object [] {c.getName(),methods[i].getName()})); 168 result.addGoodDetails(smh.getLocalString 169 (getClass().getName() + ".passed", 170 "The create method which must throw javax.ejb.CreateException was found.")); 171 } else if (!throwsCreateException) { 172 oneFailed = true; 173 result.addErrorDetails(smh.getLocalString 174 ("tests.componentNameConstructor", 175 "For [ {0} ]", 176 new Object [] {compName.toString()})); 177 result.addErrorDetails(smh.getLocalString 178 (getClass().getName() + ".debug1", 179 "For Home Interface [ {0} ] Method [ {1} ]", 180 new Object [] {home,methods[i].getName()})); 181 result.addErrorDetails(smh.getLocalString 182 (getClass().getName() + ".failed", 183 "Error: A create method was found, but did not throw javax.ejb.CreateException." )); 184 break; 185 } } } 189 return oneFailed; 190 } catch (ClassNotFoundException e) { 191 Verifier.debug(e); 192 result.addErrorDetails(smh.getLocalString 193 ("tests.componentNameConstructor", 194 "For [ {0} ]", 195 new Object [] {compName.toString()})); 196 result.failed(smh.getLocalString 197 (getClass().getName() + ".failedException", 198 "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 199 new Object [] {home, descriptor.getName()})); 200 return oneFailed; 201 } 202 } 203 } 204 | Popular Tags |