1 25 26 package org.objectweb.jonas.jtests.clients.session; 27 28 import java.io.ByteArrayInputStream ; 29 import java.io.ByteArrayOutputStream ; 30 import java.io.ObjectInputStream ; 31 import java.io.ObjectOutputStream ; 32 import java.rmi.NoSuchObjectException ; 33 import java.rmi.RemoteException ; 34 35 import javax.ejb.EJBException ; 36 import javax.ejb.EJBObject ; 37 import javax.ejb.RemoveException ; 38 import javax.ejb.EJBMetaData ; 39 import javax.ejb.Handle ; 40 import javax.ejb.HomeHandle ; 41 import javax.rmi.PortableRemoteObject ; 42 43 import org.objectweb.jonas.jtests.beans.local.Target; 44 import org.objectweb.jonas.jtests.beans.local.TargetSLHome; 45 import org.objectweb.jonas.jtests.util.JTestCase; 46 47 48 58 59 public abstract class A_ClientView extends JTestCase { 60 61 public A_ClientView(String name) { 62 super(name); 63 } 64 65 68 public abstract TargetSLHome getHome() throws Exception ; 69 70 71 72 78 79 public void testHomeLookup() throws Exception { 80 TargetSLHome h = null; 81 h = getHome(); 82 assertTrue(h != null); 83 } 84 85 86 87 88 91 public void testCreateRemove() throws Exception { 92 Target tr = getHome().create(); 93 tr.remove(); 94 } 95 96 97 98 101 public void testLongCreateRemove() throws Exception { 102 for (int i = 0; i < 500; i++) { 103 Target tr = getHome().create(); 104 tr.remove(); 105 } 106 } 107 108 109 114 public void testBusinessMethod1() throws Exception { 115 Target tr = getHome().create(); 116 assertEquals(10, tr.getTen()); 117 tr.remove(); 118 try { 119 tr.method2("Bye"); 120 fail("NoSuchObjectException must be raised"); 121 } catch (NoSuchObjectException e) { 123 } 124 } 125 126 127 130 public void testBusinessMethod2() throws Exception { 131 Target tr = getHome().create(); 132 assertEquals(10, tr.getTen()); 133 assertEquals(10, tr.getTen()); 134 tr.remove(); 135 } 136 137 138 139 142 public void testBusinessMethod3() throws Exception { 143 Target tr = getHome().create(); 144 assertEquals(10, tr.getTen()); 145 tr.method2("Hello"); 146 assertEquals(10, tr.getTen()); 147 tr.remove(); 148 } 149 150 151 154 public void testIsIdenticalOnSameBean() throws Exception { 155 Target tr = getHome().create(); 156 assertTrue(tr.isIdentical(tr)); 157 tr.remove(); 158 } 159 160 161 165 public void testGetPrimaryKey() throws Exception { 166 Target tr = getHome().create(); 167 try { 168 tr.getPrimaryKey(); 169 fail("getPrimaryKey should raise RemoteException on a session bean"); 170 } catch (RemoteException e) { 171 } finally { 172 tr.remove(); 173 } 174 } 175 176 177 181 public void testGetPrimaryKeyClass() throws Exception { 182 try { 183 getHome().getEJBMetaData().getPrimaryKeyClass(); 184 fail("getEJBMetaData().getPrimaryKeyClass should raise EJBException on a session bean home"); 185 } catch (EJBException e) { 186 } 187 } 188 189 190 194 public void testRemoveByPK() throws Exception { 195 Object pk = null; 196 try { 197 getHome().remove(pk); 198 fail("getPrimaryKey should raise Exception on a session bean"); 199 } catch (RemoteException e) { 200 } catch (RemoveException e) { 201 } 202 } 203 204 205 209 public void testGetEJBMetaData() throws Exception { 210 EJBMetaData hh = getHome().getEJBMetaData(); 211 } 212 213 217 public void testGetHomeHandle() throws Exception { 218 HomeHandle hh = getHome().getHomeHandle(); 219 } 220 221 225 public void testSerializeHandle() throws Exception { 226 TargetSLHome tgh = getHome(); 227 Target tr = tgh.create(); 228 Handle h = tr.getHandle(); 229 ObjectInputStream is = null; 230 ObjectOutputStream os = null; 231 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 232 os = new ObjectOutputStream (baos); 233 os.writeObject(h); 234 byte[] b = baos.toByteArray(); 235 ByteArrayInputStream bais = new ByteArrayInputStream (b); 236 is = new ObjectInputStream (bais); 237 Handle deserializedHandle = (Handle ) is.readObject(); 238 EJBObject ejbObject = deserializedHandle.getEJBObject(); 239 Target beanRef2 = (Target) PortableRemoteObject.narrow(ejbObject, Target.class); 240 } 241 242 248 public void testRemoveHandle() throws Exception { 249 TargetSLHome tgh = getHome(); 250 Target tr = tgh.create(); 251 Handle h = tr.getHandle(); 252 tgh.remove(h); 253 try { 254 tr.method2("Bye"); 255 fail("Cannot remove a session bean via its handle"); 256 } catch ( NoSuchObjectException e) { 257 258 } 259 } 260 261 } 262 | Popular Tags |