1 25 26 package org.objectweb.jonas.stests.util; 27 28 import java.util.Properties ; 29 import javax.naming.Context ; 30 import javax.naming.InitialContext ; 31 import javax.naming.NamingException ; 32 import javax.rmi.PortableRemoteObject ; 33 import javax.transaction.UserTransaction ; 34 import junit.framework.TestCase; 35 import org.objectweb.jonas.adm.AdmInterface; 36 37 41 public abstract class JTestCase extends TestCase { 42 protected static String jonasName = "jonas"; protected static String testtorun = null; 44 protected static Context ictx = null; 45 public static UserTransaction utx = null; private static AdmInterface admI = null; 47 48 public JTestCase(String name) { 49 super(name); 50 } 51 52 private Context getInitialContext() throws NamingException { 53 54 String registryPort = System.getProperty("jonas.registryport"); 55 Context ctx = null; 56 57 if (registryPort != null) { 58 Properties prop = new Properties (); 60 prop.put("java.naming.factory.initial", "com.sun.jndi.rmi.registry.RegistryContextFactory"); 61 prop.put("java.naming.provider.url", "rmi://localhost:" + registryPort); 62 ctx = new InitialContext (prop); 63 } else { 64 ctx = new InitialContext (); 65 } 66 return ctx; 67 } 68 69 72 protected void setUp() throws Exception { 73 if (ictx == null) { 75 ictx = getInitialContext(); 76 } 77 78 if (utx == null) { 80 utx = (UserTransaction ) PortableRemoteObject.narrow(ictx.lookup("javax.transaction.UserTransaction"), UserTransaction .class); 81 } 82 } 83 84 87 public void useBeans(String filename) { 88 89 try { 90 if (ictx == null) { 92 ictx = getInitialContext(); 93 } 94 if (admI == null) { 95 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 96 } 97 if (! admI.isLoaded(filename + ".jar")) { 98 admI.addBeans(filename + ".jar"); 99 } 100 } catch (Exception e) { 101 System.err.println("Cannot load bean: " + e); 102 } 103 } 104 105 109 public static void stopTxAt(int tt) { 110 try { 111 if (admI == null) { 112 admI = (AdmInterface) PortableRemoteObject.narrow(ictx.lookup(jonasName + "_Adm"), AdmInterface.class); 113 } 114 admI.setTransactionTimeout(tt); 115 } catch (Exception e) { 116 System.err.println("Cannot set transaction timeout: " + e); 117 } 118 } 119 120 123 public static void debug(String msg) { 124 } 126 127 130 public void sleep(int msec) { 131 try { 132 Thread.sleep(msec); 133 } catch (InterruptedException e) { 134 fail(e.toString()); 135 } 136 } 137 138 public void testEmpty() throws Exception { 139 } 140 } 141 | Popular Tags |