Package xpetstore.services.cart.interfaces

Examples of xpetstore.services.cart.interfaces.CartLocal


                                       HttpServletResponse response )
        throws Exception
    {
        String    userId = ( String ) request.getSession(  ).getAttribute( USERID_KEY );
        CartForm  frm = ( CartForm ) form;
        CartLocal cart = getCart( request );

        /* Order */
        CustomerValue cust = getPetstore(  ).getCustomer( userId );
        frm.setCustomerValue( cust );

        /* Cart items */
        Collection items = cart.getCartItems(  );
        frm.setCartItems( items );

        /* Total */
        frm.setTotal( cart.getTotal(  ) );

        return mapping.findForward( SUCCESS );
    }
View Full Code Here


                                       HttpServletResponse response )
        throws Exception
    {
        CartForm  frm = ( CartForm ) form;

        CartLocal cart = getCart( request );

        /* Cart items */
        Collection items = cart.getCartItems(  );
        frm.setCartItems( items );

        /* Total */
        double total = cart.getTotal(  );
        frm.setTotal( total );

        return mapping.findForward( SUCCESS );
    }
View Full Code Here

                                       HttpServletResponse response )
        throws Exception
    {
        CartForm  frm = ( CartForm ) form;

        CartLocal cart = getCart( request );

        /* Cart items */
        cart.updateItems( frm.getItemId(  ), frm.getQuantity(  ) );

        return mapping.findForward( SUCCESS );
    }
View Full Code Here

    //~ Methods ----------------------------------------------------------------

    public void testCart(  )
    {
        CartLocal cart = null;

        try
        {
            cart = CartUtil.getLocalHome(  ).create(  );
            cart.addItem( "EST-1" );
            cart.addItem( "EST-2" );
            cart.addItem( "EST-10" );
            cart.addItem( "EST-1", 9 );
            cart.removeItem( "EST-2" );

            // Cart count
            assertEquals( "cart.count", 2, cart.getCount(  ) );

            // Cart items
            Collection items = cart.getCartItems(  );
            assertNotNull( "items=null", items );
            assertEquals( "items.size", 2, items.size(  ) );

            for ( Iterator it = items.iterator(  ); it.hasNext(  ); )
            {
                CartItem item = ( CartItem ) it.next(  );

                if ( "EST-1".equals( item.getItemId(  ) ) )
                {
                    assertEquals( "item[EST-1].name", "Angelfish", item.getName(  ) );
                    assertEquals( "item[EST-1].description", "Large", item.getDescription(  ) );
                    assertEquals( "item[EST-1].productId", "FI-SW-01", item.getProductId(  ) );
                    assertEquals( "item[EST-1].unitCost", 16.50, item.getUnitCost(  ), 0 );
                    assertEquals( "item[EST-1].quantity", 10, item.getQuantity(  ) );
                    assertEquals( "item[EST-1].totalCost", 165.0, item.getTotalCost(  ), 0 );
                }
                else if ( "EST-10".equals( item.getItemId(  ) ) )
                {
                    assertEquals( "item[EST-10].name", "Bulldog", item.getName(  ) );
                    assertEquals( "item[EST-10].description", "Spotless Female Puppy", item.getDescription(  ) );
                    assertEquals( "item[EST-10].productId", "K9-BD-01", item.getProductId(  ) );
                    assertEquals( "item[EST-10].unitCost", 28.50, item.getUnitCost(  ), 0 );
                    assertEquals( "item[EST-10].quantity", 1, item.getQuantity(  ) );
                    assertEquals( "item[EST-10].totalCost", 28.50, item.getTotalCost(  ), 0 );
                }
                else
                {
                    assertEquals( item.getItemId(  ) + " is invalid", false, true );
                }
            }

            // Sub total         
            assertEquals( "subTotal", 193.5, cart.getTotal(  ), 0 );
        }
        catch ( Exception e )
        {
            e.printStackTrace(  );
            fail( "Error=" + e.toString(  ) );
        }
        finally
        {
            try
            {
                if ( cart != null )
                {
                    cart.remove(  );
                }
            }
            catch ( Exception e )
            {
                fail( "Unable to destroy the card. Error=" + e.toString(  ) );
View Full Code Here

        Integer orderUId = petstore.createOrder( userId, new Date(  ), items );
        frm.getOrderValue(  ).setOrderUId( orderUId );

        /* Invalidating the current cart */
        CartLocal cart = getCart( false, request );

        if ( cart != null )
        {
            request.getSession(  ).removeAttribute( CART_KEY );
            cart.remove(  );
        }

        return mapping.findForward( SUCCESS );
    }
View Full Code Here

        }
    }

    public void testUpdateCart(  )
    {
        CartLocal cart = null;

        try
        {
            cart = CartUtil.getLocalHome(  ).create(  );
            cart.addItem( "EST-1" );
            cart.addItem( "EST-10" );
            cart.updateItems( new String[] { "EST-1", "EST-10" }, new int[] { 10, 11 } );

            // Cart count
            assertEquals( "cart.count", 2, cart.getCount(  ) );

            // Cart items
            Collection items = cart.getCartItems(  );
            assertNotNull( "items=null", items );
            assertEquals( "items.size", 2, items.size(  ) );

            for ( Iterator it = items.iterator(  ); it.hasNext(  ); )
            {
                CartItem item = ( CartItem ) it.next(  );

                if ( "EST-1".equals( item.getItemId(  ) ) )
                {
                    assertEquals( "item[EST-1].name", "Angelfish", item.getName(  ) );
                    assertEquals( "item[EST-1].description", "Large", item.getDescription(  ) );
                    assertEquals( "item[EST-1].productId", "FI-SW-01", item.getProductId(  ) );
                    assertEquals( "item[EST-1].unitCost", 16.50, item.getUnitCost(  ), 0 );
                    assertEquals( "item[EST-1].quantity", 10, item.getQuantity(  ) );
                    assertEquals( "item[EST-1].totalCost", 165.0, item.getTotalCost(  ), 0 );
                }
                else if ( "EST-10".equals( item.getItemId(  ) ) )
                {
                    assertEquals( "item[EST-10].name", "Bulldog", item.getName(  ) );
                    assertEquals( "item[EST-10].description", "Spotless Female Puppy", item.getDescription(  ) );
                    assertEquals( "item[EST-10].productId", "K9-BD-01", item.getProductId(  ) );
                    assertEquals( "item[EST-10].unitCost", 28.50, item.getUnitCost(  ), 0 );
                    assertEquals( "item[EST-10].quantity", 11, item.getQuantity(  ) );
                    assertEquals( "item[EST-10].totalCost", 313.50, item.getTotalCost(  ), 0 );
                }
                else
                {
                    assertEquals( item.getItemId(  ) + " is invalid", false, true );
                }
            }

            // Sub total         
            assertEquals( "subTotal", 478.5, cart.getTotal(  ), 0 );
        }
        catch ( Exception e )
        {
            e.printStackTrace(  );
            fail( "Error=" + e.toString(  ) );
        }
        finally
        {
            try
            {
                if ( cart != null )
                {
                    cart.remove(  );
                }
            }
            catch ( Exception e )
            {
                fail( "Unable to destroy the card. Error=" + e.toString(  ) );
View Full Code Here

        HttpSession session = request.getSession(  );

        session.removeAttribute( USERID_KEY );
        session.removeAttribute( USERNAME_KEY );

        CartLocal cart = getCart( false, request );

        if ( cart != null )
        {
            session.removeAttribute( CART_KEY );
            cart.remove(  );
        }
    }
View Full Code Here

    public CartLocal getCart( boolean            create,
                              HttpServletRequest request )
        throws Exception
    {
        HttpSession session = request.getSession(  );
        CartLocal   cart = ( CartLocal ) session.getAttribute( CART_KEY );
        if ( ( cart == null ) && create )
        {
            cart = CartUtil.getLocalHome().create();
            session.setAttribute( CART_KEY, cart );
        }
View Full Code Here

TOP

Related Classes of xpetstore.services.cart.interfaces.CartLocal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.