Methods Summary |
---|
private WebForm | getBlankSubscriptionForm()
WebResponse response = getBlankSubscriptionPage();
WebForm form = response.getFormWithID("subscriptionForm");
return form;
|
private WebResponse | getBlankSubscriptionPage()
return this.webConversation.getResponse(
"http://localhost:8080/news/subscription");
|
public void | setUp()
this.webConversation = new WebConversation();
|
public void | testAccountTable()
WebResponse response = webConversation.getResponse(
"http://localhost:8080/news/sampleTable.html");
WebTable accountTable = response.getTableWithID("accountInfoTbl");
assertNotNull("account table", accountTable);
// get the checking account number
TableCell checkingCell =
accountTable.getTableCellWithID("checkingAcctNbr");
assertEquals("Checking account number",
"12345", checkingCell.asText());
|
public void | testButtonsOnSubscriptionForm()
WebForm form = getBlankSubscriptionForm();
SubmitButton subscribeBtn = form.getSubmitButton("subscribeBtn");
SubmitButton unsubscribeBtn = form.getSubmitButton("unsubscribeBtn");
assertNotNull("subscribeBtn should not be null", subscribeBtn);
assertNotNull("unsubscribeBtn should not be null", unsubscribeBtn);
|
public void | testCookies()
this.webConversation.addCookie("shoppingCartId", "98765");
WebRequest req = new GetMethodWebRequest(
"http://localhost:8080/news/cookieDemo.jsp");
WebResponse cookieDemoPage = this.webConversation.getResponse(req);
// the JSP should have created the customerId cookie
assertEquals("customer ID cookie", "12345",
this.webConversation.getCookieValue("customerId"));
// make sure the cookie we generated on the client was found
// somewhere in the HTML page
String pageSource = cookieDemoPage.getText();
assertTrue("shoppingCardId cookie was not found",
pageSource.indexOf("shoppingCartId") > -1);
|
public void | testFieldsOnSubscriptionForm()
WebForm form = getBlankSubscriptionForm();
// get the values of the two text fields
// HttpUnit treats most HTML form elements the same way
String nameFieldValue = form.getParameterValue("nameField");
String emailFieldValue = form.getParameterValue("emailField");
// the empty fields should contain empty strings. If they are
// null, this indicates they are not present on the page.
assertEquals("nameField", "", nameFieldValue);
assertEquals("emailFieldValue", "", emailFieldValue);
|
public void | testFollowLinkToSubscriptionPage()
// get the home page
WebResponse response = webConversation.getResponse(
"http://localhost:8080/news");
WebLink subscriptionLink = response.getLinkWith("subscription");
// get a request to simulate clicking on the link
WebRequest clickRequest = subscriptionLink.getRequest();
// throws HttpNotFoundException if the link is broken
WebResponse subscriptionPage =
webConversation.getResponse(clickRequest);
|
public void | testIndexPageAlternateSyntax()
WebResponse response =
webConversation.getResponse("http://localhost:8080/news");
|
public void | testIndexPageExists()Notes:
- runs fine under JDK 1.4
- under JDK 1.3.1, you must add a JAXP-compliant parser to the
CLASSPATH. Otherwise, you get java.lang.NoClassDefFoundError with
this description: "javax/xml/parsers/ParserConfigurationException".
To fix, add crimson.jar and jaxp.jar, from the ANT_HOME/lib
directory, to the CLASSPATH. Or add xerces.jar from the
TOMCAT_HOME/common/lib directory.
- you get a NoClassDefFoundError when running under Ant using the
junit task. The easy fix is to copy httpunit.jar and Tidy.jar
to the ANT_HOME/lib directory
WebRequest request =
new GetMethodWebRequest("http://localhost:8080/news");
// this next line fails if the URL is not found. It will throw
// a com.meterware.httpunit.HttpNotFoundException with the following
// message: "Error on HTTP request: 404 Not found"
WebResponse response =
webConversation.getResponse(request);
|
public void | testIndexPageLinksExist()
HttpUnitOptions.setParserWarningsEnabled(true);
WebResponse response =
webConversation.getResponse("http://localhost:8080/news");
// bogus links return null
// WebLink bogusLink = response.getLinkWith("bogus!!!");
// assertNotNull("bogus! link", bogusLink);
WebLink subscriptionLink = response.getLinkWith("subscription");
assertNotNull("subscription link", subscriptionLink);
WebLink viewSubscribersLink = response.getLinkWith("viewSubscribers");
assertNotNull("viewSubscribers link", viewSubscribersLink);
|
public void | testIndexPageSimplified()
webConversation.getResponse("http://localhost:8080/news");
|
public void | testPersonTable()
WebResponse response = webConversation.getResponse(
"http://localhost:8080/news/sampleTable.html");
// get the HTML table with 'First Name' as the text of its
// first non-blank cell
WebTable table = response.getTableStartingWith("First Name");
assertEquals("column count", 2, table.getColumnCount());
assertEquals("row count", 3, table.getRowCount());
// get the cell at row 2, column 0
TableCell cell = table.getTableCell(2, 0);
assertEquals("cell text", "Tanner", cell.asText());
|
public void | testSubmitSubscriptionWithoutRequiredField()
WebForm form = getBlankSubscriptionForm();
form.setParameter("nameField", "Eric Burke");
WebRequest request = form.getRequest("subscribeBtn");
// Submit the page. The web app should return us right back to
// the subscription page because the Email address is not specified
WebResponse response = this.webConversation.getResponse(request);
// make sure the user is warned about the missing field
String pageText = response.getText();
assertTrue("Required fields warning is not present",
pageText.indexOf("Email address is required") > -1);
// make sure the nameField has the original text
form = response.getFormWithID("subscriptionForm");
assertEquals("Name field should be pre-filled",
"Eric Burke", form.getParameterValue("nameField"));
|
public void | testSubscriptionForm()
WebForm form = getBlankSubscriptionForm();
assertEquals("subscription form action",
"subscription", form.getAction());
assertEquals("subscription form method",
"post", form.getMethod().toLowerCase());
|
public void | testViewSubscribersWithLogin()
this.webConversation.setAuthorization("eric", "secret");
this.webConversation.getResponse(
"http://localhost:8080/news/viewSubscribers");
|
public void | testViewSubscribersWithoutLogin()
try {
this.webConversation.getResponse(
"http://localhost:8080/news/viewSubscribers");
fail("viewSubscribers should require a login");
} catch (AuthorizationRequiredException expected) {
// ignored
}
|