/* 
 * This java source file is placed into the public domain.
 * 
 * The orginal author is Ceki Gulcu, QOS.ch
 * 
 * THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND, NOT EVEN
 * THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE,
 * ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE RESULTING FROM THE
 * USE, MODIFICATION, OR REDISTRIBUTION OF THIS SOFTWARE.
 */
package ch.qos.test;

import java.net.URL;
import java.net.URLClassLoader;

import box.Box;

/**
 * A small application verifying that <code>URLClassLoader</code> delegates
 * parent-first as expected.
 * 
 * This test assumes that the application is launched with box0.jar on the classpath. 
 * For example, with the following command:
 * 
 *  java -cp boxAPI.jar;box0.jar;classes ch.qos.test.ParentFirstTest
 * 
 * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
 */
public class ParentFirstTest {

	public static void main(String[] args) throws Exception {
		
		// Create a class loader whose parent will be the class loader which loaded
		// the application (i.e. the application class loader).
		URLClassLoader childClassLoader = new URLClassLoader(new URL[] { new URL("file:box1.jar") });
		
		// should load using the parent, that is from the 'box0.jar' file
		Class boxClass = childClassLoader.loadClass("box.BoxImpl");
		
		Box box = (Box) boxClass.newInstance();
		System.out.println(box);
		if(box.get() != 0) {
			throw new Exception("Wrong version. Expecting 0 but got "+box.get());
		}
	}
}
