KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > beans > remoterunner > RemoteRunnerSL


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: RemoteRunnerSL.java,v 1.4 2004/03/19 11:57:18 benoitf Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 // RemoteRunnerSL.java
27
// Stateless Session bean
28

29 package org.objectweb.jonas.jtests.beans.remoterunner;
30
31 import java.io.ByteArrayOutputStream JavaDoc;
32 import java.io.PrintStream JavaDoc;
33 import java.lang.reflect.Constructor JavaDoc;
34 import java.lang.reflect.Method JavaDoc;
35 import java.rmi.RemoteException JavaDoc;
36
37 import javax.ejb.CreateException JavaDoc;
38 import javax.ejb.SessionBean JavaDoc;
39 import javax.ejb.SessionContext JavaDoc;
40
41 import junit.framework.Test;
42 import junit.textui.TestRunner;
43
44 import org.objectweb.jonas.common.Log;
45 import org.objectweb.util.monolog.api.BasicLevel;
46 import org.objectweb.util.monolog.api.Logger;
47
48 /**
49  *
50  */

51
52 public class RemoteRunnerSL implements SessionBean JavaDoc {
53
54     static private Logger logger = null;
55     SessionContext JavaDoc ejbContext;
56  
57
58     // ------------------------------------------------------------------
59
// SessionBean implementation
60
// ------------------------------------------------------------------
61

62     /**
63      * Set the associated session context. The container calls this method
64      * after the instance creation.
65      * The enterprise Bean instance should store the reference to the context
66      * object in an instance variable.
67      * This method is called with no transaction context.
68      *
69      * @param sessionContext A SessionContext interface for the instance.
70      * @throws EJBException Thrown by the method to indicate a failure caused by
71      * a system-level error.
72      */

73     public void setSessionContext(SessionContext JavaDoc ctx) {
74         if (logger == null)
75             logger = Log.getLogger(Log.JONAS_TESTS_PREFIX);
76     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL setSessionContext");
77     ejbContext = ctx;
78     }
79     
80     /**
81      * A container invokes this method before it ends the life of the session object.
82      * This happens as a result of a client's invoking a remove operation, or when a
83      * container decides to terminate the session object after a timeout.
84      * This method is called with no transaction context.
85      *
86      * @throws EJBException Thrown by the method to indicate a failure caused by
87      * a system-level error.
88      */

89     public void ejbRemove() {
90     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbRemove");
91     }
92     
93     /**
94      * The Session bean must define 1 or more ejbCreate methods.
95      *
96      * @throws CreateException Failure to create a session EJB object.
97      */

98     public void ejbCreate() throws CreateException JavaDoc {
99     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbCreate");
100     }
101
102     /**
103      * A container invokes this method on an instance before the instance
104      * becomes disassociated with a specific EJB object.
105      */

106     public void ejbPassivate() {
107     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbPassivate");
108     }
109
110     /**
111      * A container invokes this method when the instance is taken out of
112      * the pool of available instances to become associated with a specific
113      * EJB object.
114      */

115     public void ejbActivate() {
116     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbActivate");
117     }
118     
119     // ------------------------------------------------------------------
120
// RemoteRunner implementation
121
// ------------------------------------------------------------------
122

123     /**
124      * Run a JUnit TestSuite
125      *
126      * @param jtcc the class of the JUnit TestSuite to be run
127      *
128      * The code run here is equivalent to :
129      * TestRunner.run( jtcc.suite())
130      */

131
132     public String JavaDoc run(Class JavaDoc jtcc) throws RemoteException JavaDoc {
133     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL run");
134     try{
135             Test ts = null;
136             Method JavaDoc method = jtcc.getMethod("suite", null);
137             ts = (Test)method.invoke(null, null);
138             ByteArrayOutputStream JavaDoc baos = new java.io.ByteArrayOutputStream JavaDoc();
139             PrintStream JavaDoc ps = new java.io.PrintStream JavaDoc(baos);
140             TestRunner tr = new TestRunner(ps);
141         tr.doRun(ts , false);
142         return baos.toString();
143     }catch( Exception JavaDoc e){
144         throw new RemoteException JavaDoc(e.toString());
145     }
146     
147     }
148
149   /**
150      * Run a TestCase in the JUnit TestSuite
151      *
152      * @param jtcc the class of the JUnit TestSuite to be run
153      * @param name name of the testcase to run
154      *
155      * This code run here is equivalent to do
156      * TestRunner.run(new jtcc(testtorun))
157      */

158     public String JavaDoc run(Class JavaDoc jtcc, String JavaDoc testtorun) throws RemoteException JavaDoc {
159     logger.log(BasicLevel.DEBUG, "RemoteRunnerSL run: "+testtorun);
160     try{
161             Object JavaDoc suiteInstance = null;
162             int nbParams = 1;
163             Class JavaDoc paramTypes[] = new Class JavaDoc[nbParams]; // constructor argument types
164
Object JavaDoc paramObjects[] = new Object JavaDoc[nbParams]; // constructor argument values
165
paramTypes[0] = java.lang.String JavaDoc.class;
166             paramObjects[0] = (Object JavaDoc)testtorun;
167             Constructor JavaDoc constructor = jtcc.getConstructor(paramTypes);
168             suiteInstance = constructor.newInstance(paramObjects);
169             ByteArrayOutputStream JavaDoc baos = new java.io.ByteArrayOutputStream JavaDoc();
170             PrintStream JavaDoc ps = new java.io.PrintStream JavaDoc(baos);
171             TestRunner tr = new TestRunner(ps);
172         tr.doRun((Test)suiteInstance , false);
173         return baos.toString();
174     }catch( Exception JavaDoc e){
175         throw new RemoteException JavaDoc(e.toString());
176     }
177     
178     }
179
180
181 }
182
Popular Tags