KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > webservices > EJBServiceImplBeanChk


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

24 package com.sun.enterprise.tools.verifier.tests.webservices;
25
26 import com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import java.util.*;
29 import java.lang.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /*
33  * @class.setup_props: ;
34  */

35
36 /*
37  * @testName: check
38  * @assertion_ids: JSR109_WS_4; JSR109_WS_5; JSR109_WS_6; JSR109_WS_7;
39  * JSR109_WS_8; JSR109_WS_9; JSR109_WS_47;
40  * @test_Strategy:
41  * @class.testArgs: Additional arguments (if any) to be passed when execing the client
42  * @testDescription:
43  * The Service Implementation Bean (SLSB) must have a default public constructor.
44  *
45  * The Service Implementation Bean may implement the Service Endpoint
46  * Interface, but it is not required to do so. The bean must implement all the method
47  * signatures of the SEI. The Service Implementation Bean methods are not required to throw
48  * javax.rmi.RemoteException. The business methods of the bean must be public and must not
49  * be final or static. It may implement other methods in addition to those defined by the SEI.
50  *
51  * The Service Implementation Bean (SLSB) class must be public, must not be final and must
52  * not be abstract.
53  *
54  * The Service Implementation Bean (SLSB)class must not define the finalize() method.
55  *
56  * Currently, Service Implementation Bean (SLSB) must implement the ejbCreate() and
57  * ejbRemove() methods which take no arguments. This is a requirement of the EJB container,
58  * but generally can be stubbed out with an empty implementations.
59  *
60  * The Stateless Session Bean must implement the javax.ejb.SessionBean interface either
61  * directly or indirectly.
62  *
63  * All the exceptions defined in the throws clause of the matching method of the session bean
64  * class must be defined in the throws clause of the method of the web service endpoint
65  * interface.
66  */

67 public class EJBServiceImplBeanChk extends WSTest implements WSCheck {
68
69     /**
70      * @param wsdescriptor the WebService deployment descriptor
71      * @return <code>Result</code> the results for this assertion
72      */

73     public Result check (WebServiceEndpoint wsdescriptor) {
74    
75       Result result = getInitializedResult();
76       ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
77
78      EjbDescriptor descriptor = wsdescriptor.getEjbComponentImpl();
79
80       if (descriptor != null) {
81
82           // get hold of the ServiceImplBean Class
83
String JavaDoc beanClass = descriptor.getEjbClassName();
84           // since non-empty ness is enforced by schema, this is an internal error
85
if ((beanClass == null) || ((beanClass != null) && (beanClass.length() == 0))) {
86             // internal error
87
result.addErrorDetails(smh.getLocalString
88                ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
89                 "Error: Unexpected error occurred [ {0} ]",
90                 new Object JavaDoc[] {"Service Implementation Bean Class Name Null"}));
91           }
92           Class JavaDoc<?> bean = null;
93         
94           try {
95             bean = Class.forName(beanClass, false, getVerifierContext().getClassLoader());
96           } catch (ClassNotFoundException JavaDoc e) {
97             result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
98                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
99             result.failed(smh.getLocalString
100                 (getClass().getName() + ".failed",
101                 "The [{0}] Class [{1}] could not be Loaded",new Object JavaDoc[] {"Service Impl Bean", beanClass}));
102           }
103         
104           // get hold of the SEI Class
105
String JavaDoc s = descriptor.getWebServiceEndpointInterfaceName();
106
107           if ((s == null) || (s.length() == 0)){
108                // internal error, should never happen
109
result.addErrorDetails(smh.getLocalString
110                ("com.sun.enterprise.tools.verifier.tests.webservices.Error",
111                 "Error: Unexpected error occurred [ {0} ]",
112                 new Object JavaDoc[] {"Service Endpoint Interface Class Name Null"}));
113           }
114
115           Class JavaDoc<?> sei = null;
116
117           try {
118                sei = Class.forName(s, false, getVerifierContext().getClassLoader());
119           }catch(ClassNotFoundException JavaDoc e) {
120             result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
121                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
122             result.failed(smh.getLocalString
123                 (getClass().getName() + ".failed",
124                 "The [{0}] Class [{1}] could not be Loaded",new Object JavaDoc[] {"SEI", s}));
125
126           }
127
128           // it should be a stateless session bean
129
boolean isSLSB = (javax.ejb.SessionBean JavaDoc.class).isAssignableFrom(bean);
130           boolean implementsSEI = sei.isAssignableFrom(bean);
131
132           if (!isSLSB) {
133             //result.fail does not implement javax.ejb.SessionBean interface
134
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
135                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
136             result.failed(smh.getLocalString
137               ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
138               new Object JavaDoc[] {"The Service Implementation Bean Does not Implement SessionBean Interface"}));
139           }
140           else {
141             // result.passed
142
result.addGoodDetails(smh.getLocalString ("tests.componentNameConstructor",
143                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
144              result.passed(smh.getLocalString (
145                           "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
146                            new Object JavaDoc[] {"The Service Impl Bean implements SessionBean Interface"}));
147           }
148
149           EndPointImplBeanClassChecker checker = new EndPointImplBeanClassChecker(sei,bean,result,getVerifierContext().getSchemaVersion());
150
151           if (implementsSEI) {
152             // result.passed
153
result.addGoodDetails(smh.getLocalString
154                                   ("tests.componentNameConstructor",
155                                    "For [ {0} ]",
156                                    new Object JavaDoc[] {compName.toString()}));
157              result.passed(smh.getLocalString (
158                           "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
159                            new Object JavaDoc[] {"The Service Impl Bean implements SEI"}));
160           }
161           else {
162          
163              // business methods of the bean should be public, not final and not static
164
// This check will happen as part of this call
165
Vector notImpl = checker.getSEIMethodsNotImplemented();
166              if (notImpl.size() > 0) {
167                // result.fail, Set the not implemented methods into the result info??
168
result.addErrorDetails(smh.getLocalString ("tests.componentNameConstructor",
169                                    "For [ {0} ]", new Object JavaDoc[] {compName.toString()}));
170                result.failed(smh.getLocalString
171                  ("com.sun.enterprise.tools.verifier.tests.webservices.failed", "[{0}]",
172                  new Object JavaDoc[] {"The Service Implementation Bean Does not Implement ALL SEI Methods"}));
173              }
174              else {
175                // result.pass :All SEI methods implemented
176
result.addGoodDetails(smh.getLocalString
177                                   ("tests.componentNameConstructor",
178                                    "For [ {0} ]",
179                                    new Object JavaDoc[] {compName.toString()}));
180              result.passed(smh.getLocalString (
181                           "com.sun.enterprise.tools.verifier.tests.webservices.passed", "[{0}]",
182                            new Object JavaDoc[] {"The Service Impl Bean implements all Methods of the SEI"}));
183              }
184           }
185
186           // class should be public, not final and not abstract
187
// should not define finalize()
188
if (checker.check(compName)) {
189               // result.passed stuff done inside the check() method nothing todo here
190
result.setStatus(Result.PASSED);
191           }
192           else {
193               // result.fail : stuff done inside the check() method nothing todo here
194
result.setStatus(Result.FAILED);
195           }
196
197       }
198       else {
199          // result.notapplicable
200
result.addNaDetails(smh.getLocalString
201                      ("tests.componentNameConstructor", "For [ {0} ]",
202                       new Object JavaDoc[] {compName.toString()}));
203          result.notApplicable(smh.getLocalString
204                  ("com.sun.enterprise.tools.verifier.tests.webservices.notapp",
205                  "[{0}]", new Object JavaDoc[] {"Not Applicable since this is a JAX-RPC Service Endpoint"}));
206
207       }
208        return result;
209     }
210  }
211
212
Popular Tags