KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > BodyTagTest


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import java.util.*;
24 import java.io.*;
25 import java.sql.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import com.methodhead.sitecontext.*;
31 import com.methodhead.*;
32 import org.apache.cactus.*;
33 import javax.servlet.jsp.tagext.*;
34 import javax.servlet.jsp.*;
35
36 public class BodyTagTest extends JspTestCase {
37
38   static {
39     TestUtils.initLogger();
40     TestUtils.initDb();
41   }
42
43   public BodyTagTest( String JavaDoc name ) {
44     super( name );
45   }
46
47   protected void setUp() {
48     //setLogLevel( Level.DEBUG );
49
try {
50       ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
51       TestData.createSiteContexts();
52       SiteContext.setContext( request, TestData.siteContext1 );
53     }
54     catch ( Exception JavaDoc e ) {
55       fail( e.getMessage() );
56     }
57   }
58
59   protected void tearDown() {
60   }
61
62   public void testBodyDisplay() {
63     try {
64       BodyTag tag = null;
65       
66       tag = new com.methodhead.shim.BodyTag();
67       tag.setPageContext( pageContext );
68
69       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
70       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
71
72       tag.setOnload( "onLoad()" );
73
74       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
75       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
76     }
77     catch ( Exception JavaDoc e ) {
78       e.printStackTrace();
79       fail();
80     }
81   }
82
83   public void endBodyDisplay( WebResponse response )
84   {
85     String JavaDoc output = response.getText();
86     assertEquals("<body>\n</body>\n<body onload=\"onLoad()\">\n</body>\n", output );
87   }
88
89   public void testBodyDisplayWithAttributes() {
90     try {
91       BodyTag tag = null;
92       
93       tag = new com.methodhead.shim.BodyTag();
94       tag.setPageContext( pageContext );
95
96       tag.setOnload( "onload" );
97       tag.setId( "id" );
98       tag.setStyleClass( "class" );
99       tag.setLang( "lang" );
100       tag.setDir( "dir" );
101       tag.setTitle( "title" );
102       tag.setStyle( "style" );
103       tag.setBgcolor( "bgcolor" );
104       tag.setOnunload( "onunload" );
105       tag.setOnclick( "onclick" );
106       tag.setOnmousedown( "onmousedown" );
107       tag.setOnmouseup( "onmouseup" );
108       tag.setOnmouseover( "onmouseover" );
109       tag.setOnmousemove( "onmousemove" );
110       tag.setOnmouseout( "onmouseout" );
111       tag.setOnkeypress( "onkeypress" );
112       tag.setOnkeydown( "onkeydown" );
113       tag.setOnkeyup( "onkeyup" );
114
115       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
116       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
117     }
118     catch ( Exception JavaDoc e ) {
119       e.printStackTrace();
120       fail();
121     }
122   }
123
124   public void endBodyDisplayWithAttributes( WebResponse response )
125   {
126     String JavaDoc output = response.getText();
127     assertEquals(
128       "<body " +
129       "onload=\"onload\" " +
130       "id=\"id\" " +
131       "class=\"class\" " +
132       "lang=\"lang\" " +
133       "dir=\"dir\" " +
134       "title=\"title\" " +
135       "style=\"style\" " +
136       "bgcolor=\"bgcolor\" " +
137       "onunload=\"onunload\" " +
138       "onclick=\"onclick\" " +
139       "onmousedown=\"onmousedown\" " +
140       "onmouseup=\"onmouseup\" " +
141       "onmouseover=\"onmouseover\" " +
142       "onmousemove=\"onmousemove\" " +
143       "onmouseout=\"onmouseout\" " +
144       "onkeypress=\"onkeypress\" " +
145       "onkeydown=\"onkeydown\" " +
146       "onkeyup=\"onkeyup\"" +
147       ">\n</body>\n", output );
148   }
149
150   public void testBodyEdit() {
151     try {
152       BodyTag tag = null;
153       
154       session.setAttribute( ShimGlobals.MODE_KEY, ShimGlobals.MODE_EDIT );
155       tag = new com.methodhead.shim.BodyTag();
156       tag.setPageContext( pageContext );
157
158       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
159       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
160
161       tag.setOnload( "onLoad()" );
162       tag.setOnbeforeunload( "onBeforeUnload()" );
163
164       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
165       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
166     }
167     catch ( Exception JavaDoc e ) {
168       e.printStackTrace();
169       fail();
170     }
171   }
172
173   public void endBodyEdit( WebResponse response )
174   {
175     String JavaDoc html =
176       "<body>\n" +
177       "<script type=\"text/javascript\" SRC=\"approot/js/menu-config.js\"></script>\n" +
178       "\n" +
179       "</body>\n" +
180       "<body onload=\"onLoad()\" onbeforeunload=\"onBeforeUnload()\">\n" +
181       "<script type=\"text/javascript\" SRC=\"approot/js/menu-config.js\"></script>\n" +
182       "\n" +
183       "</body>\n";
184
185     String JavaDoc output = response.getText();
186
187     assertEquals( html, output );
188   }
189
190   public void testBodyRichEdit() {
191     try {
192       BodyTag tag = null;
193       
194       request.setAttribute( ShimGlobals.MODE_KEY, ShimGlobals.MODE_RICHEDIT );
195       tag = new com.methodhead.shim.BodyTag();
196       tag.setPageContext( pageContext );
197
198       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
199       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
200
201       tag.setOnload( "onLoad()" );
202       tag.setOnbeforeunload( "onBeforeunload()" );
203
204       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
205       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
206     }
207     catch ( Exception JavaDoc e ) {
208       e.printStackTrace();
209       fail();
210     }
211   }
212
213   public void endBodyRichEdit( WebResponse response )
214   {
215     String JavaDoc output = response.getText();
216     assertEquals("<body onload=\"window.parent.init()\" onbeforeunload=\"return window.parent.toolbarFrame.onBeforeUnload()\">\n</body>\n<body onload=\"onLoad(),window.parent.init()\" onbeforeunload=\"return window.parent.toolbarFrame.onBeforeUnload()\">\n</body>\n", output );
217   }
218 }
219
Popular Tags