KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

65         SunCmpMapping[] allIasCmpMapping=null;
66         SunCmpMapping iasCmpMapping=null;
67
68         /////test vars
69
EntityMapping[] entityMapping=null;
70
71         String JavaDoc tableName=null;
72         ColumnPair[] columnPair=null;
73         //FetchedWith fetchedWith=null;
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                             SecondaryTable[] secTable=null;
110                             secTable=entityMapping[rep1].getSecondaryTable();
111                             String JavaDoc forEjb=entityMapping[rep1].getEjbName();
112
113                           //since cmrmapping can be (0..n)
114
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 JavaDoc[]{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                               //fetchedWith =cmrFieldMapping[rep11].getFetchedWith();
130

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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{tableName,forPmConfig,descriptor.getName()}));
164
165                               }
166
167                           }//end for(int rep1=0;rep<entityMapping.length;rep1++){
168

169                       }
170
171                 }
172
173
174             //} 4715917 irfan
175

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 JavaDoc[] {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 JavaDoc 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 JavaDoc forPmConfig,String JavaDoc descriptorName){
208         boolean valid=true;
209
210         String JavaDoc[] colPair=null;
211         String JavaDoc col1=null;
212         String JavaDoc 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 JavaDoc[]{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 JavaDoc[]{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 JavaDoc[]{col1,col2,forPmConfig,descriptorName}));
255
256                 }
257
258             }
259
260
261         }
262         return valid;
263     }
264 }
265
266
Popular Tags