KickJava   Java API By Example, From Geeks To Geeks.

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


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 ASEntityMappingTest extends EjbTest implements EjbCheck {
46
47     public Result check(EjbDescriptor descriptor)
48     {
49     Result result = getInitializedResult();
50     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
51         boolean oneFailed = false;
52         boolean notApp = false;
53
54         //<addition author="irfan@sun.com" [bug/rfe]-id="4715917" >
55
/*Set keys = descriptor.getEjbBundleDescriptor().getIasCmpMappingsKeys();
56
57         SunCmpMappings iasCmpMappings=null;
58         String forPmConfig=null;*/

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

63         SunCmpMapping[] allIasCmpMapping=null;
64         SunCmpMapping iasCmpMapping=null;
65
66         /////test vars
67
EntityMapping[] entityMapping=null;
68         String JavaDoc ejbName=null;
69         String JavaDoc tableName=null;
70
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
106                             ejbName=entityMapping[rep1].getEjbName();
107                             tableName=entityMapping[rep1].getTableName();
108
109                             if(validateEjbName(ejbName,descriptor)){
110
111                             result.passed(smh.getLocalString(getClass().getName()+".passed",
112                                 "PASSED [AS-CMP-MAPPING] : entity-mapping->ejb-name [{0} ] is a valid entry, in the mapping file [ {1}], "+
113                                 "of the ejb archive [ {2} ]. ",
114                                 new Object JavaDoc[]{ejbName,forPmConfig,descriptor.getName()}));
115
116                             }else{
117                             oneFailed = true;
118
119                             result.failed(smh.getLocalString(getClass().getName()+".failed1",
120                                 "FAILED [AS-CMP-MAPPING] : entity-mapping->ejb-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+
121                                 "of the ejb archive [ {2} ]. "+
122                                 "Either null/empty or the ejb-name is not present in corresponding ejb-jar.xml.",
123                                 new Object JavaDoc[]{ejbName,forPmConfig,descriptor.getName()}));
124
125                             }
126
127                             if(validateTableName(tableName)){
128
129                             result.passed(smh.getLocalString(getClass().getName()+".passed1",
130                                 "PASSED [AS-CMP-MAPPING] : entity-mapping->table-name [{0} ] is a valid entry, in the mapping file [ {1}], "+
131                                 "of the ejb archive [ {2} ]. ",
132                                 new Object JavaDoc[]{tableName,forPmConfig,descriptor.getName()}));
133
134                             }else{
135                             oneFailed = true;
136
137                             result.failed(smh.getLocalString(getClass().getName()+".failed2",
138                                 "FAILED [AS-CMP-MAPPING] : entity-mapping->table-name [{0} ] is NOT a valid entry, in the mapping file [ {1}], "+
139                                 "of the ejb archive [ {2} ]. "+
140                                 "Either null or empty.",
141                                 new Object JavaDoc[]{tableName,forPmConfig,descriptor.getName()}));
142
143                             }
144
145                       }
146
147                 }
148
149
150             //} 4715917 irfan
151

152         }
153         else
154         {
155             notApp = true;
156             result.notApplicable(smh.getLocalString
157                                  (getClass().getName() + ".notApplicable",
158                                   "NOT APPLICABLE [AS-CMP-MAPPING] : There is no ias-cmp-mappings file present, within the ejb archive [ {0} ].",
159                                   new Object JavaDoc[] {descriptor.getName()}));
160
161         }
162
163         if (oneFailed) {
164             result.setStatus(Result.FAILED);
165         } else if(notApp) {
166             result.setStatus(Result.NOT_APPLICABLE);
167         }else {
168             result.setStatus(Result.PASSED);
169         }
170
171
172         return result;
173     }
174
175     boolean validateEjbName(String JavaDoc name,EjbDescriptor descriptor){
176         boolean valid=false;
177         if(name !=null && !name.trim().equals("")){
178             //check if the ejb name exist in ejb-jar.xml
179
for (Iterator itr =descriptor.getEjbBundleDescriptor().getEjbs().iterator();
180          itr.hasNext();) {
181                   EjbDescriptor ejbDescriptor = (EjbDescriptor) itr.next();
182                       if (ejbDescriptor.getName().equals(name)) {
183                         valid =true;
184                         break;
185                       }
186              }
187         }
188         return valid;
189     }
190
191     boolean validateTableName(String JavaDoc name){
192         boolean valid=false;
193         if(name !=null && !name.trim().equals("")){
194             valid =true;
195         }
196         return valid;
197     }
198 }
199
200
201
202
203
Popular Tags