1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import javax.naming.NamingException ; 31 import javax.rmi.PortableRemoteObject ; 32 import junit.framework.Test; 33 import junit.framework.TestSuite; 34 import org.objectweb.jonas.jtests.beans.relation.mou.AHomeRemote; 35 import org.objectweb.jonas.jtests.beans.relation.mou.ARemote; 36 import org.objectweb.jonas.jtests.beans.relation.mou.BHomeRemote; 37 import org.objectweb.jonas.jtests.beans.relation.mou.BRemote; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 45 public class F_Relation2_mouEC2 extends JTestCase { 46 47 private static String BEAN_HOME_A = "relation_mou_A1Home"; 48 protected static AHomeRemote ahome = null; 49 private static String BEAN_HOME_B = "relation_mou_B1Home"; 50 protected static BHomeRemote bhome = null; 51 52 public F_Relation2_mouEC2(String name) { 53 super(name); 54 } 55 56 protected static boolean isInit = false; 57 58 protected void setUp() { 59 super.setUp(); 60 if (!isInit) { 61 useBeans("mou", true); 62 try { 63 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 64 AHomeRemote.class); 65 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 66 BHomeRemote.class); 67 } catch (NamingException e) { 68 fail("Cannot get bean home: " + e.getMessage()); 69 } 70 isInit = true; 71 } 72 } 73 74 80 protected void tearDown() throws Exception { 81 cleanall(); 82 } 83 84 private void cleanall() throws Exception { 85 debug("remove all beans"); 86 87 try { 90 utx.begin(); 91 } catch (Exception e) { 92 debug("rollback first and start a new tx"); 93 utx.rollback(); 94 utx.begin(); 95 } 96 try { 99 Collection c = ahome.findAll(); 100 for (Iterator i = c.iterator(); i.hasNext(); ) { 101 ARemote a = (ARemote) i.next(); 102 a.remove(); 103 } 104 c = bhome.findAll(); 105 for (Iterator i = c.iterator(); i.hasNext(); ) { 106 BRemote b = (BRemote) i.next(); 107 b.remove(); 108 } 109 utx.commit(); 110 } catch (Exception e) { 111 error("Exception in cleanup: " + e); 112 try { 113 utx.rollback(); 114 } finally { 115 unloadBeans("mou"); 116 isInit = false; 117 } 118 } 119 } 120 121 public void testCreateB() throws Exception { 122 bhome.create("b0"); 123 } 124 125 public void testCreateBA() throws Exception { 126 bhome.create("b0"); 127 ahome.create("a0", "b0"); 128 } 129 130 public static Test suite() { 131 return new TestSuite(F_Relation2_mouEC2.class); 132 } 133 134 public static void main(String args[]) { 135 String testtorun = null; 136 for (int argn = 0; argn < args.length; argn++) { 138 String s_arg = args[argn]; 139 Integer i_arg; 140 if (s_arg.equals("-n")) { 141 testtorun = args[++argn]; 142 } 143 } 144 if (testtorun == null) { 145 junit.textui.TestRunner.run(suite()); 146 } else { 147 junit.textui.TestRunner.run(new F_Relation2_mouEC2(testtorun)); 148 } 149 } 150 151 } 152 | Popular Tags |