Search in sources :

Example 6 with Ioc

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());
}
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 7 with Ioc

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

Example 8 with Ioc

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());
}
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 9 with Ioc

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());
}
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 10 with Ioc

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());
}
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