KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > entity > createmethod > HomeInterfaceCreateMethodExceptionRemote


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.ejb.entity.createmethod;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.deployment.EjbDescriptor;
27 import com.sun.enterprise.deployment.EjbEntityDescriptor;
28 import java.lang.ClassLoader JavaDoc;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 import java.util.logging.Level JavaDoc;
31 import java.lang.reflect.*;
32 import com.sun.enterprise.tools.verifier.*;
33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
34 import com.sun.enterprise.tools.verifier.tests.ejb.EjbUtils;
35
36 /**
37  * create<Method> method tests
38  * Entity beans home interface create method throws RemoteException test.
39  *
40  * The following are the requirements for the enterprise Bean's home interface
41  * signature:
42  *
43  * An Entity Bean's home interface defines zero or more create(...) methods.
44  *
45  * The throws clause must include java.rmi.RemoteException.
46  */

47 public class HomeInterfaceCreateMethodExceptionRemote extends EjbTest implements EjbCheck {
48
49     /**
50      * Entity beans home interface create method throws RemoteException test.
51      *
52      * The following are the requirements for the enterprise Bean's home interface
53      * signature:
54      *
55      * An Entity Bean's home interface defines zero or more create(...) methods.
56      *
57      * The throws clause must include java.rmi.RemoteException.
58      *
59      * @param descriptor the Enterprise Java Bean deployment descriptor
60      *
61      * @return <code>Result</code> the results for this assertion
62      */

63     public Result check(EjbDescriptor descriptor) {
64
65     Result result = getInitializedResult();
66     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
67
68     if (descriptor instanceof EjbEntityDescriptor) {
69         boolean oneFailed = false;
70         boolean foundAtLeastOneRemote = false;
71         // RULE: Entity home interface are only allowed to have create
72
// methods which must throw java.rmi.RemoteException
73
if(descriptor.getHomeClassName() == null || "".equals(descriptor.getHomeClassName())) {
74         result.addNaDetails(smh.getLocalString
75                           ("tests.componentNameConstructor",
76                            "For [ {0} ]",
77                            new Object JavaDoc[] {compName.toString()}));
78         result.addNaDetails(smh.getLocalString
79                        (getClass().getName() + ".debug3",
80                     "No Remote Home Interface for this ejb",
81                     new Object JavaDoc[] {}));
82         return result;
83         }
84         try {
85         Class JavaDoc c = Class.forName(descriptor.getHomeClassName(), false, getVerifierContext().getClassLoader());
86         Method methods[] = c.getDeclaredMethods();
87         Class JavaDoc [] methodExceptionTypes;
88         boolean throwsRemoteException = false;
89
90         for (int i=0; i< methods.length; i++) {
91             // clear these from last time thru loop
92
throwsRemoteException = false;
93             if (methods[i].getName().startsWith("create")) {
94             // set this once to indicate that test is applicable, if you didn't
95
// find any create methods, that's okay too, as entity beans can
96
// have zero or more create methods, & when you have zero, test
97
// is N/A
98
if (!foundAtLeastOneRemote) {
99                 foundAtLeastOneRemote = true;
100             }
101
102             methodExceptionTypes = methods[i].getExceptionTypes();
103                
104             // methods must also throw java.rmi.RemoteException
105
if (EjbUtils.isValidRemoteException(methodExceptionTypes)) {
106                 throwsRemoteException = true;
107             }
108
109             //report for this particular create method found in home interface
110
// now display the appropriate results for this particular create
111
// method
112
logger.log(Level.FINE, " Interface " + c.getName() + " method " + methods[i].getName());
113             if (throwsRemoteException ) {
114                 result.addGoodDetails(smh.getLocalString
115                           ("tests.componentNameConstructor",
116                            "For [ {0} ]",
117                            new Object JavaDoc[] {compName.toString()}));
118                 result.addGoodDetails(smh.getLocalString
119                           (getClass().getName() + ".debug1",
120                            "For Home Interface [ {0} ] Method [ {1} ]",
121                            new Object JavaDoc[] {c.getName(),methods[i].getName()}));
122                 result.addGoodDetails(smh.getLocalString
123                           (getClass().getName() + ".passed",
124                            "The create method which must throw java.rmi.RemoteException was found."));
125             } else if (!throwsRemoteException) {
126                 oneFailed = true;
127                 result.addErrorDetails(smh.getLocalString
128                            (getClass().getName() + ".debug1",
129                             "For Home Interface [ {0} ] Method [ {1} ]",
130                             new Object JavaDoc[] {c.getName(),methods[i].getName()}));
131                 result.addErrorDetails(smh.getLocalString
132                            (getClass().getName() + ".failed",
133                             "Error: A create method was found, but did not throw java.rmi.RemoteException." ));
134             } // end of reporting for this particular 'create' method
135
} // if the home interface found a "create" method
136
} // for all the methods within the home interface class, loop
137

138
139         } catch (ClassNotFoundException JavaDoc e) {
140         Verifier.debug(e);
141         result.addErrorDetails(smh.getLocalString
142                        ("tests.componentNameConstructor",
143                     "For [ {0} ]",
144                     new Object JavaDoc[] {compName.toString()}));
145         result.failed(smh.getLocalString
146                   (getClass().getName() + ".failedException",
147                    "Error: Home interface [ {0} ] does not exist or is not loadable within bean [ {1} ]",
148                    new Object JavaDoc[] {descriptor.getHomeClassName(), descriptor.getName()}));
149         }
150
151         if (!foundAtLeastOneRemote) {
152         result.addGoodDetails(smh.getLocalString
153                           ("tests.componentNameConstructor",
154                            "For [ {0} ]",
155                            new Object JavaDoc[] {compName.toString()}));
156         result.addGoodDetails(smh.getLocalString
157                       (getClass().getName() + ".debug3",
158                        "For Home Interface [ {0} ]",
159                        new Object JavaDoc[] {descriptor.getHomeClassName()}));
160         result.addGoodDetails(smh.getLocalString
161                       (getClass().getName() + ".notApplicable1",
162                        "No create method was found, test not applicable." ));
163         result.setStatus(result.PASSED);
164         } else {
165         if (oneFailed) {
166             result.setStatus(result.FAILED);
167         } else {
168             result.setStatus(result.PASSED);
169         }
170         }
171          
172         return result;
173         
174     } else {
175         result.addNaDetails(smh.getLocalString
176                           ("tests.componentNameConstructor",
177                            "For [ {0} ]",
178                            new Object JavaDoc[] {compName.toString()}));
179         result.notApplicable(smh.getLocalString
180                  (getClass().getName() + ".notApplicable",
181                   "[ {0} ] expected {1} bean, but called with {2} bean.",
182                   new Object JavaDoc[] {getClass(),"Entity","Session"}));
183         return result;
184     }
185     }
186 }
187
Popular Tags