Search in sources :

Example 6 with Animal

use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.

the class SimpleJsonIocTest method test_sys.

@Test
public void test_sys() {
    Properties properties = System.getProperties();
    properties.put("sysA", "XX");
    properties.put("sysP", "ZZZ");
    Animal f = A("name:{sys:'sysA'},misc:[{sys:'sysP'}]");
    assertEquals("XX", f.getName());
    assertEquals("ZZZ", f.getMisc().get(0).toString());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with Animal

use of org.nutz.ioc.json.pojo.Animal in project nutz by nutzam.

the class SimpleJsonIocTest method test_file.

@Test
public void test_file() {
    Animal f = A("misc:[{file:'org/nutz/ioc/json/pojo/Animal.class'}]");
    assertEquals("Animal.class", ((File) f.getMisc().get(0)).getName());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Test(org.junit.Test)

Example 8 with Animal

use of org.nutz.ioc.json.pojo.Animal 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 Animal

use of org.nutz.ioc.json.pojo.Animal 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 Animal

use of org.nutz.ioc.json.pojo.Animal 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

Test (org.junit.Test)25 Animal (org.nutz.ioc.json.pojo.Animal)25 Ioc (org.nutz.ioc.Ioc)15 NutIoc (org.nutz.ioc.impl.NutIoc)15 Properties (java.util.Properties)1 Ioc2 (org.nutz.ioc.Ioc2)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 ScopeContext (org.nutz.ioc.impl.ScopeContext)1 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)1