Package jfun.yan

Examples of jfun.yan.Container


        assertEquals(String.class, e.getExpectedType());
        assertEquals(ArrayList.class, e.getActualType());
      }
    }
    public void testContainerAsObject(){
      final Container yan1 = createYanContainer();
      final Container yan2 = createYanContainer();
      assertEquals(yan1, yan2);
      yan1.registerConstructor(Object.class);
      assertFalse(yan1.equals(yan2));
      yan1.getInstancesOfType(Object.class);
      yan1.unregisterComponent(Object.class);
View Full Code Here


     catch(NonWritablePropertyException e){
       assertTraceSize(e, 0);
       assertEquals("id", e.getPropertyName());
       assertEquals(Person.class, e.getComponentType());
     }
     Container yan = createYanContainer();
     Container yan2 = createYanContainer();
     yan.registerComponent("supermanref",
         Components.useKey("superman").bean()
         .withProperty("name", Components.useKey("personName"))
         .withProperty("age", Components.useType(Integer.class))
         .withProperty("nickname", Components.useContainer(yan2))
     );
     yan2.registerValue("Gandolf");
     try{
       yan.verify();
     }
     catch(UnresolvedComponentException e){
       assertTraceSize(e, 3);
View Full Code Here

     return yan;
   }
    public void testBeanWithSelectedProperties()
    throws Exception{
      Container yan = getContainerWithPerson();
      final Person person = (Person)yan.getInstance(Person.class);
      assertEquals("Yan", person.getName());
      assertEquals(16, person.getAge());
      assertSame(null, person.getNickname());
      assertEquals(1, person.getId());
    }
View Full Code Here

      assertSame(null, person.getNickname());
      assertEquals(1, person.getId());
    }
    public int expectArray(int[][] arr){return 1;}
    public void testBasics(){
      final Container yan = createYanContainer();
      yan.registerValue("abc");
      try{
        yan.getInstance("x");
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals("x", e.getComponentKey());
      }
      assertEquals(yan, yan);
      assertEquals(yan.toString(), yan.toString());
      yan.registerComponent("target", Components.method(this, "expectArray"));
      try{
        yan.verify();
        fail("should have failed with IrresolveableArgumentException");
      }
      catch(IrresolveableArgumentException e){
        assertEquals("target", e.getComponentKey());
        assertEquals(int[][].class, e.getParameterType());
        assertEquals(0, e.getOrdinalPosition());
        assertEquals("The #0 argument of type int[][] for component <target> is not resolveable", e.getMessage());
      }
      try{
        yan.registerComponent(Components.useKey("target"));
        fail("should have failed with UnknownComponentTypeException");
      }
      catch(UnknownComponentTypeException e){}
      try{
        yan.registerComponent(Components.useType(String.class));
        fail("should have failed with UnknownComponentTypeException");
      }
      catch(UnknownComponentTypeException e){
        assertTraceSize(e, 0);
      }
      yan.unregisterComponentsOfType(int.class);
      yan.verify();
      yan.registerComponent("target_also", Components.useKey("target"));
      try{
        yan.verify();
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals("target", e.getComponentKey());
      }
      yan.registerComponent("target",
          Components.method(this, "expectArray")
          .withArgument(0, Components.value(new int[10])));
      try{
        yan.verify();
        fail("should have failed with ParameterTypeMismatchException");
      }
      catch(ParameterTypeMismatchException e){
        assertTraceSize(e, 3);
        assertParameter(e, 0, Functions.method(this, "expectArray"), 0);
        assertEntry(e, 1, "useKey <target>");
        assertEntry(e, 2, "verify <target_also>");
        assertEquals("target_also", e.getComponentKey());
        assertEquals(int[][].class, e.getExpectedType());
        assertEquals(int[].class, e.getActualType());
        assertEquals(0, e.getOrdinalPosition());
        assertTrue(e.getMessage().startsWith(
            "type mismatch for The #0 parameter of component <target_also>")
          );
      }
      final Container yan2 = createYanContainer();
      yan.registerComponent("target", Components.useType(yan2, String.class));
      try{
        yan.verify();
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals(String.class, e.getComponentKey());
      }
      try{
        yan.getInstance("target_also");
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals(String.class, e.getComponentKey());
      }
      yan2.registerValue("target arrived!");
      assertEquals("target arrived!", yan.getInstance("target"));
    }
View Full Code Here

      NutsProcessor processor,
      ClassLoader loader, String nuts_resource,
      String appcontext_resource){
    final NutsProcessor spring =
      processor.createMetaProcessor(loader);
    final Container yan = processor.getContainer();
    /*
    final ReloadableResourceBundleMessageSource msgsrc = new ReloadableResourceBundleMessageSource();
    msgsrc.setBasename("org/springframework/context/support/messages");
    final ApplicationEventPublisher aep = new ApplicationEventPublisher(){
     
    }*/
    final Container base = new ManualContainer();
    base.registerValue("modulename", module_name);
    base.registerValue("timestamp", new Long(System.currentTimeMillis()));
    base.registerValue("classloader", loader);
    base.registerValue("container", yan);
    final NutsProcessor cinterpreter = new NutsProcessor();
    //cinterpreter.setParameterWiring(Modes.params_bytype);
    try{
      cinterpreter.processResource(appcontext_resource);
    }
    catch(IOException e){
      throw new IllegalStateException("cannot startup spring integration.");
    }
   
    final Container context = cinterpreter.getContainer().inherit(base);
    final Container2ApplicationContext ctxt = (Container2ApplicationContext)
    context.getInstance("appcontext");
   
    final Container nuts = spring.getContainer();
    final DefaultLifecycleManager manager = processor.getLifecycleManager();
   
    //final BeanPostProcessorQueue bppq = new BeanPostProcessorQueue();
    //nuts.registerValue(newBeanLifecycle(manager));
    //nuts.registerValue(ctxt);
    //nuts.registerValue(yan);
    //nuts.registerValue(bppq);
    nuts.registerValue(new SpringService(ctxt, manager));
    final String resource = nuts_resource;
    try{
      spring.processResource(resource);
    }
    catch(IOException e){
View Full Code Here

      yan2.registerValue("target arrived!");
      assertEquals("target arrived!", yan.getInstance("target"));
    }
    public void testLifeycles()
    throws Throwable{
      final Container yan = new DefaultContainer();
      final Component real_engine =
        Components.useKey("real engine").singleton(new ThreadLocalScope());
      final DefaultLifecycleDescriptor desc = new DefaultLifecycleDescriptor();
      desc.setCloser(new Phase(desc.getCloser().getPhaseKey(), ExceptionHandlers.suppresser()));
      desc.setStopper(new Phase(desc.getStopper().getPhaseKey(), ExceptionHandlers.suppresser()));
      final DefaultLifecycleManager lm = new DefaultLifecycleManager(desc);
      final DefaultLifecycleManager.DefaultLifecycle lc = lm.newLifecycle()
      .starter("start")
      .stopper("stop")
      .initializer("initialize")
      .disposer("destroy");
      final Component engine_lc = lc.manage(real_engine);
      yan.registerComponent(CarEngine.class, engine_lc);
      /*
      yan.registerComponent(CarEngine.class, LifecycleDescriptor.instance(
          Components.useKey("real engine").singleton(new ThreadLocalScope()),
          ExceptionHandlers.suppresser())
          .starter("start")
          .stopper("stop")
          .initializer("initialize")
          .disposer("destroy")
          .get());
      */
      yan.registerConstructor("real engine", CarEngine.class);
      final Component sttfrc = Components.ctor(StatefulResource.class)
      .withArgument(0, Components.useType(CarEngine.class));
      yan.registerComponent(lc.manage(sttfrc));
      /*
      yan.registerComponent(LifecycleDescriptor.instance(
          Components.ctor(StatefulResource.class)
          .withArgument(0, Components.useType(CarEngine.class))
          , ExceptionHandlers.suppresser())
          .initializer("initialize")
          .disposer("destroy")
          .starter("start")
          .stopper("stop")
          .get());
      */
      final Component car_engine = yan.getComponentOfType(CarEngine.class);
      assertNull(car_engine.getType());
     
      final StatefulResource resource = (StatefulResource)yan.getInstanceOfType(StatefulResource.class);
      final CarEngine engine = (CarEngine)yan.getInstanceOfType(CarEngine.class);
      assertEquals(0, engine.getStarted());
      assertEquals(0, engine.getStopped());
      assertEquals(0, engine.getInit());
      assertEquals(0, engine.getDisposed());

View Full Code Here

      }
      assertNull(yan.getComponentOfType(String.class));
      assertNull(yan.getComponent("string"));
    }*/
    public void testUseBadContainerKeyAndContainerType(){
      final Container yan = createYanContainer();
      yan.registerComponent("use_bad", Components.useKey(yan, "badkey"));
      try{
        yan.verify();
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals("badkey", e.getComponentKey());
        yan.unregisterComponent("use_bad");
      }
      yan.registerValue(char.class, new Character('a'));
      yan.registerComponent("use_badtype",
          Components.useType(createYanContainer(), char.class));
      try{
        yan.verify();
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals(char.class, e.getComponentKey());
        yan.unregisterComponent("use_badtype");
      }
    }
View Full Code Here

        assertEquals(char.class, e.getComponentKey());
        yan.unregisterComponent("use_badtype");
      }
    }
    public void testUseBadKeyAndType(){
      final Container yan = createYanContainer();
      yan.registerComponent("use_bad", Components.useKey("badkey"));
      try{
        yan.verify();
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals("badkey", e.getComponentKey());
        yan.unregisterComponent("use_bad");
      }
     
      yan.registerComponent("use_badtype",
          Components.useType(char.class));
      try{
        yan.verify();
        fail("should have failed with UnresolvedComponentException");
      }
      catch(UnresolvedComponentException e){
        assertEquals(char.class, e.getComponentKey());
        yan.unregisterComponent("use_badtype");
      }
    }
View Full Code Here

        yan.unregisterComponent("use_badtype");
      }
    }
   
    public void testBadUseContainerWithArguments(){
      final Container yan1 = createYanContainer();
      final Container yan2 = createYanContainer();
      final Part ref2 = Components.useContainer(yan2);
      yan1.registerComponent("target",
          Components.ctor(NeedsTouchable.class)
          .withArguments(ref2));
      run_testBadUseContainerForArguments(yan1, yan2);
View Full Code Here

          Components.ctor(NeedsTouchable.class)
          .withArguments(ref2));
      run_testBadUseContainerForArguments(yan1, yan2);
    }
    public void testBadUseContainerWithArgument(){
      final Container yan1 = createYanContainer();
      final Container yan2 = createYanContainer();
      final Part ref2 = Components.useContainer(yan2);
      yan1.registerComponent("target",
          Components.ctor(NeedsTouchable.class)
          .withArgument(0, ref2));
      run_testBadUseContainerForArguments(yan1, yan2);
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.