Search in sources :

Example 21 with Animal

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

the class SimpleJsonIocTest method test_env_list.

@Test
public void test_env_list() {
    Animal f = A("name:{env:['java.tmp.file', '/wendal']},misc:[{env:['!PATH', '/' , 'os.name', '/zozoh']}]");
    assertTrue(f.getName().length() > 0);
    assertTrue(f.getName().contains("/wendal"));
    assertTrue(f.getMisc().get(0).toString().endsWith("/zozoh"));
    System.out.println(f.getName());
    System.out.println(f.getMisc().get(0));
    f = A("name:{env:['!JAVA_HOME:/opt/jdk6', '/bin/java']}");
    assertTrue(f.getName().contains("/bin/java"));
    assertTrue(f.getName().length() > "/bin/java".length());
    f = A("name:{env:['!ERR_JAVA_HOME:/opt/jdk6', '/bin/java']}");
    assertTrue(f.getName().contains("/bin/java"));
    assertTrue(f.getName().length() > "/bin/java".length());
    assertEquals("/opt/jdk6/bin/java", f.getName());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Test(org.junit.Test)

Example 22 with Animal

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

the class SimpleJsonIocTest method test_inner.

@Test
public void test_inner() {
    Animal f = A("enemies: [ {type:'org.nutz.ioc.json.pojo.Animal', fields: {name:'xxx'}} ]");
    assertEquals("xxx", f.getEnemies()[0].getName());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Test(org.junit.Test)

Example 23 with Animal

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

the class SimpleJsonIocTest method test_refer.

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

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

the class SimpleJsonIocTest method test_singleon.

@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);
}
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 25 with Animal

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

the class SimpleJsonIocTest method test_env.

@Test
public void test_env() {
    Animal f = A("name:{env:'PATH'},misc:[{env:'PATH'}]");
    assertTrue(f.getName().length() > 0);
    assertEquals(f.getName(), f.getMisc().get(0).toString());
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) 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