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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations