KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

82         //</addition>
83
allIasCmpMapping=iasCmpMappings.getSunCmpMapping();
84
85                 for(int rep=0;rep<allIasCmpMapping.length;rep++){
86
87                       iasCmpMapping=allIasCmpMapping[rep];
88
89                       //test logic
90
entityMapping=iasCmpMapping.getEntityMapping();
91
92                       if(entityMapping == null || entityMapping.length==0){//this should never happen
93
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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{fieldName,forPmConfig,descriptor.getName()}));
147
148                               }
149                               ///check level
150
boolean validLevel=true;
151                               int level;
152
153                               if(fetchedWith !=null ){ //since optional field
154
try{
155                                         level=fetchedWith.getLevel();
156                                         strlevel=level+strlevel;
157                                         if(!(level >0 && level < Integer.MAX_VALUE))
158                                         validLevel=false;
159                                   } catch(NumberFormatException JavaDoc exception){
160                                         validLevel=false;
161
162                                   }catch(RuntimeException JavaDoc re){
163                                         //ignore
164
}
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 JavaDoc[]{strlevel,forPmConfig,descriptor.getName()}));
174
175                               }
176                               //end of level chk
177
}//end for(int rep1=0;rep<entityMapping.length;rep1++){
178

179                       }
180
181                 }
182
183
184             //}4715917
185

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 JavaDoc[] {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 JavaDoc name){
210         boolean valid=false;
211         if(name !=null && !name.trim().equals("")){
212             //may also check, if the field is present in the specified ejb //to-do-vkv#
213
valid =true;
214         }
215         return valid;
216     }
217
218     boolean validateColumnName(String JavaDoc[] 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