1 25 26 package org.objectweb.jonas.jtests.clients.jca15; 27 28 import junit.framework.*; 29 import java.io.BufferedReader ; 30 import java.io.FileInputStream ; 31 import java.io.InputStreamReader ; 32 import java.io.IOException ; 33 import java.lang.String ; 34 import java.rmi.RemoteException ; 35 import javax.rmi.PortableRemoteObject ; 36 import java.util.Collection ; 37 import java.util.Enumeration ; 38 import java.util.Hashtable ; 39 import java.util.Properties ; 40 import javax.ejb.FinderException ; 41 import javax.ejb.RemoveException ; 42 import javax.naming.Context ; 43 import javax.naming.InitialContext ; 44 import javax.naming.NamingException ; 45 import javax.transaction.UserTransaction ; 46 import javax.transaction.SystemException ; 47 48 import org.objectweb.jonas.jtests.beans.jca15.TransactedCA; 49 import org.objectweb.jonas.jtests.beans.jca15.TransactedCAHome; 50 import org.objectweb.jonas.jtests.beans.jca15.Utility; 51 import org.objectweb.jonas.jtests.util.JTestCase; 52 import org.objectweb.jonas.jtests.clients.jca15.F_securityTest; 53 54 57 58 public class F_xatransactionTest extends JTestCase { 59 60 static Context ctx = null; 61 62 64 protected static String BEAN_HOME = "TransactedCAHome"; 65 protected static TransactedCAHome home = null; 66 private static final String RAR_JNDI_NAME = "eis/ErsatzXATransaction"; 67 final public int CLOSE_HANDLE = 0; 68 final public int CLOSE_PHYSICAL = 1; 69 public int CloseType = 0; 70 static TransactedCA bean = null; 71 public String UseBeans="jca15"; 72 String err=""; 73 74 public F_xatransactionTest(String name) { 75 super(name); 76 } 77 78 protected void setUp() { 79 super.setUp(); 80 try { 81 83 if (ctx == null) { 84 err="InitialContext()"; 85 ctx = new InitialContext (); 86 } 87 if (utx == null) { 91 err="lookup(javax.transaction.UserTransaction)"; 92 utx = (UserTransaction ) ctx.lookup(Utility.USER_TRANSACTION); 93 } 94 if (home == null) { 95 useBeans(UseBeans, false); 96 } 97 getBean(); 98 assertTrue (6 == 6); 99 100 } catch (SystemException se1) { 101 String s="setUp error: Unable to "+err+" SystemException="+se1 ; 102 fail(s); 103 } catch (Exception e) { 104 fail("Cannot do setUp. Error on "+err+" Exception="+e); 105 } 106 } 107 private void getBean() throws Exception { 108 110 if (home == null) { 111 home = (TransactedCAHome)PortableRemoteObject.narrow( 112 ctx.lookup(BEAN_HOME), 113 TransactedCAHome.class); 114 bean = home.create(); 115 } 116 } 117 protected void tearDown() throws Exception { 118 } 120 protected void startUp(String testName) { 121 try { 122 bean.method1(RAR_JNDI_NAME, testName); 123 } catch (Exception ee) { 124 ee.printStackTrace(); 125 System.exit(2); 126 } 127 } 128 129 131 139 public void testIsXaresource() { 140 CloseType=CLOSE_PHYSICAL; 141 142 try { 143 startUp("testIsXaresource"); 144 assertTrue(5 == 5); 145 String ans = bean.getXid(); 146 assertTrue(5 == 5); 147 assertEquals("OK", ans); 148 bean.closeUp(CloseType); 149 assertTrue(5 == 5); 150 } catch (Exception e) { 151 System.err.println("XatransactionTest: Exception in TransactedCASLR"); 152 e.printStackTrace(); 153 } catch (Throwable t) { 154 System.err.println("XatransactionTest: Exception in TransactedCASLR"); 155 t.printStackTrace(); 156 } 157 } 158 169 public void testIsXAend1() { 170 CloseType=CLOSE_HANDLE; 172 try { 173 startUp("testIsXAend1"); 174 assertTrue(5 == 5); 175 assertTrue(bean.getCMInstance()); bean.closeUp(CloseType); 177 assertTrue(bean.getCMInstance()); assertTrue(5 == 5); 179 } catch (Exception e) { 180 System.err.println("testIsXAend1: Exception in TransactedCASLR"); 181 e.printStackTrace(); 182 } catch (Throwable t) { 183 System.err.println("testIsXAend1: Exception in TransactedCASLR"); 184 t.printStackTrace(); 185 } 186 } 187 197 public void testIsXAend2() { 198 CloseType=CLOSE_PHYSICAL; 199 200 try { 201 startUp("testIsXAend2"); 202 String ans = bean.getXid(); 203 assertEquals("FAIL", ans); } catch (Exception e) { 206 System.err.println("testIsXAend2: Exception in TransactedCASLR"); 207 e.printStackTrace(); 208 } catch (Throwable t) { 209 System.err.println("testIsXAend2: Exception in TransactedCASLR"); 210 t.printStackTrace(); 211 } 212 } 213 214 public static Test suite() { 215 return new TestSuite(F_xatransactionTest.class); 216 } 217 218 public static void main (String args[]) { 219 220 String testtorun = null; 221 222 224 for (int argn = 0; argn < args.length; argn++) { 225 226 String s_arg = args[argn]; 227 Integer i_arg; 228 229 if (s_arg.equals("-n")) { 230 testtorun = args[++argn]; 231 } 232 } 233 234 if (testtorun == null) { 235 junit.textui.TestRunner.run(suite()); 236 } else { 237 junit.textui.TestRunner.run(new F_xatransactionTest(testtorun)); 238 } 239 } 240 } 241 | Popular Tags |