/*
* Created on Mar 4, 2005
*
* Author Ben Yu
* ZBS
*/
package tests.jfun.yan;
import java.util.HashMap;
import tests.jfun.models.CompositeBean;
import tests.jfun.models.MyBean;
import tests.jfun.models.Named;
import jfun.yan.Components;
import jfun.yan.containers.DefaultContainer;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Zephyr Business Solution
*
* @author Ben Yu
*
*/
public class ComponentTestCase extends TestCase {
public static void main(String[] args){
tests.jfun.yan.Utils.runTest(suite());
}
private static TestSuite suite(){
return new TestSuite(ComponentTestCase.class);
}
private static void verify(DefaultContainer cc){
final CompositeBean cb =
(CompositeBean)cc.getInstanceOfType(CompositeBean.class);
assertEquals("qian", cb.getName());
assertEquals(2, cb.getBeans().length);
assertEquals(true, ((tests.jfun.models.MyBean)cb.getBean()).is1());
}
public void test1(){
final DefaultContainer cc = new DefaultContainer();
final tests.jfun.models.MyBean[] arr = new tests.jfun.models.MyBean[2];
cc.registerComponent(CompositeBean.class,
Components.ctor(CompositeBean.class,
new Class[]{Named.class, tests.jfun.models.MyBean[].class, String.class})
.withArgument(1, Components.value(arr))
.singleton());
/*cc.registerConstructor(Named.class, MyBean.class,
new Class[]{int[].class, short.class, String.class, boolean.class,
java.util.Map.class});*/
cc.registerComponent(Named.class,
Components.static_method(MyBean.class, "instance")
.withArgument(1, Components.value(new Short((short)33)))
.withArgument(2, Components.value("jack"))
.singleton());
cc.registerValue(int[].class, new int[]{1,2,3});
/*
cc.registerParameter(Named.class, 1,
ComponentCreators.value(new Short((short)33)));*/
//cc.registerParameter(Named.class, 2, ComponentCreators.value("jack"));
cc.registerValue(boolean.class, Boolean.valueOf(true));
final HashMap hmap = new HashMap();
hmap.put("firstname", "Jack");
hmap.put("lastname", "Nicolson");
cc.registerValue(java.util.Map.class, hmap);
//cc.registerParameter(CompositeBean.class, 1, ComponentCreators.value(arr));
cc.registerValue(String.class, "qian");
verify(cc);
}
}