001: /*
002: * @(#)IUrlClassLoaderOnlineUTestI.java
003: *
004: * Copyright (C) 2001,2002-2003 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.util.classes.v1;
028:
029: import net.sourceforge.groboutils.junit.v1.iftc.*;
030: import junit.framework.Test;
031: import junit.framework.TestCase;
032: import junit.framework.TestSuite;
033:
034: /**
035: * Just like util.http.tests, this uses the Sourceforge account to ensure
036: * that the URLs work correctly. It loads the sample applet "BeliefOfTheDay"
037: * to make sure that this is able to load classes remotely.
038: * As insurance, this also tests to make sure that the same applet is not
039: * in the current classpath.
040: * <P>
041: * The system must have access to the internet to correctly run this test.
042: *
043: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
044: * @version $Date: 2003/05/06 05:35:01 $
045: * @since May 23, 2001 (GroboUtils Alpha 0.9.0)
046: */
047: public class IUrlClassLoaderOnlineUTestI extends InterfaceTestCase {
048: private static final Class THIS_CLASS = IUrlClassLoaderOnlineUTestI.class;
049:
050: public IUrlClassLoaderOnlineUTestI(String name, ImplFactory f) {
051: super (name, IUrlClassLoader.class, f);
052: }
053:
054: public IUrlClassLoader createLoader() {
055: return (IUrlClassLoader) createImplObject();
056: }
057:
058: public static InterfaceTestSuite suite() {
059: InterfaceTestSuite suite = new InterfaceTestSuite(THIS_CLASS);
060:
061: return suite;
062: }
063:
064: //-------------------------------------------------------------------------
065:
066: protected void setUp() throws Exception {
067: super .setUp();
068:
069: // set ourself up
070: }
071:
072: protected void tearDown() throws Exception {
073: // tear ourself down
074:
075: super .tearDown();
076: }
077:
078: public void testInstantiate() {
079: assertNotNull("Creation should not return null.",
080: createLoader());
081: }
082:
083: public static final String BELIEF_CLASS = "BeliefOfTheDay";
084: public static final String BELIEF_JAR = "http://groboutils.sourceforge.net/Belief.jar";
085:
086: public static class InnerClass {
087: public InnerClass() {
088: // do nothing
089: }
090: }
091:
092: public void testGetClass1() {
093: IUrlClassLoader loader = createLoader();
094:
095: Class c = loader.loadClass(this .getClass().getName(), null);
096: assertNotNull("loadClass( " + this .getClass().getName()
097: + " ) returned null.", c);
098: assertEquals(
099: "Did not load the class from the default classloader.",
100: this .THIS_CLASS, c);
101:
102: c = loader.loadClass(BELIEF_CLASS, null);
103: assertEquals(
104: "getClass( Belief ) was found in the default classloader.",
105: null, c);
106: }
107:
108: public void testGetClass2() {
109: IUrlClassLoader loader = createLoader();
110:
111: Class c = loader.loadClass(BELIEF_CLASS, BELIEF_JAR);
112: assertNotNull(
113: "getClass( " + BELIEF_CLASS + " ) returned null.", c);
114: assertEquals("getClass( " + BELIEF_CLASS
115: + " ) returned the wrong class.", BELIEF_CLASS, c
116: .getName());
117: }
118:
119: public void testFlush() {
120: IUrlClassLoader loader = createLoader();
121:
122: Class c = loader.loadClass(this .getClass().getName(), null);
123: loader.flush();
124:
125: // Can't really test this for correctness, just for error throwing.
126: // Testing for GC size is really inaccurate.
127: }
128:
129: }
|