1 16 17 package org.apache.struts.faces.sysclient; 18 19 import java.util.Iterator ; 20 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 24 import com.gargoylesoftware.htmlunit.html.HtmlBase; 25 import com.gargoylesoftware.htmlunit.html.HtmlElement; 26 import com.gargoylesoftware.htmlunit.html.HtmlLink; 27 import com.gargoylesoftware.htmlunit.html.HtmlSpan; 28 29 30 36 37 public class SimpleTestCase extends AbstractTestCase { 38 39 40 42 43 48 public SimpleTestCase(String name) { 49 50 super(name); 51 52 } 53 54 55 57 58 60 61 64 public void setUp() throws Exception { 65 66 super.setUp(); 67 page("/simple.faces"); 68 69 } 70 71 72 75 public static Test suite() { 76 77 return (new TestSuite(SimpleTestCase.class)); 78 79 } 80 81 82 85 public void tearDown() { 86 87 super.tearDown(); 88 89 } 90 91 92 93 95 96 99 public void testBase() throws Exception { 100 101 HtmlBase base = null; 102 Iterator kids = head().getChildIterator(); 103 while (kids.hasNext()) { 104 HtmlElement kid = (HtmlElement) kids.next(); 105 if (kid instanceof HtmlBase) { 106 assertNull("Only one base element present", base); 107 base = (HtmlBase) kid; 108 } 109 } 110 assertNotNull("Exactly one base element present", base); 111 assertEquals("base", base.getTagName()); 112 assertEquals(url("/simple.jsp").toString(), base.getHrefAttribute()); 113 assertEquals("", base.getTargetAttribute()); 114 115 } 116 117 118 121 public void testHtml() throws Exception { 122 123 HtmlElement html = page.getDocumentElement(); 124 assertEquals("html", html.getTagName()); 125 assertEquals("http://www.w3.org/1999/xhtml", html.getAttributeValue("xmlns")); 126 129 } 130 131 132 136 public void testLoadMessages() throws Exception { 137 138 HtmlSpan span = null; 139 140 span = (HtmlSpan) element("lookup-simple"); 141 assertNotNull(span); 142 assertEquals("Resource Simple Text", span.asText()); 143 144 span = (HtmlSpan) element("lookup-filtered"); 145 assertNotNull(span); 146 assertEquals("Resource <b>Filtered</b> Text", span.asText()); 147 148 span = (HtmlSpan) element("lookup-unfiltered"); 149 assertNotNull(span); 150 assertEquals("Resource Unfiltered Text", span.asText()); 151 152 } 153 154 155 158 public void testMessage() throws Exception { 159 160 HtmlSpan span = null; 161 162 span = (HtmlSpan) element("message-direct"); 163 assertNotNull(span); 164 assertEquals("Resource Simple Text", span.asText()); 165 166 span = (HtmlSpan) element("message-indirect"); 167 assertNotNull(span); 168 assertEquals("Resource Simple Text", span.asText()); 169 170 span = (HtmlSpan) element("message-filtered"); 171 assertNotNull(span); 172 assertEquals("Resource <b>Filtered</b> Text", span.asText()); 173 174 span = (HtmlSpan) element("message-unfiltered"); 175 assertNotNull(span); 176 assertEquals("Resource Unfiltered Text", span.asText()); 177 178 span = (HtmlSpan) element("message-substitute"); 179 assertNotNull(span); 180 assertEquals("From Here to Eternity", span.asText()); 181 182 } 183 184 185 188 public void testStylesheet() throws Exception { 189 190 HtmlLink link = null; 191 Iterator kids = head().getChildElementsIterator(); 192 while (kids.hasNext()) { 193 HtmlElement kid = (HtmlElement) kids.next(); 194 if (kid instanceof HtmlLink) { 195 assertNull("Only one stylesheet element present", link); 196 link = (HtmlLink) kid; 197 } 198 } 199 assertNotNull("Exactly one stylesheet element present", link); 200 assertEquals("link", link.getTagName()); 201 assertEquals("", link.getCharsetAttribute()); 202 String url = this.url.toString(); 203 url = url.substring(0, url.length() - 1); 204 url = url.substring(url.lastIndexOf('/')); 205 assertEquals(url + "/stylesheet.css", link.getHrefAttribute()); 206 assertEquals("", link.getHrefLangAttribute()); 207 assertEquals("", link.getMediaAttribute()); 208 assertEquals("stylesheet", link.getRelAttribute()); 209 assertEquals("", link.getRevAttribute()); 210 assertEquals("", link.getTargetAttribute()); 211 assertEquals("text/css", link.getTypeAttribute()); 212 213 } 214 215 216 219 public void testSubview() throws Exception { 220 221 HtmlSpan span = null; 222 223 span = (HtmlSpan) element("subview:write1"); 224 assertNotNull(span); 225 assertEquals("subview:write1", span.asText()); 226 227 } 228 229 230 233 public void testTitle() throws Exception { 234 235 assertEquals("simple", title()); 236 237 } 238 239 240 243 public void testWrite() throws Exception { 244 245 HtmlSpan span = null; 246 247 span = (HtmlSpan) element("write-literal"); 248 assertNotNull(span); 249 assertEquals("Literal Write Content", span.asText()); 250 251 span = (HtmlSpan) element("write-filtered"); 252 assertNotNull(span); 253 assertEquals("Literal <b>Filtered</b> Content", span.asText()); 254 255 span = (HtmlSpan) element("write-unfiltered"); 256 assertNotNull(span); 257 assertEquals("Literal Unfiltered Content", span.asText()); 258 259 span = (HtmlSpan) element("retrieved-literal"); 260 assertNotNull(span); 261 assertEquals("Retrieved Simple Content", span.asText()); 262 263 span = (HtmlSpan) element("retrieved-filtered"); 264 assertNotNull(span); 265 assertEquals("Retrieved <b>Filtered</b> Content", span.asText()); 266 267 span = (HtmlSpan) element("retrieved-unfiltered"); 268 assertNotNull(span); 269 assertEquals("Retrieved Unfiltered Content", span.asText()); 270 271 } 272 273 274 } 275 | Popular Tags |