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.ui;
20
21 import java.io.StringWriter;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import javax.faces.component.UIViewRoot;
26
27 import org.apache.myfaces.test.mock.MockResponseWriter;
28 import org.apache.myfaces.view.facelets.FaceletTestCase;
29 import org.junit.Assert;
30 import org.junit.Test;
31
32 public class UITestCase extends FaceletTestCase
33 {
34
35 @Override
36 protected void setupComponents() throws Exception
37 {
38 application.addComponent(UIViewRoot.COMPONENT_TYPE, UIViewRoot.class
39 .getName());
40 application.addComponent(ComponentRef.COMPONENT_TYPE,
41 ComponentRef.class.getName());
42 }
43
44 @Override
45 protected void setupConvertersAndValidators() throws Exception
46 {
47 }
48
49 @Override
50 protected void setupRenderers() throws Exception
51 {
52 }
53
54 @Test
55 public void testRelativePaths() throws Exception
56 {
57 UIViewRoot root = facesContext.getViewRoot();
58 vdl.buildView(facesContext, root, "parent.xml");
59
60 StringWriter sw = new StringWriter();
61 MockResponseWriter mrw = new MockResponseWriter(sw);
62 facesContext.setResponseWriter(mrw);
63 root.encodeAll(facesContext);
64 sw.flush();
65
66 Assert.assertTrue(sw.toString().equals("Hello World!"));
67
68
69
70
71 }
72
73 @Test
74 public void testCompositionTemplate() throws Exception
75 {
76 UIViewRoot root = facesContext.getViewRoot();
77 vdl.buildView(facesContext, root, "composition-template.xml");
78
79 StringWriter sw = new StringWriter();
80 MockResponseWriter mrw = new MockResponseWriter(sw);
81 facesContext.setResponseWriter(mrw);
82 root.encodeAll(facesContext);
83 sw.flush();
84
85 String response = sw.toString();
86
87 Assert.assertTrue(response.contains("New Title"));
88 Assert.assertTrue(response.contains("New Body"));
89 }
90
91 @Test
92 public void testCompositionTemplateSimple() throws Exception
93 {
94 UIViewRoot root = facesContext.getViewRoot();
95 vdl.buildView(facesContext, root, "composition-template-simple.xml");
96
97 StringWriter sw = new StringWriter();
98 MockResponseWriter mrw = new MockResponseWriter(sw);
99 facesContext.setResponseWriter(mrw);
100 root.encodeAll(facesContext);
101 sw.flush();
102
103 String response = sw.toString();
104
105 Assert.assertTrue(response.contains("New Body"));
106 }
107
108 @Test
109 public void testComponent() throws Exception
110 {
111 Map map = new HashMap();
112 facesContext.getExternalContext().getRequestMap().put("map", map);
113
114 UIViewRoot root = facesContext.getViewRoot();
115 vdl.buildView(facesContext, root, "component.xml");
116
117 Assert.assertEquals("only one child, the component", 1, root.getChildCount());
118 Assert.assertNotNull("bound to map", map.get("c"));
119 }
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 }