3 Replies Latest reply on Nov 21, 2009 9:26 PM by versilov

    Testing Pageflows

    acerberus

      I am trying to test a pageflow definition, but am not really successful. This is the testcode i am using:


      String cid = new FacesRequest("/somepage.xhtml") {
                    
           @Override
           protected void invokeApplication(){
                invokeAction("#{someComponent.executeActionThatStartsPageflow}");
           }
                     
      }.run();
      
      new FacesRequest("/firstpageinflow.xhtml", cid) {
          @Override
           protected void invokeApplication(){
               invokeAction("next");
           }
      }.run();
      


      The first requests calls an action annotated with @Begin, which should begin a pageflow. The next action in the second request should trigger a transition to a page with an action defined on it. However, the action is not triggered and I could not find any evidence, that the next action was in fact passed on to the pageflow handler. Is there anything special about testing pageflows, since this approach seems not to work.


      Cheers
      Arno

        • 1. Re: Testing Pageflows
          acerberus

          It might have something todo with the conversation handling. When adding an 'assert isLongRunningConversation();' to the first request after the invokeAction statement, it is asserted that we are in fact in a long running conversation. When adding the assertion into the invokeApplication method of the second request I get an assertion error.


          Strangely, the conversation seems to be propagated to the second request, if I do not start a pageflow but only a plain conversation. Could this be a bug in the pageflow handling in seamtest or am I doing something completely wrong here?

          • 2. Re: Testing Pageflows
            acerberus

            Am I really the first person who tries to test pageflows, or am I missing something so obvious that you don't want to tell me :D? Come on .. there has to be someone out there who tried this before. Please, help. Or are pageflows really not testable at the moment?

            • 3. Re: Testing Pageflows
              versilov

              I've got the problem with pageflows also.
              I extended the checkout pageflow from dvdstore example — added an address form into it.
              I also expanded the test to test this form with FacesRequest.
              Strange problem — after executing faces requests for /address.xhtml page, invokeApplication() and renderResponse() methods for testing /confirm.xhtml are not invoked!


              Here's the code:


                  public long makeOrder() throws Exception {
                      String id = new FacesRequest("/product.xhtml") {
                          @Override
                          protected void beforeRequest() {
                              setParameter("id", "41");
                          }
                      }.run();

                      log.info("Before product.xhtml cid=" + id);
                      id = new FacesRequest("/product.xhtml", id) {
                          @Override
                          protected void invokeApplication() throws Exception {
                              invokeAction("#{search.addToCart}");
                          }
                      }.run();
                     
                      log.info("Before checkout.xhtml cid=" + id);
                      id = new NonFacesRequest("/checkout.xhtml", id) {
                      }.run();
                     
                      log.info("Before checkout.xhtml cid=" + id);
                      id = new FacesRequest("/checkout.xhtml", id) {
                          @Override
                          protected void applyRequestValues() throws Exception {
                             setValue("#{identity.username}", "user1");
                             setValue("#{identity.password}", "password");
                          }
                          protected void invokeApplication() throws Exception {
                              invokeAction("#{identity.login}");
                          }
                          @Override
                          protected void renderResponse() throws Exception {
                              assert getValue("#{identity.loggedIn}").equals(Boolean.TRUE);
                              User currentUser = (User) getValue("#{currentUser}");
                              assert currentUser.getUserName().equals("user1");
                          }
                      }.run();      

                      log.info("Before checkout.xhtml cid=" + id);
                      id = new FacesRequest("/checkout.xhtml", id) {
                          @Override
                          protected void invokeApplication() throws Exception {            
                              invokeAction("#{checkout.createOrder}");
                              Order order = (Order) getValue("#{currentOrder}");
                              assert order!=null;
                          }        
                          @Override
                          protected void renderResponse()   {
                              assert Manager.instance().isLongRunningConversation();
                          }
                      }.run();

                      log.info("Before address.xhtml cid=" + id);
                      id = new NonFacesRequest("/address.xhtml", id) {
                      }.run();

                      log.info("Before address.xhtml cid=" + id);
                      id = new FacesRequest("/address.xhtml", id) {
                          @Override
                          protected void applyRequestValues() throws Exception {
                             setValue("#{currentOrder.customer.address1}", "Malholland drive, 35-40");
                          }

                          @Override
                          protected void invokeApplication() throws Exception {
                              log.info("Submitting address...");
                              invokeAction("#{checkout.submitAddress}");
                          }

                          @Override
                          protected void renderResponse()   {
                              assert Manager.instance().isLongRunningConversation();
                          }
                      }.run();

                      log.info("before confirm.xhtml cid=" + id);
                      id = new NonFacesRequest("/confirm.xhtml", id) {
                      }.run();

                      final Wrapper<Long> orderId = new Wrapper<Long>();
                     
                      log.info("Before confirm.xhtml cid=" + id);
                      FacesRequest fr = new FacesRequest("/confirm.xhtml", id) {
                          @Override
                          protected void invokeApplication() throws Exception {
                              log.info("Invoking submitOrder...");
                              invokeAction("#{checkout.submitOrder}");
                          }
                          @Override
                          protected void renderResponse() throws Exception {
                              Order order = (Order) getValue("#{completedOrder}");
                              assert order!=null;
                              log.info("OrderId: " + order.getOrderId());
                              assert order.getCustomer().getUserName().equals("user1");
                              assert order.getStatus().equals(Status.OPEN);
                              assert Manager.instance().isLongRunningConversation();

                              orderId.setValue(order.getOrderId());
                              assert orderId.getValue() != null;
                          }
                      };

                      fr.run();
                     
                      return orderId.getValue();
                  }