2 Replies Latest reply on Jun 2, 2006 4:49 AM by superfis

    Injection doesn't work during TestNG test

    superfis

      Hi,

      When I put my seam action bean into testng test, I can see that my bean isn't being injected.

      Snippet of my seam action bean:

      @Stateful
      @Name( "wizardCityAction" )
      @Conversational( ifNotBegunOutcome = "wizardStart" )
      public class WizardCityActionBean implements Serializable, WizardCityAction {
      ...@In( create = true )@Out
       private WizardBackBeans backBeans;
      ...
      


      and part of my test code:

      ...
       WizardBackBeans wbb = new WizardBackBeansBean( );
       wbb.setCityId( 1 );Contexts.getConversationContext( ).set( "backBeans", wbb );WizardCityAction wca = (WizardCityAction) Component.getInstance( "wizardCityAction", true );
      ...
      


      I tried to configure environment as it has been done in Seam examples. Debugging shows that there is backBeans == null in my seam bean.
      What's wrong with my code/settings?

      Slawek

        • 1. Re: Injection doesn't work during TestNG test
          gavin.king

          that looks like it should work

          note that bijection happens at _invocation time_ in Seam, not at component instantiation time!

          • 2. Re: Injection doesn't work during TestNG test
            superfis

            Hi.

            Doscouraged @In(jection) problem I prepared simple app dedicated to be focused on this problem only.
            After I started my test app within Jboss AS, results terrified me ;) ... I can't understand why it doesn't work.

            Seam action bean:

            @Stateful
            @Name( "showAction" )
            // @Intercept( InterceptionType.ALWAYS ) // added to check if it could help
            public class ShowActionBean implements ShowAction {
            
             // this doesn't work
             @In( create = true )
             @Out
             private TestAction testAction;
            
             @Begin( join = true )
             public String go( ) {
            
             // this solution works
             // testBean = (Test) Contexts.getSessionContext( ).get( "testBean" );
            
             System.out.println( "id=" + testBean.getId( ) );
             System.out.println( "name=" + testBean.getName( ) );
             return "next";
             }
            
             @Destroy
             @Remove
             public void destroy( ) {
             }
            
            }



            Back bean:

            @Stateful
            @Name( "testBean" )
            public class TestBean implements Test {
            
             private int id;
             private String name;
            
             public int getId( ) {
             return id;
             }
            
             public void setId( int id ) {
             this.id = id;
             }
            
             public String getName( ) {
             return name;
             }
            
             public void setName( String name ) {
             this.name = name;
             }
            
             @Destroy
             @Remove
             public void destroy( ) {
             }
            
            }


            I've got created jsf site where are 2 text inputs and submit action performing showAction.go( ) method.

            When I fill up text inputs on the site and click submit button, I receive Caused by: java.lang.NullPointerException in go( ) method for System.out.println( "id=" + testBean.getId( ) ) line.
            When I use testBean = (Test) Contexts.getSessionContext( ).get( "testBean" ), everything works correctly and I have received testBean from CONVERSATION context.

            How to make @In(jections) working?

            Regards, Slawek