Search in sources :

Example 1 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader 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 2 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class AopJsonIocTest method test_simple.

@Test
public void test_simple() {
    Nutzs.cd();
    IocLoader il = new JsonLoader("org/nutz/ioc/json/aop.js");
    Ioc ioc = new NutIoc(il);
    StringBuilder sb = ioc.get(StringBuilder.class, "sb");
    Mammal fox = ioc.get(Mammal.class, "fox");
    assertEquals("Fox", fox.getName());
    assertEquals("B:getName0;A:getName0;", sb.toString());
    sb.delete(0, sb.length());
    fox.getName();
    fox.getName();
    assertEquals("B:getName0;A:getName0;B:getName0;A:getName0;", sb.toString());
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Mammal(org.nutz.ioc.json.pojo.Mammal) 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 3 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class Nutzs method getIoc.

public static Ioc getIoc(String key) {
    Ioc nut = nuts.get(key);
    if (null == nut) {
        synchronized (Nutzs.class) {
            nut = nuts.get(key);
            try {
                if (null == nut) {
                    nut = new NutIoc(new JsonLoader(key));
                    nuts.put(key, nut);
                }
            } catch (Exception e) {
                throw Lang.wrapThrow(e);
            }
        }
    }
    return nut;
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc)

Example 4 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class PlugsTest method test_get_plugin_from_ioc.

@Test
public void test_get_plugin_from_ioc() {
    Ioc ioc = new NutIoc(new JsonLoader("org/nutz/plugin/plugin.js"));
    PluginManager<Log> manager = new IocPluginManager<Log>(ioc, "pluB", "pluA", "pluC");
    assertNotNull(manager.get());
    assertTrue(manager.get() instanceof SystemLogAdapter);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Log(org.nutz.log.Log) SystemLogAdapter(org.nutz.log.impl.SystemLogAdapter) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 5 with JsonLoader

use of org.nutz.ioc.loader.json.JsonLoader in project nutz by nutzam.

the class JsonAopConfigrationTest method test_jsonAop.

@Test
public void test_jsonAop() {
    Nutzs.cd();
    Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/aop/config/impl/jsonfile-aop.js"));
    Assert.assertTrue(ioc.getNames().length > 0);
    for (String name : ioc.getNames()) {
        ioc.get(null, name);
    }
    MyMI mi = ioc.get(MyMI.class, "myMI");
    assertTrue(mi.getTime() == 0);
    Pet2 pet2 = ioc.get(Pet2.class, "pet2");
    pet2.sing();
    assertTrue(mi.getTime() == 1);
    pet2.sing();
    assertTrue(mi.getTime() == 2);
    ioc.depose();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Aggregations

JsonLoader (org.nutz.ioc.loader.json.JsonLoader)9 Test (org.junit.Test)7 Ioc (org.nutz.ioc.Ioc)6 NutIoc (org.nutz.ioc.impl.NutIoc)6 IocLoader (org.nutz.ioc.IocLoader)5 AsyncAopIocLoader (org.nutz.aop.interceptor.async.AsyncAopIocLoader)1 TransIocLoader (org.nutz.aop.interceptor.ioc.TransIocLoader)1 ObjectLoadException (org.nutz.ioc.ObjectLoadException)1 Animal (org.nutz.ioc.json.pojo.Animal)1 Mammal (org.nutz.ioc.json.pojo.Mammal)1 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)1 PropertiesIocLoader (org.nutz.ioc.loader.properties.PropertiesIocLoader)1 XmlIocLoader (org.nutz.ioc.loader.xml.XmlIocLoader)1 IocObject (org.nutz.ioc.meta.IocObject)1 Log (org.nutz.log.Log)1 SystemLogAdapter (org.nutz.log.impl.SystemLogAdapter)1