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.remon.Main; 39 import org.objectweb.jonas.jtests.beans.relation.remon.MainHome; 40 import org.objectweb.jonas.jtests.util.JTestCase; 41 42 47 public class F_Remon extends JTestCase { 48 49 52 private static MainHome mainhome = null; 53 54 57 public F_Remon(String name) { 58 super(name); 59 } 60 61 protected static boolean isInit = false; 62 63 67 protected void setUp() { 68 super.setUp(); 69 if (!isInit) { 70 useBeans("remon", false); 71 try { 72 mainhome = (MainHome) PortableRemoteObject.narrow(ictx.lookup("relation_remon_MainHome"), 73 MainHome.class); 74 } catch (NamingException e) { 75 fail("Cannot get bean home: " + e.getMessage()); 76 } 77 isInit = true; 78 } 79 } 80 81 87 protected void tearDown() throws Exception { 88 cleanall(); 89 } 91 92 97 private void cleanall() throws Exception { 98 debug("remove all beans"); 99 100 try { 103 cleanAllBeans(mainhome); 104 } catch (Exception e) { 105 error("Exception in cleanup: " + e); 106 unloadBeans("remon"); 107 isInit = false; 108 } 109 } 110 111 private void cleanAllBeans(MainHome home) throws RemoteException , RemoveException { 112 try { 113 Collection c = home.findAll(); 114 for (Iterator i = c.iterator(); i.hasNext(); ) { 115 EJBObject p = (EJBObject ) i.next(); 116 p.remove(); 117 } 118 } catch (FinderException e) { 119 } 120 } 121 122 126 public void testCreateMain() throws Exception { 127 mainhome.create("A1", "100", "at1"); 128 } 129 130 133 public static Test suite() { 134 return new TestSuite(F_Remon.class); 135 } 136 137 public static void main(String args[]) throws Exception { 138 String testtorun = null; 139 140 for (int argn = 0; argn < args.length; argn++) { 142 String sarg = args[argn]; 143 if (sarg.equals("-n")) { 144 testtorun = args[++argn]; 145 } 146 } 147 if (testtorun == null) { 148 junit.textui.TestRunner.run(suite()); 149 } else { 150 junit.textui.TestRunner.run(new F_Remon(testtorun)); 151 } 152 } 153 154 } 155 | Popular Tags |