1 25 26 package org.objectweb.jonas.jtests.clients.j2eeca; 27 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.rmi.PortableRemoteObject ; 31 import javax.transaction.UserTransaction ; 32 33 import junit.framework.Test; 34 import junit.framework.TestSuite; 35 36 import org.objectweb.jonas.jtests.beans.j2eeca.transactedCA; 37 import org.objectweb.jonas.jtests.beans.j2eeca.transactedCAHome; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 44 45 public class F_transactionTest extends JTestCase { 46 47 private static UserTransaction utx = null; 48 49 static Context ctx = null; 50 51 53 protected static String BEAN_HOME = "transactedCAHome"; 54 protected static transactedCAHome home = null; 55 private static final String RAR_JNDI_NAME = "FictionalLoTransaction"; 56 final public int CLOSE_HANDLE = 0; 57 final public int CLOSE_PHYSICAL = 1; 58 public int CloseType = 0; 59 static transactedCA bean = null; 60 public String UseBeans="j2eeca"; 61 62 public F_transactionTest(String name) { 63 super(name); 64 } 65 66 protected void setUp() { 67 super.setUp(); 68 try { 69 71 if (ctx == null) { 72 ctx = new InitialContext (); 73 } 74 75 77 if (utx == null) { 78 utx = (UserTransaction ) ctx.lookup("javax.transaction.UserTransaction"); 79 } 80 81 if (home == null) { 82 useBeans(UseBeans, false); 83 } 84 getBean(); 85 assertTrue (6 == 6); 86 87 } catch (Exception e) { 88 fail("Cannot lookup UserTransaction in setUp: " +e); 89 } 90 } 91 private void getBean() throws Exception { 92 94 if (home == null) { 95 home = (transactedCAHome)PortableRemoteObject.narrow( 96 ctx.lookup(BEAN_HOME), 97 transactedCAHome.class); 98 bean = home.create(); 99 } 100 } 101 protected void tearDown() throws Exception { 102 } 104 protected void startUp(String testName) { 105 try { 106 bean.method1(RAR_JNDI_NAME, testName); 107 } catch (Exception ee) { 108 ee.printStackTrace(); 109 System.exit(2); 110 } 111 } 112 113 115 124 public void testTransaction1() { 125 CloseType=CLOSE_PHYSICAL; 126 startUp("testTransaction1"); 127 try { 128 bean.beginLoTransaction(); 129 assertTrue (6 == 6); 130 bean.closeUp(CloseType); 131 bean.commitLoTransaction(); 132 assertTrue (6 == 6); 133 } catch (Exception e) { 134 assertTrue(6==7); 135 } 136 } 137 138 public void testTransaction2() { 139 CloseType=CLOSE_PHYSICAL; 140 startUp("testTransaction2"); 141 try { 142 bean.closeUp(CloseType); 143 bean.commitLoTransaction(); 144 assertTrue (6 == 7); 145 } catch (Exception e) { 146 assertTrue(6==6); } 148 } 149 150 public static Test suite() { 151 return new TestSuite(F_transactionTest.class); 152 } 153 154 public static void main (String args[]) { 155 156 String testtorun = null; 157 158 160 for (int argn = 0; argn < args.length; argn++) { 161 162 String s_arg = args[argn]; 163 Integer i_arg; 164 165 if (s_arg.equals("-n")) { 166 testtorun = args[++argn]; 167 } 168 } 169 170 if (testtorun == null) { 171 junit.textui.TestRunner.run(suite()); 172 } else { 173 junit.textui.TestRunner.run(new F_transactionTest(testtorun)); 174 } 175 } 176 } 177 | Popular Tags |