1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.view.facelets.tag.jstl.core;
20
21 import java.util.Map;
22
23 import javax.faces.application.StateManager;
24 import javax.faces.component.UIComponent;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.event.PhaseId;
27
28 import org.apache.myfaces.shared.config.MyfacesConfig;
29 import org.apache.myfaces.view.facelets.FaceletTestCase;
30 import org.apache.myfaces.view.facelets.bean.Employee;
31 import org.junit.Assert;
32 import org.junit.Test;
33
34 public class CifTestCase extends FaceletTestCase
35 {
36
37 protected void setUpServletObjects() throws Exception
38 {
39 super.setUpServletObjects();
40
41 servletContext.addInitParameter(StateManager.PARTIAL_STATE_SAVING_PARAM_NAME,
42 "true");
43 servletContext.addInitParameter(MyfacesConfig.INIT_PARAM_REFRESH_TRANSIENT_BUILD_ON_PSS,"true");
44 }
45
46 @Test
47 public void testIf1() throws Exception
48 {
49 facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
50
51 Map session = facesContext.getExternalContext().getSessionMap();
52 Employee e = new Employee();
53 session.put("employee", e);
54
55 UIViewRoot root = facesContext.getViewRoot();
56
57
58 e.setManagement(true);
59 vdl.buildView(facesContext, root,"if2.xhtml");
60 UIComponent c = root.findComponent("form");
61 Assert.assertNotNull("form is null", c);
62 c = root.findComponent("start");
63 Assert.assertNotNull("start is null", c);
64 c = root.findComponent("end");
65 Assert.assertNotNull("end is null", c);
66
67
68
69 e.setManagement(false);
70
71
72
73 root = facesContext.getViewRoot();
74 vdl.buildView(facesContext, root,"if2.xhtml");
75 c = root.findComponent("form");
76 Assert.assertNull("form is not null", c);
77
78 c = root.findComponent("start");
79 Assert.assertNotNull("start is null", c);
80 c = root.findComponent("end");
81 Assert.assertNotNull("end is null", c);
82 facesContext.getAttributes().remove(root);
83
84 }
85
86 @Test
87 public void testIf2() throws Exception
88 {
89 facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
90
91 Map session = facesContext.getExternalContext().getSessionMap();
92 Employee e = new Employee();
93 session.put("employee", e);
94
95 UIViewRoot root = facesContext.getViewRoot();
96
97
98 e.setManagement(false);
99 vdl.buildView(facesContext, root,"if2.xhtml");
100 UIComponent c = root.findComponent("form");
101 Assert.assertNull("form is not null", c);
102 c = root.findComponent("start");
103 Assert.assertNotNull("start is null", c);
104 c = root.findComponent("end");
105 Assert.assertNotNull("end is null", c);
106
107
108
109 e.setManagement(true);
110 root = facesContext.getViewRoot();
111 vdl.buildView(facesContext, root,"if2.xhtml");
112 c = root.findComponent("form");
113 Assert.assertNotNull("form is null", c);
114
115 c = root.findComponent("start");
116 Assert.assertNotNull("start is null", c);
117 c = root.findComponent("end");
118 Assert.assertNotNull("start is null", c);
119 }
120
121 @Test
122 public void testIf3() throws Exception
123 {
124 facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);
125
126 Map session = facesContext.getExternalContext().getSessionMap();
127 Employee e = new Employee();
128 session.put("employee", e);
129
130 UIViewRoot root = facesContext.getViewRoot();
131
132
133 e.setManagement(true);
134 vdl.buildView(facesContext, root,"if3.xhtml");
135 UIComponent c = root.findComponent("form");
136 Assert.assertNotNull("form is null", c);
137 Assert.assertNotNull(c.getFacet("header"));
138 c = root.findComponent("start");
139 Assert.assertNotNull("start is null", c);
140 c = root.findComponent("end");
141 Assert.assertNotNull("end is null", c);
142
143
144
145 e.setManagement(false);
146 root = facesContext.getViewRoot();
147 vdl.buildView(facesContext, root,"if3.xhtml");
148 c = root.findComponent("form");
149 Assert.assertNotNull("form is null", c);
150 Assert.assertNull(c.getFacet("header"));
151
152 c = root.findComponent("start");
153 Assert.assertNotNull("start is null", c);
154 c = root.findComponent("end");
155 Assert.assertNotNull("start is null", c);
156 }
157 }