1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
30
31
32
33
34
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
53
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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
118
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
133
134
135
136
137
138 }
139 }