Search in sources :

Example 1 with NutIoc

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

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

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

the class SimpleJsonIocTest method test_null_json_file.

@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);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) IocLoader(org.nutz.ioc.IocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 4 with NutIoc

use of org.nutz.ioc.impl.NutIoc 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 5 with NutIoc

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

the class AnnotationIocLoaderTest method test_ioc_inject_by_setter.

@Test
public void test_ioc_inject_by_setter() throws ObjectLoadException {
    AnnotationIocLoader loader = new AnnotationIocLoader(getClass().getPackage().getName());
    Logs.get().error(loader.load(null, "issue1060"));
    NutIoc ioc = new NutIoc(loader);
    // 放个假的
    ioc.getIocContext().save("app", "dao", new ObjectProxy(new NutDao()));
    ioc.get(Issue1060.class);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) NutDao(org.nutz.dao.impl.NutDao) ObjectProxy(org.nutz.ioc.ObjectProxy) Test(org.junit.Test)

Aggregations

NutIoc (org.nutz.ioc.impl.NutIoc)20 Test (org.junit.Test)16 Ioc (org.nutz.ioc.Ioc)10 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 MapLoader (org.nutz.ioc.loader.map.MapLoader)6 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)4 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 ScopeContext (org.nutz.ioc.impl.ScopeContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 NutDao (org.nutz.dao.impl.NutDao)1 Pet (org.nutz.dao.test.meta.Pet)1 IocMaking (org.nutz.ioc.IocMaking)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 ValueProxy (org.nutz.ioc.ValueProxy)1 ValueProxyMaker (org.nutz.ioc.ValueProxyMaker)1 ComboContext (org.nutz.ioc.impl.ComboContext)1