Package org.nutz.ioc

Examples of org.nutz.ioc.Ioc


        s = s + "\nevents:{";
        s = s + "\n    fetch: 'onFetch',";
        s = s + "\n    create: 'onCreate',";
        s = s + "\n    depose: 'onDepose'";
        s = s + "\n}";
        Ioc ioc = I(J("fox", s));

        Animal f = ioc.get(Animal.class, "fox");
        assertEquals(1, f.getCreateTime());
        assertEquals(1, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.get(Animal.class, "fox");

        assertEquals(1, f.getCreateTime());
        assertEquals(2, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

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


        s = s + "\nevents:{";
        s = s + "\n    fetch: 'onFetch',";
        s = s + "\n    create: 'onCreate',";
        s = s + "\n    depose: 'onDepose'";
        s = s + "\n}";
        Ioc ioc = I(J("fox", s));

        Animal f = ioc.get(Animal.class, "fox");
        assertEquals(1, f.getCreateTime());
        assertEquals(1, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.get(Animal.class, "fox");

        assertEquals(1, f.getCreateTime());
        assertEquals(1, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

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

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

        s = s + "\nevents:{";
        s = s + "\n    fetch: 'org.nutz.ioc.json.pojo.WhenFetchAnimal',";
        s = s + "\n    create: 'org.nutz.ioc.json.pojo.WhenCreateAnimal',";
        s = s + "\n    depose: 'org.nutz.ioc.json.pojo.WhenDeposeAnimal'";
        s = s + "\n}";
        Ioc ioc = I(J("fox", s));

        Animal f = ioc.get(Animal.class, "fox");
        assertEquals(10, f.getCreateTime());
        assertEquals(10, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.get(Animal.class, "fox");

        assertEquals(10, f.getCreateTime());
        assertEquals(20, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.reset();
        assertEquals(10, f.getCreateTime());
        assertEquals(20, f.getFetchTime());
        assertEquals(10, f.getDeposeTime());
    }
View Full Code Here

        s = s + "\nevents:{";
        s = s + "\n    fetch: 'org.nutz.ioc.json.pojo.WhenFetchAnimal',";
        s = s + "\n    create: 'org.nutz.ioc.json.pojo.WhenCreateAnimal',";
        s = s + "\n    depose: 'org.nutz.ioc.json.pojo.WhenDeposeAnimal'";
        s = s + "\n}";
        Ioc ioc = I(J("fox", s));

        Animal f = ioc.get(Animal.class, "fox");
        assertEquals(10, f.getCreateTime());
        assertEquals(10, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.get(Animal.class, "fox");

        assertEquals(10, f.getCreateTime());
        assertEquals(10, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());

        ioc.reset();
        assertEquals(10, f.getCreateTime());
        assertEquals(10, f.getFetchTime());
        assertEquals(0, f.getDeposeTime());
    }
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

    }

    private static Map<String, Ioc> nuts = new HashMap<String, Ioc>();

    public static Ioc getIoc(String key) {
        Ioc nut = nuts.get(key);
        if (null == nut) {
            synchronized (Nutzs.class) {
                nut = nuts.get(key);
                try {
                    if (null == nut) {
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

TOP

Related Classes of org.nutz.ioc.Ioc

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.