Package jfun.yan

Examples of jfun.yan.Container


        e.printResolutionTrace();
        throw e;
      }
    }
    public void testMonadPlus(){
      final Container yan = createYanContainer();
      yan.registerComponent("a", Monad.mzero());
      try{
        yan.verify();
        fail("should have failed with ComponentResolutionException");
      }
      catch(ComponentResolutionException e){
        assertTraceSize(e, 2);
        assertEntry(e, 0, "fail <mzero>");
        assertEquals("mzero", e.getMessage());
      }
      yan.registerComponent("a", Monad.mzero().optional());
      try{
        yan.getInstance("a");
        fail("should have failed with DefaultingException");
      }
      catch(DefaultingException e){}
      yan.registerComponent("a", Components.useKey("b").option("hello world"));
      assertEquals("hello world", yan.getInstance("a"));
    }
View Full Code Here


     
      return (Container) ois.readObject();
    }
    private Touchable getTouchableFromSerializedContainer()
    throws IOException, ClassNotFoundException {
      Container yan = createPicoContainerWithTouchableAndDependsOnTouchable();
      // Add a list too, using a constant parameter
      yan.registerComponent("list",
          Components.ctor(ArrayList.class, new Class[]{int.class})
          .withArgument(0, Components.value(10)));
     

      yan = trans(yan);
     
      DependsOnTouchable dependsOnTouchable = (DependsOnTouchable)
      yan.getInstanceOfType(DependsOnTouchable.class);
      assertNotNull(dependsOnTouchable);
      return (Touchable) yan.getInstanceOfType(Touchable.class);
    }
View Full Code Here

        //e.printResolutionTrace();
      }
    }
    public void testFloatingMethod(){
      final Class type = Mtds.class;
      Container yan = createYanContainer();
      try{
        Components.static_method(type, "greet");
        fail("should have failed with IllegalArgumentException");
      }
      catch(IllegalArgumentException e){}
      try{
        Components.fun(Functions.instance_method(type, "getGreeting"));
        fail("should have failed with IllegalArgumentException");
      }
      catch(IllegalArgumentException e){}
      yan.registerComponent(Components.static_method(type, "instance"));
      yan.registerValue("Tom");
      yan.registerComponent("target",
          Components.fun(Functions.instance_method(type, "greet"))
          .withArgument(1, Components.value("Jerry")));
      assertEquals("hello Jerry, I am Tom", ""+yan.getInstance("target"));
      yan.registerComponent(Components.static_method(type, "instance"));
      yan.registerComponent("target",
          Components.fun(Functions.instance_method(type, "greet"))
          //.withArgument(0, Components.value("should not see this"))
          .withArgument(0, Components.useType(Mtds.class)
              //.withArgument(0,  Components.value("should not see me"))
              .withArgument(0,  Components.value("Jerry"))
              .withArgument(0,  Components.value("should not see me"))
          )
          );
      assertEquals("hello Tom, I am Jerry", ""+yan.getInstance("target"));

    }
View Full Code Here

    }
    public static String tag(String prefix, int i){
      return prefix+i;
    }
    public void testComponentArgumentsShouldNotPropogateToParts(){
      final Container yan = createYanContainer();
      yan.registerValue("default prefix");
      yan.registerComponent(Components.value(1));
      final Component tag = Components.method(this, "tag");
      final Component target = tag
        .withArgument(0, Components.method(this, "tag"))
        .withArgument(1, Components.value(0));
      yan.registerComponent("target", target);
      final Object result = yan.getInstance("target");
      assertEquals("default prefix10", ""+result);
    }
View Full Code Here

      assertEquals("default prefix10", ""+result);
    }
    public void testUsePropertyCannotBeAppliedToTopLevel(){
      final Component use1 = Components.useProperty(String.class, "prop1", String.class)
        .withProperty("prop1", Components.value("hello"));
      final Container yan = createYanContainer();
      yan.registerComponent("target", use1);
      try{
        yan.verify();
      }
      catch(YanException e){
        assertTraceSize(e, 2);
        //e.printResolutionTrace();
        assertEquals("useProperty can only be used for parameter or property",
            e.getMessage());
      }
      try{
        yan.instantiateComponent(use1);
        //yan.getInstance("target");
      }
      catch(YanException e){
        //e.printResolutionTrace();
        assertTraceSize(e, 2);
View Full Code Here

    }
    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{
        yan.verify();
      }
      catch(YanException e){
        assertTraceSize(e, 2);
        //e.printResolutionTrace();
        assertEquals("useArgument can only be used for parameter or property",
            e.getMessage());
      }
      try{
        yan.getInstances();
      }
      catch(YanException e){
        assertTraceSize(e, 2);
        //e.printResolutionTrace();
        assertEquals("useArgument can only be used for parameter or property",
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})});
      yan.verifyComponent(target);
      final MyBean mb = (MyBean)yan.instantiateComponent(target);
      assertTrue(mb.is1());
      assertEquals("Ent", mb.getName());
      assertEquals((short)-1, mb.getShort());
      assertEquals(3, mb.getNums().length);
    }
View Full Code Here

    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
          );
      final CopyCommand cm = (CopyCommand)yan.instantiateComponent(cc_src_dst);
      assertEquals("d:/", cm.getSource());
      assertEquals("e:/abc", cm.getDest());
      assertTrue(cm.isForce());
      assertEquals("", cm.getOptions());
    }
View Full Code Here

        .manage(c);
      c = man2.newLifecycle()
        .starter("start2")
        .stopper("stop2")
        .manage(c);
      Container yan = createYanContainer();
      yan.registerComponent("target", c);
      Automobile a = (Automobile)yan.getInstance("target");
      assertFalse(a.isRunning1());
      assertFalse(a.isRunning2());
      man1.start();
      assertTrue(a.isRunning1());
      assertFalse(a.isRunning2());
View Full Code Here

      assertFalse(a.isRunning1());
      assertFalse(a.isRunning2());
    }
    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);

      yan.registerComponent("cc1", cc1);
      yan.registerComponent("cc2", cc2);
      yan.registerComponent("cc3", cc3);
      yan.registerComponent("cc4", cc4);
      yan.registerComponent("cc5", cc5);
      yan.registerComponent("cc6", cc4.singleton());
      assertEquals("manualwired", yan.getInstance("cc1").toString());
      assertEquals("autowiredmanualwired", yan.getInstance("cc2").toString());
      assertEquals("autowiredmanualwired", yan.getInstance("cc3").toString());
      assertEquals("autowiredmanualwired", yan.getInstance("cc4").toString());
      assertEquals("manualwiredmanualwired", yan.getInstance("cc5").toString());
      assertEquals("autowiredmanualwired", yan.getInstance("cc6").toString());
    }
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.