2 Replies Latest reply on May 6, 2008 4:56 PM by evdelst

    TestNG & @In problems

    evdelst

      I have problems getting the @In to work during testing.


      First some code:


      @Name("dummy")
      public class DummyBean {
         @In(value="user") String user; 
         public String test() {
            return "hello "+user ;
         }
      }



      Test code:


         @Test
         public void testAction() throws Exception {
            new ComponentTest() {
      
               @Override
               protected void testComponents() throws Exception {
                  setValue("#{user}", "x");
                  assert invokeMethod("#{dummy.test}").equals("hello x");
               }
               
            }.run();
         }
      



      I get the following error:


      javax.el.ELException: org.jboss.seam.RequiredException: @In attribute requires non-null value: dummy.user



      I tried with
      #{dummy.user}
      and dummy.user, but that also doesn't work.


      Has anyone got a clue how to inject a simple String value within a test?


      Cheers,


      Edwin


        • 1. Re: TestNG & @In problems
          inabatch

          Hi,


          Earlier, I solved your same problem.
          Please try this.



          Contexts.getConversationContext().set("user", "x");

          protected void testComponents() throws Exception {
              Contexts.getConversationContext().set("user", "x");
              assert invokeMethod("#{dummy.test()}").equals("hello x");
          }
          



          If target scope is wrong, you may have to fix target scope(e.g. getSessionContext()).


          Best regards,
          Nobuyuki Inaba

          • 2. Re: TestNG & @In problems
            evdelst

            That was it.


            Thank you for your help!


            Regards,


            Edwin van der Elst