1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.jsp;
22
23 import java.io.StringWriter;
24
25 import javax.servlet.jsp.JspException;
26 import javax.servlet.jsp.JspWriter;
27
28 import org.apache.struts2.views.jsp.ui.AnchorTag;
29 import org.apache.struts2.views.jsp.ui.StrutsBodyContent;
30
31
32 /***
33 *
34 */
35 public class AnchorTagTest extends AbstractUITagTest {
36 private StringWriter writer = new StringWriter();
37 private AnchorTag tag;
38
39 public void testActionURL() {
40 tag.setHref("TestAction.action");
41 try {
42 tag.doStartTag();
43 tag.doEndTag();
44 assertTrue( writer.toString().indexOf("href=\"TestAction.action\"") > -1);
45 } catch (JspException ex) {
46 ex.printStackTrace();
47 fail();
48 }
49 }
50
51 public void testAddParameters() {
52 tag.setHref("/TestAction.action");
53 String bodyText = "<img src=\"#\"/>";
54 try {
55 StrutsBodyContent bodyContent = new StrutsBodyContent(null);
56 bodyContent.print(bodyText);
57 tag.setBodyContent(bodyContent);
58
59 tag.doStartTag();
60 tag.doEndTag();
61 } catch (Exception ex) {
62 ex.printStackTrace();
63 fail();
64 }
65 }
66
67
68 protected void setUp() throws Exception {
69 super.setUp();
70
71 request.setScheme("http");
72 request.setServerName("localhost");
73 request.setServerPort(80);
74
75 tag = new AnchorTag();
76 tag.setPageContext(pageContext);
77 JspWriter jspWriter = new StrutsMockJspWriter(writer);
78 pageContext.setJspWriter(jspWriter);
79 }
80
81 }