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 TestPopCommand extends TestCase { 20 21 22 private String pageTitle = "Stack MVC"; 23 24 25 private String testHost = System.getProperty("test_host"); 26 27 32 public TestPopCommand(String name) { 33 super(name); 34 } 35 36 41 public void testLegalPop() 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, stackTable.getRowCount()); 57 58 WebForm popForm = response.getFormWithID("PopForm"); 60 response = conversation.getResponse(popForm.getRequest()); 61 stackTable = response.getTableWithID("StackTable"); 62 assertEquals("Checking size of popped stack", 0, stackTable.getRowCount()); 63 } 64 65 70 public void testIllegalPop() throws Exception { 71 WebConversation conversation = new WebConversation(); 72 73 String initStackUrl = testHost + "stackmvc/controller?CommandName=Clear"; 75 WebResponse response = conversation.getResponse(initStackUrl); 76 77 WebForm pushForm = response.getFormWithID("PushForm"); 79 WebRequest pushRequest = pushForm.getRequest(); 80 response = conversation.getResponse(pushRequest); 81 82 WebForm popForm = response.getFormWithID("PopForm"); 84 response = conversation.getResponse(popForm.getRequest()); 85 popForm = response.getFormWithID("PopForm"); 86 response = conversation.getResponse(popForm.getRequest()); 87 88 WebTable errorMessageTable = response.getTableWithID("ErrorMessageTable"); 90 String errorMessage = errorMessageTable.getCellAsText(0,0); 91 assertEquals("Checking error message", "Attempt to pop empty stack.", errorMessage); 92 } 93 94 95 100 public static void main(String [] args) { 101 System.out.println("JUnit testing Pop command."); 102 TestRunner.run(new TestSuite(TestPopCommand.class)); 104 } 105 } 106 | Popular Tags |