KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jrmp > test > DynLoadingUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jrmp.test;
23
24 import java.io.File JavaDoc;
25 import java.net.URL JavaDoc;
26 import java.rmi.RemoteException JavaDoc;
27 import java.security.CodeSource JavaDoc;
28 import javax.ejb.CreateException JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30 import javax.naming.NamingException JavaDoc;
31
32 import junit.framework.Test;
33 import junit.framework.TestCase;
34 import junit.framework.TestSuite;
35
36 import org.jboss.test.JBossTestCase;
37
38 import org.jboss.test.jrmp.interfaces.IString;
39 import org.jboss.test.jrmp.interfaces.StatelessSession;
40 import org.jboss.test.jrmp.interfaces.StatelessSessionHome;
41
42 /**
43  * Test of RMI dynamic class loading.
44  *
45  * @author Scott.Stark@jboss.org
46  * @author Author: david jencks d_jencks@users.sourceforge.net
47  * @version $Revision: 37406 $
48  */

49 public class DynLoadingUnitTestCase
50        extends JBossTestCase
51 {
52    /**
53     * Constructor for the DynLoadingUnitTestCase object
54     *
55     * @param name Description of Parameter
56     */

57    public DynLoadingUnitTestCase(String JavaDoc name)
58    {
59       super(name);
60    }
61
62    /**
63     * A unit test for JUnit
64     *
65     * @exception Exception Description of Exception
66     */

67    public void testAccess() throws Exception JavaDoc
68    {
69       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
70       getLog().debug("Lookup StatefulSession");
71       Object JavaDoc obj = jndiContext.lookup("StatefulSession");
72       StatelessSessionHome home = (StatelessSessionHome)obj;
73       getLog().debug("Found StatefulSession Home");
74       StatelessSession bean = home.create();
75       getLog().debug("Created StatefulSession");
76       IString echo = bean.copy("jrmp-dl");
77       getLog().debug("bean.copy(jrmp-dl) = " + echo);
78       Class JavaDoc clazz = echo.getClass();
79       CodeSource JavaDoc cs = clazz.getProtectionDomain().getCodeSource();
80       URL JavaDoc location = cs.getLocation();
81       getLog().debug("IString.class = " + clazz);
82       getLog().debug("IString.class location = " + location);
83       assertTrue("CodeSource URL.protocol != file", location.getProtocol().equals("file") == false);
84       bean.remove();
85    }
86
87    //not modified to use getJ2eeSetup since there is only one test.
88

89    /**
90     * Remove any local IString implementation so that we test RMI class loading.
91     *
92     * @exception Exception Description of Exception
93     */

94    protected void setUp() throws Exception JavaDoc
95    {
96       super.setUp();
97       URL JavaDoc istringImpl = getClass().getResource("/org/jboss/test/jrmp/ejb/AString.class");
98       if (istringImpl != null)
99       {
100          getLog().debug("Found IString impl at: " + istringImpl);
101          File JavaDoc implFile = new File JavaDoc(istringImpl.getFile());
102          getLog().debug("Removed: " + implFile.delete());
103       }
104       deploy("jrmp-dl.jar");
105    }
106
107    /**
108     * The teardown method for JUnit
109     *
110     * @exception Exception Description of Exception
111     */

112    protected void tearDown() throws Exception JavaDoc
113    {
114       undeploy("jrmp-dl.jar");
115       super.tearDown();
116    }
117
118 }
119
Popular Tags