Search in sources :

Example 16 with NutIoc

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) AnnotationIocLoader(org.nutz.ioc.loader.annotation.AnnotationIocLoader) NutIoc(org.nutz.ioc.impl.NutIoc) DogMaster(org.nutz.ioc.meta.issue348.DogMaster) Test(org.junit.Test)

Example 17 with NutIoc

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);
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) ComboContext(org.nutz.ioc.impl.ComboContext) IocContext(org.nutz.ioc.IocContext) ScopeContext(org.nutz.ioc.impl.ScopeContext) MapLoader(org.nutz.ioc.loader.map.MapLoader) Ioc2(org.nutz.ioc.Ioc2) Test(org.junit.Test)

Example 18 with NutIoc

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) MapLoader(org.nutz.ioc.loader.map.MapLoader) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Example 19 with NutIoc

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) IocTO00(org.nutz.ioc.json.pojo.IocTO00) MapLoader(org.nutz.ioc.loader.map.MapLoader) HashMap(java.util.HashMap) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) HashMap(java.util.HashMap) Map(java.util.Map) NutMap(org.nutz.lang.util.NutMap) Test(org.junit.Test)

Example 20 with NutIoc

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();
}
Also used : NutIoc(org.nutz.ioc.impl.NutIoc) Bee(org.nutz.ioc.loader.xml.meta.Bee) Ioc(org.nutz.ioc.Ioc) NutIoc(org.nutz.ioc.impl.NutIoc) Test(org.junit.Test)

Aggregations

NutIoc (org.nutz.ioc.impl.NutIoc)20 Test (org.junit.Test)16 Ioc (org.nutz.ioc.Ioc)10 JsonLoader (org.nutz.ioc.loader.json.JsonLoader)6 MapLoader (org.nutz.ioc.loader.map.MapLoader)6 AnnotationIocLoader (org.nutz.ioc.loader.annotation.AnnotationIocLoader)4 Ioc2 (org.nutz.ioc.Ioc2)3 IocContext (org.nutz.ioc.IocContext)2 IocLoader (org.nutz.ioc.IocLoader)2 ScopeContext (org.nutz.ioc.impl.ScopeContext)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Before (org.junit.Before)1 NutDao (org.nutz.dao.impl.NutDao)1 Pet (org.nutz.dao.test.meta.Pet)1 IocMaking (org.nutz.ioc.IocMaking)1 ObjectProxy (org.nutz.ioc.ObjectProxy)1 ValueProxy (org.nutz.ioc.ValueProxy)1 ValueProxyMaker (org.nutz.ioc.ValueProxyMaker)1 ComboContext (org.nutz.ioc.impl.ComboContext)1