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 import java.util.Enumeration ; 68 69 import com.iv.flash.util.Util; 70 import com.iv.flash.api.FlashFile; 71 import com.iv.flash.api.FlashDef; 72 import com.iv.flash.api.text.FontDef; 73 74 87 public class ConditionalValveServletTest 88 extends ServletTestCase 89 { 90 93 Turbine turbine; 94 95 98 public ConditionalValveServletTest(String name) 99 { 100 super(name); 101 } 102 103 106 public static Test suite() 107 { 108 return new TestSuite(ConditionalValveServletTest.class); 109 } 110 111 116 protected void setUp() 117 throws Exception 118 { 119 super.setUp(); 120 config.setInitParameter("properties", 121 "/WEB-INF/conf/ConditionalValveTRP.properties"); 122 turbine = new Turbine(); 123 turbine.init(config); 124 } 125 126 129 protected void tearDown() 130 throws Exception 131 { 132 turbine.destroy(); 133 super.tearDown(); 134 } 135 136 140 public void beginHomepage(WebRequest theRequest) 141 { 142 theRequest.setURL(null, "/test", "/servlet/test", null, null); 143 } 144 145 149 public void testHomepage() 150 throws Exception 151 { 152 turbine.doGet(request, response); 153 } 154 155 158 public void endHomepage(WebResponse theResponse) 159 throws Exception 160 { 161 assertEquals("Test Application", theResponse.getTitle()); 163 164 WebTable table = theResponse.getTableWithID("layout"); 166 assertNotNull("Table: layout was not found.", table); 167 assertEquals("Incorrect number of rows in layout table.", 168 3, table.getRowCount()); 169 assertEquals("Incorrect number of columns in layout table.", 170 1, table.getColumnCount()); 171 172 assertEquals("Turbine Test App", 173 table.getTableCellWithID("topNav").asText().trim()); 174 assertEquals("Powered By Turbine!", 175 table.getTableCellWithID("bottomNav").asText().trim()); 176 assertEquals("Please stand by, This is only a test.", 177 table.getTableCellWithID("screen").asText().trim()); 178 } 179 180 184 public void beginErrorTemplate(WebRequest theRequest) 185 { 186 theRequest.setURL(null, "/test", "/servlet/test", 187 "/action/NoSuchAction", null); 188 } 189 190 193 public void testErrorTemplate() 194 throws Exception 195 { 196 turbine.doGet(request, response); 197 } 198 199 203 public void endErrorTemplate(WebResponse theResponse) 204 throws Exception 205 { 206 assertEquals("Test Application", theResponse.getTitle()); 208 209 WebTable table = theResponse.getTableWithID("error"); 211 assertNotNull("Table: error was not found.", table); 212 assertEquals("Incorrect number of rows in error table.", 2, 213 table.getRowCount()); 214 assertEquals("Incorrect number of columns in error table.", 1, 215 table.getColumnCount()); 216 217 assertEquals("Error", table.getCellAsText(0, 0).trim()); 218 assertTrue("No exception or stack trace?", 219 table.getCellAsText(1, 0).trim().length() > 0); 220 } 221 222 226 public void beginJspPage(WebRequest theRequest) 227 { 228 theRequest.setURL(null, "/test", "/servlet/test", 229 "/template/Index.jsp", null); 230 } 231 232 236 public void testJspPage() 237 throws Exception 238 { 239 turbine.doGet(request, response); 240 } 241 242 245 public void endJspPage(WebResponse theResponse) 246 throws Exception 247 { 248 assertEquals("Test Application JSP Page", theResponse.getTitle()); 249 } 250 251 255 public void beginJGenPage(WebRequest theRequest) 256 { 257 theRequest.setURL(null, "/test", "/servlet/test", 258 "/template/JGenTestScreen.swt", null); 259 } 260 261 265 public void testJGenPage() 266 throws Exception 267 { 268 turbine.doGet(request, response); 269 } 270 271 274 public void endJGenPage(WebResponse response) 275 throws Exception 276 { 277 281 String baseDir = System.getProperty("basedir"); 282 assertNotNull("Could not get the 'basedir' system property.", baseDir); 283 Util.init( baseDir+"/target/rttest/tomcat40/webapps/test/WEB-INF/conf/" ); 284 285 287 FlashFile f = FlashFile.parse( "unknown", response.getInputStream() ); 288 289 293 Enumeration defs = f.definitions(); 294 295 boolean fontFound = false; 296 297 while( defs.hasMoreElements() ) 298 { 299 if ( defs.nextElement() instanceof FontDef ) 300 { 301 fontFound = true; 302 } 303 } 304 305 if ( ! fontFound ) 306 { 307 fail( "No font def found in returned flash content." ); 308 } 309 } 310 } 311 | Popular Tags |