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.WebTable;
08:
09: import junit.framework.TestCase;
10: import junit.framework.TestSuite;
11: import junit.textui.TestRunner;
12:
13: /**
14: * Tests operation of the StackMVC Push command.
15: *
16: * @author Jitender Miglani
17: * @author Philip Johnson
18: */
19: public class TestPushCommand extends TestCase {
20:
21: /** The stackMVC's single page title. */
22: private String pageTitle = "Stack MVC";
23:
24: /** Get the test host. */
25: private String testHost = System.getProperty("test_host");
26:
27: /**
28: * Required for JUnit.
29: *
30: * @param name Test case name.
31: */
32: public TestPushCommand(String name) {
33: super (name);
34: }
35:
36: /**
37: * Tests the stackMVC pop operation under normal situation.
38: *
39: * @throws Exception If problems occur
40: */
41: public void testPush() throws Exception {
42: WebConversation conversation = new WebConversation();
43:
44: // Get the initialized stack page and check that we got it.
45: String initStackUrl = testHost
46: + "stackmvc/controller?CommandName=Clear";
47: WebResponse response = conversation.getResponse(initStackUrl);
48: assertEquals("Checking initialized stack page", pageTitle,
49: response.getTitle());
50:
51: // Push the default value (1) onto the stack.
52: WebForm pushForm = response.getFormWithID("PushForm");
53: WebRequest pushRequest = pushForm.getRequest();
54: response = conversation.getResponse(pushRequest);
55:
56: // Check that the stack contains a single "2"
57: WebTable stackTable = response.getTableWithID("StackTable");
58: assertEquals("Checking stack size (1)", 1, stackTable
59: .getRowCount());
60: assertEquals("Checking stack contents", "1", stackTable
61: .getTableCell(0, 0).asText());
62:
63: // Now push a second, explicit value (2) onto stack.
64: pushForm = response.getFormWithID("PushForm");
65: pushRequest = pushForm.getRequest();
66: pushRequest.setParameter("number", "2");
67: response = conversation.getResponse(pushRequest);
68:
69: // Check that the stack contains two elements and that top of stack is "2".
70: stackTable = response.getTableWithID("StackTable");
71: assertEquals("Checking stack size (2)", 2, stackTable
72: .getRowCount());
73: assertEquals("Checking stack contents (2)", "2", stackTable
74: .getTableCell(1, 0).asText());
75: }
76:
77: /**
78: * Provide stand-alone execution of this test case during initial development.
79: *
80: * @param args The command line arguments
81: */
82: public static void main(String[] args) {
83: System.out.println("JUnit testing Push command.");
84: //Runs all no-arg methods starting with "test".
85: TestRunner.run(new TestSuite(TestPushCommand.class));
86: }
87: }
|