Search in sources :

Example 1 with ScopeContext

use of org.nutz.ioc.impl.ScopeContext in project nutz by nutzam.

the class DefaultValueTypes method test_el.

@Test
public void test_el() {
    IocContext context = new ScopeContext("abc");
    String json = "{obj:{type:'org.nutz.ioc.val.DefaultValueTypes', fields:{name:{el:'sys[\"os.arch\"]'}}}}";
    System.out.println(Json.toJson(Json.fromJson(json)));
    Ioc2 ioc = new NutIoc(new MapLoader(json), context, "abc");
    DefaultValueTypes self = ioc.get(DefaultValueTypes.class, "obj");
    assertEquals(System.getProperties().get("os.arch"), self.name);
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) IocContext(org.nutz.ioc.IocContext) ScopeContext(org.nutz.ioc.impl.ScopeContext) MapLoader(org.nutz.ioc.loader.map.MapLoader) Ioc2(org.nutz.ioc.Ioc2) Test(org.junit.Test)

Example 2 with ScopeContext

use of org.nutz.ioc.impl.ScopeContext in project nutz by nutzam.

the class ChainParsingTest method test_constants_context.

@Test
public void test_constants_context() {
    String s = "@Context.save('xx', 'tt', null)";
    ChainNode cn = N(s);
    assertEquals(s, cn.toString());
    IocMaking ing = new IocMaking(null, null, new ScopeContext("app"), null, null, null);
    assertFalse((Boolean) cn.eval(ing));
}
Also used : ScopeContext(org.nutz.ioc.impl.ScopeContext) IocMaking(org.nutz.ioc.IocMaking) Test(org.junit.Test)

Example 3 with ScopeContext

use of org.nutz.ioc.impl.ScopeContext in project nutz by nutzam.

the class DefaultValueTypes method test_refer_context.

@Test
public void test_refer_context() {
    IocContext context = new ScopeContext("abc");
    String json = "{obj:{singleton:false,fields:{ic:{refer:'$conText'}}}}";
    Ioc2 ioc = new NutIoc(new MapLoader(json), context, "abc");
    TestReferContext trc = ioc.get(TestReferContext.class);
    assertTrue(context == trc.ic);
    IocContext context2 = new ScopeContext("rrr");
    trc = ioc.get(TestReferContext.class, "obj", context2);
    assertTrue(trc.ic instanceof ComboContext);
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) ComboContext(org.nutz.ioc.impl.ComboContext) IocContext(org.nutz.ioc.IocContext) ScopeContext(org.nutz.ioc.impl.ScopeContext) MapLoader(org.nutz.ioc.loader.map.MapLoader) Ioc2(org.nutz.ioc.Ioc2) Test(org.junit.Test)

Example 4 with ScopeContext

use of org.nutz.ioc.impl.ScopeContext 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)

Aggregations

Test (org.junit.Test)4 ScopeContext (org.nutz.ioc.impl.ScopeContext)4 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 NutIoc (org.nutz.ioc.impl.NutIoc)2 MapLoader (org.nutz.ioc.loader.map.MapLoader)2 IocMaking (org.nutz.ioc.IocMaking)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 ComboContext (org.nutz.ioc.impl.ComboContext)1 Animal (org.nutz.ioc.json.pojo.Animal)1