1 23 24 25 package com.sun.enterprise.tools.verifier.tests.ejb.ias.cmpmapping; 26 27 28 import java.util.*; 29 import com.sun.enterprise.deployment.EjbDescriptor; 30 import com.sun.enterprise.deployment.EjbSessionDescriptor; 31 import com.sun.enterprise.tools.verifier.*; 32 import com.sun.enterprise.tools.verifier.tests.*; 33 34 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 35 36 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 37 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 38 import com.sun.enterprise.tools.common.dd.ResourceRef; 39 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal; 40 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 41 import com.sun.enterprise.tools.verifier.tests.ejb.*; 42 import com.sun.enterprise.tools.common.dd.cmpmapping.*; 43 44 public class ASCmrFieldMappingTest extends EjbTest implements EjbCheck { 45 46 47 48 public Result check(EjbDescriptor descriptor) 49 { 50 Result result = getInitializedResult(); 51 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 52 boolean oneFailed = false; 53 boolean notApp = false; 54 55 60 SunCmpMappings iasCmpMappings = descriptor.getEjbBundleDescriptor().getIasCmpMappings(); 61 String forPmConfig = com.sun.enterprise.deployment.EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY; 62 64 SunCmpMapping[] allIasCmpMapping=null; 65 SunCmpMapping iasCmpMapping=null; 66 67 EntityMapping[] entityMapping=null; 69 70 String cmrfieldName=null; 71 ColumnPair[] columnPair=null; 72 FetchedWith fetchedWith=null; 73 String strlevel=""; 74 75 76 if(iasCmpMappings!=null) 78 { 79 86 allIasCmpMapping=iasCmpMappings.getSunCmpMapping(); 88 89 for(int rep=0;rep<allIasCmpMapping.length;rep++){ 90 91 iasCmpMapping=allIasCmpMapping[rep]; 92 93 entityMapping=iasCmpMapping.getEntityMapping(); 95 96 if(entityMapping == null || entityMapping.length==0){ oneFailed = true; 98 99 result.failed(smh.getLocalString(getClass().getName()+".failed", 100 "FAILED [AS-CMP-MAPPING] : entity-mapping is NOT a valid entry, in the mapping file [ {0}], "+ 101 "of the ejb archive [ {1} ]. "+ 102 "Either null or empty.", 103 new Object []{forPmConfig,descriptor.getName()})); 104 continue; 105 106 } 107 108 for(int rep1=0;rep1<entityMapping.length;rep1++){ 109 CmrFieldMapping[] cmrFieldMapping=null; 110 cmrFieldMapping=entityMapping[rep1].getCmrFieldMapping(); 111 String forEjb=entityMapping[rep1].getEjbName(); 112 113 if(cmrFieldMapping == null || cmrFieldMapping.length==0){ 115 result.notApplicable(smh.getLocalString (getClass().getName() + ".notApplicable", 116 "NOT APPLICABLE [AS-CMP-MAPPING] : There is no cmr-field-mappings element present for ejb [ {0} ]in the mapping file [ {1}], "+ 117 "of the ejb archive [ {2} ]. ", 118 new Object []{forEjb,forPmConfig,descriptor.getName()})); 119 continue; 120 121 } 122 123 124 125 for(int rep11=0;rep11<cmrFieldMapping.length;rep11++){ 126 127 cmrfieldName=cmrFieldMapping[rep11].getCmrFieldName(); 128 columnPair=cmrFieldMapping[rep11].getColumnPair(); 129 fetchedWith =cmrFieldMapping[rep11].getFetchedWith(); 130 131 if(validateCmrFieldName(cmrfieldName)){ 132 133 result.passed(smh.getLocalString(getClass().getName()+".passed", 134 "PASSED [AS-CMP-MAPPING] : cmr-field-mapping->cmr-field-name [{0} ] is a valid entry, in the mapping file [ {1}], "+ 135 "of the ejb archive [ {2} ]. ", 136 new Object []{cmrfieldName,forPmConfig,descriptor.getName()})); 137 138 }else{ 139 oneFailed = true; 140 141 result.failed(smh.getLocalString(getClass().getName()+".failed1", 142 "FAILED [AS-CMP-MAPPING] : cmr-field-mapping->cmr-field-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+ 143 "of the ejb archive [ {2} ]. "+ 144 "Either null or empty.", 145 new Object []{cmrfieldName,forPmConfig,descriptor.getName()})); 146 147 } 148 149 if(validateColumnPair(columnPair,result,forPmConfig,descriptor.getName())){ 150 151 result.passed(smh.getLocalString(getClass().getName()+".passed1", 152 "PASSED [AS-CMP-MAPPING] : All the cmr-field-mapping->column-pair for field-name [{0} ], are valid, in the mapping file [ {1}], "+ 153 "of the ejb archive [ {2} ]. ", 154 new Object []{cmrfieldName,forPmConfig,descriptor.getName()})); 155 156 }else{ 157 oneFailed = true; 158 159 result.failed(smh.getLocalString(getClass().getName()+".failed2", 160 "FAILED [AS-CMP-MAPPING] : At least one cmr-field-mapping->column-pair, for field-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+ 161 "of the ejb archive [ {2} ]. "+ 162 "Either null or empty.", 163 new Object []{cmrfieldName,forPmConfig,descriptor.getName()})); 164 165 } 166 167 boolean validLevel=true; 169 int level; 170 171 if(fetchedWith !=null ){ try{ 173 level=fetchedWith.getLevel(); 174 strlevel=level+strlevel; 175 if(!(level >0 && level < Integer.MAX_VALUE)) 176 validLevel=false; 177 } catch(NumberFormatException exception){ 178 validLevel=false; 179 180 }catch(RuntimeException re){ 181 } 183 } 184 if(!validLevel){ 185 oneFailed = true; 186 187 result.failed(smh.getLocalString(getClass().getName()+".failed3", 188 "FAILED [AS-CMP-MAPPING] : The cmr-field-mapping->fetched-with->level [ {0} ], for field-name [{1} ] is NOT a valid entry, in the mapping file [ {1}], "+ 189 "of the ejb archive [ {2} ]. "+ 190 "Should be an integer between 1 to Integer.MAX_VALUE.", 191 new Object []{strlevel,forPmConfig,descriptor.getName()})); 192 193 } 194 196 } 198 } 199 200 } 201 202 203 205 } 206 else 207 { 208 notApp = true; 209 result.notApplicable(smh.getLocalString 210 (getClass().getName() + ".notApplicable1", 211 "NOT APPLICABLE [AS-CMP-MAPPING] : There is no ias-cmp-mappings file present, within the ejb archive [ {0} ].", 212 new Object [] {descriptor.getName()})); 213 214 } 215 216 if (oneFailed) { 217 result.setStatus(Result.FAILED); 218 } else if(notApp) { 219 result.setStatus(Result.NOT_APPLICABLE); 220 }else { 221 result.setStatus(Result.PASSED); 222 } 223 224 225 return result; 226 } 227 228 boolean validateCmrFieldName(String name){ 229 boolean valid=false; 230 if(name !=null && !name.trim().equals("")){ 231 valid =true; 232 } 233 return valid; 234 } 235 236 boolean validateColumnPair(ColumnPair[] columnPair,Result result,String forPmConfig,String descriptorName){ 237 boolean valid=true; 238 239 String [] colPair=null; 240 String col1=null; 241 String col2=null; 242 if(columnPair ==null && columnPair.length ==0 ){ 243 result.failed(smh.getLocalString(getClass().getName()+".failed4", 244 "ERROR [AS-CMP-MAPPING] : The cmr-field-mapping->column-pair is EMPTY/NULL, in the mapping file [ {0}], "+ 245 "of the ejb archive [ {1} ]. "+ 246 "Atleast one column of the pair, null or empty.", 247 new Object []{forPmConfig,descriptorName})); 248 valid =false; 249 return valid; 250 } else{ 251 for(int rep=0;rep<columnPair.length;rep++) 252 { 253 boolean pairValid=false; 254 if(columnPair[rep] !=null ){ 255 colPair=columnPair[rep].getColumnName(); 256 if(colPair !=null && colPair.length==2){ 257 col1=colPair[0]; 258 col2=colPair[1]; 259 260 if(col1!=null && !col1.trim().equals("") && 261 col2!=null && !col2.trim().equals("")){ 262 pairValid=true; 263 264 } 265 266 } 267 } 268 269 if(pairValid){ 270 271 result.passed(smh.getLocalString(getClass().getName()+".passed2", 272 "PASSED [AS-CMP-MAPPING] : The cmr-field-mapping->column-pair entry [ {0}/{1} ] is valid, in the mapping file [ {2}], "+ 273 "of the ejb archive [ {3} ]. ", 274 new Object []{col1,col2,forPmConfig,descriptorName})); 275 276 }else{ 277 valid = false; 278 279 result.failed(smh.getLocalString(getClass().getName()+".failed5", 280 "FAILED [AS-CMP-MAPPING] : The cmr-field-mapping->column-pair entry [ {0}/{1} ] , is NOT a valid entry, in the mapping file [ {2}], "+ 281 "of the ejb archive [ {3} ]. "+ 282 "Atleast one column of the pair, null or empty.", 283 new Object []{col1,col2,forPmConfig,descriptorName})); 284 285 } 286 287 } 288 289 290 } 291 return valid; 292 } 293 } 294 295 | Popular Tags |