1 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 name ) { 48 super( name ); 49 } 50 51 public void setUp() throws Exception { 52 super.setUp(); 53 54 ConnectionSingleton.runBatchUpdate( new FileReader( "webapp/WEB-INF/db/transfer-reset.sql" ) ); 55 } 56 57 public void tearDown() throws Exception { 58 super.tearDown(); 59 } 60 61 public void beginDoGet( WebRequest webRequest ) { 62 webRequest.setURL( "dev.danhensgen.com", "", "", "/page1.shtml", "" ); 66 } 67 68 public void testDoGet() throws Exception { 69 TestData.createSiteMap(); 70 TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) ); 71 72 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 webRequest.setURL( "dev.danhensgen.com", "", "", "/invalid.shtml", "" ); 91 } 92 93 public void testDoGetPageNotFound() throws Exception { 94 TestData.createSiteMap(); 95 TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) ); 96 97 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 webRequest.setURL( "dev.danhensgen.com", "", "", "/invalid.shtml", "" ); 117 } 118 119 public void testDoGetPageNotFoundWithPage() throws Exception { 120 TestData.createPageNotFoundPage(); 121 TestData.createWebappFiles( ServletUtils.getRealFile( request, "" ) ); 122 123 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 assertEquals( 410, webResponse.getStatusCode() ); 139 assertEquals( "This is a template.\n", webResponse.getText() ); 140 } 141 } 142 | Popular Tags |