use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.
the class SimpleIocTest method test_error_bean.
@Test(expected = IocException.class)
public void test_error_bean() {
Ioc ioc = new NutIoc(new AnnotationIocLoader(DogMaster.class.getPackage().getName()));
try {
ioc.get(DogMaster.class);
fail("Never Success");
} catch (IocException e) {
}
ioc.get(DogMaster.class);
ioc.depose();
}
use of org.nutz.ioc.impl.NutIoc 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.impl.NutIoc 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();
}
use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.
the class SimpleJsonIocTest method test_2darray_by_map_iocvalue.
@Test
public void test_2darray_by_map_iocvalue() {
Map<String, Map<String, Object>> map = new HashMap<String, Map<String, Object>>();
Map<String, Object> objMap = new HashMap<String, Object>();
String[][] strss = new String[2][2];
strss[0][0] = "a";
strss[0][1] = "b";
strss[1][0] = "c";
strss[1][1] = "d";
objMap.put("args", new Object[] { strss });
map.put("obj", objMap);
Ioc ioc = new NutIoc(new MapLoader(map));
IocTO00 obj = ioc.get(IocTO00.class, "obj");
assertEquals(2, obj.getStrss().length);
assertEquals(2, obj.getStrss()[0].length);
assertEquals("a", obj.getStrss()[0][0]);
assertEquals("b", obj.getStrss()[0][1]);
assertEquals("c", obj.getStrss()[1][0]);
assertEquals("d", obj.getStrss()[1][1]);
ioc.depose();
}
use of org.nutz.ioc.impl.NutIoc in project nutz by nutzam.
the class XmlIocLoaderTest method test_simple_case.
@Test
public void test_simple_case() {
Ioc ioc = new NutIoc(getNew("org/nutz/ioc/loader/xml/conf/simple.xml"));
Bee c = ioc.get(Bee.class, "C");
assertEquals("TheC", c.getName());
assertEquals(15, c.getAge());
assertEquals("TheQueen", c.getMother().getName());
assertEquals(3, c.getFriends().size());
assertEquals("TheA", c.getFriends().get(0).getName());
assertEquals("TheB", c.getFriends().get(1).getName());
assertEquals(1, c.getMap().size());
assertEquals("ABC", c.getMap().get("abc"));
ioc.depose();
}
Aggregations