TestShoppingCartServletpublic class TestShoppingCartServlet extends org.apache.cactus.ServletTestCase
Fields Summary |
---|
private ShoppingCartServlet | servlet |
Constructors Summary |
---|
public TestShoppingCartServlet(String name)
super(name);
this.servlet = new ShoppingCartServlet();
|
Methods Summary |
---|
public void | beginAddItemToCart(org.apache.cactus.WebRequest webRequest)
webRequest.addParameter("operation",
ShoppingCartServlet.INSERT_ITEM);
webRequest.addParameter("itemID", "12345");
| public void | beginRemoveItemFromCart(org.apache.cactus.WebRequest webRequest)
webRequest.addParameter("operation", ShoppingCartServlet.REMOVE_ITEM);
webRequest.addParameter("itemID", "12345");
| public void | testAddItemToCart()
this.servlet.doGet(this.request, this.response);
Object obj = this.session.getAttribute(ShoppingCartServlet.CART);
assertNotNull("Shopping Cart should exist.", obj);
assertTrue("Object should be a ShoppingCart",
obj instanceof ShoppingCart);
ShoppingCart cart = (ShoppingCart) obj;
Item item = cart.getItem("12345");
assertNotNull("Item should exist.", item);
| public void | testRemoveItemFromCart()
// we need to setup the session with data the servlet expects
// to exist.
ShoppingCart cart = new ShoppingCart();
cart.addItem(new Item("12345", "Description"));
this.session.setAttribute(ShoppingCartServlet.CART, cart);
// now execute the doGet to remove the item from the cart.
this.servlet.doGet(this.request, this.response);
Object obj = this.session.getAttribute(ShoppingCartServlet.CART);
assertNotNull("Shopping Cart should exist.", obj);
assertTrue("Object should be a ShoppingCart",
obj instanceof ShoppingCart);
cart = (ShoppingCart) obj;
Item item = cart.getItem("12345");
assertNull("Item should not exist.", item);
|
|