KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
26 import junit.framework.*;
27 import org.apache.log4j.*;
28 import com.methodhead.persistable.*;
29 import com.methodhead.test.*;
30 import com.methodhead.auth.*;
31 import com.methodhead.aikp.*;
32 import com.methodhead.sitecontext.*;
33 import com.methodhead.*;
34 import com.methodhead.util.*;
35 import servletunit.struts.*;
36 import org.apache.struts.action.*;
37 import org.apache.cactus.*;
38
39 public class ViewPageServletTest extends ServletTestCase {
40
41   ViewPageServlet servlet = null;
42
43   static {
44     TestUtils.initLogger();
45   }
46
47   public ViewPageServletTest( String JavaDoc name ) {
48     super( name );
49   }
50
51   public void setUp() throws Exception JavaDoc {
52     super.setUp();
53
54     ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) );
55   }
56
57   public void tearDown() throws Exception JavaDoc {
58     super.tearDown();
59   }
60
61   public void beginDoGet( WebRequest webRequest ) {
62     //
63
// this doesn't really matter since we'll force certain values later
64
//
65
webRequest.setURL( "dev.danhensgen.com", "", "", "/page1.shtml", "" );
66   }
67
68   public void testDoGet() throws Exception JavaDoc {
69     TestData.createSiteMap();
70     TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) );
71
72     //
73
// we need to do what the ShimFilter normally would
74
//
75
SiteContext.setContext( request, SiteContext.getDefaultContext() );
76     request.setAttribute( ShimGlobals.PAGEALIAS_KEY, "page1" );
77
78     servlet = new ViewPageServlet();
79     servlet.doGet( request, response );
80   }
81
82   public void endDoGet( WebResponse webResponse ) {
83     assertEquals( "\nHello from MockModule.display().\n\n", webResponse.getText() );
84   }
85
86   public void beginDoGetPageNotFound( WebRequest webRequest ) {
87     //
88
// this doesn't really matter since we'll force certain values later
89
//
90
webRequest.setURL( "dev.danhensgen.com", "", "", "/invalid.shtml", "" );
91   }
92
93   public void testDoGetPageNotFound() throws Exception JavaDoc {
94     TestData.createSiteMap();
95     TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) );
96
97     //
98
// we need to do what the ShimFilter normally would
99
//
100
SiteContext.setContext( request, SiteContext.getDefaultContext() );
101     request.setAttribute( ShimGlobals.PAGEALIAS_KEY, "invalid" );
102
103     servlet = new ViewPageServlet();
104     servlet.doGet( request, response );
105   }
106
107   public void endDoGetPageNotFound( WebResponse webResponse ) {
108     assertEquals( 410, webResponse.getStatusCode() );
109     assertTrue( webResponse.getText().indexOf( "Page Not Found" ) > 0 );
110   }
111
112   public void beginDoGetPageNotFoundWithPage( WebRequest webRequest ) {
113     //
114
// this doesn't really matter since we'll force certain values later
115
//
116
webRequest.setURL( "dev.danhensgen.com", "", "", "/invalid.shtml", "" );
117   }
118
119   public void testDoGetPageNotFoundWithPage() throws Exception JavaDoc {
120     TestData.createPageNotFoundPage();
121     TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) );
122
123     //
124
// we need to do what the ShimFilter normally would
125
//
126
SiteContext.setContext( request, SiteContext.getDefaultContext() );
127     request.setAttribute( ShimGlobals.PAGEALIAS_KEY, "invalid" );
128
129     servlet = new ViewPageServlet();
130     servlet.doGet( request, response );
131   }
132
133   public void endDoGetPageNotFoundWithPage( WebResponse webResponse ) {
134     //
135
// we used template3.jsp for the pagenotfound page and it contains this
136
// text
137
//
138
assertEquals( 410, webResponse.getStatusCode() );
139     assertEquals( "This is a template.\n", webResponse.getText() );
140   }
141 }
142
Popular Tags