1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbpostcreatemethod; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.ClassLoader ; 27 import com.sun.enterprise.tools.verifier.tests.*; 28 import javax.ejb.EntityBean ; 29 import java.lang.reflect.*; 30 import com.sun.enterprise.deployment.*; 31 import java.util.*; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 34 35 44 public class EjbPostCreateMethodName extends EjbTest implements EjbCheck { 45 46 47 59 public Result check(EjbDescriptor descriptor) { 60 61 Result result = getInitializedResult(); 62 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 63 boolean ejbCreateExists = false; 64 65 if (descriptor instanceof EjbEntityDescriptor) { 66 boolean oneFailed = false; 67 boolean found = false; 68 int foundAtLeastOne = 0; 69 try { 70 Context context = getVerifierContext(); 71 ClassLoader jcl = context.getClassLoader(); 72 Class c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 73 Method [] methods = c.getDeclaredMethods(); 74 Vector<Method> createMethodSuffix = new Vector<Method>(); 75 for (int i = 0; i < methods.length; i++) { 76 if (methods[i].getName().startsWith("ejbCreate")) { 78 createMethodSuffix.addElement((Method)methods[i]); 79 ejbCreateExists = true; 80 } 81 } 82 83 do { 85 for (int i = 0; i < methods.length; i++) { 86 found = false; 87 88 if (methods[i].getName().startsWith("ejbPostCreate")) { 90 found = true; 91 String matchSuffix = methods[i].getName().substring(13); 92 for (int k = 0; k < createMethodSuffix.size(); k++) { 93 if (matchSuffix.equals(((Method)createMethodSuffix.elementAt(k)).getName().substring(9))) { 94 foundAtLeastOne++; 95 96 result.addGoodDetails(smh.getLocalString 99 ("tests.componentNameConstructor", 100 "For [ {0} ]", 101 new Object [] {compName.toString()})); 102 result.addGoodDetails(smh.getLocalString 103 (getClass().getName() + ".debug1", 104 "For EJB Class [ {0} ] method [ {1} ]", 105 new Object [] {descriptor.getEjbClassName(),methods[i].getName()})); 106 result.addGoodDetails(smh.getLocalString 107 (getClass().getName() + ".passed", 108 "[ {0} ] declares [ {1} ] method.", 109 new Object [] {descriptor.getEjbClassName(),methods[i].getName()})); 110 } 111 } 112 if (found == true && foundAtLeastOne == 0) { 113 oneFailed = true; 114 result.addErrorDetails(smh.getLocalString 115 ("tests.componentNameConstructor", 116 "For [ {0} ]", 117 new Object [] {compName.toString()})); 118 result.failed(smh.getLocalString 119 (getClass().getName() + ".failedException", 120 "Error: [ {0} ] class not found.", 121 new Object [] {descriptor.getEjbClassName()})); 122 break; 123 } 124 } 125 } 126 if (oneFailed == false) 127 break; 128 } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0)); 129 130 if (ejbCreateExists == false){ 131 result.addNaDetails(smh.getLocalString 132 ("tests.componentNameConstructor", 133 "For [ {0} ]", 134 new Object [] {compName.toString()})); 135 result.notApplicable(smh.getLocalString 136 (getClass().getName() + ".notApplicable1", 137 "[ {0} ] does not declare any ejbPostCreate(...) methods.", 138 new Object [] {descriptor.getEjbClassName()})); 139 } 140 if (foundAtLeastOne == 0 && ejbCreateExists == true){ 141 result.addErrorDetails(smh.getLocalString 142 ("tests.componentNameConstructor", 143 "For [ {0} ]", 144 new Object [] {compName.toString()})); 145 result.failed(smh.getLocalString 146 (getClass().getName() + ".failedException1", 147 "Error: ejbPostCreate<Method> method corresponding to the ejbCreate<Method> method does not exist!", 148 new Object [] {})); 149 150 } 151 } catch (ClassNotFoundException e) { 152 Verifier.debug(e); 153 result.addErrorDetails(smh.getLocalString 154 ("tests.componentNameConstructor", 155 "For [ {0} ]", 156 new Object [] {compName.toString()})); 157 result.failed(smh.getLocalString 158 (getClass().getName() + ".failedException", 159 "Error: [ {0} ] class not found.", 160 new Object [] {descriptor.getEjbClassName()})); 161 oneFailed = true; 162 } 163 164 if (oneFailed) { 165 result.setStatus(result.FAILED); 166 } else if (foundAtLeastOne == 0) { 167 result.setStatus(result.NOT_APPLICABLE); 168 } else { 169 result.setStatus(result.PASSED); 170 } 171 172 return result; 173 174 } else { 175 result.addNaDetails(smh.getLocalString 176 ("tests.componentNameConstructor", 177 "For [ {0} ]", 178 new Object [] {compName.toString()})); 179 result.notApplicable(smh.getLocalString 180 (getClass().getName() + ".notApplicable", 181 "[ {0} ] expected {1} bean, but called with {2} bean.", 182 new Object [] {getClass(),"Entity","Session"})); 183 return result; 184 } 185 } 186 } 187 | Popular Tags |