/* 
 * 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 ch.qos.ChildFirstClassLoader;

import box.Box;

/**
 * A small application verifying that the <code>ChildFirstClassLoader</code>
 * follows the child=first delegation model.
 * 
 * This test assumes that the box0.jar is on the java classpath. For example, 
 * that the application is run with the following command:
 * 
 *  java -cp boxAPI.jar;box0.jar;classes ch.qos.test.ChildFirstTest
 * 
 * @author <a href="http://www.qos.ch/log4j/">Ceki G&uuml;lc&uuml;</a>
 */
public class ChildFirstTest {

	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).
		ChildFirstClassLoader childClassLoader = new ChildFirstClassLoader(new URL[0]);
		childClassLoader.addURL(new URL("file:box1.jar"));
		
		// should load using child class loader, that is from 'box1.jar'
		Class boxClass = childClassLoader.loadClass("box.BoxImpl");
		
		Box box = (Box) boxClass.newInstance();
		System.out.println(box);
		if(box.get() != 1) {
			throw new Exception("Wrong version. Expecting 1 but got "+box.get());
		}
	}
}
