1 24 25 package org.objectweb.jonas.jtests.clients.entity; 26 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 30 import javax.naming.NamingException ; 31 import javax.rmi.PortableRemoteObject ; 32 33 import junit.framework.Test; 34 import junit.framework.TestSuite; 35 36 import org.objectweb.jonas.jtests.beans.relation.rcycle.PersonRemote; 37 import org.objectweb.jonas.jtests.beans.relation.rcycle.PersonHomeRemote; 38 import org.objectweb.jonas.jtests.util.JTestCase; 39 40 45 public class F_RcycleEC2 extends JTestCase { 46 47 private static final int ID_L_ERIC = 1; 48 49 private static final int ID_JL_HELENE = 2; 50 51 private static final int ID_L_GUILHEM = 3; 52 53 private static final int ID_L_MALVA = 4; 54 55 private static PersonHomeRemote personhome = null; 56 57 public F_RcycleEC2(String name) { 58 super(name); 59 } 60 61 protected static boolean isInit = false; 62 63 protected void setUp() { 64 super.setUp(); 65 if (!isInit) { 66 useBeans("rcycle", true); 67 try { 68 personhome = (PersonHomeRemote) PortableRemoteObject.narrow(ictx.lookup("RcyclePersonHome"), 69 PersonHomeRemote.class); 70 } catch (NamingException e) { 71 fail("Cannot get bean home: " + e.getMessage()); 72 } 73 isInit = true; 74 } 75 } 76 77 81 public void testFindAll() throws Exception { 82 Collection cp = personhome.findAll(); 83 assertEquals("Number of Persons: ", 4, cp.size()); 84 } 85 86 90 public void testFindQuery1() throws Exception { 91 Collection cp = personhome.findQuery1(); 92 assertEquals("Number of Persons: ", 0, cp.size()); 93 } 94 95 99 public void testFindQuery2() throws Exception { 100 Collection cp = personhome.findQuery2(); 101 assertEquals("Number of Persons: ", 0, cp.size()); 102 } 103 104 108 public void testFindSpouse3() throws Exception { 109 PersonRemote p = personhome.findSpouse3(); 110 assertNull("Laurent Guilhem spouse: ", p); 111 } 112 113 117 public void testSpouseRelation() throws Exception { 118 PersonRemote ph = personhome.findByPrimaryKey(new Integer (ID_L_ERIC)); 119 Integer iw = ph.retrieveSpouse(); 120 assertEquals("Wife of Laurent Eric: ", ID_JL_HELENE, iw.intValue()); 121 PersonRemote pw = personhome.findByPrimaryKey(iw); 122 Integer ih = pw.retrieveSpouse(); 123 assertEquals("Husband of Joanin-Laurent Helene: ", ID_L_ERIC, ih.intValue()); 124 PersonRemote pc = personhome.findByPrimaryKey(new Integer (ID_L_GUILHEM)); 125 Integer in = pc.retrieveSpouse(); 126 assertNull("Laurent Guilhem spouse: ", in); 127 } 128 129 133 public void testGuardianRelation() throws Exception { 134 Integer iLEric = new Integer (ID_L_ERIC); 135 PersonRemote ph = personhome.findByPrimaryKey(iLEric); 136 Collection c = ph.retrieveGuardianOf(); 137 assertEquals("Laurent Eric guardian of: ", 2, c.size()); 138 for (Iterator i = c.iterator(); i.hasNext();) { 139 Integer ip = (Integer ) i.next(); 140 PersonRemote p = personhome.findByPrimaryKey(ip); 141 assertEquals("Guardian of " + p.getName() + ": ", iLEric, p.retrieveGuardian()); 142 } 143 } 144 145 149 public void testParentsChildrenRelation() throws Exception { 150 Integer iLEric = new Integer (ID_L_ERIC); 151 PersonRemote ph = personhome.findByPrimaryKey(iLEric); 152 Collection cc = ph.retrieveChildren(); 153 assertEquals("Laurent Eric father of: ", 2, cc.size()); 154 for (Iterator i = cc.iterator(); i.hasNext();) { 155 Integer ip = (Integer ) i.next(); 156 PersonRemote p = personhome.findByPrimaryKey(ip); 157 Collection cp = p.retrieveParents(); 158 assertTrue("Father of " + p.getName() + ": ", cp.contains(iLEric)); 159 } 160 } 161 162 166 public void testCmrNull() throws Exception { 167 PersonRemote ph = personhome.findByPrimaryKey(new Integer (ID_L_ERIC)); 168 assertTrue("CMR null is NOT null", ph.testCmrNull()); 169 } 170 171 175 public void testPrefetch() throws Exception { 176 try { 178 utx.begin(); 179 Integer iLEric = new Integer (ID_L_ERIC); 180 PersonRemote ph = personhome.findByPrimaryKey(iLEric); 181 Collection cc = ph.retrieveChildrenNames(); 183 assertEquals("Laurent Eric father of: ", 2, cc.size()); 184 } finally { 185 utx.commit(); 186 } 187 } 188 189 protected boolean initStateOK() throws Exception { 190 return true; 191 } 192 193 public static Test suite() { 194 return new TestSuite(F_RcycleEC2.class); 195 } 196 197 public static void main(String args[]) { 198 String testtorun = null; 199 for (int argn = 0; argn < args.length; argn++) { 201 String sarg = args[argn]; 202 if (sarg.equals("-n")) { 203 testtorun = args[++argn]; 204 } 205 } 206 if (testtorun == null) { 207 junit.textui.TestRunner.run(suite()); 208 } else { 209 junit.textui.TestRunner.run(new F_RcycleEC2(testtorun)); 210 } 211 } 212 } 213 | Popular Tags |