1 23 package com.sun.enterprise.tools.verifier.tests.ejb.entity.findermethod; 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 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils; 35 36 48 public class HomeInterfaceFindMethodExceptionRemote extends EjbTest implements EjbCheck { 49 50 51 67 public Result check(EjbDescriptor descriptor) { 68 69 Result result = getInitializedResult(); 70 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 71 72 if (descriptor instanceof EjbEntityDescriptor) { 73 String persistence = 74 ((EjbEntityDescriptor)descriptor).getPersistenceType(); 75 if (EjbEntityDescriptor.BEAN_PERSISTENCE.equals(persistence)) { 76 boolean oneFailed = false; 77 if(descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) { 80 result.addNaDetails(smh.getLocalString 81 ("tests.componentNameConstructor", 82 "For [ {0} ]", 83 new Object [] {compName.toString()})); 84 result.addNaDetails(smh.getLocalString 85 (getClass().getName() + ".notApplicable1", 86 "No Remote Interface for this Ejb", 87 new Object [] {})); 88 return result; 89 } 90 91 try { 92 Context context = getVerifierContext(); 93 ClassLoader jcl = context.getClassLoader(); 94 Class c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader()); 95 Method methods[] = c.getDeclaredMethods(); 96 Class [] methodExceptionTypes; 97 boolean throwsRemoteException = false; 98 99 for (int i=0; i< methods.length; i++) { 100 throwsRemoteException = false; 102 if (methods[i].getName().startsWith("find")) { 103 methodExceptionTypes = methods[i].getExceptionTypes(); 104 105 if (EjbUtils.isValidRemoteException(methodExceptionTypes)) { 107 throwsRemoteException = true; 108 break; 109 } 110 111 if (throwsRemoteException ) { 115 result.addGoodDetails(smh.getLocalString 116 ("tests.componentNameConstructor", 117 "For [ {0} ]", 118 new Object [] {compName.toString()})); 119 result.addGoodDetails(smh.getLocalString 120 (getClass().getName() + ".debug1", 121 "For Home Interface [ {0} ] Method [ {1} ]", 122 new Object [] {c.getName(),methods[i].getName()})); 123 result.addGoodDetails(smh.getLocalString 124 (getClass().getName() + ".passed", 125 "The find<METHOD> method which must throw java.rmi.RemoteException was found.")); 126 } else if (!throwsRemoteException) { 127 oneFailed = true; 128 result.addErrorDetails(smh.getLocalString 129 ("tests.componentNameConstructor", 130 "For [ {0} ]", 131 new Object [] {compName.toString()})); 132 result.addErrorDetails(smh.getLocalString 133 (getClass().getName() + ".debug1", 134 "For Home Interface [ {0} ] Method [ {1} ]", 135 new Object [] {c.getName(),methods[i].getName()})); 136 result.addErrorDetails(smh.getLocalString 137 (getClass().getName() + ".failed", 138 "Error: A find<METHOD> method was found, but did not throw java.rmi.RemoteException." )); 139 } } } 143 144 } catch (ClassNotFoundException e) { 145 Verifier.debug(e); 146 result.addErrorDetails(smh.getLocalString 147 ("tests.componentNameConstructor", 148 "For [ {0} ]", 149 new Object [] {compName.toString()})); 150 result.failed(smh.getLocalString 151 (getClass().getName() + ".failedException", 152 "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 153 new Object [] {descriptor.getHomeClassName(), descriptor.getName()})); 154 } 155 156 if (oneFailed) { 157 result.setStatus(result.FAILED); 158 } else { 159 result.setStatus(result.PASSED); 160 } 161 return result; 162 } else { result.addNaDetails(smh.getLocalString 164 ("tests.componentNameConstructor", 165 "For [ {0} ]", 166 new Object [] {compName.toString()})); 167 result.notApplicable(smh.getLocalString 168 (getClass().getName() + ".notApplicable2", 169 "Expected [ {0} ] managed persistence, but [ {1} ] bean has [ {2} ] managed persistence.", 170 new Object [] {EjbEntityDescriptor.BEAN_PERSISTENCE,descriptor.getName(),persistence})); 171 return result; 172 } 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 |