Examples of Ioc


Examples of org.nutz.ioc.Ioc

    assertEquals(0, f.getDeposeTime());
  }

  @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

Examples of org.nutz.ioc.Ioc

    s += "b:{type:'org.nutz.ioc.json.RecurReferJsonIocTest$RB',";
    s += "fields:{nm:'B', ra:{refer:'a'}}";
    s += "}";
    s += "}";

    Ioc ioc = new NutIoc(new MapLoader(s));
    RA a = ioc.get(RA.class, "a");
    assertEquals("A", a.nm);
    assertEquals("B", a.rb.nm);

    RB b = ioc.get(RB.class, "b");
    assertEquals("A", b.ra.nm);
    assertEquals("B", b.nm);
  }
View Full Code Here

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

Examples of org.nutz.ioc.Ioc

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

Examples of org.nutz.ioc.Ioc

  }

  @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

Examples of org.nutz.ioc.Ioc

    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

Examples of org.nutz.ioc.Ioc

    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

Examples of org.nutz.ioc.Ioc

    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

Examples of org.nutz.ioc.Ioc

    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

Examples of org.nutz.ioc.Ioc

    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
TOP
Copyright © 2018 www.massapi.com. 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.