1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import javax.naming.NamingException ; 29 import javax.rmi.PortableRemoteObject ; 30 31 import junit.framework.Test; 32 import junit.framework.TestSuite; 33 34 import org.objectweb.jonas.jtests.beans.relation.oou.AHomeRemote; 35 import org.objectweb.jonas.jtests.beans.relation.oou.ARemote; 36 import org.objectweb.jonas.jtests.beans.relation.oou.BHomeRemote; 37 import org.objectweb.jonas.jtests.beans.relation.oou.BRemote; 38 39 42 public class G_Relation_oouEC2 extends A_Cmp2Util { 43 44 private static String BEAN_HOME_A = "relation_oou_AHome"; 45 private static String BEAN_HOME_B = "relation_oou_BHome"; 46 protected static AHomeRemote ahome = null; 47 protected static BHomeRemote bhome = null; 48 49 public G_Relation_oouEC2(String name) { 50 super(name); 51 } 52 53 54 public void testEmpty() throws Exception { 55 } 56 57 protected static boolean isInit = false; 58 59 protected void setUp() { 60 super.setUp(); 61 boolean ok = false; 62 int nbtry = 0; 63 while (!ok && nbtry < 3) { 64 if (!isInit) { 65 useBeans("oou", false); 67 try { 69 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_A), 70 AHomeRemote.class); 71 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME_B), 72 BHomeRemote.class); 73 } catch (NamingException e) { 74 fail("Cannot get bean home: " + e.getMessage()); 75 } 76 try { 78 ahome.findByPrimaryKey("a2"); 79 } catch (Exception e) { 80 try { 82 utx.begin(); 83 ARemote a1 = ahome.create("a1"); 84 ARemote a2 = ahome.create("a2"); 85 ahome.create("a3"); 86 bhome.create("b1"); 87 bhome.create("b2"); 88 bhome.create("b3"); 89 a1.assignB("b1"); 90 a2.assignB("b2"); 91 } catch (Exception i) { 92 fail("InitialState creation problem: "+i); 93 } finally { 94 try { 95 utx.commit(); 96 } catch (Exception ii) { 97 } 98 } 99 } 100 isInit = true; 101 } 102 nbtry++; 105 try { 106 if (initStateOK()) { 107 ok = true; 108 } 109 } catch (Exception e) { 110 } 111 if (!ok) { 112 isInit = false; 113 unloadBeans("oou"); 114 } 115 } 116 } 117 118 119 123 boolean initStateOK() throws Exception { 124 boolean isOk = true; 125 126 msgerror = new StringBuffer (); 127 128 ARemote a1 = ahome.findByPrimaryKey("a1"); 129 BRemote b1 = bhome.findByPrimaryKey("b1"); 130 ARemote a2 = ahome.findByPrimaryKey("a2"); 131 BRemote b2 = bhome.findByPrimaryKey("b2"); 132 ARemote a3 = ahome.findByPrimaryKey("a3"); 133 BRemote b3 = bhome.findByPrimaryKey("b3"); 134 String idB1 = a1.retrieveB(); 135 String idB2 = a2.retrieveB(); 136 String idB3 = a3.retrieveB(); 137 138 if (idB1!=null && !idB1.equals("b1")){ 139 isOk = false; 140 msgerror.append("Wrong relation for a1->b1" 141 +"(expected: A1.retrieveB()='b1'" 142 + ", found:" + idB1 + ")"); 143 } 144 else if (idB2!=null && !idB2.equals("b2")){ 145 isOk = false; 146 msgerror.append("Wrong relation for a2->b2" 147 +"(expected: A2.retrieveB()='b2'" 148 + ", found:" + idB2 + ")"); 149 } 150 else if (idB3!=null){ 151 isOk = false; 152 msgerror.append("Wrong relation for b3->a3" 153 +"(expected: B3.retrieveA()=null" 154 + ", found:" + idB3 + ")"); 155 } 156 return isOk; 157 } 158 159 160 161 164 public void _testBasicSetEmpty(int tx) throws Exception { 165 if ((tx == TX_CALL) || (tx == TX_RB)) { 166 utx.begin(); 167 } 168 ARemote a = ahome.findByPrimaryKey("a3"); 169 if (tx == TX_CONT) { 170 a.assignBInNewTx("b3"); 171 } else { 172 a.assignB("b3"); 173 } 174 if (tx == TX_CALL) { 175 utx.commit(); 176 } else if (tx == TX_RB) { 177 utx.rollback(); 178 } 179 String idB = a.retrieveB(); 181 if (tx != TX_RB) { 182 assertEquals("Wrong assign null for relation a3->b3 : ","b3", idB); 183 } else { 184 assertNull("Wrong assign null for relation a3->b3 : ", idB); 185 } 186 if (tx != TX_RB) { 188 a.assignB(null); 189 } 190 checkIsInitialState(); 191 } 192 193 public void testBasicSetEmptyTxNo() throws Exception { 194 _testBasicSetEmpty(TX_NO); 195 } 196 public void testBasicSetEmptyTxCall() throws Exception { 197 _testBasicSetEmpty(TX_CALL); 198 } 199 public void testBasicSetEmptyTxCont() throws Exception { 200 _testBasicSetEmpty(TX_CONT); 201 } 202 203 204 205 public static Test suite() { 206 return new TestSuite(G_Relation_oouEC2.class); 207 } 208 209 public static void main (String args[]) { 210 String testtorun = null; 211 for (int argn = 0; argn < args.length; argn++) { 213 String s_arg = args[argn]; 214 Integer i_arg; 215 if (s_arg.equals("-n")) { 216 testtorun = args[++argn]; 217 } 218 } 219 if (testtorun == null) { 220 junit.textui.TestRunner.run(suite()); 221 } else { 222 junit.textui.TestRunner.run(new G_Relation_oouEC2(testtorun)); 223 } 224 } 225 } 226 227 | Popular Tags |