TestPushCommand.java :  » Code-Analyzer » JBlanket » csdl » stackmvc » control » command » Java Open Source

Java Open Source » Code Analyzer » JBlanket 
JBlanket » csdl » stackmvc » control » command » TestPushCommand.java
package csdl.stackmvc.control.command;

import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebForm;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
import com.meterware.httpunit.WebTable;

import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

/**
 * Tests operation of the StackMVC Push command.
 *
 * @author Jitender Miglani
 * @author Philip Johnson
 */
public class TestPushCommand extends TestCase {

  /** The stackMVC's single page title. */
  private String pageTitle = "Stack MVC";

  /** Get the test host. */
  private String testHost = System.getProperty("test_host");

  /**
   * Required for JUnit.
   *
   * @param name Test case name.
   */
  public TestPushCommand(String name) {
    super(name);
  }

  /**
   * Tests the stackMVC pop operation under normal situation.
   *
   * @throws Exception If problems occur
   */
  public void testPush() throws Exception {
    WebConversation conversation = new WebConversation();

    // Get the initialized stack page and check that we got it.
    String initStackUrl = testHost + "stackmvc/controller?CommandName=Clear";
    WebResponse response = conversation.getResponse(initStackUrl);
    assertEquals("Checking initialized stack page", pageTitle, response.getTitle());

    // Push the default value (1) onto the stack.
    WebForm pushForm = response.getFormWithID("PushForm");
    WebRequest pushRequest = pushForm.getRequest();
    response = conversation.getResponse(pushRequest);

    // Check that the stack contains a single "2"
    WebTable stackTable = response.getTableWithID("StackTable");
    assertEquals("Checking stack size (1)", 1, stackTable.getRowCount());
    assertEquals("Checking stack contents", "1", stackTable.getTableCell(0,0).asText());

    // Now push a second, explicit value (2) onto stack.
    pushForm = response.getFormWithID("PushForm");
    pushRequest = pushForm.getRequest();
    pushRequest.setParameter("number", "2");
    response = conversation.getResponse(pushRequest);

    // Check that the stack contains two elements and that top of stack is "2".
    stackTable = response.getTableWithID("StackTable");
    assertEquals("Checking stack size (2)", 2, stackTable.getRowCount());
    assertEquals("Checking stack contents (2)", "2", stackTable.getTableCell(1,0).asText());
  }


  /**
   * Provide stand-alone execution of this test case during initial development.
   *
   * @param args The command line arguments
   */
  public static void main(String[] args) {
    System.out.println("JUnit testing Push command.");
    //Runs all no-arg methods starting with "test".
    TestRunner.run(new TestSuite(TestPushCommand.class));
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.