use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class EvensJsonIocTest method test_events_by_trigger_for_singleton.
@Test
public void test_events_by_trigger_for_singleton() {
String s = "fields: {name:'Fox'},";
s = s + "\nevents:{";
s = s + "\n fetch: 'org.nutz.ioc.json.pojo.WhenFetchAnimal',";
s = s + "\n create: 'org.nutz.ioc.json.pojo.WhenCreateAnimal',";
s = s + "\n depose: 'org.nutz.ioc.json.pojo.WhenDeposeAnimal'";
s = s + "\n}";
Ioc ioc = I(J("fox", s));
Animal f = ioc.get(Animal.class, "fox");
assertEquals(10, f.getCreateTime());
assertEquals(10, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.get(Animal.class, "fox");
assertEquals(10, f.getCreateTime());
assertEquals(20, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.reset();
assertEquals(10, f.getCreateTime());
assertEquals(20, f.getFetchTime());
assertEquals(10, f.getDeposeTime());
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class EvensJsonIocTest method test_events_by_trigger_for_un_singleton.
@Test
public void test_events_by_trigger_for_un_singleton() {
String s = "singleton:false, fields: {name:'Fox'},";
s = s + "\nevents:{";
s = s + "\n fetch: 'org.nutz.ioc.json.pojo.WhenFetchAnimal',";
s = s + "\n create: 'org.nutz.ioc.json.pojo.WhenCreateAnimal',";
s = s + "\n depose: 'org.nutz.ioc.json.pojo.WhenDeposeAnimal'";
s = s + "\n}";
Ioc ioc = I(J("fox", s));
Animal f = ioc.get(Animal.class, "fox");
assertEquals(10, f.getCreateTime());
assertEquals(10, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.get(Animal.class, "fox");
assertEquals(10, f.getCreateTime());
assertEquals(10, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.reset();
assertEquals(10, f.getCreateTime());
assertEquals(10, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class RecurReferJsonIocTest method test_refer_each_other.
@Test
public void test_refer_each_other() {
String s = "{";
s += "a:{type:'org.nutz.ioc.json.RecurReferJsonIocTest$RA',";
s += "fields:{nm:'A', rb:{refer:'b'}}";
s += "},";
s += "b:{type:'org.nutz.ioc.json.RecurReferJsonIocTest$RB',";
s += "fields:{nm:'B', ra:{refer:'a'}}";
s += "}";
s += "}";
Ioc ioc = new NutIoc(new MapLoader(s));
RA a = ioc.get(RA.class, "a");
assertEquals("A", a.nm);
assertEquals("B", a.rb.nm);
RB b = ioc.get(RB.class, "b");
assertEquals("A", b.ra.nm);
assertEquals("B", b.nm);
ioc.depose();
}
use of org.nutz.ioc.Ioc in project nutz by nutzam.
the class SimpleJsonIocTest method test_2darray_by_map_iocvalue.
@Test
public void test_2darray_by_map_iocvalue() {
Map<String, Map<String, Object>> map = new HashMap<String, Map<String, Object>>();
Map<String, Object> objMap = new HashMap<String, Object>();
String[][] strss = new String[2][2];
strss[0][0] = "a";
strss[0][1] = "b";
strss[1][0] = "c";
strss[1][1] = "d";
objMap.put("args", new Object[] { strss });
map.put("obj", objMap);
Ioc ioc = new NutIoc(new MapLoader(map));
IocTO00 obj = ioc.get(IocTO00.class, "obj");
assertEquals(2, obj.getStrss().length);
assertEquals(2, obj.getStrss()[0].length);
assertEquals("a", obj.getStrss()[0][0]);
assertEquals("b", obj.getStrss()[0][1]);
assertEquals("c", obj.getStrss()[1][0]);
assertEquals("d", obj.getStrss()[1][1]);
ioc.depose();
}
use of org.nutz.ioc.Ioc 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());
}
Aggregations