View Javadoc

1   /*
2    * $Id: HeadTagTest.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
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); // null = should use calendar-blue.css
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(); // must be done between start and end
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(); // must be done between start and end
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 }