1 package org.objectweb.jonas.jtests.clients.hotdeploy; 2 3 import junit.framework.*; 4 5 import org.objectweb.jonas.jtests.util.JTestCase; 6 import org.objectweb.jonas.jtests.beans.hotdeploy.HotDeploy; 7 import org.objectweb.jonas.jtests.beans.hotdeploy.HotDeployHome; 8 9 import java.io.File ; 10 import java.io.FileInputStream ; 11 import java.io.FileOutputStream ; 12 import java.io.IOException ; 13 14 import javax.rmi.PortableRemoteObject ; 15 import javax.naming.NamingException ; 16 17 18 19 public class F_EjbJarHotDeploy extends JTestCase { 20 21 private static String BEAN_HOME = "HotDeployHome"; 22 private HotDeployHome bhome1 = null; 23 private HotDeployHome bhome2 = null; 24 private String jonasbase = null; 25 private String sep = File.separator; 26 27 public F_EjbJarHotDeploy(String name) { 28 super(name); 29 } 30 31 public static Test suite() { 32 return new TestSuite(F_EjbJarHotDeploy.class); 33 } 34 35 public void setUp() { 36 jonasbase = System.getProperty("jonas.base"); 37 } 38 39 private void copy(String source, String dest) throws IOException { 40 File src = new File (jonasbase + sep + "ejbjars" + sep + source); 41 File dst = new File (jonasbase + sep + "ejbjars" + sep + dest); 42 43 FileInputStream is = new FileInputStream (src); 44 FileOutputStream os = new FileOutputStream (dst); 45 46 byte[] b = new byte[1024]; 47 int t; 48 while ((t = is.read(b, 0, b.length - 1)) != -1) { 49 os.write(b, 0, t); 50 } 51 52 } 53 54 public void testBeanHotDeployTwice() throws Exception { 55 System.err.println("Start Test"); 57 copy("hotdeploy1.jar", "hotdeploy.jar"); 58 System.err.println("Copy executed"); 59 useBeans("hotdeploy", false); 60 System.err.println("First Deployment OK"); 61 try { 62 bhome1 = (HotDeployHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), HotDeployHome.class); 63 } catch (NamingException e) { 64 fail("Cannot get HotDeployHome:" + e); 65 } 66 System.err.println("Home retrieved"); 67 68 HotDeploy bean1 = bhome1.create(); 69 String envVal1 = bean1.getEnvString(); 70 int beanVal1 = bean1.getVersionNumber(); 71 int helperVal1 = bean1.getHelperClassVersionNumber(); 72 73 System.err.println("getValues OK"); 74 unloadBeans("hotdeploy"); 75 System.err.println("Unload first"); 76 77 copy("hotdeploy2.jar", "hotdeploy.jar"); 79 80 System.err.println("Copy Second jar"); 81 useBeans("hotdeploy", false); 82 System.err.println("Seconf Load OK"); 83 try { 84 bhome2 = (HotDeployHome) PortableRemoteObject.narrow(ictx.lookup(BEAN_HOME), HotDeployHome.class); 85 } catch (NamingException e) { 86 fail("Cannot get HotDeployHome:" + e); 87 } 88 89 HotDeploy bean2 = bhome2.create(); 90 String envVal2 = bean2.getEnvString(); 91 int beanVal2 = bean2.getVersionNumber(); 92 int helperVal2 = bean2.getHelperClassVersionNumber(); 93 unloadBeans("hotdeploy"); 94 95 assertEquals("1.XML env String", "value1", envVal1); 96 assertEquals("1.Static bean attr", 1, beanVal1); 97 assertEquals("1.Static helper attr", 1, helperVal1); 98 99 assertEquals("2.XML env String", "value2", envVal2); 100 assertEquals("2.Static bean attr", 2, beanVal2); 101 assertEquals("2.Static helper attr", 2, helperVal2); 102 103 } 104 105 public static void main (String args[]) { 106 String testtorun = null; 107 for (int argn = 0; argn < args.length; argn++) { 109 String s_arg = args[argn]; 110 Integer i_arg; 111 if (s_arg.equals("-n")) { 112 testtorun = args[++argn]; 113 } 114 } 115 if (testtorun == null) { 116 junit.textui.TestRunner.run(suite()); 117 } else { 118 junit.textui.TestRunner.run(new F_EjbJarHotDeploy(testtorun)); 119 } 120 } 121 } 122 | Popular Tags |