1 package csdl.stackmvc.control.command; 2 3 import com.meterware.httpunit.WebConversation; 4 import com.meterware.httpunit.WebForm; 5 import com.meterware.httpunit.WebRequest; 6 import com.meterware.httpunit.WebResponse; 7 import com.meterware.httpunit.WebLink; 8 import com.meterware.httpunit.WebTable; 9 10 import junit.framework.TestCase; 11 import junit.framework.TestSuite; 12 import junit.textui.TestRunner; 13 14 20 public class TestClearCommand extends TestCase { 21 22 23 private String pageTitle = "Stack MVC"; 24 25 26 private String testHost = System.getProperty("test_host"); 27 28 33 public TestClearCommand(String name) { 34 super(name); 35 } 36 37 42 public void testClear() throws Exception { 43 WebConversation conversation = new WebConversation(); 44 45 String url = testHost + "stackmvc/welcome.jsp"; 47 WebResponse response = conversation.getResponse(url); 48 assertEquals("Checking welcome.jsp retrieval", pageTitle, response.getTitle()); 49 50 WebLink startLink = response.getLinkWithID("InitStack"); 52 response = conversation.getResponse(startLink.getRequest()); 53 assertEquals("Checking index.jsp retrieval", pageTitle, response.getTitle()); 54 55 WebForm pushForm = response.getFormWithID("PushForm"); 57 WebRequest pushRequest = pushForm.getRequest(); 58 pushRequest.setParameter("number", "2"); 59 response = conversation.getResponse(pushRequest); 60 61 WebTable stackTable = response.getTableWithID("StackTable"); 63 assertEquals("Checking stack size", 1, stackTable.getRowCount()); 64 65 WebForm clearForm = response.getFormWithID("ClearForm"); 67 response = conversation.getResponse(clearForm.getRequest()); 68 stackTable = response.getTableWithID("StackTable"); 69 assertEquals("Checking size of cleared stack", 0, stackTable.getRowCount()); 70 } 71 72 73 78 public static void main(String [] args) { 79 System.out.println("JUnit testing Clear command."); 80 TestRunner.run(new TestSuite(TestClearCommand.class)); 82 } 83 } 84 | Popular Tags |