Package org.nutz.ioc

Examples of org.nutz.ioc.Ioc


public class AopJsonIocTest {

  @Test
  public void test_simple() {
    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();
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

  }

  @Test
  public void test_null_json_file() {
    IocLoader loader = new JsonLoader("org/nutz/ioc/json/empty.js");
    Ioc ioc = new NutIoc(loader);
    assertEquals(0, ioc.getNames().length);
  }
View Full Code Here

    assertEquals(AnimalRace.MAMMAL, a.getRace());
  }

  @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

    assertFalse(f3 == f4);
  }

  @Test
  public void test_refer() {
    Ioc ioc = I(J("fox", "type:'org.nutz.ioc.json.pojo.Animal',fields:{name:'Fox'}"),
          J("rabit", "name:'Rabit',enemies:[{refer:'fox'},{refer:'fox'}]"));
    Animal r = ioc.get(Animal.class, "rabit");
    Animal f = ioc.get(Animal.class, "fox");
    assertEquals(2, r.getEnemies().length);
    assertTrue(f == r.getEnemies()[0]);
    assertTrue(f == r.getEnemies()[1]);
    assertEquals("Fox", f.getName());
    assertEquals("Rabit", r.getName());
View Full Code Here

    assertEquals("Rabit", r.getName());
  }

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

    assertEquals("BBB", f.getRelations().get("b").getName());
  }

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

    assertEquals(3, fox.getAge());
  }

  @Test
  public void test_java_with_arguments() {
    Ioc ioc = I(J("fox", "name:'Fox',age:10"),
          J("wolf", "name:{java:'$fox.showName(\"_\", 2, \"W\")'},age:{java:'$fox.age'}"));
    Animal fox = ioc.get(Animal.class, "fox");
    Animal wolf = ioc.get(Animal.class, "wolf");
    assertEquals("Fox", fox.getName());
    assertEquals(fox.getAge(), wolf.getAge());
    assertEquals("__W", wolf.getName());
  }
View Full Code Here

    assertEquals("__W", wolf.getName());
  }

  @Test
  public void test_parent() {
    Ioc ioc = I(J("fox", "name:'P',age:10"), J("f2", "parent:'fox',fields:{age:5}"));
    Animal fox = ioc.get(Animal.class, "fox");
    assertEquals("P", fox.getName());
    assertEquals(10, fox.getAge());
    Animal f2 = ioc.get(Animal.class, "f2");
    assertEquals("P", f2.getName());
    assertEquals(5, f2.getAge());
  }
View Full Code Here

    assertEquals(5, f2.getAge());
  }

  @Test
  public void test_muilt_parent() {
    Ioc ioc = I(J("fox", "name:'P',age:10"), J("f2", "parent:'fox'"), J("f3", "parent:'f2'"));
    Animal f3 = ioc.get(Animal.class, "f3");
    assertEquals(10, f3.getAge());
  }
View Full Code Here

TOP

Related Classes of org.nutz.ioc.Ioc

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.