KickJava   Java API By Example, From Geeks To Geeks.

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


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.security.CodeSource JavaDoc;
27
28 import javax.naming.InitialContext JavaDoc;
29
30 import org.jboss.test.JBossTestCase;
31 import org.jboss.test.jrmp.interfaces.IString;
32
33 /**
34  * Test of RMI dynamic class loading from a sar.
35  *
36  * @author adrian@jboss.com
37  * @version $Revision: 37406 $
38  */

39 public class DynLoadingFromSARUnpackedUnitTestCase extends JBossTestCase
40 {
41    public DynLoadingFromSARUnpackedUnitTestCase(String JavaDoc name)
42    {
43       super(name);
44    }
45
46    /**
47     * A unit test for JUnit
48     *
49     * @exception Exception Description of Exception
50     */

51    public void testAccess() throws Exception JavaDoc
52    {
53       InitialContext JavaDoc jndiContext = new InitialContext JavaDoc();
54       getLog().debug("Lookup IString");
55       Object JavaDoc obj = jndiContext.lookup("test/jrmp/IString");
56       IString echo = (IString) obj;
57       getLog().debug("found = " + echo);
58       Class JavaDoc clazz = echo.getClass();
59       CodeSource JavaDoc cs = clazz.getProtectionDomain().getCodeSource();
60       URL JavaDoc location = cs.getLocation();
61       getLog().debug("IString.class = " + clazz);
62       getLog().debug("IString.class location = " + location);
63       assertTrue("CodeSource URL.protocol != file", location.getProtocol().equals("file") == false);
64    }
65
66    /**
67     * Remove any local IString implementation so that we test RMI class loading.
68     *
69     * @exception Exception Description of Exception
70     */

71    protected void setUp() throws Exception JavaDoc
72    {
73       super.setUp();
74       URL JavaDoc istringImpl = getClass().getResource("/org/jboss/test/jrmp/ejb/AString.class");
75       if (istringImpl != null)
76       {
77          getLog().debug("Found IString impl at: " + istringImpl);
78          File JavaDoc implFile = new File JavaDoc(istringImpl.getFile());
79          getLog().debug("Removed: " + implFile.delete());
80       }
81       deploy("jrmp-dl-unpacked.sar");
82    }
83
84    /**
85     * The teardown method for JUnit
86     *
87     * @exception Exception Description of Exception
88     */

89    protected void tearDown() throws Exception JavaDoc
90    {
91       undeploy("jrmp-dl-unpacked.sar");
92       super.tearDown();
93    }
94
95 }
96
Popular Tags