Search in sources :

Example 1 with MapLoader

use of org.nutz.ioc.loader.map.MapLoader 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 MapLoader

use of org.nutz.ioc.loader.map.MapLoader in project nutz by nutzam.

the class IocCustomizedValueTypeTest method test_simple_customized.

@Test
public void test_simple_customized() {
    String json = "{xb:{name:{cc:'XiaoBai'}}}";
    Ioc2 ioc = new NutIoc(new MapLoader(json));
    ioc.addValueProxyMaker(new ValueProxyMaker() {

        public ValueProxy make(IocMaking ing, IocValue iv) {
            if ("cc".equalsIgnoreCase(iv.getType())) {
                return new StaticValue("CC:" + iv.getValue());
            }
            return null;
        }

        public String[] supportedTypes() {
            return Lang.array("cc");
        }
    });
    Pet pet = ioc.get(Pet.class, "xb");
    assertEquals("CC:XiaoBai", pet.getName());
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) MapLoader(org.nutz.ioc.loader.map.MapLoader) IocMaking(org.nutz.ioc.IocMaking) ValueProxy(org.nutz.ioc.ValueProxy) ValueProxyMaker(org.nutz.ioc.ValueProxyMaker) IocValue(org.nutz.ioc.meta.IocValue) Ioc2(org.nutz.ioc.Ioc2) Pet(org.nutz.dao.test.meta.Pet) Test(org.junit.Test)

Example 3 with MapLoader

use of org.nutz.ioc.loader.map.MapLoader in project nutz by nutzam.

the class Utils method I.

static Ioc2 I(String... ss) {
    String json = "{";
    json += Lang.concat(',', ss);
    json += "}";
    return new NutIoc(new MapLoader(json));
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) MapLoader(org.nutz.ioc.loader.map.MapLoader)

Example 4 with MapLoader

use of org.nutz.ioc.loader.map.MapLoader 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 5 with MapLoader

use of org.nutz.ioc.loader.map.MapLoader in project nutz by nutzam.

the class RecurReferJsonIocTest method test_refer_each_other.

@Test
public void test_refer_each_other() {
    String s = "{";
    s += "a:{type:'org.nutz.ioc.json.RecurReferJsonIocTest$RA',";
    s += "fields:{nm:'A', rb:{refer:'b'}}";
    s += "},";
    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);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) MapLoader(org.nutz.ioc.loader.map.MapLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Aggregations

NutIoc (org.nutz.ioc.impl.NutIoc)6 MapLoader (org.nutz.ioc.loader.map.MapLoader)6 Test (org.junit.Test)5 Ioc2 (org.nutz.ioc.Ioc2)3 Ioc (org.nutz.ioc.Ioc)2 IocContext (org.nutz.ioc.IocContext)2 ScopeContext (org.nutz.ioc.impl.ScopeContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Pet (org.nutz.dao.test.meta.Pet)1 IocMaking (org.nutz.ioc.IocMaking)1 ValueProxy (org.nutz.ioc.ValueProxy)1 ValueProxyMaker (org.nutz.ioc.ValueProxyMaker)1 ComboContext (org.nutz.ioc.impl.ComboContext)1 IocTO00 (org.nutz.ioc.json.pojo.IocTO00)1 IocValue (org.nutz.ioc.meta.IocValue)1 NutMap (org.nutz.lang.util.NutMap)1