Package org.nutz.ioc.impl

Examples of org.nutz.ioc.impl.NutIoc


public class JsonAopConfigrationTest {

    @Test
    public void test_jsonAop(){
        Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/aop/config/impl/jsonfile-aop.js"));
        Assert.assertTrue(ioc.getNames().length > 0);
        for (String name : ioc.getNames()) {
            ioc.get(null, name);
        }
        MyMI mi = ioc.get(MyMI.class, "myMI");
        assertTrue(mi.getTime() == 0);
        Pet2 pet2 = ioc.get(Pet2.class,"pet2");
        pet2.sing();
        assertTrue(mi.getTime() == 1);
        pet2.sing();
        assertTrue(mi.getTime() == 2);
    }
View Full Code Here


        assertEquals(0, f.getDeposeTime());
    }

    @Test
    public void test_event_from_parent() {
        Ioc ioc = new NutIoc(new JsonLoader("org/nutz/ioc/json/events.js"));
        Animal f = ioc.get(Animal.class, "fox");
        assertEquals(1, f.getCreateTime());
        assertEquals(1, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.depose();
        assertEquals(1, f.getCreateTime());
        assertEquals(1, f.getFetchTime());
        assertEquals(1, f.getDeposeTime());
    }
View Full Code Here

        if (null == nut) {
            synchronized (Nutzs.class) {
                nut = nuts.get(key);
                try {
                    if (null == nut) {
                        nut = new NutIoc(new JsonLoader(key));
                        nuts.put(key, nut);
                    }
                }
                catch (Exception e) {
                    throw Lang.wrapThrow(e);
View Full Code Here

        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);
    }
View Full Code Here

    @Test
    public void test_simple() {
      DefaultClassDefiner.reset();
        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();
View Full Code Here

        pluginManager.get();
    }
   
    @Test
    public void test_get_plugin_from_ioc(){
        Ioc ioc = new NutIoc(new JsonLoader("org/nutz/plugin/plugin.js"));
        PluginManager<Log> manager = new IocPluginManager<Log>(ioc, "pluB","pluA","pluC");
        assertNotNull(manager.get());
        assertTrue(manager.get() instanceof SystemLogAdapter);
    }
View Full Code Here

        }
    }

    @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());
View Full Code Here

public class IocCustomizedValueTypeTest {

    @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());
    }
View Full Code Here

    @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);
    }
View Full Code Here

        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]);
View Full Code Here

TOP

Related Classes of org.nutz.ioc.impl.NutIoc

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.