1 package org.apache.turbine; 2 3 56 57 import junit.framework.Test; 58 import junit.framework.TestCase; 59 import junit.framework.TestSuite; 60 61 import com.meterware.httpunit.WebTable; 62 import com.meterware.httpunit.WebResponse; 63 64 import org.apache.cactus.ServletTestCase; 65 import org.apache.cactus.WebRequest; 66 67 76 public class TurbineServletTest 77 extends ServletTestCase 78 { 79 82 Turbine turbine; 83 84 87 public TurbineServletTest(String name) 88 { 89 super(name); 90 } 91 92 95 public static Test suite() 96 { 97 return new TestSuite(TurbineServletTest.class); 98 } 99 100 105 protected void setUp() 106 throws Exception 107 { 108 super.setUp(); 109 config.setInitParameter("properties", 110 "/WEB-INF/conf/TurbineResources.properties"); 111 turbine = new Turbine(); 112 turbine.init(config); 113 } 114 115 118 protected void tearDown() 119 throws Exception 120 { 121 turbine.destroy(); 122 super.tearDown(); 123 } 124 125 129 public void beginHomepage(WebRequest theRequest) 130 { 131 theRequest.setURL(null, "/test", "/servlet/test", null, null); 132 } 133 134 138 public void testHomepage() 139 throws Exception 140 { 141 turbine.doGet(request, response); 142 } 143 144 147 public void endHomepage(WebResponse theResponse) 148 throws Exception 149 { 150 assertEquals("Test Application", theResponse.getTitle()); 152 153 WebTable table = theResponse.getTableWithID("layout"); 155 assertNotNull("Table: layout was not found.", table); 156 assertEquals("Incorrect number of rows in layout table.", 157 3, table.getRowCount()); 158 assertEquals("Incorrect number of columns in layout table.", 159 1, table.getColumnCount()); 160 161 assertEquals("Turbine Test App", 162 table.getTableCellWithID("topNav").asText().trim()); 163 assertEquals("Powered By Turbine!", 164 table.getTableCellWithID("bottomNav").asText().trim()); 165 assertEquals("Please stand by, This is only a test.", 166 table.getTableCellWithID("screen").asText().trim()); 167 } 168 169 173 public void beginErrorTemplate(WebRequest theRequest) 174 { 175 theRequest.setURL(null, "/test", "/servlet/test", 176 "/action/NoSuchAction", null); 177 } 178 179 182 public void testErrorTemplate() 183 throws Exception 184 { 185 turbine.doGet(request, response); 186 } 187 188 192 public void endErrorTemplate(WebResponse theResponse) 193 throws Exception 194 { 195 assertEquals("Test Application", theResponse.getTitle()); 197 198 WebTable table = theResponse.getTableWithID("error"); 200 assertNotNull("Table: error was not found.", table); 201 assertEquals("Incorrect number of rows in error table.", 2, 202 table.getRowCount()); 203 assertEquals("Incorrect number of columns in error table.", 1, 204 table.getColumnCount()); 205 206 assertEquals("Error", table.getCellAsText(0, 0).trim()); 207 assertTrue("No exception or stack trace?", 208 table.getCellAsText(1, 0).trim().length() > 0); 209 } 210 } 211 | Popular Tags |