Search in sources :

Example 26 with Ioc

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());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 27 with Ioc

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());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 28 with Ioc

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) MapLoader(org.nutz.ioc.loader.map.MapLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 29 with Ioc

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) IocTO00(org.nutz.ioc.json.pojo.IocTO00) MapLoader(org.nutz.ioc.loader.map.MapLoader) HashMap(java.util.HashMap) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) HashMap(java.util.HashMap) Map(java.util.Map) NutMap(org.nutz.lang.util.NutMap) Test(org.junit.Test)

Example 30 with Ioc

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());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Aggregations

Ioc (org.nutz.ioc.Ioc)35 NutIoc (org.nutz.ioc.impl.NutIoc)29 Test (org.junit.Test)27 Animal (org.nutz.ioc.json.pojo.Animal)15 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 IocTO00 (org.nutz.ioc.json.pojo.IocTO00)2 MapLoader (org.nutz.ioc.loader.map.MapLoader)2 Stopwatch (org.nutz.lang.Stopwatch)2 LoadingException (org.nutz.mvc.LoadingException)2 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 HttpSession (javax.servlet.http.HttpSession)1 User (net.wendal.nutzdemo.bean.User)1 Dao (org.nutz.dao.Dao)1 ComboContext (org.nutz.ioc.impl.ComboContext)1