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.ui;
22
23 import org.apache.struts2.components.Head;
24 import org.apache.struts2.views.jsp.AbstractUITagTest;
25
26 /***
27 * Unit test for {@link HeadTag}.
28 * <p/>
29 * Note: If unit test fails with encoding difference check the src/test/struts.properties
30 * and adjust the .txt files accordingly
31 *
32 */
33 public class HeadTagTest extends AbstractUITagTest {
34
35 private HeadTag tag;
36
37 public void testHead1() throws Exception {
38 tag.doStartTag();
39 tag.doEndTag();
40
41 verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
42 }
43
44 public void testHead1NoCalender() throws Exception {
45 tag.doStartTag();
46 tag.doEndTag();
47 tag.setCalendarcss(null);
48
49 verify(HeadTagTest.class.getResource("HeadTagTest-1.txt"));
50 }
51
52 public void testHead2() throws Exception {
53 tag.setTheme("ajax");
54 tag.doStartTag();
55 Head component = (Head) tag.getComponent();
56 assertTrue(!component.isDebug());
57 tag.doEndTag();
58
59 verify(HeadTagTest.class.getResource("HeadTagTest-2.txt"));
60 assertTrue("should have debug false", writer.toString().indexOf("isDebug: false") > -1);
61 }
62
63 public void testHead3() throws Exception {
64 tag.setTheme("ajax");
65 tag.setDebug("true");
66 tag.doStartTag();
67 Head component = (Head) tag.getComponent();
68 assertTrue(component.isDebug());
69 tag.doEndTag();
70
71 verify(HeadTagTest.class.getResource("HeadTagTest-3.txt"));
72 assertTrue("should have debug true", writer.toString().indexOf("isDebug: true") > -1);
73 }
74
75 public void testHead4() throws Exception {
76 tag.setCalendarcss("my-calendar");
77 tag.doStartTag();
78 tag.doEndTag();
79
80 verify(HeadTagTest.class.getResource("HeadTagTest-4.txt"));
81 assertEquals("my-calendar", tag.getCalendarcss());
82 }
83
84 public void testHead4b() throws Exception {
85 tag.setCalendarcss("my-calendar.css");
86 tag.doStartTag();
87 Head component = (Head) tag.getComponent();
88 assertEquals("my-calendar.css", component.getCalendarcss());
89 tag.doEndTag();
90
91 verify(HeadTagTest.class.getResource("HeadTagTest-4.txt"));
92 assertEquals("my-calendar.css", tag.getCalendarcss());
93 }
94
95 protected void setUp() throws Exception {
96 super.setUp();
97 tag = new HeadTag();
98 tag.setPageContext(pageContext);
99 }
100
101 protected void tearDown() throws Exception {
102 super.tearDown();
103 }
104
105 }