1 23 24 package com.sun.enterprise.tools.verifier.tests.ejb.ias.cmpmapping; 25 26 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.Ejb; 37 import com.sun.enterprise.tools.common.dd.ResourceRef; 38 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal; 39 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 40 import com.sun.enterprise.tools.verifier.tests.ejb.*; 41 import com.sun.enterprise.tools.common.dd.cmpmapping.*; 42 43 public class ASCmpFieldMappingTest extends EjbTest implements EjbCheck { 44 45 public Result check(EjbDescriptor descriptor) 46 { 47 Result result = getInitializedResult(); 48 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 49 boolean oneFailed = false; 50 boolean notApp = false; 51 52 57 String forPmConfig = com.sun.enterprise.deployment.EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY; 58 SunCmpMappings iasCmpMappings = descriptor.getEjbBundleDescriptor().getIasCmpMappings(); 59 61 SunCmpMapping[] allIasCmpMapping=null; 62 SunCmpMapping iasCmpMapping=null; 63 64 EntityMapping[] entityMapping=null; 66 67 String fieldName=null; 68 String [] columName=null; 69 FetchedWith fetchedWith=null; 70 String strlevel=""; 71 72 if(iasCmpMappings!=null) 74 { 75 82 allIasCmpMapping=iasCmpMappings.getSunCmpMapping(); 84 85 for(int rep=0;rep<allIasCmpMapping.length;rep++){ 86 87 iasCmpMapping=allIasCmpMapping[rep]; 88 89 entityMapping=iasCmpMapping.getEntityMapping(); 91 92 if(entityMapping == null || entityMapping.length==0){ oneFailed = true; 94 95 result.failed(smh.getLocalString(getClass().getName()+".failed", 96 "FAILED [AS-CMP-MAPPING] : entity-mapping is NOT a valid entry, in the mapping file [ {0}], "+ 97 "of the ejb archive [ {1} ]. "+ 98 "Either null or empty.", 99 new Object []{forPmConfig,descriptor.getName()})); 100 continue; 101 102 } 103 104 for(int rep1=0;rep1<entityMapping.length;rep1++){ 105 CmpFieldMapping[] cmpFieldMapping=null; 106 cmpFieldMapping=entityMapping[rep1].getCmpFieldMapping(); 107 108 for(int rep11=0;rep11<cmpFieldMapping.length;rep11++){ 109 110 fieldName=cmpFieldMapping[rep11].getFieldName(); 111 columName=cmpFieldMapping[rep11].getColumnName(); 112 fetchedWith =cmpFieldMapping[rep11].getFetchedWith(); 113 114 if(validateFieldName(fieldName)){ 115 116 result.passed(smh.getLocalString(getClass().getName()+".passed", 117 "PASSED [AS-CMP-MAPPING] : cmp-field-mapping->field-name [{0} ] is a valid entry, in the mapping file [ {1}], "+ 118 "of the ejb archive [ {2} ]. ", 119 new Object []{fieldName,forPmConfig,descriptor.getName()})); 120 121 }else{ 122 oneFailed = true; 123 124 result.failed(smh.getLocalString(getClass().getName()+".failed1", 125 "FAILED [AS-CMP-MAPPING] : cmp-field-mapping->field-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+ 126 "of the ejb archive [ {2} ]. "+ 127 "Either null or empty.", 128 new Object []{fieldName,forPmConfig,descriptor.getName()})); 129 130 } 131 132 if(validateColumnName(columName)){ 133 134 result.passed(smh.getLocalString(getClass().getName()+".passed1", 135 "PASSED [AS-CMP-MAPPING] : All the cmp-field-mapping->column-name for field-name [{0} ], are valid, in the mapping file [ {1}], "+ 136 "of the ejb archive [ {2} ]. ", 137 new Object []{fieldName,forPmConfig,descriptor.getName()})); 138 139 }else{ 140 oneFailed = true; 141 142 result.failed(smh.getLocalString(getClass().getName()+".failed2", 143 "FAILED [AS-CMP-MAPPING] : At least one cmp-field-mapping->column-name, for field-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+ 144 "of the ejb archive [ {2} ]. "+ 145 "Either null or empty.", 146 new Object []{fieldName,forPmConfig,descriptor.getName()})); 147 148 } 149 boolean validLevel=true; 151 int level; 152 153 if(fetchedWith !=null ){ try{ 155 level=fetchedWith.getLevel(); 156 strlevel=level+strlevel; 157 if(!(level >0 && level < Integer.MAX_VALUE)) 158 validLevel=false; 159 } catch(NumberFormatException exception){ 160 validLevel=false; 161 162 }catch(RuntimeException re){ 163 } 165 } 166 if(!validLevel){ 167 oneFailed = true; 168 169 result.failed(smh.getLocalString(getClass().getName()+".failed3", 170 "FAILED [AS-CMP-MAPPING] : The cmp-field-mapping->fetched-with->level [ {0} ], for field-name [{1} ] is NOT a valid entry, in the mapping file [ {1}], "+ 171 "of the ejb archive [ {2} ]. "+ 172 "Should be an integer between 1 to Integer.MAX_VALUE.", 173 new Object []{strlevel,forPmConfig,descriptor.getName()})); 174 175 } 176 } 179 } 180 181 } 182 183 184 186 } 187 else 188 { 189 notApp = true; 190 result.notApplicable(smh.getLocalString 191 (getClass().getName() + ".notApplicable", 192 "NOT APPLICABLE [AS-CMP-MAPPING] : There is no ias-cmp-mappings file present, within the ejb archive [ {0} ].", 193 new Object [] {descriptor.getName()})); 194 195 } 196 197 if (oneFailed) { 198 result.setStatus(Result.FAILED); 199 } else if(notApp) { 200 result.setStatus(Result.NOT_APPLICABLE); 201 }else { 202 result.setStatus(Result.PASSED); 203 } 204 205 206 return result; 207 } 208 209 boolean validateFieldName(String name){ 210 boolean valid=false; 211 if(name !=null && !name.trim().equals("")){ 212 valid =true; 214 } 215 return valid; 216 } 217 218 boolean validateColumnName(String [] name){ 219 boolean valid=true; 220 if(name ==null && name.length ==0 ){ 221 222 valid =false; 223 return valid; 224 } else{ 225 for(int rep=0;rep<name.length;rep++) 226 { 227 if(name[rep]==null || name[rep].trim().equals("")){ 228 valid=false; 229 break; 230 } 231 232 233 } 234 235 236 } 237 return valid; 238 } 239 } 240 241 242 | Popular Tags |