1 25 26 package org.objectweb.jonas.jtests.clients.entity; 27 28 import java.io.FileInputStream ; 29 import java.io.FileOutputStream ; 30 import java.io.ObjectInputStream ; 31 import java.io.ObjectOutputStream ; 32 33 import javax.ejb.EJBHome ; 34 import javax.ejb.Handle ; 35 import javax.ejb.HomeHandle ; 36 import javax.rmi.PortableRemoteObject ; 37 38 import org.objectweb.jonas.jtests.beans.ebasic.Simple; 39 import org.objectweb.jonas.jtests.beans.ebasic.SimpleHome; 40 import org.objectweb.jonas.jtests.util.JTestCase; 41 42 45 public abstract class A_Handle extends JTestCase { 46 47 public A_Handle(String name) { 48 super(name); 49 } 50 51 protected void setUp() { 52 super.setUp(); 53 useBeans("ebasic", true); 54 } 55 56 59 abstract public SimpleHome getHome(); 60 61 66 public void testHandle() throws Exception { 67 int val1 = 11; 68 int val2 = 12; 69 Simple s1 = getHome().create("pkforhandle", val1, val2); 70 Handle handle1 = s1.getHandle(); 71 FileOutputStream fos = new FileOutputStream ("handleSimple.ser"); 72 ObjectOutputStream outStream = new ObjectOutputStream (fos); 73 outStream.writeObject(handle1); 75 outStream.flush(); 76 fos.close(); 77 78 FileInputStream fis = new FileInputStream ("handleSimple.ser"); 80 ObjectInputStream inStream = new ObjectInputStream (fis); 81 Handle handle2 = (Handle )inStream.readObject(); 83 fis.close(); 84 85 Object ref = handle2.getEJBObject(); 88 Simple s2 = (Simple)PortableRemoteObject.narrow(ref, Simple.class); 89 90 try { 91 assertTrue(s1.isIdentical(s2)); 92 } finally { 93 s1.remove(); 94 } 95 } 96 97 102 public void testHomeHandle() throws Exception { 103 SimpleHome sh1 = getHome(); 104 Simple s1 = sh1.create("pkforhomehandle",100, 102); 105 HomeHandle hhandle1 = sh1.getHomeHandle(); 106 FileOutputStream fos = new FileOutputStream ("homehandleSimple.ser"); 107 ObjectOutputStream outStream = new ObjectOutputStream (fos); 108 outStream.writeObject(hhandle1); 110 outStream.flush(); 111 fos.close(); 112 FileInputStream fis = new FileInputStream ("homehandleSimple.ser"); 114 ObjectInputStream inStream = new ObjectInputStream (fis); 115 HomeHandle hhandle2 = (HomeHandle )inStream.readObject(); 117 fis.close(); 118 EJBHome eh = hhandle2.getEJBHome(); 119 SimpleHome sh2 = (SimpleHome)PortableRemoteObject.narrow(eh,SimpleHome.class) ; 120 try { 121 Simple s2 = sh2.findByPrimaryKey("pkforhomehandle"); 122 } finally { 123 s1.remove(); 124 } 125 126 } 127 } 128 | Popular Tags |