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