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