Package jfun.yan

Examples of jfun.yan.Container


      assertEquals("autowiredmanualwired", yan.getInstance("cc4").toString());
      assertEquals("manualwiredmanualwired", yan.getInstance("cc5").toString());
      assertEquals("autowiredmanualwired", yan.getInstance("cc6").toString());
    }
    private void assertBool(Component c, boolean a){
      final Container yan = createYanContainer();
      yan.registerComponent("target", c);
      final Boolean result = (Boolean)yan.getInstance("target");
      assertEquals(a, result.booleanValue());
    }
View Full Code Here


    }
    private void testHigherOrderMethod(Component c)
    throws Exception{
      try{
        final Component sz0 = c.method("size");
        final Container yan = createYanContainer();
        yan.registerComponent("list", c);
        yan.registerComponent("size", sz0);
        assertEquals(new Integer(0), yan.getInstance("size"));
        final Component sz1 = c.followedBy(new Binder(){
          public Creator bind(Object l){
            return Components.value(l).method("add", new Class[]{Object.class})
              .withArgument(0, Components.useKey("elem1"));
          }
        }).method("size", null);
        yan.registerValue("elem1", "val1");
        yan.registerComponent("size", sz1);
        assertEquals(new Integer(1), yan.getInstance("size"));
       
        final Component sz2 = c.followedBy(new Binder(){
          public Creator bind(Object l){
            final Component adder =
              Components.value(l).method("add", new Class[]{Object.class});
           
            return adder
              .withArgument(0, Components.useKey("elem1"))
              .seq(adder.withArgument(0, Components.useKey("elem2")));
          }
        }).method(java.util.List.class.getMethod("size", new Class[0]));
        yan.registerValue("elem2", "val2");
        yan.registerComponent("size", sz2);
        assertEquals(new Integer(2), yan.getInstance("size"));
        assertFalse(sz0.equals(sz1));
        assertFalse(sz1.equals(sz0));
        assertFalse(sz0.equals(sz2));
        assertFalse(sz2.equals(sz0));
        assertFalse(sz2.equals(sz1));
View Full Code Here

      }
    }

    protected void assertError(Component c, Class etype, String msg)
    throws Throwable{
      Container yan = createYanContainer();
      yan.registerComponent("target", c);
      try{
        yan.getInstance("target");
      }
      catch(Throwable e){
        if(etype.isInstance(e)){
          assertEquals(msg, e.getMessage());
          return;
View Full Code Here

        }
      }
      fail("should have failed with: "+msg);
    }
    protected void assertResult(Component c, Object val){
      Container yan = createYanContainer();
      yan.registerComponent("target", c);
      assertEquals(val, yan.getInstance("target"));
    }
View Full Code Here

      assertEquals(obj, obj);
      map.put(obj, obj);
      assertEquals(obj, map.get(obj));
    }
    private Container getGbeanContainer(Component gb){
      Container yan = createYanContainer();
      yan.registerValue("firstname", "Jack");
      //yan.registerValue("lastname", "Nicolson");
      yan.registerValue("middle", new Character('M'));
      yan.registerValue("age", new Integer(10));

      yan.registerComponent("target", gb);
      return yan;
    }
View Full Code Here

      yan.registerComponent("target", gb);
      return yan;
    }
    private void runTestGiveBean(Component gb){
      final Container yan = getGbeanContainer(gb);
      yan.verify();
      final GiveBean target = (GiveBean)yan.getInstance("target");
      assertEquals("Jack", target.getFname());
      assertEquals("M", target.getMiddleInitial());
      assertEquals(10, target.getAge());
      assertTrue(target.isAwake());
    }
View Full Code Here

        assertSame(yin, yang.getYin());
        assertSame(yang, yin.getYang());
    }
    public void testShouldBeAbleToHandleMutualDependenciesWithProxy()
    throws IntrospectionException{
        Container yan = new ProxyContainer();
          /*new DefaultContainer(new CachingComponentAdapterFactory(
                new SetterInjectionComponentAdapterFactory()));*/

        yan.registerComponent(Components.bean(Yin.class, new String[]{"yang"})
            .withArgument(1, Components.value("bad ying"))
        );
        yan.registerComponent(Components.bean(Yang.class)
            .withProperty("nonexistent", Components.value("bad yang"))
            .singleton(new ThreadLocalScope())
            );
        yan.verify();
        IYin yin = (IYin) yan.getInstanceOfType(IYin.class);
        IYang yang = (IYang) yan.getInstanceOfType(IYang.class);

        assertNotSame(yin, yang.getYin());
        assertNotSame(yang, yin.getYang());
    }
View Full Code Here

        //new SetterInjectionComponentAdapter("a", A.class, null);
        Component bAdapter =
          Components.bean(B.class).singleton();
          //new SetterInjectionComponentAdapter("b", B.class, null);

        Container yan = new DefaultContainer();
        yan.verify();
        yan.registerComponent("b", bAdapter);
        yan.registerComponent("a", aAdapter);
        try {
            //aAdapter.getComponentInstance(yan);
          yan.getInstance("a");
        } catch (UnsatisfiedComponentException e) {
          //System.out.println(e.getMessage());
          assertEquals("The property list of type java.util.List for component <a> is not resolveable",
              e.getMessage());
            //assertTrue(e.getUnsatisfiableDependencies().contains(List.class));
            //assertTrue(e.getUnsatisfiableDependencies().contains(String.class));
        }
        yan.registerComponent("a", aAdapter.optionalProperty("string")
            .ignoreProperty("list"));
        final B b = (B) yan.getInstance("b");
        A a = (A) yan.getInstance("a");
        assertEquals("default", a.getString());
        assertEquals(new java.util.ArrayList(), a.getList());
        assertSame(b, a.getB());
        yan.registerValue("hello");
        a = (A) yan.getInstance("a");
        assertEquals("hello", a.getString());
        assertEquals(new java.util.ArrayList(), a.getList());
        assertSame(b, a.getB());
        final java.util.List list1 = new java.util.LinkedList();
        list1.add("abc");
        yan.registerValue(list1);
        a = (A) yan.getInstance("a");
        assertEquals("hello", a.getString());
        assertEquals(new java.util.ArrayList(), a.getList());
        assertSame(b, a.getB());
    }
View Full Code Here

        //new SetterInjectionComponentAdapter("a", A.class, null);
        Component bAdapter =
          Components.bean(B.class);
          //new SetterInjectionComponentAdapter("b", B.class, null);

        Container yan = new DefaultContainer();
        yan.verify();
        yan.registerComponent("b", bAdapter);
        yan.registerComponent("a", aAdapter);
        try {
            //aAdapter.getComponentInstance(yan);
          yan.verify();
        } catch (UnsatisfiedComponentException e) {
          //System.out.println(e.getMessage());
            //assertTrue(e.getUnsatisfiableDependencies().contains(List.class));
            //assertTrue(e.getUnsatisfiableDependencies().contains(String.class));
        }
View Full Code Here

        Component cAdapter =Components.bean(C.class);
          //new Component("c", C.class, null);
        //Component cNullAdapter = Components.bean(C.class);
          //new Component("c0", C.class, null);

        Container yan = new DefaultContainer();
        yan.registerComponent("b", bAdapter);
        yan.registerComponent("c", cAdapter);
        yan.registerComponent("c0", cAdapter);
        yan.registerConstructor(ArrayList.class, new Class[0]);

        C c = (C) yan.getInstance("c");
          //(C) cAdapter.getComponentInstance(yan);
        assertTrue(c.instantiatedAsBean());
        C c0 = (C) yan.getInstance("c0");
          //(C) cNullAdapter.getComponentInstance(yan);
        assertTrue(c0.instantiatedAsBean());
    }
View Full Code Here

TOP

Related Classes of jfun.yan.Container

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.