1 25 26 29 package org.objectweb.jonas.jtests.beans.remoterunner; 30 31 import java.io.ByteArrayOutputStream ; 32 import java.io.PrintStream ; 33 import java.lang.reflect.Constructor ; 34 import java.lang.reflect.Method ; 35 import java.rmi.RemoteException ; 36 37 import javax.ejb.CreateException ; 38 import javax.ejb.SessionBean ; 39 import javax.ejb.SessionContext ; 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 51 52 public class RemoteRunnerSL implements SessionBean { 53 54 static private Logger logger = null; 55 SessionContext ejbContext; 56 57 58 62 73 public void setSessionContext(SessionContext 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 89 public void ejbRemove() { 90 logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbRemove"); 91 } 92 93 98 public void ejbCreate() throws CreateException { 99 logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbCreate"); 100 } 101 102 106 public void ejbPassivate() { 107 logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbPassivate"); 108 } 109 110 115 public void ejbActivate() { 116 logger.log(BasicLevel.DEBUG, "RemoteRunnerSL ejbActivate"); 117 } 118 119 123 131 132 public String run(Class jtcc) throws RemoteException { 133 logger.log(BasicLevel.DEBUG, "RemoteRunnerSL run"); 134 try{ 135 Test ts = null; 136 Method method = jtcc.getMethod("suite", null); 137 ts = (Test)method.invoke(null, null); 138 ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 139 PrintStream ps = new java.io.PrintStream (baos); 140 TestRunner tr = new TestRunner(ps); 141 tr.doRun(ts , false); 142 return baos.toString(); 143 }catch( Exception e){ 144 throw new RemoteException (e.toString()); 145 } 146 147 } 148 149 158 public String run(Class jtcc, String testtorun) throws RemoteException { 159 logger.log(BasicLevel.DEBUG, "RemoteRunnerSL run: "+testtorun); 160 try{ 161 Object suiteInstance = null; 162 int nbParams = 1; 163 Class paramTypes[] = new Class [nbParams]; Object paramObjects[] = new Object [nbParams]; paramTypes[0] = java.lang.String .class; 166 paramObjects[0] = (Object )testtorun; 167 Constructor constructor = jtcc.getConstructor(paramTypes); 168 suiteInstance = constructor.newInstance(paramObjects); 169 ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 170 PrintStream ps = new java.io.PrintStream (baos); 171 TestRunner tr = new TestRunner(ps); 172 tr.doRun((Test)suiteInstance , false); 173 return baos.toString(); 174 }catch( Exception e){ 175 throw new RemoteException (e.toString()); 176 } 177 178 } 179 180 181 } 182 | Popular Tags |