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.WebTable; 8 9 import junit.framework.TestCase; 10 import junit.framework.TestSuite; 11 import junit.textui.TestRunner; 12 13 19 public class TestPushCommand extends TestCase { 20 21 22 private String pageTitle = "Stack MVC"; 23 24 25 private String testHost = System.getProperty("test_host"); 26 27 32 public TestPushCommand(String name) { 33 super(name); 34 } 35 36 41 public void testPush() throws Exception { 42 WebConversation conversation = new WebConversation(); 43 44 String initStackUrl = testHost + "stackmvc/controller?CommandName=Clear"; 46 WebResponse response = conversation.getResponse(initStackUrl); 47 assertEquals("Checking initialized stack page", pageTitle, response.getTitle()); 48 49 WebForm pushForm = response.getFormWithID("PushForm"); 51 WebRequest pushRequest = pushForm.getRequest(); 52 response = conversation.getResponse(pushRequest); 53 54 WebTable stackTable = response.getTableWithID("StackTable"); 56 assertEquals("Checking stack size (1)", 1, stackTable.getRowCount()); 57 assertEquals("Checking stack contents", "1", stackTable.getTableCell(0,0).asText()); 58 59 pushForm = response.getFormWithID("PushForm"); 61 pushRequest = pushForm.getRequest(); 62 pushRequest.setParameter("number", "2"); 63 response = conversation.getResponse(pushRequest); 64 65 stackTable = response.getTableWithID("StackTable"); 67 assertEquals("Checking stack size (2)", 2, stackTable.getRowCount()); 68 assertEquals("Checking stack contents (2)", "2", stackTable.getTableCell(1,0).asText()); 69 } 70 71 72 77 public static void main(String [] args) { 78 System.out.println("JUnit testing Push command."); 79 TestRunner.run(new TestSuite(TestPushCommand.class)); 81 } 82 } 83 | Popular Tags |