Package org.nutz.ioc.json.pojo

Examples of org.nutz.ioc.json.pojo.Animal


    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());
  }
View Full Code Here


    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());
  }
View Full Code Here

    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());
  }
View Full Code Here

    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());
  }
View Full Code Here

    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());
  }
View Full Code Here

  }

  @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());
  }
View Full Code Here

  @Test
  public void test_simple_scope() {
    Ioc2 ioc = IJ("f1", "scope:'app',fields:{name:'F1'}"),
            J("f2", "scope:'MyScope',fields:{name:'F2'}"));

    Animal f1 = ioc.get(Animal.class, "f1");
    assertEquals("F1", f1.getName());

    Animal f2 = ioc.get(Animal.class, "f2");
    assertEquals("F2", f2.getName());
    Animal f22 = ioc.get(Animal.class, "f2");
    assertEquals("F2", f22.getName());
    assertFalse(f2 == f22);

    ScopeContext ic = new ScopeContext("MyScope");
    Map<String, ObjectProxy> map = ic.getObjs();
    f2 = ioc.get(Animal.class, "f2", ic);
    assertEquals("F2", f2.getName());
    f22 = ioc.get(Animal.class, "f2", ic);
    assertEquals("F2", f22.getName());
    assertTrue(f2 == f22);
    assertEquals(1, map.size());

    ioc.get(Animal.class, "f1", ic);
View Full Code Here

public class SimpleJsonIocTest {

  @Test
  public void test_refer_self() {
    Ioc ioc = I(J("fox", "name:'Fox',another:{refer:'fox'}"));
    Animal f = ioc.get(Animal.class, "fox");
    assertEquals("Fox", f.getName());
    assertTrue(f == f.getAnother());
  }
View Full Code Here

    assertEquals(0, ioc.getNames().length);
  }

  @Test
  public void test_normal() {
    Animal a = A("age:23,name:'monkey',race:'MAMMAL'");
    assertEquals(23, a.getAge());
    assertEquals("monkey", a.getName());
    assertEquals(AnimalRace.MAMMAL, a.getRace());
  }
View Full Code Here

  }

  @Test
  public void test_singleon() {
    Ioc ioc = I(J("fox", "name:'Fox'"));
    Animal f = ioc.get(Animal.class, "fox");
    Animal f2 = ioc.get(Animal.class, "fox");
    assertTrue(f == f2);

    ioc = I(J("fox", "singleton:false, fields: {name:'Fox'}"));
    Animal f3 = ioc.get(Animal.class, "fox");
    Animal f4 = ioc.get(Animal.class, "fox");
    assertFalse(f3 == f4);
  }
View Full Code Here

TOP

Related Classes of org.nutz.ioc.json.pojo.Animal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.