KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > util > classes > v1 > IUrlClassLoaderOnlineUTestI


1 /*
2  * @(#)IUrlClassLoaderOnlineUTestI.java
3  *
4  * Copyright (C) 2001,2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  */

26
27 package net.sourceforge.groboutils.util.classes.v1;
28
29 import net.sourceforge.groboutils.junit.v1.iftc.*;
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34
35 /**
36  * Just like util.http.tests, this uses the Sourceforge account to ensure
37  * that the URLs work correctly. It loads the sample applet "BeliefOfTheDay"
38  * to make sure that this is able to load classes remotely.
39  * As insurance, this also tests to make sure that the same applet is not
40  * in the current classpath.
41  * <P>
42  * The system must have access to the internet to correctly run this test.
43  *
44  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
45  * @version $Date: 2003/05/06 05:35:01 $
46  * @since May 23, 2001 (GroboUtils Alpha 0.9.0)
47  */

48 public class IUrlClassLoaderOnlineUTestI extends InterfaceTestCase
49 {
50     private static final Class JavaDoc THIS_CLASS = IUrlClassLoaderOnlineUTestI.class;
51     
52     public IUrlClassLoaderOnlineUTestI( String JavaDoc name, ImplFactory f )
53     {
54         super( name, IUrlClassLoader.class, f );
55     }
56
57     
58     public IUrlClassLoader createLoader()
59     {
60         return (IUrlClassLoader)createImplObject();
61     }
62     
63     
64     public static InterfaceTestSuite suite()
65     {
66         InterfaceTestSuite suite = new InterfaceTestSuite( THIS_CLASS );
67         
68         return suite;
69     }
70     
71     //-------------------------------------------------------------------------
72

73     protected void setUp() throws Exception JavaDoc
74     {
75         super.setUp();
76         
77         // set ourself up
78
}
79     
80     
81     protected void tearDown() throws Exception JavaDoc
82     {
83         // tear ourself down
84

85         super.tearDown();
86     }
87
88     
89     public void testInstantiate()
90     {
91         assertNotNull( "Creation should not return null.",
92             createLoader() );
93     }
94     
95     
96     public static final String JavaDoc BELIEF_CLASS = "BeliefOfTheDay";
97     public static final String JavaDoc BELIEF_JAR =
98         "http://groboutils.sourceforge.net/Belief.jar";
99     
100     public static class InnerClass
101     {
102         public InnerClass()
103         {
104             // do nothing
105
}
106     }
107     
108     
109     public void testGetClass1()
110     {
111         IUrlClassLoader loader = createLoader();
112         
113         Class JavaDoc c = loader.loadClass( this.getClass().getName(), null );
114         assertNotNull( "loadClass( "+this.getClass().getName()+
115             " ) returned null.",
116             c );
117         assertEquals( "Did not load the class from the default classloader.",
118             this.THIS_CLASS, c );
119         
120         c = loader.loadClass( BELIEF_CLASS, null );
121         assertEquals(
122             "getClass( Belief ) was found in the default classloader.",
123             null, c );
124     }
125     
126     
127     public void testGetClass2()
128     {
129         IUrlClassLoader loader = createLoader();
130         
131         Class JavaDoc c = loader.loadClass( BELIEF_CLASS, BELIEF_JAR );
132         assertNotNull( "getClass( "+BELIEF_CLASS+" ) returned null.", c );
133         assertEquals( "getClass( "+BELIEF_CLASS+" ) returned the wrong class.",
134             BELIEF_CLASS, c.getName() );
135     }
136     
137     
138     public void testFlush()
139     {
140         IUrlClassLoader loader = createLoader();
141         
142         Class JavaDoc c = loader.loadClass( this.getClass().getName(), null );
143         loader.flush();
144         
145         // Can't really test this for correctness, just for error throwing.
146
// Testing for GC size is really inaccurate.
147
}
148     
149 }
150
Popular Tags