Search in sources :

Example 11 with Animal

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

Example 12 with Animal

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]);
}
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 13 with Animal

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

Example 14 with Animal

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

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