8 Replies Latest reply on Oct 10, 2010 2:44 AM by logan

    page scope propagation in Integration Tests

    lucas84

      hi guys,




      Is in integration tests support for page scope?? Here is simple example where it doesn't work. The environment is seam-2.2.0 GA


      page.xml for page I'm trying to test


      <page xmlns="http://jboss.com/products/seam/pages"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.1.xsd">
      
          <rewrite pattern="/offers/{offerId}/details" />    
          <action execute="#{singleOfferRentOrderAction.initialize}"/>
          <param name="offerId" value="#{singleOfferRentOrderAction.offerId}" required="true"/>
          
      </page>
      



      Integration test:


              new NonFacesRequest("/offers/details.xhtml") {
                  @Override
                  protected void beforeRequest() {
                      setParameter("offerId", "1");
                  }
              }.run();
      
              new FacesRequest("/offers/details.xhtml") {
      
                  @Override
                  protected void updateModelValues() throws Exception {
      
                      //renting details
                      setValue("#{singleOfferRentOrderAction.rentFromDate}", DateUtils.create(2009, 07, 10));
                      setValue("#{singleOfferRentOrderAction.rentToDate}", DateUtils.create(2009, 07, 20));
                      setValue("#{singleOfferRentOrderAction.quantity}", 1l);
      
                      //charging options
                      setValue("#{singleOfferRentOrderAction.isTransportIncluded}", true);
                      setValue("#{singleOfferRentOrderAction.isInsuranceIncluded}", true);
                      setValue("#{singleOfferRentOrderAction.isInstallmentIncluded}", true);
                      setValue("#{singleOfferRentOrderAction.isIncludeDeposit}", true);
      
                      //delivery details
                      setValue("#{singleOfferRentOrderAction.deliveryCityName}", "Szczecin");
                      setValue("#{singleOfferRentOrderAction.deliveryZipCode}", "70-781");
                      setValue("#{singleOfferRentOrderAction.deliveryStreet}", "Wyzwolenia");
                      setValue("#{singleOfferRentOrderAction.deliveryHouseNo}", "15");
                  }
      
                  @Override
                  protected void invokeApplication() throws Exception {
      
                      String outcome = (String) invokeAction("#{singleOfferRentOrderAction.perform}");
                      assertEquals(outcome, "success");
                  }
      
              }.run();
      
      



      Component, which I use in test


      @Scope(ScopeType.PAGE)
      @Name("singleOfferRentOrderAction")
      public class SingleOfferRentOrderAction extends RentOrderAction {
      
          private Long offerId;
          
          public String initialize() {
             ...
          }
      
          public String perform() {
             ...
          }
      
      }
      



      As you can see in the test case I do NonFacesRequest to /offers/details.xhtml (Get method) just to set parameter and fire initialize method. Than I do FacesRequest(Post method) to /offers/details.xhtml in order to submit the form and invoke action method. I am on the same page, so the same instance of singleOfferRentOrderAction (as it is kept in a page scope) should be retrieved among request.  The problem is that I get new instance of singleOfferRentOrderAction in facesRequest (so it isn't initialized). I quess the problem is that page scope isn't supported so I get new instance. In production it works well.


      My questions are:


      1) is page scope supported?


      2) if do what I do wrong


      thx for any replies and hints