use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class SimpleJsonIocTest method test_java_simple.
@Test
public void test_java_simple() {
Ioc ioc = I(J("fox", "name:{java: '@Name.toUpperCase()'}, age:{java:'@Name.length()'}"));
Animal fox = ioc.get(Animal.class, "fox");
assertEquals("FOX", fox.getName());
assertEquals(3, fox.getAge());
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class AopJsonIocTest method test_simple.
@Test
public void test_simple() {
Nutzs.cd();
IocLoader il = new JsonLoader("org/nutz/ioc/json/aop.js");
Ioc ioc = new NutIoc(il);
StringBuilder sb = ioc.get(StringBuilder.class, "sb");
Mammal fox = ioc.get(Mammal.class, "fox");
assertEquals("Fox", fox.getName());
assertEquals("B:getName0;A:getName0;", sb.toString());
sb.delete(0, sb.length());
fox.getName();
fox.getName();
assertEquals("B:getName0;A:getName0;B:getName0;A:getName0;", sb.toString());
ioc.depose();
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class EvensJsonIocTest method test_events_for_un_singleton.
@Test
public void test_events_for_un_singleton() {
String s = "singleton:false, fields: {name:'Fox'},";
s = s + "\nevents:{";
s = s + "\n fetch: 'onFetch',";
s = s + "\n create: 'onCreate',";
s = s + "\n depose: 'onDepose'";
s = s + "\n}";
Ioc ioc = I(J("fox", s));
Animal f = ioc.get(Animal.class, "fox");
assertEquals(1, f.getCreateTime());
assertEquals(1, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.get(Animal.class, "fox");
assertEquals(1, f.getCreateTime());
assertEquals(1, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.reset();
assertEquals(1, f.getCreateTime());
assertEquals(1, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class EvensJsonIocTest method test_init_with_field.
@Test
public void test_init_with_field() {
String s = "fields: {name:'Fox'},";
s = s + "\nevents:{";
s = s + "\n create: 'org.nutz.ioc.json.pojo.WhenCreateFox'";
s = s + "\n}";
Ioc ioc = I(J("fox", s));
Animal fox = ioc.get(Animal.class, "fox");
assertEquals("$Fox", fox.getName());
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class EvensJsonIocTest method test_events_for_singleton.
@Test
public void test_events_for_singleton() {
String s = "fields: {name:'Fox'},";
s = s + "\nevents:{";
s = s + "\n fetch: 'onFetch',";
s = s + "\n create: 'onCreate',";
s = s + "\n depose: 'onDepose'";
s = s + "\n}";
Ioc ioc = I(J("fox", s));
Animal f = ioc.get(Animal.class, "fox");
assertEquals(1, f.getCreateTime());
assertEquals(1, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.get(Animal.class, "fox");
assertEquals(1, f.getCreateTime());
assertEquals(2, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.reset();
assertEquals(1, f.getCreateTime());
assertEquals(2, f.getFetchTime());
assertEquals(1, f.getDeposeTime());
}
Aggregations