1 5 package com.opensymphony.webwork.views.jsp; 6 7 import com.opensymphony.webwork.ServletActionContext; 8 import com.opensymphony.xwork.ActionContext; 9 10 import java.io.InputStream ; 11 import java.net.URL ; 12 import java.util.StringTokenizer ; 13 14 15 19 public abstract class AbstractUITagTest extends AbstractTagTest { 20 22 29 public void verify(URL url) throws Exception { 30 if (url == null) { 31 fail("unable to verify a null URL"); 32 } else if (this.writer == null) { 33 fail("AbstractJspWriter.writer not initialized. Unable to verify"); 34 } 35 36 StringBuffer buffer = new StringBuffer (128); 37 InputStream in = url.openStream(); 38 byte[] buf = new byte[4096]; 39 int nbytes; 40 41 while ((nbytes = in.read(buf)) > 0) { 42 buffer.append(new String (buf, 0, nbytes)); 43 } 44 45 in.close(); 46 47 51 String writerString = writer.toString(); 52 String bufferString = buffer.toString(); 53 54 assertEquals(bufferString, writerString); 55 } 56 57 protected void setUp() throws Exception { 58 super.setUp(); 59 60 ServletActionContext.setServletContext(pageContext.getServletContext()); 61 } 62 63 protected void tearDown() throws Exception { 64 super.tearDown(); 65 ActionContext.setContext(null); 66 } 67 68 75 private String normalize(Object obj) { 76 StringTokenizer st = new StringTokenizer (obj.toString().trim(), " \t\r\n"); 77 StringBuffer buffer = new StringBuffer (128); 78 79 while (st.hasMoreTokens()) { 80 buffer.append(st.nextToken()); 81 82 if (st.hasMoreTokens()) { 83 buffer.append(" "); 84 } 85 } 86 87 return buffer.toString(); 88 } 89 } 90 | Popular Tags |