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 com.sun.enterprise.deployment.EjbEntityDescriptor; 27 import com.sun.enterprise.deployment.EjbDescriptor; 28 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 29 import com.sun.enterprise.tools.verifier.*; 30 import java.lang.ClassLoader ; 31 import java.lang.reflect.Method ; 32 33 import com.sun.enterprise.tools.verifier.tests.*; 34 35 43 public class EjbFindByPrimaryKeyName extends EjbTest implements EjbCheck { 44 45 46 57 public Result check(EjbDescriptor descriptor) { 58 59 Result result = getInitializedResult(); 60 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 61 62 if (descriptor instanceof EjbEntityDescriptor) { 63 String persistence = ((EjbEntityDescriptor)descriptor).getPersistenceType(); 64 boolean ejbFindByPrimaryKeyMethodFound = false; 65 boolean oneFailed = false; 66 try { 67 Context context = getVerifierContext(); 69 ClassLoader jcl = context.getClassLoader(); 70 Class EJBClass = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader()); 71 do { 73 Method [] ejbFinderMethods = EJBClass.getDeclaredMethods(); 74 for (int j = 0; j < ejbFinderMethods.length; ++j) { 75 if (ejbFinderMethods[j].getName().equals("ejbFindByPrimaryKey")) { 76 ejbFindByPrimaryKeyMethodFound = true; 81 result.addGoodDetails(smh.getLocalString 82 ("tests.componentNameConstructor", 83 "For [ {0} ]", 84 new Object [] {compName.toString()})); 85 result.addGoodDetails(smh.getLocalString 86 (getClass().getName() + ".debug1", 87 "For EJB Class [ {0} ] Finder Method [ {1} ]", 88 new Object [] {EJBClass.getName(),ejbFinderMethods[j].getName()})); 89 result.addGoodDetails(smh.getLocalString 90 (getClass().getName() + ".passed", 91 "An [ {0} ] method was found.", 92 new Object [] {ejbFinderMethods[j].getName()})); 93 break; 94 } 95 } 96 } while (((EJBClass = EJBClass.getSuperclass()) != null) && (!ejbFindByPrimaryKeyMethodFound)); 97 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)&&ejbFindByPrimaryKeyMethodFound) { 98 result.setStatus(result.PASSED); 99 return result; 100 } else { 101 if(EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence) && !ejbFindByPrimaryKeyMethodFound) { 102 oneFailed = true; 103 result.addErrorDetails(smh.getLocalString 104 ("tests.componentNameConstructor", 105 "For [ {0} ]", 106 new Object [] {compName.toString()})); 107 result.addErrorDetails(smh.getLocalString 108 (getClass().getName() + ".debug3", 109 "For EJB Class [ {0} ]", 110 new Object [] {descriptor.getEjbClassName()})); 111 result.addErrorDetails(smh.getLocalString 112 (getClass().getName() + ".failed", 113 "Error: No ejbFindByPrimaryKey method was found in bean class.")); 114 } else if(EjbEntityDescriptor.CONTAINER_PERSISTENCE.equals(persistence) && ejbFindByPrimaryKeyMethodFound) { 115 oneFailed = true; 116 result.addErrorDetails(smh.getLocalString 117 ("tests.componentNameConstructor", 118 "For [ {0} ]", 119 new Object [] {compName.toString()})); 120 result.addErrorDetails(smh.getLocalString 121 (getClass().getName() + ".debug3", 122 "For EJB Class [ {0} ]", 123 new Object [] {descriptor.getEjbClassName()})); 124 result.addErrorDetails(smh.getLocalString 125 (getClass().getName() + ".failed1", 126 "Error: ejbFindByPrimaryKey method was found for CMP bean class.")); 127 } else { result.addNaDetails(smh.getLocalString 129 ("tests.componentNameConstructor", 130 "For [ {0} ]", 131 new Object [] {compName.toString()})); 132 result.notApplicable(smh.getLocalString 133 (getClass().getName() + ".notApplicable2", 134 "Expected persistence type [ {0} ], but bean [ {1} ] has persistence type [ {2} ]", 135 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence})); 136 return result; 137 } 138 } 139 } catch (ClassNotFoundException e) { 140 Verifier.debug(e); 141 result.addErrorDetails(smh.getLocalString 142 ("tests.componentNameConstructor", 143 "For [ {0} ]", 144 new Object [] {compName.toString()})); 145 result.failed(smh.getLocalString 146 (getClass().getName() + ".failedException", 147 "Error: EJB Class [ {0} ] does not exist or is not loadable.", 148 new Object [] {descriptor.getEjbClassName()})); 149 oneFailed = true; 150 } 151 if (oneFailed) { 152 result.setStatus(result.FAILED); 153 } else { 154 result.setStatus(result.PASSED); 155 } 156 return result; 157 } else { 158 result.addNaDetails(smh.getLocalString 159 ("tests.componentNameConstructor", 160 "For [ {0} ]", 161 new Object [] {compName.toString()})); 162 result.notApplicable(smh.getLocalString 163 (getClass().getName() + ".notApplicable", 164 "[ {0} ] expected {1} bean, but called with {2} bean.", 165 new Object [] {getClass(),"Entity","Session"})); 166 return result; 167 } 168 } 169 } 170 | Popular Tags |