1 24 25 package org.objectweb.jonas.jtests.clients.entity; 26 27 import java.rmi.RemoteException ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import javax.ejb.EJBObject ; 31 import javax.ejb.FinderException ; 32 import javax.ejb.RemoveException ; 33 import javax.naming.NamingException ; 34 import javax.rmi.PortableRemoteObject ; 35 import junit.framework.Assert; 36 import junit.framework.Test; 37 import junit.framework.TestSuite; 38 import org.objectweb.jonas.jtests.beans.relation.dass.DassHome; 39 import org.objectweb.jonas.jtests.beans.relation.dass.P1Remote; 40 import org.objectweb.jonas.jtests.beans.relation.dass.P1HomeRemote; 41 import org.objectweb.jonas.jtests.beans.relation.dass.P2Remote; 42 import org.objectweb.jonas.jtests.beans.relation.dass.P2HomeRemote; 43 import org.objectweb.jonas.jtests.beans.relation.dass.P3Remote; 44 import org.objectweb.jonas.jtests.beans.relation.dass.P3HomeRemote; 45 import org.objectweb.jonas.jtests.beans.relation.dass.P4Remote; 46 import org.objectweb.jonas.jtests.beans.relation.dass.P4HomeRemote; 47 import org.objectweb.jonas.jtests.beans.relation.dass.ARemote; 48 import org.objectweb.jonas.jtests.beans.relation.dass.AHomeRemote; 49 import org.objectweb.jonas.jtests.beans.relation.dass.BRemote; 50 import org.objectweb.jonas.jtests.beans.relation.dass.BHomeRemote; 51 import org.objectweb.jonas.jtests.util.JTestCase; 52 53 58 public class F_Dass extends JTestCase { 59 60 63 private static P1HomeRemote p1home = null; 64 private static P2HomeRemote p2home = null; 65 private static P3HomeRemote p3home = null; 66 private static P4HomeRemote p4home = null; 67 private static AHomeRemote ahome = null; 68 private static BHomeRemote bhome = null; 69 70 73 public F_Dass(String name) { 74 super(name); 75 } 76 77 protected static boolean isInit = false; 78 79 83 protected void setUp() { 84 super.setUp(); 85 if (!isInit) { 86 useBeans("dass", false); 87 try { 88 p1home = (P1HomeRemote) PortableRemoteObject.narrow(ictx.lookup("relation_dass_P1Home"), 89 P1HomeRemote.class); 90 p2home = (P2HomeRemote) PortableRemoteObject.narrow(ictx.lookup("relation_dass_P2Home"), 91 P2HomeRemote.class); 92 p3home = (P3HomeRemote) PortableRemoteObject.narrow(ictx.lookup("relation_dass_P3Home"), 93 P3HomeRemote.class); 94 p4home = (P4HomeRemote) PortableRemoteObject.narrow(ictx.lookup("relation_dass_P4Home"), 95 P4HomeRemote.class); 96 ahome = (AHomeRemote) PortableRemoteObject.narrow(ictx.lookup("relation_dass_AHome"), 97 AHomeRemote.class); 98 bhome = (BHomeRemote) PortableRemoteObject.narrow(ictx.lookup("relation_dass_BHome"), 99 BHomeRemote.class); 100 } catch (NamingException e) { 101 fail("Cannot get bean home: " + e.getMessage()); 102 } 103 isInit = true; 104 } 105 } 106 107 113 protected void tearDown() throws Exception { 114 cleanall(); 115 } 117 118 123 private void cleanall() throws Exception { 124 debug("remove all beans"); 125 126 try { 129 cleanAllBeans(ahome); 130 cleanAllBeans(bhome); 131 cleanAllBeans(p1home); 132 cleanAllBeans(p2home); 133 cleanAllBeans(p3home); 134 cleanAllBeans(p4home); 135 } catch (Exception e) { 136 error("Exception in cleanup: " + e); 137 unloadBeans("dass"); 138 isInit = false; 139 } 140 } 141 142 private void cleanAllBeans(DassHome home) throws RemoteException , RemoveException { 143 try { 144 Collection c = home.findAll(); 145 for (Iterator i = c.iterator(); i.hasNext(); ) { 146 EJBObject p = (EJBObject ) i.next(); 147 p.remove(); 148 } 149 } catch (FinderException e) { 150 } 151 } 152 153 157 public void testCreateA() throws Exception { 158 ahome.create("A1"); 159 } 160 161 public void testCreateB() throws Exception { 162 bhome.create("B1"); 163 } 164 165 171 public void _testCreateA2B() throws Exception { 172 ARemote a1 = ahome.create("A1"); 173 bhome.create("B1"); 174 a1.assignB("B1"); 175 String cmrval = a1.getBcmrvalue(); 176 assertTrue("Bad cmr value:" + cmrval, "B1".equals(cmrval)); 177 } 178 179 public void _testCreateA2BTx() throws Exception { 180 try { 181 utx.begin(); 182 _testCreateA2B(); 183 } finally { 184 try { 185 utx.commit(); 186 } catch (Exception ii) { 187 } 188 } 189 } 190 191 195 public void testCreateP1P2() throws Exception { 196 P1Remote p1 = p1home.create("P", "100"); 197 P2Remote p2 = p2home.create("P"); 198 String val = p2.getP1Value(); 199 assertTrue("Cannot access bean P1", "100".equals(val)); 200 } 201 202 206 public void testCreateP3() throws Exception { 207 P1Remote p1 = p1home.create("P", "100"); 208 P4Remote p4 = p4home.create("P", "102"); 209 P3Remote p3 = p3home.create("P3", "P"); 210 String val = p3.getP1Value(); 211 assertTrue("Cannot access bean P1", "100".equals(val)); 212 val = p3.getP4Value(); 213 assertTrue("Cannot access bean P4", "102".equals(val)); 214 } 215 216 219 public static Test suite() { 220 return new TestSuite(F_Dass.class); 221 } 222 223 public static void main(String args[]) throws Exception { 224 String testtorun = null; 225 226 for (int argn = 0; argn < args.length; argn++) { 228 String sarg = args[argn]; 229 if (sarg.equals("-n")) { 230 testtorun = args[++argn]; 231 } 232 } 233 if (testtorun == null) { 234 junit.textui.TestRunner.run(suite()); 235 } else { 236 junit.textui.TestRunner.run(new F_Dass(testtorun)); 237 } 238 } 239 240 } 241 | Popular Tags |