1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.ejbfindbyprimarykey; 24 25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 26 import java.lang.reflect.*; 27 import java.util.*; 28 import com.sun.enterprise.deployment.EjbEntityDescriptor; 29 import com.sun.enterprise.deployment.EjbDescriptor; 30 import com.sun.enterprise.deployment.MethodDescriptor; 31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 32 import com.sun.enterprise.tools.verifier.tests.ejb.RmiIIOPUtils; 33 import com.sun.enterprise.tools.verifier.*; 34 import java.lang.ClassLoader ; 35 import com.sun.enterprise.tools.verifier.tests.*; 36 37 45 public class EjbFindByPrimaryKeyArgs extends EjbTest implements EjbCheck { 46 47 48 60 public Result check(EjbDescriptor descriptor) { 61 62 Result result = getInitializedResult(); 63 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 64 65 if (descriptor instanceof EjbEntityDescriptor) { 66 String persistentType = 67 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 68 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistentType)) { 69 Class [] ejbFinderMethodParameterTypes; 70 boolean ejbFindByPrimaryKeyMethodFound = false; 71 boolean oneFailed = false; 72 boolean isLegalRMIIIOP = false; 73 try { 74 Context context = getVerifierContext(); 76 ClassLoader jcl = context.getClassLoader(); 77 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 78 do { 80 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 81 82 for (int j = 0; j < ejbFinderMethods.length; ++j) { 83 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) { 84 ejbFindByPrimaryKeyMethodFound = true; 87 88 ejbFinderMethodParameterTypes = ejbFinderMethods[j].getParameterTypes(); 90 if (RmiIIOPUtils.isValidRmiIIOPParameters(ejbFinderMethodParameterTypes)) { 91 isLegalRMIIIOP = true; 93 } 94 95 if (ejbFindByPrimaryKeyMethodFound && isLegalRMIIIOP) { 96 result.addGoodDetails(smh.getLocalString 97 ("tests.componentNameConstructor", 98 "For [ {0} ]", 99 new Object [] {compName.toString()})); 100 result.addGoodDetails(smh.getLocalString 101 (getClass().getName() + ".debug1", 102 "For EJB Class [ {0} ] Finder Method [ {1} ]", 103 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 104 result.addGoodDetails(smh.getLocalString 105 (getClass().getName() + ".passed", 106 "An [ {0} ] method with valid RMI-IIOP argument types was found.", 107 new Object [] {ejbFinderMethods[j].getName()})); 108 } else if (ejbFindByPrimaryKeyMethodFound && (!isLegalRMIIIOP)) { 109 oneFailed = true; 110 result.addErrorDetails(smh.getLocalString 111 ("tests.componentNameConstructor", 112 "For [ {0} ]", 113 new Object [] {compName.toString()})); 114 result.addErrorDetails(smh.getLocalString 115 (getClass().getName() + ".debug1", 116 "For EJB Class [ {0} ] Finder Method [ {1} ]", 117 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()} 118 )); 119 result.addErrorDetails(smh.getLocalString 120 (getClass().getName() + ".failed", 121 "Error: An [ {0} ] method was found, but [ {1} ] method has illegal parameter values. [ {2} ] methods arguments types must be legal types for RMI-IIOP.", 122 new Object [] {ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName(),ejbFinderMethods[j].getName()})); 123 } 124 break; 126 } 127 } 128 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound)); 129 130 if (!ejbFindByPrimaryKeyMethodFound) { 131 oneFailed = true; 132 result.addErrorDetails(smh.getLocalString 133 ("tests.componentNameConstructor", 134 "For [ {0} ]", 135 new Object [] {compName.toString()})); 136 result.addErrorDetails(smh.getLocalString 137 (getClass().getName() + ".debug3", 138 "For EJB Class [ {0} ]", 139 new Object [] {descriptor.getEjbClassName()})); 140 result.addErrorDetails(smh.getLocalString 141 (getClass().getName() + ".failed1", 142 "Error: No ejbFindByPrimaryKey method was found in bean class.")); 143 } 144 145 } catch (ClassNotFoundException e) { 146 Verifier.debug(e); 147 result.addErrorDetails(smh.getLocalString 148 ("tests.componentNameConstructor", 149 "For [ {0} ]", 150 new Object [] {compName.toString()})); 151 result.failed(smh.getLocalString 152 (getClass().getName() + ".failedException", 153 "Error: EJB Class [ {0} ] does not exist or is not loadable.", 154 new Object [] {descriptor.getEjbClassName()})); 155 oneFailed = true; 156 } 157 158 if (oneFailed) { 159 result.setStatus(result.FAILED); 160 } else { 161 result.setStatus(result.PASSED); 162 } 163 } else { result.addNaDetails(smh.getLocalString 165 ("tests.componentNameConstructor", 166 "For [ {0} ]", 167 new Object [] {compName.toString()})); 168 result.notApplicable(smh.getLocalString 169 (getClass().getName() + ".notApplicable2", 170 "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", 171 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistentType})); 172 } 173 174 return result; 175 176 } else { 177 result.addNaDetails(smh.getLocalString 178 ("tests.componentNameConstructor", 179 "For [ {0} ]", 180 new Object [] {compName.toString()})); 181 result.notApplicable(smh.getLocalString 182 (getClass().getName() + ".notApplicable", 183 "[ {0} ] expected {1} bean, but called with {2} bean.", 184 new Object [] {getClass(),"Entity","Session"})); 185 return result; 186 } 187 } 188 } 189 | Popular Tags |