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