1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.tags;
17
18 import java.util.Arrays;
19 import java.util.List;
20
21 import javax.servlet.jsp.PageContext;
22 import javax.servlet.jsp.tagext.JspTag;
23
24 import org.jdom.Element;
25 import org.seasar.cubby.CubbyConstants;
26
27 public class LinkTagTest extends AbstractStandardTagTestCase {
28
29 private LinkTag tag;
30
31 @Override
32 protected void setUp() throws Exception {
33 include(getClass().getName().replace('.', '/') + ".dicon");
34 super.setUp();
35 tag = new LinkTag();
36 setupBodyTag(tag);
37 setupErrors(context);
38 context.setAttribute(CubbyConstants.ATTR_CONTEXT_PATH, "/brabra",
39 PageContext.REQUEST_SCOPE);
40 }
41
42 public void testDoTag() throws Exception {
43 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
44 tag.setActionMethod("foo");
45 doLifecycle(tag);
46
47 System.out.println(context.getResult());
48
49 assertEquals("URL出力", "/brabra/mockFormTagTest/foo", context
50 .getResult());
51 }
52
53 public void testDoTagWithParam() throws Exception {
54 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
55 tag.setActionMethod("bar");
56 doLifecycle(tag, new ChildrenFactory() {
57 public List<JspTag> create() {
58 ParamTag paramTag1 = new ParamTag();
59 paramTag1.setParent(tag);
60 paramTag1.setName("id");
61 paramTag1.setValue("123");
62 ParamTag paramTag2 = new ParamTag();
63 paramTag2.setParent(tag);
64 paramTag2.setName("token");
65 paramTag2.setValue("abc");
66 return Arrays.asList(new JspTag[] { paramTag1, paramTag2 });
67 }
68 });
69
70 System.out.println(context.getResult());
71
72 assertEquals("パラメータ付きでURL出力",
73 "/brabra/mockFormTagTest/bar/123?token=abc", context
74 .getResult());
75 }
76
77 public void testDoTagOutputTag() throws Exception {
78 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
79 tag.setActionMethod("foo");
80 tag.setTag("a");
81 tag.setAttr("href");
82 jspBody.setBody("body");
83 doLifecycle(tag);
84
85 System.out.println(context.getResult());
86
87 Element element = getResultAsElementFromContext();
88 String message = "タグ出力";
89 assertEquals(message, "a", element.getName());
90 assertEquals(message, 1, element.getAttributes().size());
91 assertEquals(message, "/brabra/mockFormTagTest/foo", element
92 .getAttributeValue("href"));
93 assertEquals(message, 0, element.getChildren().size());
94 assertEquals(message, "body", element.getValue());
95 }
96
97 public void testDoTagOutputTagWithParam() throws Exception {
98 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
99 tag.setActionMethod("bar");
100 tag.setTag("img");
101 tag.setAttr("src");
102 doLifecycle(tag, new ChildrenFactory() {
103 public List<JspTag> create() {
104 ParamTag paramTag1 = new ParamTag();
105 paramTag1.setParent(tag);
106 paramTag1.setName("id");
107 paramTag1.setValue("123");
108 ParamTag paramTag2 = new ParamTag();
109 paramTag2.setParent(tag);
110 paramTag2.setName("token");
111 paramTag2.setValue("abc");
112 return Arrays.asList(new JspTag[] { paramTag1, paramTag2 });
113 }
114 });
115
116 System.out.println(context.getResult());
117
118 Element element = getResultAsElementFromContext();
119 String message = "パラメータ付きでタグ出力";
120 assertEquals(message, "img", element.getName());
121 assertEquals(message, 1, element.getAttributes().size());
122 assertEquals(message, "/brabra/mockFormTagTest/bar/123?token=abc",
123 element.getAttributeValue("src"));
124 assertEquals(message, 0, element.getChildren().size());
125 }
126
127 public void testDoTagWithProtocol() throws Exception {
128 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
129 tag.setActionMethod("foo");
130 tag.setProtocol("https");
131 doLifecycle(tag);
132
133 System.out.println(context.getResult());
134
135 assertEquals("URL出力", "https://localhost/brabra/mockFormTagTest/foo", context
136 .getResult());
137 }
138
139 public void testDoTagWithPort() throws Exception {
140 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
141 tag.setActionMethod("foo");
142 tag.setPort(8080);
143 doLifecycle(tag);
144
145 System.out.println(context.getResult());
146
147 assertEquals("URL出力", "http://localhost:8080/brabra/mockFormTagTest/foo", context
148 .getResult());
149 }
150
151 public void testDoTagWithProtocolAndPort() throws Exception {
152 tag.setActionClass(MockFormTagTestAction.class.getCanonicalName());
153 tag.setActionMethod("foo");
154 tag.setProtocol("https");
155 tag.setPort(8080);
156 doLifecycle(tag);
157
158 System.out.println(context.getResult());
159
160 assertEquals("URL出力", "https://localhost:8080/brabra/mockFormTagTest/foo", context
161 .getResult());
162 }
163 }