2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.clay.utils;
19
20 import java.io.File;
21 import java.util.Map;
22 import java.util.TreeMap;
23
24 import javax.faces.component.UIComponent;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.shale.clay.config.beans.AttributeBean;
30 import org.apache.shale.clay.config.beans.ComponentBean;
31 import org.apache.shale.test.base.AbstractViewControllerTestCase;
32
33 public class ClayAmalgamTestCase extends AbstractViewControllerTestCase {
34
35 private ClayAmalgam clayAmalgam = null;
36
37 protected void setUp() throws Exception {
38 super.setUp();
39
40
41 String documentRoot = System.getProperty("documentRoot");
42 if (documentRoot == null) {
43 documentRoot = System.getProperty("user.dir") + "//target//test-classes";
44 }
45 servletContext.setDocumentRoot(new File(documentRoot));
46
47 clayAmalgam = new ClayAmalgam();
48 application.addComponent("org.apache.shale.clay.component.Clay", "org.apache.shale.clay.component.Clay");
49 }
50
51
52 public ClayAmalgamTestCase(String name) {
53 super(name);
54 }
55
56
57 public static Test suite() {
58 return (new TestSuite(ClayAmalgamTestCase.class));
59 }
60
61
62 public void testClayImport() {
63
64 Map requestParams = new TreeMap();
65
66 requestParams.put("url", "/org/apache/shale/clay/utils/hello.html");
67 externalContext.setRequestParameterMap(requestParams);
68
69 ComponentBean displayElement = new ComponentBean();
70 displayElement.setId("clayImport");
71 displayElement.setComponentType("org.apache.shale.clay.component.Clay");
72 displayElement.setJsfid("clayImport");
73
74 UIComponent component = application.createComponent("org.apache.shale.clay.component.Clay");
75 component.setId("clayImport");
76 component.getAttributes().put("url","#{param.url}");
77 component.getAttributes().put("escapeXml", Boolean.TRUE.toString());
78
79 clayAmalgam.clayImport(facesContext, component, displayElement);
80
81 assertEquals("jsfid", "outputText", displayElement.getJsfid());
82 assertEquals("componentType", "javax.faces.HtmlOutputText", displayElement.getComponentType());
83
84 AttributeBean attr = displayElement.getAttribute("escape");
85 assertNotNull("escape", attr);
86 assertEquals("escape", Boolean.FALSE.toString(), attr.getValue());
87
88 attr = displayElement.getAttribute("isTransient");
89 assertNotNull("isTransient", attr);
90 assertEquals("isTransient", Boolean.TRUE.toString(), attr.getValue());
91
92 attr = displayElement.getAttribute("value");
93 assertNotNull("value", attr);
94 assertEquals("value", "<html><head></head><body bgcolor=\"blue\">Hello World</body></html>", attr.getValue());
95
96
97 component.getAttributes().put("escapeXml", Boolean.FALSE.toString());
98 displayElement = new ComponentBean();
99 displayElement.setId("clayImport");
100 displayElement.setComponentType("org.apache.shale.clay.component.Clay");
101 displayElement.setJsfid("clayImport");
102
103 clayAmalgam.clayImport(facesContext, component, displayElement);
104
105 assertEquals("jsfid", "outputText", displayElement.getJsfid());
106 assertEquals("componentType", "javax.faces.HtmlOutputText", displayElement.getComponentType());
107
108 attr = displayElement.getAttribute("escape");
109 assertNotNull("escape", attr);
110 assertEquals("escape", Boolean.FALSE.toString(), attr.getValue());
111
112 attr = displayElement.getAttribute("isTransient");
113 assertNotNull("isTransient", attr);
114 assertEquals("isTransient", Boolean.TRUE.toString(), attr.getValue());
115
116 attr = displayElement.getAttribute("value");
117 assertNotNull("value", attr);
118 assertEquals("value", "<html><head></head><body bgcolor=\"blue\">Hello World</body></html>", attr.getValue());
119
120
121
122 requestParams = new TreeMap();
123 requestParams.put("url", "classpath*:/org/apache/shale/clay/utils/hello.html");
124 externalContext.setRequestParameterMap(requestParams);
125
126 displayElement = new ComponentBean();
127 displayElement.setId("clayImport");
128 displayElement.setComponentType("org.apache.shale.clay.component.Clay");
129 displayElement.setJsfid("clayImport");
130
131 component = application.createComponent("org.apache.shale.clay.component.Clay");
132 component.setId("clayImport");
133 component.getAttributes().put("url","#{param.url}");
134 component.getAttributes().put("escapeXml", Boolean.TRUE.toString());
135
136 clayAmalgam.clayImport(facesContext, component, displayElement);
137 attr = displayElement.getAttribute("value");
138 assertNotNull("value", attr);
139 assertEquals("value", "", attr.getValue());
140
141
142
143 requestParams = new TreeMap();
144 requestParams.put("url", "/org/apache/shale/clay/utils/notfound.html");
145 externalContext.setRequestParameterMap(requestParams);
146
147 displayElement = new ComponentBean();
148 displayElement.setId("clayImport");
149 displayElement.setComponentType("org.apache.shale.clay.component.Clay");
150 displayElement.setJsfid("clayImport");
151
152 component = application.createComponent("org.apache.shale.clay.component.Clay");
153 component.setId("clayImport");
154 component.getAttributes().put("url","#{param.url}");
155 component.getAttributes().put("escapeXml", Boolean.TRUE.toString());
156
157 clayAmalgam.clayImport(facesContext, component, displayElement);
158 attr = displayElement.getAttribute("value");
159 assertNotNull("value", attr);
160 assertEquals("value", "", attr.getValue());
161
162
163 }
164
165
166 public void testClayOut() {
167 ComponentBean displayElement = new ComponentBean();
168 displayElement.setId("clayOut");
169 displayElement.setComponentType("org.apache.shale.clay.component.Clay");
170 displayElement.setJsfid("clayOut");
171
172 UIComponent component = application.createComponent("org.apache.shale.clay.component.Clay");
173 component.setId("clayOut");
174 component.getAttributes().put("value","<html><head></head><body bgcolor=\"blue\">Hello World</body></html>");
175 component.getAttributes().put("escapeXml", Boolean.FALSE.toString());
176
177
178 clayAmalgam.clayOut(facesContext, component, displayElement);
179
180 assertEquals("jsfid", "outputText", displayElement.getJsfid());
181 assertEquals("componentType", "javax.faces.HtmlOutputText", displayElement.getComponentType());
182
183 AttributeBean attr = displayElement.getAttribute("escape");
184 assertNotNull("escape", attr);
185 assertEquals("escape", Boolean.FALSE.toString(), attr.getValue());
186
187 attr = displayElement.getAttribute("isTransient");
188 assertNotNull("isTransient", attr);
189 assertEquals("isTransient", Boolean.TRUE.toString(), attr.getValue());
190
191 attr = displayElement.getAttribute("value");
192 assertNotNull("value", attr);
193 assertEquals("value", "<html><head></head><body bgcolor=\"blue\">Hello World</body></html>", attr.getValue());
194
195 }
196
197 }