1 23 24 25 26 package com.sun.enterprise.tools.verifier.tests.ejb.ias.cmpmapping; 27 28 29 import java.util.*; 30 import com.sun.enterprise.deployment.EjbDescriptor; 31 import com.sun.enterprise.deployment.EjbSessionDescriptor; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.tools.verifier.tests.*; 34 35 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 36 37 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 38 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 39 import com.sun.enterprise.tools.common.dd.ResourceRef; 40 import com.sun.enterprise.tools.common.dd.DefaultResourcePrincipal; 41 import com.sun.enterprise.deployment.ResourceReferenceDescriptor; 42 import com.sun.enterprise.tools.verifier.tests.ejb.*; 43 import com.sun.enterprise.tools.common.dd.cmpmapping.*; 44 45 public class ASSecondaryTableTest extends EjbTest implements EjbCheck { 46 47 48 49 public Result check(EjbDescriptor descriptor) 50 { 51 Result result = getInitializedResult(); 52 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 53 boolean oneFailed = false; 54 boolean notApp = false; 55 56 61 SunCmpMappings iasCmpMappings = descriptor.getEjbBundleDescriptor().getIasCmpMappings(); 62 String forPmConfig = com.sun.enterprise.deployment.EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY; 63 65 SunCmpMapping[] allIasCmpMapping=null; 66 SunCmpMapping iasCmpMapping=null; 67 68 EntityMapping[] entityMapping=null; 70 71 String tableName=null; 72 ColumnPair[] columnPair=null; 73 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 SecondaryTable[] secTable=null; 110 secTable=entityMapping[rep1].getSecondaryTable(); 111 String forEjb=entityMapping[rep1].getEjbName(); 112 113 if(secTable == null || secTable.length==0){ 115 result.notApplicable(smh.getLocalString (getClass().getName() + ".notApplicable", 116 "NOT APPLICABLE [AS-CMP-MAPPING] : There is no secondary-table 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<secTable.length;rep11++){ 126 127 tableName=secTable[rep11].getTableName(); 128 columnPair=secTable[rep11].getColumnPair(); 129 131 if(validateCmrFieldName(tableName)){ 132 133 result.passed(smh.getLocalString(getClass().getName()+".passed", 134 "PASSED [AS-CMP-MAPPING] : secondary-table->table-name [{0} ] is a valid entry, in the mapping file [ {1}], "+ 135 "of the ejb archive [ {2} ]. ", 136 new Object []{tableName,forPmConfig,descriptor.getName()})); 137 138 }else{ 139 oneFailed = true; 140 141 result.failed(smh.getLocalString(getClass().getName()+".failed1", 142 "FAILED [AS-CMP-MAPPING] : secondary-table->table-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 []{tableName,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 secondary-table->column-pair for field-name [{0} ], are valid, in the mapping file [ {1}], "+ 153 "of the ejb archive [ {2} ]. ", 154 new Object []{tableName,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 secondary-table->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 []{tableName,forPmConfig,descriptor.getName()})); 164 165 } 166 167 } 169 } 170 171 } 172 173 174 176 } 177 else 178 { 179 notApp = true; 180 result.notApplicable(smh.getLocalString 181 (getClass().getName() + ".notApplicable", 182 "NOT APPLICABLE [AS-CMP-MAPPING] : There is no ias-cmp-mappings file present, within the ejb archive [ {0} ].", 183 new Object [] {descriptor.getName()})); 184 185 } 186 187 if (oneFailed) { 188 result.setStatus(Result.FAILED); 189 } else if(notApp) { 190 result.setStatus(Result.NOT_APPLICABLE); 191 }else { 192 result.setStatus(Result.PASSED); 193 } 194 195 196 return result; 197 } 198 199 boolean validateCmrFieldName(String name){ 200 boolean valid=false; 201 if(name !=null && !name.trim().equals("")){ 202 valid =true; 203 } 204 return valid; 205 } 206 207 boolean validateColumnPair(ColumnPair[] columnPair,Result result,String forPmConfig,String descriptorName){ 208 boolean valid=true; 209 210 String [] colPair=null; 211 String col1=null; 212 String col2=null; 213 if(columnPair ==null && columnPair.length ==0 ){ 214 result.failed(smh.getLocalString(getClass().getName()+".failed3", 215 "ERROR [AS-CMP-MAPPING] : The secondary-table->column-pair is EMPTY/NULL, in the mapping file [ {0}], "+ 216 "of the ejb archive [ {1} ]. "+ 217 "Atleast one column of the pair, null or empty.", 218 new Object []{forPmConfig,descriptorName})); 219 valid =false; 220 return valid; 221 } else{ 222 for(int rep=0;rep<columnPair.length;rep++) 223 { 224 boolean pairValid=false; 225 if(columnPair[rep] !=null ){ 226 colPair=columnPair[rep].getColumnName(); 227 if(colPair !=null && colPair.length==2){ 228 col1=colPair[0]; 229 col2=colPair[1]; 230 231 if(col1!=null && !col1.trim().equals("") && 232 col2!=null && !col2.trim().equals("")){ 233 pairValid=true; 234 235 } 236 237 } 238 } 239 240 if(pairValid){ 241 242 result.passed(smh.getLocalString(getClass().getName()+".passed2", 243 "PASSED [AS-CMP-MAPPING] : The cmr-field-mapping->column-pair entry [ {0}/{1} ] is valid, in the mapping file [ {2}], "+ 244 "of the ejb archive [ {3} ]. ", 245 new Object []{col1,col2,forPmConfig,descriptorName})); 246 247 }else{ 248 valid = false; 249 250 result.failed(smh.getLocalString(getClass().getName()+".failed4", 251 "FAILED [AS-CMP-MAPPING] : The secondary-table->column-pair entry [ {0}/{1} ] , is NOT a valid entry, in the mapping file [ {2}], "+ 252 "of the ejb archive [ {3} ]. "+ 253 "Atleast one column of the pair, null or empty.", 254 new Object []{col1,col2,forPmConfig,descriptorName})); 255 256 } 257 258 } 259 260 261 } 262 return valid; 263 } 264 } 265 266 | Popular Tags |