use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class SimpleJsonIocTest method test_map.
@Test
public void test_map() {
Animal f = A("map : {asia:34, europe: 45}");
assertEquals(34, f.getMap().get("asia").intValue());
assertEquals(45, f.getMap().get("europe").intValue());
f = A("relations: {a: {type:'org.nutz.ioc.json.pojo.Animal', fields: {name:'AAA'}}" + ",b: {type:'org.nutz.ioc.json.pojo.Animal', fields: {name:'BBB'}}}");
assertEquals(2, f.getRelations().size());
assertEquals("AAA", f.getRelations().get("a").getName());
assertEquals("BBB", f.getRelations().get("b").getName());
}
use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class SimpleJsonIocTest method test_array_and_refer.
@Test
public void test_array_and_refer() {
Ioc ioc = I(J("fox", "name:'Fox'"), J("rabit", "name:'Rabit',enemies:[{refer:'fox:org.nutz.ioc.json.pojo.Animal'},null]"));
Animal r = ioc.get(Animal.class, "rabit");
Animal f = ioc.get(Animal.class, "fox");
assertEquals(2, r.getEnemies().length);
assertTrue(f == r.getEnemies()[0]);
assertEquals("Fox", f.getName());
assertEquals("Rabit", r.getName());
assertNull(r.getEnemies()[1]);
}
use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.
the class EvensJsonIocTest method test_event_from_parent.
@Test
public void test_event_from_parent() {
Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/json/events.js"));
Animal f = ioc.get(Animal.class, "fox");
assertEquals(1, f.getCreateTime());
assertEquals(1, f.getFetchTime());
assertEquals(0, f.getDeposeTime());
ioc.depose();
assertEquals(1, f.getCreateTime());
assertEquals(1, f.getFetchTime());
assertEquals(1, f.getDeposeTime());
}
use of org.nutz.ioc.json.pojo.Animal 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.json.pojo.Animal 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());
}
Aggregations