use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class ScopeJsonIocTest method test_simple_scope.
@Test
public void test_simple_scope() {
Ioc2 ioc = I(J("f1", "scope:'app',fields:{name:'F1'}"), J("f2", "scope:'MyScope',fields:{name:'F2'}"));
Animal f1 = ioc.get(Animal.class, "f1");
assertEquals("F1", f1.getName());
Animal f2 = ioc.get(Animal.class, "f2");
assertEquals("F2", f2.getName());
Animal f22 = ioc.get(Animal.class, "f2");
assertEquals("F2", f22.getName());
assertFalse(f2 == f22);
ScopeContext ic = new ScopeContext("MyScope");
Map<String, ObjectProxy> map = ic.getObjs();
f2 = ioc.get(Animal.class, "f2", ic);
assertEquals("F2", f2.getName());
f22 = ioc.get(Animal.class, "f2", ic);
assertEquals("F2", f22.getName());
assertTrue(f2 == f22);
assertEquals(1, map.size());
ioc.get(Animal.class, "f1", ic);
assertEquals(1, map.size());
}
use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class SimpleJsonIocTest method test_create_by_args.
@Test
public void test_create_by_args() {
Ioc ioc = I(J("fox", "age:10"), J("xb", "parent:'fox',args:['XiaoBai']"));
Animal xb = ioc.get(Animal.class, "xb");
assertEquals("XiaoBai", xb.getName());
}
use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class SimpleJsonIocTest method test_java_with_arguments.
@Test
public void test_java_with_arguments() {
Ioc ioc = I(J("fox", "name:'Fox',age:10"), J("wolf", "name:{java:'$fox.showName(\"_\", 2, \"W\")'},age:{java:'$fox.age'}"));
Animal fox = ioc.get(Animal.class, "fox");
Animal wolf = ioc.get(Animal.class, "wolf");
assertEquals("Fox", fox.getName());
assertEquals(fox.getAge(), wolf.getAge());
assertEquals("__W", wolf.getName());
}
use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class SimpleJsonIocTest method test_sys_list.
@Test
public void test_sys_list() {
Animal f = A("name:{sys:['/tmp/','PATH', '/wendal']},misc:[{sys:['PATH', '/' , 'os.name', '/zozoh']}]");
assertTrue(f.getName().length() > 0);
assertTrue(f.getName().contains("/wendal"));
assertTrue(f.getName().contains("/tmp"));
assertTrue(f.getMisc().get(0).toString().endsWith("/zozoh"));
}
use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class SimpleJsonIocTest method test_java_neg.
@Test
public void test_java_neg() {
Animal f = A("name:{java:'org.nutz.ioc.json.pojo.JavaValueTest.abc(\"/tmp/\", -1)'}");
assertTrue(f.getName().length() > 0);
System.out.println(f.getName());
assertTrue(f.getName().equals("/tmp/,-1"));
}
Aggregations