KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ias > cmpmapping > ASCmrFieldMappingTest


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

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         //<addition author="irfan@sun.com" [bug/rfe]-id="4715917" >
56
/*Set keys = descriptor.getEjbBundleDescriptor().getIasCmpMappingsKeys();
57
58         SunCmpMappings iasCmpMappings=null;
59         String forPmConfig=null;*/

60         SunCmpMappings iasCmpMappings = descriptor.getEjbBundleDescriptor().getIasCmpMappings();
61         String JavaDoc forPmConfig = com.sun.enterprise.deployment.EjbBundleXmlReader.IAS_CMP_MAPPING_JAR_ENTRY;
62         //</addition>
63

64         SunCmpMapping[] allIasCmpMapping=null;
65         SunCmpMapping iasCmpMapping=null;
66
67         /////test vars
68
EntityMapping[] entityMapping=null;
69
70         String JavaDoc cmrfieldName=null;
71         ColumnPair[] columnPair=null;
72         FetchedWith fetchedWith=null;
73         String JavaDoc strlevel="";
74
75
76         //<addition author="irfan@sun.com" [bug/rfe]-id="4715917" >
77
if(iasCmpMappings!=null)
78         {
79         /*if(keys!=null && keys.size()>0)
80         {
81             Iterator it = keys.iterator();
82             while(it.hasNext()) {
83
84                 forPmConfig=(String) it.next();
85                 iasCmpMappings= descriptor.getEjbBundleDescriptor().getIasCmpMappings(forPmConfig);*/

86          //</addition>
87
allIasCmpMapping=iasCmpMappings.getSunCmpMapping();
88
89                 for(int rep=0;rep<allIasCmpMapping.length;rep++){
90
91                       iasCmpMapping=allIasCmpMapping[rep];
92
93                       //test logic
94
entityMapping=iasCmpMapping.getEntityMapping();
95
96                       if(entityMapping == null || entityMapping.length==0){//this should never happen
97
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 JavaDoc[]{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 JavaDoc forEjb=entityMapping[rep1].getEjbName();
112
113                           //since cmrmapping can be (0..n)
114
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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{cmrfieldName,forPmConfig,descriptor.getName()}));
164
165                               }
166
167                               ///check level
168
boolean validLevel=true;
169                               int level;
170
171                               if(fetchedWith !=null ){ //since optional field
172
try{
173                                         level=fetchedWith.getLevel();
174                                         strlevel=level+strlevel;
175                                         if(!(level >0 && level < Integer.MAX_VALUE))
176                                         validLevel=false;
177                                   } catch(NumberFormatException JavaDoc exception){
178                                         validLevel=false;
179
180                                   }catch(RuntimeException JavaDoc re){
181                                         //ignore
182
}
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 JavaDoc[]{strlevel,forPmConfig,descriptor.getName()}));
192
193                               }
194                               //end of level chk
195

196                           }//end for(int rep1=0;rep<entityMapping.length;rep1++){
197

198                       }
199
200                 }
201
202
203             //} 4715917 irfan
204

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 JavaDoc[] {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 JavaDoc 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 JavaDoc forPmConfig,String JavaDoc descriptorName){
237         boolean valid=true;
238
239         String JavaDoc[] colPair=null;
240         String JavaDoc col1=null;
241         String JavaDoc 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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{col1,col2,forPmConfig,descriptorName}));
284
285                 }
286
287             }
288
289
290         }
291         return valid;
292     }
293 }
294
295
Popular Tags