2 Replies Latest reply on Jun 10, 2015 2:53 PM by marcelolotif.araujo

    Seam how to set @RequestParameter variable in integration test

    lsk6745
      How to set @RequestParameter variable in integration test?

      for example
      --------------------------------------
      in PasswordUpdateAction bean:  

      @RequestParameter("userAccountId")
      private Integer userAccountId;

      @Create
      public void init() {
         if (userAccountId != null) {
         ...
         }
      }

      // getter and setter

      --------------------------------------
      In integration test:

      @Test
      public void shouldUpdateSuccess() throws Exception {
                             
         new ComponentTest() {

              @Override
              protected void testComponents() throws Exception {
                   invokeMethod("#{PasswordUpdateAction.setUserAccountId(1)}"); // no luck
                   setValue("#{passwordUpdateAction.userAccountId}", 1); // no luck too       
                   ...

      --------------------------------------

      How to set 1 into userAccountId?
      Thanks for any ideas or guess.


        • 1. Re: Seam how to set @RequestParameter variable in integration test
          lsk6745
          Got better insight after some searching. Solved by using
          new FacesRequest() and overide applyRequestValues() + setParameter()
          • 2. Re: Seam how to set @RequestParameter variable in integration test
            marcelolotif.araujo

            Thank you for this answer! I was searching on google like crazy and nothing solved my problem, this was the only thing that worked. For the record, here is a code snippet of the solution:

             

            public class SomeClassTest {

                 @Test

                 public void testSomeMethod() throws Exception{

                      new FacesRequest(){

                           @Override

                           protected void applyRequestValues() {

                                setParameter("someRequestParameter", "1234");

                           }

                           @Override

                           protected void invokeApplication() throws Exception {

                                invokeMethod("#{someClass.someMethod()}");

                                Assert.assertTrue(true);

                           }

                      }.run();

                 }

            }

             

            @Name("someClass")

            @Scope(ScopeType.CONVERSATION)

            @AutoCreate

            @PerNestedConversation

            public class SomeClass implements java.io.Serializable {

             

                 @RequestParameter

                 String someRequestParameter;

             

                 public void loadData() {

                      System.out.println("someRequestParameter: " + someRequestParameter);

                 }
            }