1 Reply Latest reply on May 14, 2009 9:52 PM by Brendan Farragher

    How to set cookie for Seam integration test

    Brendan Farragher Newbie

      Hi. Does anybody know how to go about setting a cookie for an integration test? I have tried doing this with FacesContext.getExternalRequest.getRequestCookieMap() inside of the test case, but the cookie doesn't show up when I print out the cookie map during code execution in debug mode. I also tried creating the FacesRequest object inside of the test case, and before calling run() on FacesRequest instance, I set the cookie on it via .getCookies().add(myCookie), but then I get an UnsupportedOperationException, so it's not implemented.

      Thanks.

        • 1. Re: How to set cookie for Seam integration test
          Brendan Farragher Newbie

          Sorry to bump this one again, but does anyone know if setting a cookie for an integration test can be done? Inside the TestNG test case method, I am trying to do something like the following. I get a java.lang.UnsupportedOperationException on the getCookies().add(cookie) call. It also doesn't seem correct anyway to be setting cookies on the request. I am just trying to experiment with what is available on the FacesRequest. I tried grabbing the response object from ExternalContext, to add the cookie on the response, but that also doesn't work, or seem to be the correct approach:



          ...
          
          FacesRequest testPageRequest =  
          new FacesRequest("/testPage.xhtml")
          {
            /**
             * This method simulates setting UI values
             */
            @Override
            protected void updateModelValues() throws Exception
            {     
                  /**
                   * Set cookie
                   */
          
                          
                  Cookie cookie = new Cookie("TEST_COOKIE","TEST COOKIE");
                                          
                  cookie.setDomain("mydomain.net");
                  cookie.setPath("/");
                                          
                  this.getCookies().add(cookie);
          
          //((HttpServletResponse)this.getFacesContext().getCurrentInstance().getExternalContext().getResponse()).addCookie(cookie);                      
                                          
            }
          
          ...




          Thanks.