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.*; 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.Ejb; 37 import com.sun.enterprise.tools.common.dd.ejb.Cmp; 38 import com.sun.enterprise.tools.common.dd.ejb.Finder; 39 import com.sun.enterprise.tools.common.dd.ejb.OneOneFinders; 40 import java.io.*; 41 import java.util.jar.*; 42 import java.util.zip.*; 43 44 62 public class ASEjbCMP extends EjbTest implements EjbCheck { 63 64 public boolean oneFailed = false; 65 public boolean oneWarning = false; 66 public Result check(EjbDescriptor descriptor) 67 { 68 Result result = getInitializedResult(); 69 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 70 71 SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject(); 72 Ejb testCase = null; 73 if(ejbJar!=null) 74 { 75 testCase = super.getEjb(descriptor.getName(),ejbJar); 76 Cmp cmpBean = testCase.getCmp(); 77 if(cmpBean != null) 78 { 79 String mappingProps = cmpBean.getMappingProperties(); 81 if(mappingProps == null) 82 { 83 oneWarning = true; 84 result.warning(smh.getLocalString(getClass().getName()+".warning", 85 "WARNING [AS-EJB cmp] : mapping-properties Element is not defined")); 86 } 87 else 88 { 89 if(mappingProps.length()==0) 90 { 91 oneFailed = true; 92 result.failed(smh.getLocalString(getClass().getName()+".failed", 93 "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value")); 94 } 95 else { File f = Verifier.getJarFile(((EjbBundleArchivist) descriptor.getEjbBundleDescriptor().getArchivist()).getEjbJarFile().getName()); 97 JarFile jarFile = null; 98 ZipEntry deploymentEntry=null; 99 try { 100 jarFile = new JarFile(f); 101 if(jarFile!=null) 102 deploymentEntry = jarFile.getEntry(mappingProps); 103 104 105 } 106 catch(IOException e){} 107 finally{ 108 try{ if(jarFile!=null) jarFile.close();} 109 catch(IOException e){} 110 } 111 112 if(deploymentEntry !=null){ 113 result.passed(smh.getLocalString(getClass().getName()+".passed", 114 "PASSED [AS-EJB cmp] : mapping-properties file is {0}", 115 new Object []{mappingProps})); 116 } 117 else{ 118 result.failed(smh.getLocalString(getClass().getName()+".failed", 120 "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value")); 121 122 123 } 124 } 125 } 126 127 String isOneOne = cmpBean.getIsOneOneCmp(); 129 if(isOneOne == null) 130 { 131 oneWarning = true; 132 result.warning(smh.getLocalString(getClass().getName()+".warning1", 133 "WARNING [AS-EJB cmp] : is-one-one-cmp Element is not defined")); 134 } 135 else 136 { 137 if(isOneOne.length()==0) 138 { 139 oneFailed = true; 140 result.failed(smh.getLocalString(getClass().getName()+".failed1", 141 "FAILED [AS-EJB cmp] : is-one-one-cmp cannot be an empty string. It can be either true or false")); 142 } 143 else 144 { 145 if(!isOneOne.equals("true") && !isOneOne.equals("false")) 146 { 147 oneFailed = true; 148 result.failed(smh.getLocalString(getClass().getName()+".failed2", 149 "FAILED [AS-EJB cmp] : is-one-one-cmp cannot be {0}. It can either be true or false", 150 new Object []{isOneOne})); 151 } 152 else 153 { 154 result.passed(smh.getLocalString(getClass().getName()+".passed1", 155 "PASSED [AS-EJB cmp] : is-one-one-cmp is {0}", 156 new Object []{isOneOne})); 157 } 158 } 159 } 160 161 OneOneFinders finders = cmpBean.getOneOneFinders(); 163 if(finders!=null) 164 { 165 testFinders(finders,result); 166 } 167 else 168 { 169 oneWarning = true; 170 result.warning(smh.getLocalString(getClass().getName()+".warning2", 171 "WARNING [AS-EJB cmp] : one-one-finders Element is not defined")); 172 } 173 174 if(oneFailed) 175 result.setStatus(Result.FAILED); 176 else if(oneWarning) 177 result.setStatus(Result.WARNING); 178 } 179 else 180 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 181 "NOT APPLICABLE [AS-EJB cmp] : {0} is not a CMP Entity Bean.", 182 new Object [] {testCase.getEjbName()})); 183 } 184 else 185 { 186 result.failed(smh.getLocalString(getClass().getName()+".notRun", 187 "NOT RUN [AS-EJB cmp] Could not create SunEjbJar Object.")); 188 } 189 return result; 190 } 191 192 public void testFinders(OneOneFinders finders, Result result) 193 { 194 Finder finder[] = finders.getFinder(); 195 for (int i=0;i<finder.length;i++) 196 { 197 String methodName = finder[i].getMethodName(); 199 if(methodName.length()==0) 200 { 201 oneFailed = true; 202 result.failed(smh.getLocalString(getClass().getName()+".failed3", 203 "FAILED [AS-EJB finder] : method-name cannot be an empty string.")); 204 } 205 else 206 { 207 result.passed(smh.getLocalString(getClass().getName()+".passed2", 209 "PASSED [AS-EJB finder] : method-name is {0}", 210 new Object []{methodName})); 211 } 212 213 String value = finder[i].getQueryParams(); 215 testQuery(value,result,"finder","query-params"); 216 217 value = finder[i].getQueryFilter(); 219 testQuery(value,result,"finder","query-filter"); 220 221 value = finder[i].getQueryVariables(); 223 testQuery(value,result,"finder","query-variables"); 224 } 225 226 } 227 228 public void testQuery(String value, Result result,String parent, String child) 229 { 230 if(value == null) 231 { 232 oneWarning = true; 233 result.warning(smh.getLocalString(getClass().getName()+".warning3", 234 "WARNING [AS-EJB {0}] : {1} Element is not defined", 235 new Object []{parent,child})); 236 } 237 else 238 { 239 if(value.length()==0) 240 { 241 oneFailed = true; 242 result.failed(smh.getLocalString(getClass().getName()+".failed4", 243 "FAILED [AS-EJB {0}] : {1} cannot be an empty string", 244 new Object []{parent,child})); 245 } 246 else 247 { 248 result.passed(smh.getLocalString(getClass().getName()+".passed3", 249 "PASSED [AS-EJB {0}] : {1} is/are {2}", 250 new Object []{parent, child, value})); 251 } 252 } 253 } 254 } 255 | Popular Tags |