KickJava   Java API By Example, From Geeks To Geeks.

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


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

25
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
27 import java.util.*;
28 import com.sun.enterprise.deployment.*;
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.ejb.Cmp;
38 import com.sun.enterprise.tools.common.dd.ejb.Finder;
39 import com.sun.enterprise.tools.common.dd.ejb.OneOneFinders;
40 import java.io.*;
41 import java.util.jar.*;
42 import java.util.zip.*;
43
44 /** ejb [0,n]
45  * cmp ?
46  * mapping-properties ? [String]
47  * is-one-one-cmp ? [String]
48  * one-one-finders ?
49  * finder [1,n]
50  * method-name [String]
51  * query-params ? [String]
52  * query-filter ? [String]
53  * query-variables ? [String]
54  *
55  * The cmp element describes the runtime information for a CMP enitity bean.
56  * mapping-properties - The vendor specific O/R mapping file
57  * is-one-one-cmp - boolean field used to identify CMP 1.1 descriptors
58  * one-one-finders - The finders for CMP 1.1
59  *
60  * @author Irfan Ahmed
61  */

62 public class ASEjbCMP extends EjbTest implements EjbCheck {
63
64     public boolean oneFailed = false;
65     public boolean oneWarning = false;
66     public Result check(EjbDescriptor descriptor)
67     {
68         Result result = getInitializedResult();
69         ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
70
71         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
72         Ejb testCase = null;
73         if(ejbJar!=null)
74         {
75             testCase = super.getEjb(descriptor.getName(),ejbJar);
76             Cmp cmpBean = testCase.getCmp();
77             if(cmpBean != null)
78             {
79                 //mapping-properties
80
String JavaDoc mappingProps = cmpBean.getMappingProperties();
81                 if(mappingProps == null)
82                 {
83                     oneWarning = true;
84                     result.warning(smh.getLocalString(getClass().getName()+".warning",
85                         "WARNING [AS-EJB cmp] : mapping-properties Element is not defined"));
86                 }
87                 else
88                 {
89                     if(mappingProps.length()==0)
90                     {
91                         oneFailed = true;
92                         result.failed(smh.getLocalString(getClass().getName()+".failed",
93                             "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value"));
94                     }
95                     else//4690436
96
{ File f = Verifier.getJarFile(((EjbBundleArchivist) descriptor.getEjbBundleDescriptor().getArchivist()).getEjbJarFile().getName());
97                         JarFile jarFile = null;
98                         ZipEntry deploymentEntry=null;
99                         try {
100                               jarFile = new JarFile(f);
101                               if(jarFile!=null)
102                               deploymentEntry = jarFile.getEntry(mappingProps);
103                               
104
105                         }
106                         catch(IOException e){}
107                         finally{
108                            try{ if(jarFile!=null) jarFile.close();}
109                            catch(IOException e){}
110                         }
111
112                         if(deploymentEntry !=null){
113                         result.passed(smh.getLocalString(getClass().getName()+".passed",
114                             "PASSED [AS-EJB cmp] : mapping-properties file is {0}",
115                             new Object JavaDoc[]{mappingProps}));
116                         }
117                         else{
118                         //invalid entry
119
result.failed(smh.getLocalString(getClass().getName()+".failed",
120                             "FAILED [AS-EJB cmp] : mapping-properties field must contain a vaild non-empty value"));
121
122
123                         }
124                     }
125                 }
126
127                 //is-one-one-cmp
128
String JavaDoc isOneOne = cmpBean.getIsOneOneCmp();
129                 if(isOneOne == null)
130                 {
131                     oneWarning = true;
132                     result.warning(smh.getLocalString(getClass().getName()+".warning1",
133                         "WARNING [AS-EJB cmp] : is-one-one-cmp Element is not defined"));
134                 }
135                 else
136                 {
137                     if(isOneOne.length()==0)
138                     {
139                         oneFailed = true;
140                         result.failed(smh.getLocalString(getClass().getName()+".failed1",
141                             "FAILED [AS-EJB cmp] : is-one-one-cmp cannot be an empty string. It can be either true or false"));
142                     }
143                     else
144                     {
145                         if(!isOneOne.equals("true") && !isOneOne.equals("false"))
146                         {
147                             oneFailed = true;
148                             result.failed(smh.getLocalString(getClass().getName()+".failed2",
149                                 "FAILED [AS-EJB cmp] : is-one-one-cmp cannot be {0}. It can either be true or false",
150                                 new Object JavaDoc[]{isOneOne}));
151                         }
152                         else
153                         {
154                             result.passed(smh.getLocalString(getClass().getName()+".passed1",
155                                 "PASSED [AS-EJB cmp] : is-one-one-cmp is {0}",
156                                 new Object JavaDoc[]{isOneOne}));
157                         }
158                     }
159                 }
160
161                 //one-one-finders
162
OneOneFinders finders = cmpBean.getOneOneFinders();
163                 if(finders!=null)
164                 {
165                     testFinders(finders,result);
166                 }
167                 else
168                 {
169                     oneWarning = true;
170                     result.warning(smh.getLocalString(getClass().getName()+".warning2",
171                         "WARNING [AS-EJB cmp] : one-one-finders Element is not defined"));
172                 }
173
174                 if(oneFailed)
175                     result.setStatus(Result.FAILED);
176                 else if(oneWarning)
177                     result.setStatus(Result.WARNING);
178             }
179             else
180                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
181                     "NOT APPLICABLE [AS-EJB cmp] : {0} is not a CMP Entity Bean.",
182                     new Object JavaDoc[] {testCase.getEjbName()}));
183         }
184         else
185         {
186             result.failed(smh.getLocalString(getClass().getName()+".notRun",
187                 "NOT RUN [AS-EJB cmp] Could not create SunEjbJar Object."));
188         }
189         return result;
190     }
191
192     public void testFinders(OneOneFinders finders, Result result)
193     {
194         Finder finder[] = finders.getFinder();
195         for (int i=0;i<finder.length;i++)
196         {
197             //method-name
198
String JavaDoc methodName = finder[i].getMethodName();
199             if(methodName.length()==0)
200             {
201                 oneFailed = true;
202                 result.failed(smh.getLocalString(getClass().getName()+".failed3",
203                     "FAILED [AS-EJB finder] : method-name cannot be an empty string."));
204             }
205             else
206             {
207                 //TODO Should the method name exist in Home interfaces
208
result.passed(smh.getLocalString(getClass().getName()+".passed2",
209                     "PASSED [AS-EJB finder] : method-name is {0}",
210                     new Object JavaDoc[]{methodName}));
211             }
212
213             //query-params
214
String JavaDoc value = finder[i].getQueryParams();
215             testQuery(value,result,"finder","query-params");
216
217             //query-filter
218
value = finder[i].getQueryFilter();
219             testQuery(value,result,"finder","query-filter");
220
221             //query-variables
222
value = finder[i].getQueryVariables();
223             testQuery(value,result,"finder","query-variables");
224         }
225
226     }
227
228     public void testQuery(String JavaDoc value, Result result,String JavaDoc parent, String JavaDoc child)
229     {
230         if(value == null)
231         {
232             oneWarning = true;
233             result.warning(smh.getLocalString(getClass().getName()+".warning3",
234                 "WARNING [AS-EJB {0}] : {1} Element is not defined",
235                 new Object JavaDoc[]{parent,child}));
236         }
237         else
238         {
239             if(value.length()==0)
240             {
241                 oneFailed = true;
242                 result.failed(smh.getLocalString(getClass().getName()+".failed4",
243                     "FAILED [AS-EJB {0}] : {1} cannot be an empty string",
244                     new Object JavaDoc[]{parent,child}));
245             }
246             else
247             {
248                 result.passed(smh.getLocalString(getClass().getName()+".passed3",
249                     "PASSED [AS-EJB {0}] : {1} is/are {2}",
250                     new Object JavaDoc[]{parent, child, value}));
251             }
252         }
253     }
254 }
255
Popular Tags