1 5 package com.opensymphony.webwork.views.jsp; 6 7 import javax.servlet.jsp.JspException ; 8 import javax.servlet.jsp.JspWriter ; 9 import java.io.StringWriter ; 10 11 12 18 public class URLTagTest extends AbstractUITagTest { 19 private StringWriter writer = new StringWriter (); 20 private URLTag tag; 21 22 public void testActionURL() { 23 tag.setValue("TestAction.action"); 24 25 try { 26 tag.doStartTag(); 27 tag.doEndTag(); 28 assertEquals("TestAction.action", writer.toString()); 29 } catch (JspException ex) { 30 ex.printStackTrace(); 31 fail(); 32 } 33 } 34 35 public void testAddParameters() { 36 request.setAttribute("webwork.request_uri", "/Test.action"); 37 38 request.setAttribute("webwork.request_uri", "/TestAction.action"); 39 request.setQueryString("param0=value0"); 40 41 try { 42 tag.doStartTag(); 43 tag.addParameter("param1", "value1"); 44 tag.addParameter("param2", "value2"); 45 tag.doEndTag(); 46 assertEquals("/TestAction.action?param2=value2&param0=value0&param1=value1", writer.toString()); 47 } catch (JspException ex) { 48 ex.printStackTrace(); 49 fail(); 50 } 51 } 52 53 public void testEvaluateValue() { 54 Foo foo = new Foo(); 55 foo.setTitle("test"); 56 stack.push(foo); 57 tag.setValue("%{title}"); 58 59 try { 60 tag.doStartTag(); 61 tag.doEndTag(); 62 assertEquals("test", writer.toString()); 63 } catch (JspException ex) { 64 ex.printStackTrace(); 65 fail(); 66 } 67 } 68 69 public void testHttps() { 70 request.setScheme("https"); 71 request.setServerName("localhost"); 72 request.setServerPort(443); 73 74 tag.setValue("list-members.action"); 75 76 try { 77 tag.doStartTag(); 78 tag.doEndTag(); 79 assertEquals("list-members.action", writer.toString()); 80 } catch (JspException ex) { 81 ex.printStackTrace(); 82 fail(); 83 } 84 } 85 86 protected void setUp() throws Exception { 87 super.setUp(); 88 89 request.setScheme("http"); 90 request.setServerName("localhost"); 91 request.setServerPort(80); 92 93 tag = new URLTag(); 94 tag.setPageContext(pageContext); 95 JspWriter jspWriter = new WebWorkMockJspWriter(writer); 96 pageContext.setJspWriter(jspWriter); 97 } 98 99 public class Foo { 100 private String title; 101 102 public void setTitle(String title) { 103 this.title = title; 104 } 105 106 public String getTitle() { 107 return title; 108 } 109 110 public String toString() { 111 return "Foo is: " + title; 112 } 113 } 114 } 115 | Popular Tags |