KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.*;
25 import junit.framework.*;
26 import org.apache.log4j.*;
27 import com.methodhead.persistable.*;
28 import com.methodhead.test.*;
29 import org.apache.cactus.*;
30 import javax.servlet.jsp.tagext.*;
31 import javax.servlet.jsp.*;
32 import com.methodhead.sitecontext.*;
33 import com.methodhead.*;
34
35 public class HeadTagTest extends JspTestCase {
36
37   static {
38     TestUtils.initLogger();
39     TestUtils.initDb();
40   }
41
42   public HeadTagTest( String JavaDoc name ) {
43     super( name );
44   }
45
46   protected void setUp() {
47     //setLogLevel( Level.DEBUG );
48
try {
49       request.setAttribute( SiteContext.SITECONTEXT_KEY, SiteContext.getDefaultContext() );
50     }
51     catch ( Exception JavaDoc e ) {
52       fail( e.getMessage() );
53     }
54   }
55
56   protected void tearDown() {
57   }
58
59   public void testHeadViewPage() {
60     try {
61       HeadTag tag = null;
62       Page page = null;
63
64       page = new Page();
65       page.setString( "title", "Test Page" );
66       request.setAttribute( ShimGlobals.PAGE_KEY, page );
67       tag = new HeadTag();
68       tag.setPageContext( pageContext );
69
70       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
71       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
72
73     }
74     catch ( Exception JavaDoc e ) {
75       e.printStackTrace();
76       fail();
77     }
78   }
79
80   public void endHeadViewPage( WebResponse response )
81   {
82     String JavaDoc output = response.getText();
83     assertEquals(
84       "<head>\n" +
85       "<base HREF=\"http://localhost:8082/transfercm-test/\"/>\n" +
86       "<title>Test Page</title>\n" +
87       "</head>\n",
88       output );
89   }
90
91   public void testHeadViewPageAltTitleAndMeta() {
92     try {
93       HeadTag tag = null;
94       Page page = null;
95
96       page = new Page();
97       page.setString( "title", "Test Page" );
98       page.setString( "alttitle", "altTest Page" );
99       page.setString( "metadescription", "metadescription" );
100       page.setString( "metakeywords", "metakeywords" );
101       request.setAttribute( ShimGlobals.PAGE_KEY, page );
102       tag = new HeadTag();
103       tag.setPageContext( pageContext );
104
105       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
106       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
107
108     }
109     catch ( Exception JavaDoc e ) {
110       e.printStackTrace();
111       fail();
112     }
113   }
114
115   public void endHeadViewPageAltTitleAndMeta( WebResponse response )
116   {
117     String JavaDoc output = response.getText();
118     assertEquals(
119       "<head>\n" +
120       "<base HREF=\"http://localhost:8082/transfercm-test/\"/>\n" +
121       "<title>altTest Page</title>\n" +
122       "<meta name=\"description\" content=\"metadescription\"/>\n" +
123       "<meta name=\"keywords\" content=\"metakeywords\"/>\n" +
124       "</head>\n",
125       output );
126   }
127
128   public void testHeadEditPage() {
129     try {
130       HeadTag tag = null;
131       Page page = null;
132
133       page = new Page();
134       page.setString( "title", "Test Page" );
135       request.setAttribute( ShimGlobals.PAGE_KEY, page );
136       session.setAttribute( ShimGlobals.MODE_KEY, ShimGlobals.MODE_EDIT );
137       tag = new HeadTag();
138       tag.setPageContext( pageContext );
139
140       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
141       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
142
143     }
144     catch ( Exception JavaDoc e ) {
145       e.printStackTrace();
146       fail();
147     }
148   }
149
150   public void endHeadEditPage( WebResponse response )
151   {
152     //
153
// should get domain specified by site context in base tag when we're logged in
154
//
155
String JavaDoc output = response.getText();
156     assertEquals(
157       "<head>\n" +
158       "<base HREF=\"http://DEFAULT:8082/transfercm-test/\"/>\n" +
159       "<title>Test Page</title>\n" +
160       "</head>\n",
161       output );
162   }
163
164   public void testHeadDefine() {
165     try {
166       HeadTag tag = null;
167
168       request.setAttribute( ShimGlobals.PANELMAP_KEY, new HashMap() );
169       tag = new HeadTag();
170       tag.setPageContext( pageContext );
171
172       assertEquals( Tag.SKIP_BODY, tag.doStartTag() );
173       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
174
175     }
176     catch ( Exception JavaDoc e ) {
177       e.printStackTrace();
178       fail();
179     }
180   }
181
182   public void testHeadRichEditPage() {
183     try {
184       HeadTag tag = null;
185       Page page = null;
186       Panel panel = null;
187
188       page = new Page();
189       page.setString( "title", "Test Page" );
190       panel = new Panel();
191       panel.setName( "body" );
192       panel.setModuleClass( "com.methodhead.shim.MockModule" );
193       page.addPanel( panel );
194       request.setAttribute( ShimGlobals.EDITPANEL_KEY, "body" );
195       session.setAttribute( ShimGlobals.MODE_KEY, ShimGlobals.MODE_EDIT );
196       request.setAttribute( ShimGlobals.PAGE_KEY, page );
197       tag = new HeadTag();
198       tag.setPageContext( pageContext );
199
200       assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
201       assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
202
203     }
204     catch ( Exception JavaDoc e ) {
205       e.printStackTrace();
206       fail();
207     }
208   }
209
210   public void endHeadRichEditPage( WebResponse response )
211   {
212     //
213
// should get domain specified by site context in base tag when we're logged in
214
//
215
String JavaDoc output = response.getText();
216     assertEquals(
217       "<head>\n" +
218       "<base HREF=\"http://DEFAULT:8082/transfercm-test/\"/>\n" +
219       "<title>Test Page</title>\n" +
220       "</head>\n",
221       output );
222   }
223
224   public void testHeadWithSiteContextPath() throws Exception JavaDoc {
225     TestData.createSiteContexts();
226
227     HeadTag tag = null;
228     Page page = null;
229
230     //
231
// set site context to something with a path
232
//
233
request.setAttribute( SiteContext.SITECONTEXT_KEY, TestData.siteContext3 );
234
235     page = new Page();
236     page.setString( "title", "Test Page" );
237     request.setAttribute( ShimGlobals.PAGE_KEY, page );
238
239     tag = new HeadTag();
240     tag.setPageContext( pageContext );
241
242     assertEquals( Tag.EVAL_BODY_INCLUDE, tag.doStartTag() );
243     assertEquals( Tag.EVAL_PAGE, tag.doEndTag() );
244   }
245
246   public void endHeadWithSiteContextPath( WebResponse response ) {
247     String JavaDoc output = response.getText();
248     assertEquals(
249       "<head>\n" +
250       "<base HREF=\"http://localhost:8082/transfercm-test/path/\"/>\n" +
251       "<title>Test Page</title>\n" +
252       "</head>\n",
253       output );
254   }
255 }
256
Popular Tags