FileDocCategorySizeDatePackage
TestShoppingCartServlet.javaAPI DocExample2285Sat Mar 15 19:39:50 GMT 2003com.oreilly.javaxp.cactus.servlet

TestShoppingCartServlet

public class TestShoppingCartServlet extends org.apache.cactus.ServletTestCase
author
Brian M. Coyner $version $Id: TestShoppingCartServlet.java,v 1.2 2003/02/27 00:24:44 jepc Exp $

Fields Summary
private ShoppingCartServlet
servlet
Constructors Summary
public TestShoppingCartServlet(String name)

        super(name);
        this.servlet = new ShoppingCartServlet();
    
Methods Summary
public voidbeginAddItemToCart(org.apache.cactus.WebRequest webRequest)

        webRequest.addParameter("operation",
                                ShoppingCartServlet.INSERT_ITEM);
        webRequest.addParameter("itemID", "12345");
    
public voidbeginRemoveItemFromCart(org.apache.cactus.WebRequest webRequest)

        webRequest.addParameter("operation", ShoppingCartServlet.REMOVE_ITEM);
        webRequest.addParameter("itemID", "12345");
    
public voidtestAddItemToCart()

        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 voidtestRemoveItemFromCart()

        // 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);