View Javadoc

1   /* Licensed to the Apache Software Foundation (ASF) under one or more
2    * contributor license agreements.  See the NOTICE file distributed with
3    * this work for additional information regarding copyright ownership.
4    * The ASF licenses this file to you under the Apache License, Version 2.0
5    * (the "License"); you may not use this file except in compliance with
6    * the License.  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15  */
16  
17  package org.apache.myfaces.context;
18  
19  import java.util.Map;
20  
21  import javax.faces.FactoryFinder;
22  import javax.faces.context.FacesContext;
23  import org.apache.myfaces.context.servlet.FacesContextImpl;
24  import org.apache.myfaces.test.base.AbstractJsfTestCase;
25  
26  /**
27   * Tests the facesContext isAjaxRequest
28   * with all its sideconditions
29   *
30   * @author Werner Punz(latest modification by $Author: struberg $)
31   * @version $Revision: 1188694 $ $Date: 2011-10-25 10:07:44 -0500 (Tue, 25 Oct 2011) $
32   */
33  public class TestIsAjaxRequest extends AbstractJsfTestCase {
34      Map<String, String> requestParameterMap = null;
35      FacesContext context = null;
36  
37      public TestIsAjaxRequest() {
38          super("TestIsAjaxRequest");
39      }
40  
41      public void setUp() throws Exception {
42          super.setUp();
43  
44          //requestParameterMap = new HashMap<String, String>();
45          //ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParameterMap);
46          FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
47              "org.apache.myfaces.context.PartialViewContextFactoryImpl");     
48          FactoryFinder.setFactory (FactoryFinder.EXCEPTION_HANDLER_FACTORY,
49          "org.apache.myfaces.context.ExceptionHandlerFactoryImpl");
50          context = new FacesContextImpl(servletContext, request, response);
51      }
52  
53      public void tearDown() throws Exception {
54          super.tearDown();
55          //requestParameterMap.clear();
56      }
57  
58      public void testNoEntry() {
59  
60          assertFalse("no ajax request found", context.getPartialViewContext().isAjaxRequest());
61      }
62  
63      public void testEntry() {
64          request.addHeader("Faces-Request", "partial/ajax");
65          assertTrue("no ajax request found", context.getPartialViewContext().isAjaxRequest());
66      }
67  }