Search in sources :

Example 1 with IocLoader

use of org.nutz.ioc.IocLoader in project nutz by nutzam.

the class XmlIocLoaderTest method testXmlIocLoader.

@Test
public void testXmlIocLoader() throws ObjectLoadException {
    IocLoader iocLoader = getNew("org/nutz/ioc/loader/xml/conf/zzh-offered.xml");
    assertTrue(iocLoader.getName() != null);
    assertTrue(iocLoader.getName().length > 0);
    for (String name : iocLoader.getName()) {
        assertNotNull(name);
        assertNotNull(iocLoader.load(null, name));
        IocObject iocObject = iocLoader.load(null, name);
        if (iocObject.hasArgs()) {
            for (IocValue iocValue : iocObject.getArgs()) {
                iocValue.getType();
                iocValue.getValue();
                checkValue(iocValue);
            }
        }
        if (iocObject.getFields() != null) {
            for (IocField iocField : iocObject.getFields().values()) {
                assertNotNull(iocField.getName());
                if (iocField.getValue() != null) {
                    IocValue iocValue = iocField.getValue();
                    checkValue(iocValue);
                }
            }
        }
    }
    iocLoader.load(null, "obj").getFields().values().iterator().next().getValue().getValue();
}
Also used : IocValue(org.nutz.ioc.meta.IocValue) IocObject(org.nutz.ioc.meta.IocObject) IocLoader(org.nutz.ioc.IocLoader) IocField(org.nutz.ioc.meta.IocField) Test(org.junit.Test)

Example 2 with IocLoader

use of org.nutz.ioc.IocLoader 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 3 with IocLoader

use of org.nutz.ioc.IocLoader 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 4 with IocLoader

use of org.nutz.ioc.IocLoader in project nutz by nutzam.

the class ComboIocLoader method toString.

// TODO 这个方法好好整理一下 ...
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("/*ComboIocLoader*/\n{");
    for (IocLoader loader : iocLoaders) {
        String str = Json.toJson(loader);
        // 肯定有!!
        str = str.replaceFirst("[{]", "");
        // 肯定有!!
        int index = str.lastIndexOf("}");
        StringBuilder sb2 = new StringBuilder(str);
        sb2.setCharAt(index, ' ');
        sb.append(sb2).append("\n");
    }
    sb.append("}");
    return sb.toString();
}
Also used : XmlIocLoader(org.nutz.ioc.loader.xml.XmlIocLoader) IocLoader(org.nutz.ioc.IocLoader) AsyncAopIocLoader(org.nutz.aop.interceptor.async.AsyncAopIocLoader) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) PropertiesIocLoader(org.nutz.ioc.loader.properties.PropertiesIocLoader) TransIocLoader(org.nutz.aop.interceptor.ioc.TransIocLoader)

Example 5 with IocLoader

use of org.nutz.ioc.IocLoader in project nutz by nutzam.

the class SimpleJsonIocTest method test_load_from_reader.

@Test
public void test_load_from_reader() throws ObjectLoadException {
    IocLoader loader = new JsonLoader(Streams.fileInr("org/nutz/ioc/json/main.js"));
    assertTrue(loader.getName().length > 0);
}
Also used : IocLoader(org.nutz.ioc.IocLoader) JsonLoader(org.nutz.ioc.loader.json.JsonLoader) Test(org.junit.Test)

Aggregations

IocLoader (org.nutz.ioc.IocLoader)8 Test (org.junit.Test)5 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)5 IocObject (org.nutz.ioc.meta.IocObject)3 AsyncAopIocLoader (org.nutz.aop.interceptor.async.AsyncAopIocLoader)2 TransIocLoader (org.nutz.aop.interceptor.ioc.TransIocLoader)2 Ioc (org.nutz.ioc.Ioc)2 NutIoc (org.nutz.ioc.impl.NutIoc)2 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)2 PropertiesIocLoader (org.nutz.ioc.loader.properties.PropertiesIocLoader)2 XmlIocLoader (org.nutz.ioc.loader.xml.XmlIocLoader)2 IocContext (org.nutz.ioc.IocContext)1 IocException (org.nutz.ioc.IocException)1 IocMaking (org.nutz.ioc.IocMaking)1 ObjectLoadException (org.nutz.ioc.ObjectLoadException)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 Mammal (org.nutz.ioc.json.pojo.Mammal)1 ComboIocLoader (org.nutz.ioc.loader.combo.ComboIocLoader)1 IocField (org.nutz.ioc.meta.IocField)1 IocValue (org.nutz.ioc.meta.IocValue)1