KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > jtests > clients > hotdeploy > F_EjbJarHotDeploy


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 JavaDoc;
10 import java.io.FileInputStream JavaDoc;
11 import java.io.FileOutputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13
14 import javax.rmi.PortableRemoteObject JavaDoc;
15 import javax.naming.NamingException JavaDoc;
16
17
18
19 public class F_EjbJarHotDeploy extends JTestCase {
20
21     private static String JavaDoc BEAN_HOME = "HotDeployHome";
22     private HotDeployHome bhome1 = null;
23     private HotDeployHome bhome2 = null;
24     private String JavaDoc jonasbase = null;
25     private String JavaDoc sep = File.separator;
26     
27     public F_EjbJarHotDeploy(String JavaDoc 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 JavaDoc source, String JavaDoc dest) throws IOException JavaDoc {
40         File JavaDoc src = new File JavaDoc(jonasbase + sep + "ejbjars" + sep + source);
41         File JavaDoc dst = new File JavaDoc(jonasbase + sep + "ejbjars" + sep + dest);
42         
43         FileInputStream JavaDoc is = new FileInputStream JavaDoc(src);
44         FileOutputStream JavaDoc os = new FileOutputStream JavaDoc(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 JavaDoc {
55         // copy $JONAS_BASE/ejbjars/hotdeploy1.jar -> $JONAS_BASE/ejbjars/hotdeploy.jar
56
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 JavaDoc e) {
64             fail("Cannot get HotDeployHome:" + e);
65         }
66         System.err.println("Home retrieved");
67         
68         HotDeploy bean1 = bhome1.create();
69         String JavaDoc 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 $JONAS_BASE/ejbjars/hotdeploy2.jar -> $JONAS_BASE/ejbjars/hotdeploy.jar
78
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 JavaDoc e) {
86             fail("Cannot get HotDeployHome:" + e);
87         }
88         
89         HotDeploy bean2 = bhome2.create();
90         String JavaDoc 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 JavaDoc args[]) {
106         String JavaDoc testtorun = null;
107         // Get args
108
for (int argn = 0; argn < args.length; argn++) {
109             String JavaDoc s_arg = args[argn];
110             Integer JavaDoc 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