Search in sources :

Example 16 with Animal

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

the class ScopeJsonIocTest method test_simple_scope.

@Test
public void test_simple_scope() {
    Ioc2 ioc = I(J("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);
    assertEquals(1, map.size());
}
Also used : ScopeContext(org.nutz.ioc.impl.ScopeContext) Animal(org.nutz.ioc.json.pojo.Animal) Ioc2(org.nutz.ioc.Ioc2) ObjectProxy(org.nutz.ioc.ObjectProxy) Test(org.junit.Test)

Example 17 with Animal

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

the class SimpleJsonIocTest method test_create_by_args.

@Test
public void test_create_by_args() {
    Ioc ioc = I(J("fox", "age:10"), J("xb", "parent:'fox',args:['XiaoBai']"));
    Animal xb = ioc.get(Animal.class, "xb");
    assertEquals("XiaoBai", xb.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 18 with Animal

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

the class SimpleJsonIocTest method test_java_with_arguments.

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

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

the class SimpleJsonIocTest method test_sys_list.

@Test
public void test_sys_list() {
    Animal f = A("name:{sys:['/tmp/','PATH', '/wendal']},misc:[{sys:['PATH', '/' , 'os.name', '/zozoh']}]");
    assertTrue(f.getName().length() > 0);
    assertTrue(f.getName().contains("/wendal"));
    assertTrue(f.getName().contains("/tmp"));
    assertTrue(f.getMisc().get(0).toString().endsWith("/zozoh"));
}
Also used : Animal(org.nutz.ioc.json.pojo.Animal) Test(org.junit.Test)

Example 20 with Animal

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

the class SimpleJsonIocTest method test_java_neg.

@Test
public void test_java_neg() {
    Animal f = A("name:{java:'org.nutz.ioc.json.pojo.JavaValueTest.abc(\"/tmp/\", -1)'}");
    assertTrue(f.getName().length() > 0);
    System.out.println(f.getName());
    assertTrue(f.getName().equals("/tmp/,-1"));
}
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