[jboss-user] [Microcontainer] - Re: Injecting beans into Unit Tests under 1.02

alesj do-not-reply at jboss.com
Fri Sep 21 06:17:24 EDT 2007


You can use MicrocontainerTest and MicrocontainerTestDelegate to do your injection.
They have all the handy methods to provide you the beans you deployed, e.g.:

  |    /**
  |     * Get a bean
  |     * 
  |     * @param name the bean name
  |     * @return the bean
  |     * @throws IllegalStateException when the bean does not exist
  |     */
  |    protected Object getBean(Object name)
  |    {
  |       return getBean(name, ControllerState.INSTALLED);
  |    }
  |    
  |    /**
  |     * Get a bean
  |     * 
  |     * @param name the name of the bean
  |     * @param state the state of the bean
  |     * @return the bean
  |     * @throws IllegalStateException when the bean does not exist at that state
  |     */
  |    protected Object getBean(Object name, ControllerState state)
  |    {
  |       return getMCDelegate().getBean(name, state);
  |    }
  | 
  |    /**
  |     * Get a context
  |     * 
  |     * @param name the bean name
  |     * @return the context
  |     * @throws IllegalStateException when the context does not exist 
  |     */
  |    protected KernelControllerContext getControllerContext(Object name)
  |    {
  |       return getControllerContext(name, ControllerState.INSTALLED);
  |    }
  | 
  |    /**
  |     * Get a context
  |     * 
  |     * @param name the name of the bean
  |     * @param state the state of the bean
  |     * @return the context
  |     * @throws IllegalStateException when the context does not exist at that state
  |     */
  |    protected KernelControllerContext getControllerContext(Object name, ControllerState state)
  |    {
  |       return getMCDelegate().getControllerContext(name, state);
  |    }
  | 

You simply provide the XML file with the beans, how you actually use that injection is up to you.

Check out how we use it in our tons of test cases.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087155#4087155

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087155



More information about the jboss-user mailing list