1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime; 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.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 32 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 33 34 import java.io.*; 35 import java.util.jar.*; 36 import java.util.zip.*; 37 38 import com.sun.enterprise.deployment.runtime.IASEjbCMPFinder; 39 40 59 public class ASEjbCMP extends EjbTest implements EjbCheck { 60 61 public boolean oneFailed = false; 62 public boolean oneWarning = false; 63 public Result check(EjbDescriptor descriptor) { 64 65 Result result = getInitializedResult(); 66 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 67 try { 68 if (descriptor instanceof IASEjbCMPEntityDescriptor){ 69 70 IASEjbCMPEntityDescriptor cmpBean = (IASEjbCMPEntityDescriptor)descriptor; 71 72 if(cmpBean != null){ 73 String mappingProps = cmpBean.getMappingProperties(); 74 if(mappingProps == null){ 75 oneWarning = true; 76 addWarningDetails(result, compName); 77 result.warning(smh.getLocalString(getClass().getName()+".warning", 78 "WARNING [AS-EJB cmp] : mapping-properties Element is not defined")); 79 }else{ 80 if(mappingProps.length()==0) { 81 oneFailed = true; 82 addErrorDetails(result, compName); 83 result.failed(smh.getLocalString(getClass().getName()+".failed", 84 "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value")); 85 } 86 else{ JarFile jarFile = null; 89 ZipEntry deploymentEntry=null; 90 if(jarFile!=null) 93 deploymentEntry = jarFile.getEntry(mappingProps); 94 100 if(deploymentEntry !=null){ 101 addGoodDetails(result, compName); 102 result.passed(smh.getLocalString(getClass().getName()+".passed", 103 "PASSED [AS-EJB cmp] : mapping-properties file is {0}", 104 new Object []{mappingProps})); 105 }else{ 106 addErrorDetails(result, compName); 107 result.failed(smh.getLocalString(getClass().getName()+".failed", 109 "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value")); 110 } 111 } 112 } 113 114 try{ 115 boolean oneoneCmp = cmpBean.getCMPVersion()==EjbCMPEntityDescriptor.CMP_1_1; 116 addGoodDetails(result, compName); 117 result.passed(smh.getLocalString(getClass().getName()+".passed1", 118 "PASSED [AS-EJB cmp] : is-one-one-cmp is {0}", 119 new Object []{new Boolean (oneoneCmp)})); 120 }catch(Exception ex){ 121 oneWarning = true; 122 addWarningDetails(result, compName); 123 result.warning(smh.getLocalString(getClass().getName()+".warning1", 124 "WARNING [AS-EJB cmp] : is-one-one-cmp Element is not defined")); 125 } 126 127 try{ 128 Map finders = cmpBean.getOneOneFinders(); 131 if(finders!=null){ 132 testFinders(finders,result); 133 }else{ 134 oneWarning = true; 135 addWarningDetails(result, compName); 136 result.warning(smh.getLocalString(getClass().getName()+".warning2", 137 "WARNING [AS-EJB cmp] : one-one-finders Element is not defined")); 138 } 139 }catch(Exception ex){ 140 oneFailed = true; 141 addErrorDetails(result, compName); 142 result.failed(smh.getLocalString(getClass().getName()+".failed1", 143 "FAILED [AS-EJB cmp] : getOneOneFinders Failed.", 144 new Object []{cmpBean})); 145 } 146 147 if(oneFailed){ 148 result.setStatus(Result.FAILED);} 149 else{ if(oneWarning) 150 result.setStatus(Result.WARNING);} 151 152 }else{ 153 addNaDetails(result, compName); 154 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 155 "NOT APPLICABLE [AS-EJB cmp] : {0} is not a CMP Entity Bean.", 156 new Object [] {descriptor.getName()})); 157 } 158 }else{ 159 addNaDetails(result, compName); 160 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 161 "NOT APPLICABLE [AS-EJB cmp] : {0} is not a CMP Entity Bean.", 162 new Object [] {descriptor.getName()})); 163 } 164 }catch(Exception ex){ 165 oneFailed = true; 166 addErrorDetails(result, compName); 167 result.failed(smh.getLocalString(getClass().getName()+".notRun", 168 "NOT RUN [AS-EJB cmp] Could not create descriptor Object.")); 169 } 170 return result; 171 } 172 173 174 public void testFinders(Map finders, Result result) { 175 try{ 176 Set keySet = finders.keySet(); 177 Iterator it = keySet.iterator(); 178 while (it.hasNext()){ 179 Object obj = it.next(); 180 IASEjbCMPFinder finder = (IASEjbCMPFinder)finders.get(obj); 181 182 String methodName = finder.getMethodName(); 184 if(methodName.length()==0){ 185 oneFailed = true; 186 result.failed(smh.getLocalString(getClass().getName()+".failed2", 187 "FAILED [AS-EJB finder] : method-name cannot be an empty string.")); 188 }else{ 189 result.passed(smh.getLocalString(getClass().getName()+".passed2", 190 "PASSED [AS-EJB finder] : method-name is {0}", 191 new Object []{methodName})); 192 } 193 194 String value = finder.getQueryParameterDeclaration(); 196 testQuery(value,result,"finder","query-params"); 197 198 value = finder.getQueryFilter(); 200 testQuery(value,result,"finder","query-filter"); 201 202 value = finder.getQueryVariables(); 204 testQuery(value,result,"finder","query-variables"); 205 206 value = finder.getQueryOrdering(); 208 testQuery(value,result,"finder","query-ordering"); 209 } 210 }catch(Exception ex){ 211 oneFailed = true; 212 result.failed(smh.getLocalString(getClass().getName()+".notRun", 213 "NOT RUN [AS-EJB cmp] Could not create descriptor Object.")); 214 } 215 } 216 217 public void testQuery(String value, Result result,String parent, String child){ 218 if(value == null){ 219 oneWarning = true; 220 result.warning(smh.getLocalString(getClass().getName()+".warning3", 221 "WARNING [AS-EJB {0}] : {1} Element is not defined", 222 new Object []{parent,child})); 223 }else{ 224 if(value.length()==0){ 225 oneFailed = true; 226 result.failed(smh.getLocalString(getClass().getName()+".failed3", 227 "FAILED [AS-EJB {0}] : {1} cannot be an empty string", 228 new Object []{parent,child})); 229 }else{ 230 result.passed(smh.getLocalString(getClass().getName()+".passed3", 231 "PASSED [AS-EJB {0}] : {1} is/are {2}", 232 new Object []{parent, child, value})); 233 } 234 } 235 } 236 } 237 | Popular Tags |