001: package org.objectweb.jonas.jtests.clients.hotdeploy;
002:
003: import junit.framework.*;
004:
005: import org.objectweb.jonas.jtests.util.JTestCase;
006: import org.objectweb.jonas.jtests.beans.hotdeploy.HotDeploy;
007: import org.objectweb.jonas.jtests.beans.hotdeploy.HotDeployHome;
008:
009: import java.io.File;
010: import java.io.FileInputStream;
011: import java.io.FileOutputStream;
012: import java.io.IOException;
013:
014: import javax.rmi.PortableRemoteObject;
015: import javax.naming.NamingException;
016:
017: public class F_EjbJarHotDeploy extends JTestCase {
018:
019: private static String BEAN_HOME = "HotDeployHome";
020: private HotDeployHome bhome1 = null;
021: private HotDeployHome bhome2 = null;
022: private String jonasbase = null;
023: private String sep = File.separator;
024:
025: public F_EjbJarHotDeploy(String name) {
026: super (name);
027: }
028:
029: public static Test suite() {
030: return new TestSuite(F_EjbJarHotDeploy.class);
031: }
032:
033: public void setUp() {
034: jonasbase = System.getProperty("jonas.base");
035: }
036:
037: private void copy(String source, String dest) throws IOException {
038: File src = new File(jonasbase + sep + "ejbjars" + sep + source);
039: File dst = new File(jonasbase + sep + "ejbjars" + sep + dest);
040:
041: FileInputStream is = new FileInputStream(src);
042: FileOutputStream os = new FileOutputStream(dst);
043:
044: byte[] b = new byte[1024];
045: int t;
046: while ((t = is.read(b, 0, b.length - 1)) != -1) {
047: os.write(b, 0, t);
048: }
049:
050: }
051:
052: public void testBeanHotDeployTwice() throws Exception {
053: // copy $JONAS_BASE/ejbjars/hotdeploy1.jar -> $JONAS_BASE/ejbjars/hotdeploy.jar
054: System.err.println("Start Test");
055: copy("hotdeploy1.jar", "hotdeploy.jar");
056: System.err.println("Copy executed");
057: useBeans("hotdeploy", false);
058: System.err.println("First Deployment OK");
059: try {
060: bhome1 = (HotDeployHome) PortableRemoteObject.narrow(ictx
061: .lookup(BEAN_HOME), HotDeployHome.class);
062: } catch (NamingException e) {
063: fail("Cannot get HotDeployHome:" + e);
064: }
065: System.err.println("Home retrieved");
066:
067: HotDeploy bean1 = bhome1.create();
068: String envVal1 = bean1.getEnvString();
069: int beanVal1 = bean1.getVersionNumber();
070: int helperVal1 = bean1.getHelperClassVersionNumber();
071:
072: System.err.println("getValues OK");
073: unloadBeans("hotdeploy");
074: System.err.println("Unload first");
075:
076: // copy $JONAS_BASE/ejbjars/hotdeploy2.jar -> $JONAS_BASE/ejbjars/hotdeploy.jar
077: copy("hotdeploy2.jar", "hotdeploy.jar");
078:
079: System.err.println("Copy Second jar");
080: useBeans("hotdeploy", false);
081: System.err.println("Seconf Load OK");
082: try {
083: bhome2 = (HotDeployHome) PortableRemoteObject.narrow(ictx
084: .lookup(BEAN_HOME), HotDeployHome.class);
085: } catch (NamingException e) {
086: fail("Cannot get HotDeployHome:" + e);
087: }
088:
089: HotDeploy bean2 = bhome2.create();
090: String envVal2 = bean2.getEnvString();
091: int beanVal2 = bean2.getVersionNumber();
092: int helperVal2 = bean2.getHelperClassVersionNumber();
093: unloadBeans("hotdeploy");
094:
095: assertEquals("1.XML env String", "value1", envVal1);
096: assertEquals("1.Static bean attr", 1, beanVal1);
097: assertEquals("1.Static helper attr", 1, helperVal1);
098:
099: 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: // Get args
108: 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
119: .run(new F_EjbJarHotDeploy(testtorun));
120: }
121: }
122: }
|