Package jfun.yan

Examples of jfun.yan.Component


            e.getMessage());
      }

    }
    public void testUseArgumentCannotBeAppliedToTopLevel(){
      final Component use1 = Components.useArgument(Functions.ctor(String.class,null),
          0, String.class)
        .withArgument(0, Components.value("hello"));
      final Container yan = createYanContainer();
      yan.registerComponent("target", use1);
      try{
View Full Code Here


    }
    public void testPropertiesAndArgumentsApplyToBothBeanComponentAndBaseComponent()
    throws Exception{
      final Container yan = createYanContainer();
      final Component c1 = Components.ctor(MyBean.class, null);
      final Component c2 = c1.bean(new String[]{"1","nums"})
      .withProperties(new String[]{"1","nums"},
          new Component[]{Components.value(true),
          Components.value(new int[]{1,2,3})
      })
      .bean(new String[]{"name","short"});
      final Component target = c2
      .withProperties(new String[]{"1","name","short","nums"},
          new Component[]{Components.value(false),
          Components.value("Ent"),
          Components.value((short)-1),
          Components.value(new int[]{1,2,3,4})});
View Full Code Here

      assertEquals((short)-1, mb.getShort());
      assertEquals(3, mb.getNums().length);
    }
    public void testConstructorParametesUsedAsMandatoryProperties()
    throws Exception{
      final Component c1 = Components.ctor(CopyCommand.class);
      final Component cc = Beans.beanComponent(c1, new String[]{"source","dest"});

      final Container yan = createYanContainer();
      verifyPropertyNotResolved(yan, cc);
      yan.registerComponent(boolean.class, Components.value(true));
      verifyPropertyNotResolved(yan, cc);
      //System.out.println();
      assertComponentInfo(c1, 2,
          "0=class java.lang.String, 1=class java.lang.String", "",
          tests.jfun.models.CopyCommand.class
          );
      assertComponentInfo(cc, 0, "",
          "source=class java.lang.String, dest=class java.lang.String, force=boolean, options=class java.lang.String",
          tests.jfun.models.CopyCommand.class
          );
      //System.out.println(jfun.yan.etc.Introspector.getComponentInfo(cc));
      //System.out.println(jfun.yan.etc.Introspector.getExpectedProperties(c1));
      final Component cc_src = cc.withProperty("source", Components.value("d:/"));
      //System.out.println(jfun.yan.etc.Introspector.getComponentInfo(cc_src));
      assertComponentInfo(cc_src, 0, "",
          "dest=class java.lang.String, force=boolean, options=class java.lang.String",
          tests.jfun.models.CopyCommand.class
          );     
      verifyPropertyNotResolved(yan, cc_src);
      final Component cc_src_dst = cc_src.withProperty("dest", Components.value("e:/abc"));
      //System.out.println(jfun.yan.etc.Introspector.getComponentInfo(cc_src_dst));
      assertComponentInfo(cc_src_dst, 0, "",
          "force=boolean, options=class java.lang.String",
          tests.jfun.models.CopyCommand.class
          );
View Full Code Here

        inners[i] = inner;
      }
    }
    public void testHigherOrderMethod()
    throws Exception{
      final Component c = Components.ctor(ArrayList.class, null);
      testHigherOrderMethod(c);
      testHigherOrderMethod(c.cast(null));
      final Component nested = Components.ctor(MultiBean.class);
      testHigherOrderMethod(
          nested.bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .method("getInner").method("getList")
      );

      testHigherOrderMethod(
          nested.cast(null).bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .method("getInner").method("getList")
      );
      testHigherOrderMethod(
          nested.cast(null).bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .method("getInner").method("getListAsObject")
      );
      try{
        testHigherOrderMethod(
            nested.bean(new String[]{"inner"})
            .withProperty("inner",
                Components.ctor(MultiBean.InnerBean.class)
            )
            .method("getInner").method("getListAsObject")
        );
        fail("should have failed with IllegalArgumentException");
      }
      catch(IllegalArgumentException e){
        assertEquals("method java.lang.Object.size not found", e.getMessage());
      }
     
     
      //test nested bean
      testHigherOrderMethod(
          nested.bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .getter("inner").getter("list")
      );
      testHigherOrderMethod(
          nested.setter("inner")
          .withArgument(0,
              Components.ctor(MultiBean.InnerBean.class)
          )
          .getter("inner").getter("list")
      );
      testHigherOrderMethod(
          nested.cast(null).bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .getter("inner").getter("list")
      );
      testHigherOrderMethod(
          nested.cast(null).setter("inner")
          .withArgument(0,
              Components.ctor(MultiBean.InnerBean.class)
          )
          .getter("inner").getter("list")
      );
      try{
        testHigherOrderMethod(
            nested.bean(new String[]{"inner"})
            .withProperty("inner",
                Components.ctor(MultiBean.InnerBean.class)
            )
            .getter("inner").getter("listAsObject")
        );
        fail("should have failed with IllegalArgumentException");
      }
      catch(IllegalArgumentException e){
        assertEquals("method java.lang.Object.size not found", e.getMessage());
      }
      testHigherOrderMethod(
          nested.cast(null).bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .getter("innerAsObject").method("getListAsObject")
      );
      testHigherOrderMethod(
          nested.cast(null).bean(new String[]{"inner"})
          .withProperty("inner",
              Components.ctor(MultiBean.InnerBean.class)
          )
          .getter("innerAsObject").getter("listAsObject")
      );
      try{
        testHigherOrderMethod(
            nested.bean(new String[]{"inner"})
            .withProperty("inner",
                Components.ctor(MultiBean.InnerBean.class)
            )
            .getter("innerAsObject").getter("list")
        );
View Full Code Here

      return Components.ctor(MultiBean.InnerBean.class).setter("active")
        .withArgument(0, Components.value(a));
    }
    public void testHigherOrderMethodWithIndexedProperties()
    throws Exception{
      final Component nested = Components.ctor(MultiBean.class);
      final Component inner1 = innerInstance(true);
      final Component inner2 = innerInstance(false);
      Component data = nested.setter("inner")
      .withArgument(0, inner1)  
      .setter("inners", 0)
      .withArgument(0, inner2)
      .setter("inners", 1)
      .withArgument(0, innerInstance(true));
      testHigherOrderMethod(
          data
          .getter("inners", 0).getter("list")
      );
      assertBool(data.getter("inners", 0).getter("active"), false);
      assertBool(data.getter("inners", 1).getter("active"), true);
     
     
      data = nested.cast(null).setter("inner")
      .withArgument(0, inner1)  
      .setter("inners", 0)
      .withArgument(0, inner2)
      .setter("inners", 1)
      .withArgument(0, innerInstance(true))
      ;
      testHigherOrderMethod(
          data
          .getter("inner").getter("list")
      );
      assertBool(data.getter("inners", 0).getter("active"), false);
      assertBool(data.getter("inners", 1).getter("active"), true);

    }
View Full Code Here

      }
    };
    bench.start(true);
  }
  public void testBenchSingletonCustomFactory() throws Exception{
    final Component ssoo = yan.getComponent("ssoo").factory(MyFactory.class);
    final MyFactory factory = (MyFactory)yan.instantiateComponent(ssoo);
     Benchmark bench = new Benchmark("Nuts: Singleton Bean with custom factory", LOOP*10){
     
      public void run() throws Exception {
        final Soo foo = (Soo)factory.create();
View Full Code Here

    }
    public void testComponentManagedByMoreThanOneLifecycleManagers()
    throws Throwable{
      DefaultLifecycleManager man1 = new DefaultLifecycleManager();
      DefaultLifecycleManager man2 = new DefaultLifecycleManager();
      Component c = Components.ctor(Automobile.class);
      c = man1.newLifecycle()
        .starter("start1")
        .stopper("stop1")
        .manage(c);
      c = man2.newLifecycle()
View Full Code Here

    }
    public void testParameterCustomizationShouldNotPropogateToTheNextLevel()
    throws Exception{
      Container yan = this.createYanContainer();
      yan.registerValue("autowired");
      final Component manual = Components.value("manualwired");
      final Component cc1 = Components.ctor(Echo.class).method("newInstance")
        .withArgument(0, manual);
      final Component cc2 = Components.ctor(Echo.class).method("add")
        .withArgument(0, manual);
      final Component cc3 = Components.static_method(Echo.class, "newInstance")
      .method("add")
      .withArgument(0, manual);
      final Component cc4 = Components.static_method(Echo.class, "newInstance")
      .bean()
      .method("add")
      .withArgument(0, manual);
      final Component cc5 = Components.static_method(Echo.class, "newInstance")
      .bean()
      .withArgument(0, manual)
      .method("add")
      .withArgument(0, manual);
View Full Code Here

      assertEquals(a, result.booleanValue());
    }
    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"));
View Full Code Here

          return void.class;
        }
      };
    }
    private Creator giveProperties(Object v, String[] givers){
      Component r = Components.value(v);
      for(int i=0; i<givers.length; i++){
        r = r.followedBy(Components.method(v, givers[i]));
      }
      return r;
    }
View Full Code Here

TOP

Related Classes of jfun.yan.Component

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.