1 package com.sun.enterprise.tools.verifier.tests.ejb.ias; 2 3 25 26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 27 import java.util.*; 28 import com.sun.enterprise.deployment.EjbDescriptor; 29 import com.sun.enterprise.deployment.EjbSessionDescriptor; 30 import com.sun.enterprise.tools.verifier.*; 31 import com.sun.enterprise.tools.verifier.tests.*; 32 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 34 35 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 36 import com.sun.enterprise.tools.common.dd.ejb.EnterpriseBeans; 37 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 38 import com.sun.enterprise.deployment.EjbEntityDescriptor; 39 import com.sun.enterprise.deployment.EjbSessionDescriptor; 40 import com.sun.enterprise.deployment.EjbMessageBeanDescriptor; 41 import java.lang.reflect.*; 42 50 public class ASEjbIsReadOnlyBean extends EjbTest implements EjbCheck { 51 52 boolean oneFailed= false; 53 boolean oneWarning = false; 54 55 60 public Result check(EjbDescriptor descriptor) { 61 62 Result result = getInitializedResult(); 63 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 64 65 SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject(); 66 String ejbName = null; 67 Ejb testCase = null; 68 if(ejbJar!=null) 69 { 70 testCase = getEjb(descriptor.getName(),ejbJar); 71 String isReadOnlyBean = testCase.getIsReadOnlyBean(); 72 if(isReadOnlyBean != null) 73 { 74 if(isReadOnlyBean.length()==0) 75 { 76 oneFailed = true; 77 result.failed(smh.getLocalString(getClass().getName()+".failed", 78 "FAILED [AS-EJB ejb] : is-read-only-bean cannot be an empty string")); 79 } 80 else 81 { 82 if(!isReadOnlyBean.equals("true") && !isReadOnlyBean.equals("false")) 83 { 84 oneFailed = true; 85 result.failed(smh.getLocalString(getClass().getName()+".failed1", 86 "FAILED [AS-EJB ejb] : is-read-only-bean cannot be {0}. It can only be true or false", 87 new Object []{isReadOnlyBean})); 88 } 89 else 90 { 91 if(isReadOnlyBean.equals("true")) 92 testROBSpecific(descriptor,testCase,result); 93 else 94 { 95 result.passed(smh.getLocalString(getClass().getName()+".passed", 96 "PASSED [AS-EJB ejb] is-read-only-bean is {0}", 97 new Object []{isReadOnlyBean})); 98 } 99 } 100 } 101 if(oneFailed) 102 result.setStatus(Result.FAILED); 103 else if(oneWarning) 104 result.setStatus(Result.WARNING); 105 } 106 else 107 { 108 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 109 "NOT APPLICABLE [AS-EJB ejb] is-read-only-bean Element not defined")); 110 } 111 } 112 else 113 { 114 result.addErrorDetails(smh.getLocalString 115 ("tests.componentNameConstructor", 116 "For [ {0} ]", 117 new Object [] {compName.toString()})); 118 result.addErrorDetails(smh.getLocalString 119 (getClass().getName() + ".notRun", 120 "NOT RUN [AS-EJB] : Could not create an SunEjbJar object")); 121 } 122 return result; 123 } 124 125 public void testROBSpecific(EjbDescriptor descriptor, Ejb testCase,Result result) 126 { 127 if(descriptor instanceof EjbEntityDescriptor) 129 { 130 result.passed(smh.getLocalString(getClass().getName()+".passed1", 131 "PASSED [AS-EJB ejb] : Read Only Beans can only be Entity Beans")); 132 } 133 else if(descriptor instanceof EjbSessionDescriptor) 134 { 135 oneFailed = true; 136 result.failed(smh.getLocalString(getClass().getName()+".failed2", 137 "FAILED [AS-EJB ejb] : Read Only Beans cannot be Session Beans. They can only be Entity Beans")); 138 return; 139 } 140 else if(descriptor instanceof EjbMessageBeanDescriptor) 141 { 142 oneFailed = true; 143 result.failed(smh.getLocalString(getClass().getName()+".failed3", 144 "FAILED [AS-EJB ejb] : Read Only Beans cannot be Message Driven Beans. They can only be Entity Beans")); 145 return; 146 } 147 148 String txnType = descriptor.getTransactionType(); 150 if(txnType.equals(descriptor.CONTAINER_TRANSACTION_TYPE)) 151 { 152 result.passed(smh.getLocalString(getClass().getName()+".passed2", 153 "PASSED [AS-EJB ejb] : Read Only Beans can only have Container Managed Transactions")); 154 } 155 else 156 { 157 oneFailed = true; 158 result.failed(smh.getLocalString(getClass().getName()+".failed4", 159 "FAILED [AS-EJB ejb] : Read Only Beans cannot have Bean Managed Transactions")); 160 } 161 162 String homeName = descriptor.getHomeClassName(); 164 Class homeClass = null; 165 boolean foundCreateMethod = false; 166 boolean foundRemoveMethod = false; 167 try 168 { 169 homeClass = getVerifierContext().getClassLoader().loadClass(homeName); 170 Method methods[] = homeClass.getMethods(); 171 for(int i=0;i<methods.length;i++) 172 { 173 if(methods[i].getName().startsWith("create")) 174 { 175 foundCreateMethod = true; 176 break; 177 } 178 } 179 180 for(int i=0;i<methods.length;i++) 181 { 182 if(methods[i].getName().startsWith("remove")) 183 { 184 foundRemoveMethod = true; 185 break; 186 } 187 } 188 if(foundCreateMethod) 189 { 190 oneWarning = true; 191 result.addWarningDetails(smh.getLocalString(getClass().getName()+".warning1", 192 "WARNING [AS-EJB ejb] : Read Only Beans should have zero create Methods")); 193 } 194 else 195 result.passed(smh.getLocalString(getClass().getName()+".passed3", 196 "PASSED [AS-EJB ejb] : Read Only Bean has zero create Methods")); 197 198 if(foundRemoveMethod) 199 { 200 oneWarning = true; 201 result.addWarningDetails(smh.getLocalString(getClass().getName()+".warning2", 202 "WARNING [AS-EJB ejb] : Read Only Beans should have zero remove Methods")); 203 } 204 else 205 { 206 result.passed(smh.getLocalString(getClass().getName()+".passed4", 207 "PASSED [AS-EJB ejb] : Read Only Bean has zero remove Methods")); 208 } 209 210 String refreshPeriod = testCase.getRefreshPeriodInSeconds(); 212 if(refreshPeriod!=null) 213 { 214 if(refreshPeriod.length()==0) 215 { 216 oneFailed = true; 217 result.failed(smh.getLocalString(getClass().getName()+".failed5", 218 "FAILED [AS-EJB ejb] : refresh-period-in-seconds is empty. It should be between 0 and {0}",new Object []{new Long ( Long.MAX_VALUE)})); 219 } 220 else 221 { 222 try 223 { 224 long refValue = Long.valueOf(refreshPeriod).longValue(); 225 if(refValue <0 || refValue > Long.MAX_VALUE) 226 { 227 result.failed(smh.getLocalString(getClass().getName()+".failed6", 228 "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and {0}." ,new Object []{new Long ( Long.MAX_VALUE)})); 229 } 230 else 231 result.passed(smh.getLocalString(getClass().getName()+".passed5", 232 "PASSED [AS-EJB ejb] : refresh-period-in-seconds is {0}",new Object []{new Long (refValue)})); 233 } 234 catch(NumberFormatException nfex) 235 { 236 Verifier.debug(nfex); 237 result.failed(smh.getLocalString(getClass().getName()+".failed6", 238 "FAILED [AS-EJB ejb] : refresh-period-in-seconds is invalid. It should be between 0 and {0}", new Object []{new Long (Long.MAX_VALUE)} )); 239 } 240 } 241 } 242 243 if(oneFailed) 244 result.setStatus(Result.FAILED); 245 } 246 catch(ClassNotFoundException cfne) 247 { 248 Verifier.debug(cfne); 249 result.addErrorDetails(smh.getLocalString 250 ("tests.componentNameConstructor", 251 "For [ {0} ]", 252 new Object [] {(new ComponentNameConstructor(descriptor)).toString()})); 253 result.failed(smh.getLocalString 254 (getClass().getName() + ".failed7", 255 "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]", 256 new Object [] {homeName, descriptor.getName()})); 257 } 258 } 259 } 260 261 | Popular Tags |