KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.tools.verifier.tests.webservices;
24
25 import com.sun.enterprise.deployment.*;
26 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
27 import com.sun.enterprise.tools.verifier.Result;
28 import com.sun.enterprise.tools.verifier.Verifier;
29
30 import java.lang.reflect.Method JavaDoc;
31
32 /*
33  * @class.setup_props: ;
34  */

35
36 /*
37  * @testName: check
38  * @assertion_ids: JSR109_WS_05;
39  * @test_Strategy:
40  * @class.testArgs:
41  * @testDescription: Service Implementation Bean(SLSB) must implement the ejbRemove() method which take no
42  * arguments.
43  *
44  * This is a requirement of the EJB container,but generally can be stubbed out with an empty implementations
45  */

46
47 public class EjbRemoveMethodNameExistInSLSB extends WSTest implements WSCheck {
48
49     /**
50      * @param descriptor the WebServices descriptor
51      * @return <code>Result</code> the results for this assertion
52      */

53     public Result check (WebServiceEndpoint wsdescriptor) {
54
55     Result result = getInitializedResult();
56     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
57     boolean foundFailure=false;
58         if (wsdescriptor.implementedByEjbComponent()) {
59             EjbDescriptor ejbdesc = wsdescriptor.getEjbComponentImpl();
60             if (ejbdesc != null && (ejbdesc instanceof EjbSessionDescriptor)) {
61                 EjbSessionDescriptor descriptor = (EjbSessionDescriptor)ejbdesc;
62                 if (EjbSessionDescriptor.STATELESS.equals(descriptor.getSessionType())) {
63                     try {
64                         //Context context = getVerifierContext();
65
ClassLoader JavaDoc jcl = getVerifierContext().getClassLoader();
66                         Class JavaDoc c = Class.forName(descriptor.getEjbClassName(), false, getVerifierContext().getClassLoader());
67                         int foundAtLeastOne = 0;
68
69                         do {
70                             Method JavaDoc [] methods = c.getDeclaredMethods();
71                             for (int i = 0; i < methods.length; i++) {
72                                 // The method name must be ejbRemove.
73
if (methods[i].getName().startsWith("ejbRemove")) {
74                                     foundAtLeastOne++;
75                                     result.addGoodDetails(smh.getLocalString
76                                             ("tests.componentNameConstructor",
77                                                     "For [ {0} ]",
78                                                     new Object JavaDoc[] {compName.toString()}));
79                                     result.addGoodDetails(smh.getLocalString
80                                             (getClass().getName() + ".passed",
81                                                     "[ {0} ] declares [ {1} ] method.",
82                                                     new Object JavaDoc[] {descriptor.getEjbClassName(),methods[i].getName()}));
83                                 }
84                             }
85                         } while (((c = c.getSuperclass()) != null) && (foundAtLeastOne == 0));
86                         if (foundAtLeastOne == 0){
87                             foundFailure = true;
88                             result.addErrorDetails(smh.getLocalString
89                                     ("tests.componentNameConstructor",
90                                             "For [ {0} ]",
91                                             new Object JavaDoc[] {compName.toString()}));
92                             result.failed(smh.getLocalString
93                                     (getClass().getName() + ".failed",
94                                             "Error: [ {0} ] does not properly declare at least one ejbRemove() method. [ {1} ] is not a valid bean.",
95                                             new Object JavaDoc[] {descriptor.getEjbClassName(),descriptor.getEjbClassName()}));
96                         }
97                     } catch (ClassNotFoundException JavaDoc e) {
98                         Verifier.debug(e);
99                         result.addErrorDetails(smh.getLocalString
100                                 ("tests.componentNameConstructor",
101                                         "For [ {0} ]",
102                                         new Object JavaDoc[] {compName.toString()}));
103                         result.failed(smh.getLocalString
104                                 (getClass().getName() + ".failedException",
105                                         "Error: [ {0} ] class not found.",
106                                         new Object JavaDoc[] {descriptor.getEjbClassName()}));
107                         return result;
108                     }
109                 } else {
110                     result.addNaDetails(smh.getLocalString
111                             ("tests.componentNameConstructor", "For [ {0} ]",
112                                     new Object JavaDoc[] {compName.toString()}));
113                     result.notApplicable(smh.getLocalString
114                             (getClass().getName() + ".notApplicable",
115                                     "NOT APPLICABLE :Service Implementation bean is not a stateless Session Bean"));
116                     return result;
117                 }
118             } else {
119                 result.addNaDetails(smh.getLocalString
120                         ("tests.componentNameConstructor",
121                                 "For [ {0} ]",
122                                 new Object JavaDoc[] {compName.toString()}));
123                 result.notApplicable(smh.getLocalString
124                         (getClass().getName() + ".notApplicable1",
125                                 "NOT APPLICABLE:Service Implementation bean is null or not a session bean descriptor "));
126                 return result;
127             }
128
129             if (foundFailure) {
130                 result.setStatus(result.FAILED);
131             } else {
132                 result.setStatus(result.PASSED);
133             }
134             return result;
135
136         } else {
137             result.addNaDetails(smh.getLocalString
138                     ("tests.componentNameConstructor",
139                             "For [ {0} ]",
140                             new Object JavaDoc[] {compName.toString()}));
141             result.notApplicable(smh.getLocalString
142                     (getClass().getName() + ".notApplicable2",
143                             "Not Applicable: Service Implementation bean is not implemented by Ejb."));
144             return result;
145         }
146     }
147 }
148
Popular Tags