01: package csdl.stackmvc.control.command;
02:
03: import com.meterware.httpunit.WebConversation;
04: import com.meterware.httpunit.WebForm;
05: import com.meterware.httpunit.WebRequest;
06: import com.meterware.httpunit.WebResponse;
07: import com.meterware.httpunit.WebLink;
08: import com.meterware.httpunit.WebTable;
09:
10: import junit.framework.TestCase;
11: import junit.framework.TestSuite;
12: import junit.textui.TestRunner;
13:
14: /**
15: * Tests operation of the StackMVC Clear command.
16: *
17: * @author Jitender Miglani
18: * @author Philip Johnson
19: */
20: public class TestClearCommand extends TestCase {
21:
22: /** The stackMVC's only page title. */
23: private String pageTitle = "Stack MVC";
24:
25: /** Get the test host. */
26: private String testHost = System.getProperty("test_host");
27:
28: /**
29: * Required for JUnit.
30: *
31: * @param name Test case name.
32: */
33: public TestClearCommand(String name) {
34: super (name);
35: }
36:
37: /**
38: * Tests the stackMVC clear operation.
39: *
40: * @throws Exception If problems occur
41: */
42: public void testClear() throws Exception {
43: WebConversation conversation = new WebConversation();
44:
45: // Get welcome.jsp page and check for successful retrieval
46: String url = testHost + "stackmvc/welcome.jsp";
47: WebResponse response = conversation.getResponse(url);
48: assertEquals("Checking welcome.jsp retrieval", pageTitle,
49: response.getTitle());
50:
51: // Go to the stack page and check that we got it OK.
52: WebLink startLink = response.getLinkWithID("InitStack");
53: response = conversation.getResponse(startLink.getRequest());
54: assertEquals("Checking index.jsp retrieval", pageTitle,
55: response.getTitle());
56:
57: // Now try pushing "2" onto the stack.
58: WebForm pushForm = response.getFormWithID("PushForm");
59: WebRequest pushRequest = pushForm.getRequest();
60: pushRequest.setParameter("number", "2");
61: response = conversation.getResponse(pushRequest);
62:
63: // Check that the stack contains a single "2"
64: WebTable stackTable = response.getTableWithID("StackTable");
65: assertEquals("Checking stack size", 1, stackTable.getRowCount());
66:
67: // Now try clearing the stack
68: WebForm clearForm = response.getFormWithID("ClearForm");
69: response = conversation.getResponse(clearForm.getRequest());
70: stackTable = response.getTableWithID("StackTable");
71: assertEquals("Checking size of cleared stack", 0, stackTable
72: .getRowCount());
73: }
74:
75: /**
76: * Provide stand-alone execution of this test case during initial development.
77: *
78: * @param args The command line arguments
79: */
80: public static void main(String[] args) {
81: System.out.println("JUnit testing Clear command.");
82: //Runs all no-arg methods starting with "test".
83: TestRunner.run(new TestSuite(TestClearCommand.class));
84: }
85: }
|