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  package org.apache.myfaces.context;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import javax.faces.FactoryFinder;
22  import javax.faces.context.FacesContext;
23  import javax.faces.context.PartialViewContext;
24  
25  import org.apache.myfaces.context.servlet.FacesContextImpl;
26  import org.apache.myfaces.test.base.AbstractJsfTestCase;
27  
28  /**
29   * Testcases for the request parameter handling
30   * and setter handing on the get and
31   * set renderPhaseClientIds in the FacesContext class!
32   *
33   * @author Werner Punz(latest modification by $Author: bommel $)
34   * @version $Revision: 954308 $ $Date: 2010-06-13 15:52:08 -0500 (Sun, 13 Jun 2010) $
35   */
36  public class RenderPhaseClientIdsTest extends AbstractJsfTestCase {
37  
38      public RenderPhaseClientIdsTest() {
39          super("RenderPhaseClientIdsTest");
40      }
41  
42      @Override
43      protected void setUp() throws Exception {
44          super.setUp();
45          FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
46          "org.apache.myfaces.context.PartialViewContextFactoryImpl");     
47          FactoryFinder.setFactory (FactoryFinder.EXCEPTION_HANDLER_FACTORY,
48          "org.apache.myfaces.context.ExceptionHandlerFactoryImpl");
49      }
50      
51      /**
52       * Empty String as request param
53       * has to result in an empty list
54       */
55      public void testRequestParams1() {
56          String empty = "    \n \t  ";
57          Map<String, String> requestParamMap = new HashMap<String, String>();
58          requestParamMap.put(PartialViewContext.PARTIAL_RENDER_PARAM_NAME, empty);
59          ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParamMap);
60  
61          FacesContext context = new FacesContextImpl(servletContext, wrapper, response);
62          
63          PartialViewContext pprContext = context.getPartialViewContext();
64  
65          assertTrue(pprContext.getRenderIds().isEmpty());
66      }
67  
68      /**
69       * no request param, has to result in an empty list
70       */
71      public void testRequestParams2() {
72          Map<String, String> requestParamMap = new HashMap<String, String>();
73          ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParamMap);
74  
75          FacesContext context = new FacesContextImpl(servletContext, wrapper, response);
76          
77          PartialViewContext pprContext = context.getPartialViewContext();
78  
79          assertTrue(pprContext.getRenderIds().isEmpty());
80      }
81  
82      /**
83       * NO_PARTIAL_PHASE_CLIENT_IDS as request param, has to result in an empty list
84       */
85      /*
86      public void testRequestParams4() {
87          Map<String, String> requestParamMap = new HashMap<String, String>();
88          requestParamMap.put(PartialViewContext.PARTIAL_RENDER_PARAM_NAME, 
89                              PartialViewContext.NO_PARTIAL_PHASE_CLIENT_IDS);
90          ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParamMap);
91  
92          FacesContext context = new FacesContextImpl(servletContext, wrapper, response);
93          
94          PartialViewContext pprContext = context.getPartialViewContext();
95  
96          assertTrue(pprContext.getRenderIds().isEmpty());
97      }*/
98  
99      /**
100      * list with one element has to result in a list with one element
101      */
102     public void testRequestParams5() {
103         String params = " view1:panel1:_component1  ";
104         Map<String, String> requestParamMap = new HashMap<String, String>();
105         requestParamMap.put(PartialViewContext.PARTIAL_RENDER_PARAM_NAME, params);
106         ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParamMap);
107 
108         FacesContext context = new FacesContextImpl(servletContext, wrapper, response);
109         
110         PartialViewContext pprContext = context.getPartialViewContext();
111 
112         assertTrue("Length must be one",pprContext.getRenderIds().size() == 1);
113         assertTrue("Value match",pprContext.getRenderIds().iterator().next().equals("view1:panel1:_component1"));
114     }
115 
116     /**
117      * test on a full blown list containing various
118      * blank chars
119      */
120     public void testRequestParams6() {
121         String params = " view1:panel1:_component1 view1:panel1:_component2 \n  component3 component4  ";
122         Map<String, String> requestParamMap = new HashMap<String, String>();
123         requestParamMap.put(PartialViewContext.PARTIAL_RENDER_PARAM_NAME, params);
124         ContextTestRequestWrapper wrapper = new ContextTestRequestWrapper(request, requestParamMap);
125 
126         FacesContext context = new FacesContextImpl(servletContext, wrapper, response);
127         
128         PartialViewContext pprContext = context.getPartialViewContext();
129 
130         assertTrue("Length must be four",pprContext.getRenderIds().size() == 4);
131 
132         // FIXME: Latest spec uses a Collection so order is not garanteed
133 //        assertTrue("Value match",pprContext.getRenderIds().get(0).equals("view1:panel1:_component1"));
134 //        assertTrue("Value match",pprContext.getRenderIds().get(2).equals("component3"));
135 //
136 //
137 //        assertTrue("Value match",pprContext.getRenderIds().get(3).equals("component4"));
138     }
139 }