Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/AccountBeanTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/AccountBeanTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/AccountBeanTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/AccountBeanTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,192 @@
+package com.ibatis.jpetstore.presentation;
+
+import com.ibatis.common.util.PaginatedArrayList;
+import com.ibatis.jpetstore.domain.Account;
+import com.ibatis.jpetstore.domain.DomainFixture;
+import com.ibatis.jpetstore.service.AccountService;
+import com.ibatis.jpetstore.service.CatalogService;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+
+import java.util.List;
+
+public class AccountBeanTest extends MockObjectTestCase {
+
+  public void testShouldSuccessfullyCallServicesToCreateNewAccount() {
+    Account account = DomainFixture.newTestAccount();
+
+    Mock accountServiceMock = mock(AccountService.class);
+
+    accountServiceMock.expects(once())
+        .method("insertAccount")
+        .with(NOT_NULL);
+
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL)
+        .will(returnValue(account));
+
+    Mock catalogServiceMock = mock(CatalogService.class);
+
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+
+    String result = accountBean.newAccount();
+    assertEquals(AbstractBean.SUCCESS, result);
+  }
+
+  public void testShouldSuccessfullyCallServicesToUpdateExistingAccount() {
+    Account account = DomainFixture.newTestAccount();
+
+    Mock accountServiceMock = mock(AccountService.class);
+
+    accountServiceMock.expects(once())
+        .method("updateAccount")
+        .with(NOT_NULL);
+
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL)
+        .will(returnValue(account));
+
+    Mock catalogServiceMock = mock(CatalogService.class);
+
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+
+    String result = accountBean.editAccount();
+    assertEquals(AbstractBean.SUCCESS, result);
+  }
+
+  public void testShouldCallEditAccountFormReturningSuccess() {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL)
+        .will(returnValue(account));
+    Mock catalogServiceMock = mock(CatalogService.class);
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+    assertEquals(AbstractBean.SUCCESS, accountBean.editAccountForm());
+  }
+
+  public void testShouldSwitchPageDirection() {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    Mock catalogServiceMock = mock(CatalogService.class);
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+    accountBean.setMyList(new PaginatedArrayList(5));
+    accountBean.setPageDirection("next");
+    assertEquals(AbstractBean.SUCCESS,accountBean.switchMyListPage());
+    accountBean.setPageDirection("previous");
+    assertEquals(AbstractBean.SUCCESS,accountBean.switchMyListPage());
+  }
+
+  public void testShouldSignoffAccount() {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL,NOT_NULL)
+        .will(returnValue(account));
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+    accountBean.signon();
+
+    assertEquals(AbstractBean.SUCCESS, accountBean.signoff());
+    assertFalse(accountBean.isAuthenticated());
+  }
+
+  public void testShouldSignonAccount() {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL,NOT_NULL)
+        .will(returnValue(account));
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+    assertEquals(AbstractBean.SUCCESS, accountBean.signon());
+    assertTrue(accountBean.isAuthenticated());
+  }
+
+  public void testShouldFailToSignonAccount() {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NULL,NULL)
+        .will(returnValue(null));
+    Mock catalogServiceMock = mock(CatalogService.class);
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    assertEquals(AbstractBean.FAILURE, accountBean.signon());
+    assertFalse(accountBean.isAuthenticated());
+  }
+
+  public void testShouldGetCategories() {
+    AccountBean bean = new AccountBean();
+    List categories = bean.getCategories();
+    assertTrue(categories.contains("DOGS"));
+    assertTrue(categories.contains("CATS"));
+    assertTrue(categories.contains("BIRDS"));
+    assertTrue(categories.contains("REPTILES"));
+    assertTrue(categories.contains("FISH"));
+  }
+
+  public void testShouldGetLanguages() {
+    AccountBean bean = new AccountBean();
+    List langs = bean.getLanguages();
+    assertTrue(langs.contains("english"));
+    assertTrue(langs.contains("japanese"));
+  }
+
+  public void testShouldResetBooleanOptions() {
+    AccountBean bean = new AccountBean();
+    bean.setAccount(DomainFixture.newTestAccount());
+    bean.getAccount().setBannerOption(true);
+    bean.getAccount().setListOption(true);
+    bean.reset();
+    assertFalse(bean.getAccount().isBannerOption());
+    assertFalse(bean.getAccount().isListOption());
+  }
+
+  public void testShouldClearAccountBean() {
+    Mock accountServiceMock = mock(AccountService.class);
+    Mock catalogServiceMock = mock(CatalogService.class);
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(DomainFixture.newTestAccount());
+    accountBean.setRepeatedPassword("something");
+    accountBean.setPageDirection("F");
+    accountBean.setMyList(new PaginatedArrayList(5));
+
+    accountBean.clear();
+
+    assertEquals(null, accountBean.getAccount().getFirstName());
+    assertEquals(null, accountBean.getRepeatedPassword());
+    assertEquals(null, accountBean.getPageDirection());
+    assertEquals(null, accountBean.getMyList());
+  }
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/AccountBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CartBeanTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CartBeanTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CartBeanTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CartBeanTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,121 @@
+package com.ibatis.jpetstore.presentation;
+
+import com.ibatis.jpetstore.domain.Cart;
+import com.ibatis.jpetstore.domain.CartItem;
+import com.ibatis.jpetstore.domain.Item;
+import com.ibatis.jpetstore.service.CatalogService;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.apache.struts.beanaction.ActionContext;
+
+public class CartBeanTest extends MockObjectTestCase {
+
+  public void testShouldSuccessfullyReturnFromViewCart() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    assertEquals(AbstractBean.SUCCESS, bean.viewCart());
+  }
+
+  public void testShouldSwitchPagesBackAndForth() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    assertEquals(AbstractBean.SUCCESS, bean.viewCart());
+
+    Cart cart = new Cart();
+    for (int i = 0; i < cart.getCartItemList().getPageSize() * 2; i++) {
+      cart.getCartItemList().add(new Item());
+    }
+    bean.setCart(cart);
+    bean.setPageDirection("next");
+    assertEquals(AbstractBean.SUCCESS, bean.switchCartPage());
+    assertEquals(1, cart.getCartItemList().getPageIndex());
+    bean.setPageDirection("previous");
+    assertEquals(AbstractBean.SUCCESS, bean.switchCartPage());
+    assertEquals(0, cart.getCartItemList().getPageIndex());
+
+  }
+
+  public void testShouldClearAllCartData() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    Cart cart = new Cart();
+    bean.setCart(cart);
+    bean.setWorkingItemId("not null");
+    bean.setPageDirection("not null");
+    bean.clear();
+    assertFalse(cart == bean.getCart());
+    assertNull(bean.getWorkingItemId());
+    assertNull(bean.getPageDirection());
+  }
+
+  public void testShouldAddItemToCart() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(atLeastOnce())
+        .method("isItemInStock")
+        .with(NOT_NULL)
+        .will(returnValue(true));
+    Item item = new Item();
+    item.setItemId("AnID");
+    catalogServiceMock.expects(atLeastOnce())
+        .method("getItem")
+        .with(NOT_NULL)
+        .will(returnValue(item));
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    bean.setWorkingItemId("SomeItem");
+    assertEquals(AbstractBean.SUCCESS, bean.addItemToCart());
+    CartItem cartItem = (CartItem)bean.getCart().getCartItemList().get(0);
+    assertEquals(1,cartItem.getQuantity());
+    assertEquals(AbstractBean.SUCCESS, bean.addItemToCart());
+    assertEquals(2,cartItem.getQuantity());
+  }
+
+  public void testShouldFailToRemoveItemFromCart() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    bean.setWorkingItemId("nonexistant");
+    assertEquals(AbstractBean.FAILURE, bean.removeItemFromCart());
+  }
+
+  public void testShouldRemoveItemFromCart() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(atLeastOnce())
+        .method("isItemInStock")
+        .with(NOT_NULL)
+        .will(returnValue(true));
+    Item item = new Item();
+    item.setItemId("AnID");
+    catalogServiceMock.expects(atLeastOnce())
+        .method("getItem")
+        .with(NOT_NULL)
+        .will(returnValue(item));
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    bean.setWorkingItemId("AnID");
+    bean.addItemToCart();
+    assertEquals(AbstractBean.SUCCESS, bean.removeItemFromCart());
+  }
+
+  public void testShouldUpdateCartQuantities() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(atLeastOnce())
+        .method("isItemInStock")
+        .with(NOT_NULL)
+        .will(returnValue(true));
+    Item item = new Item();
+    item.setItemId("AnID");
+    catalogServiceMock.expects(atLeastOnce())
+        .method("getItem")
+        .with(NOT_NULL)
+        .will(returnValue(item));
+    CartBean bean = new CartBean((CatalogService) catalogServiceMock.proxy());
+    bean.setWorkingItemId("AnID");
+    bean.addItemToCart();
+
+    ActionContext.getActionContext().getParameterMap().put("AnID", "5");
+
+    assertEquals(AbstractBean.SUCCESS, bean.updateCartQuantities());
+    CartItem cartItem = (CartItem)bean.getCart().getCartItemList().get(0);
+    assertEquals(5,cartItem.getQuantity());
+  }
+
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CartBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CatalogBeanTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CatalogBeanTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CatalogBeanTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CatalogBeanTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,147 @@
+package com.ibatis.jpetstore.presentation;
+
+import com.ibatis.common.util.PaginatedArrayList;
+import com.ibatis.common.util.PaginatedList;
+import com.ibatis.jpetstore.domain.Category;
+import com.ibatis.jpetstore.domain.Item;
+import com.ibatis.jpetstore.domain.Product;
+import com.ibatis.jpetstore.service.CatalogService;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+
+public class CatalogBeanTest extends MockObjectTestCase {
+
+  public void testShouldPopulateCategoryByIdForViewing() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new Category()));
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(4)));
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    bean.setCategoryId("DOGS");
+    assertEquals(AbstractBean.SUCCESS, bean.viewCategory());
+    assertNotNull(bean.getCategory());
+    assertNotNull(bean.getProductList());
+  }
+
+  public void testShouldPopulateProductByIdForViewing() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getProduct")
+        .with(NOT_NULL)
+        .will(returnValue(new Product()));
+    catalogServiceMock.expects(once())
+        .method("getItemListByProduct")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(4)));
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    bean.setProductId("EST-1");
+    assertEquals(AbstractBean.SUCCESS, bean.viewProduct());
+    assertNotNull(bean.getProduct());
+    assertNotNull(bean.getItemList());
+  }
+
+  public void testShouldPopulateItemByIdForViewing() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getItem")
+        .with(NOT_NULL)
+        .will(returnValue(new Item()));
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    bean.setItemId("FS-SW-1");
+    assertEquals(AbstractBean.SUCCESS, bean.viewItem());
+    assertNotNull(bean.getItem());
+  }
+
+  public void testShouldFailToSearchProducts() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    bean.setKeyword(null);
+    assertEquals(AbstractBean.FAILURE, bean.searchProducts());
+    assertNull(bean.getProductList());
+  }
+
+  public void testShouldSearchProductsByKeyword() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("searchProductList")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(4)));
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    bean.setKeyword("dog");
+    assertEquals(AbstractBean.SUCCESS, bean.searchProducts());
+    assertNotNull(bean.getProductList());
+  }
+
+  public void testShouldSwitchProductPageBackAndForth() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    PaginatedList productList = new PaginatedArrayList(2);
+    productList.add(new Product());
+    productList.add(new Product());
+    productList.add(new Product());
+    productList.add(new Product());
+    productList.add(new Product());
+    bean.setProductList(productList);
+
+    bean.setPageDirection("next");
+    bean.switchProductListPage();
+    assertEquals(1, productList.getPageIndex());
+    bean.setPageDirection("previous");
+    bean.switchProductListPage();
+    assertEquals(0, productList.getPageIndex());
+  }
+
+  public void testShouldSwitchItemPageBackAndForth() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    PaginatedList itemList = new PaginatedArrayList(2);
+    itemList.add(new Item());
+    itemList.add(new Item());
+    itemList.add(new Item());
+    itemList.add(new Item());
+    itemList.add(new Item());
+    bean.setItemList(itemList);
+
+    bean.setPageDirection("next");
+    assertEquals(AbstractBean.SUCCESS, bean.switchItemListPage());
+    assertEquals(1, itemList.getPageIndex());
+    bean.setPageDirection("previous");
+    assertEquals(AbstractBean.SUCCESS, bean.switchItemListPage());
+    assertEquals(0, itemList.getPageIndex());
+  }
+
+  public void testShouldClearCatalogBean() {
+    Mock catalogServiceMock = mock(CatalogService.class);
+    CatalogBean bean = new CatalogBean((CatalogService) 
catalogServiceMock.proxy());
+    bean.setKeyword("not null");
+    bean.setPageDirection("not null");
+    bean.setCategoryId("not null");
+    bean.setProductId("not null");
+    bean.setItemId("not null");
+    bean.setCategory(new Category());
+    bean.setProduct(new Product());
+    bean.setItem(new Item());
+    bean.setCategoryList(new PaginatedArrayList(2));
+    bean.setProductList(new PaginatedArrayList(2));
+    bean.setItemList(new PaginatedArrayList(2));
+    bean.clear();
+    assertNull(bean.getKeyword());
+    assertNull(bean.getPageDirection());
+    assertNull(bean.getCategoryId());
+    assertNull(bean.getCategory());
+    assertNull(bean.getCategoryList());
+    assertNull(bean.getProductId());
+    assertNull(bean.getProduct());
+    assertNull(bean.getProductList());
+    assertNull(bean.getItemId());
+    assertNull(bean.getItem());
+    assertNull(bean.getItemList());
+  }
+
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/CatalogBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/OrderBeanTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/OrderBeanTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/OrderBeanTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/OrderBeanTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,223 @@
+package com.ibatis.jpetstore.presentation;
+
+import com.ibatis.common.util.PaginatedArrayList;
+import com.ibatis.jpetstore.service.AccountService;
+import com.ibatis.jpetstore.service.OrderService;
+import com.ibatis.jpetstore.service.CatalogService;
+import com.ibatis.jpetstore.domain.Order;
+import com.ibatis.jpetstore.domain.Account;
+import com.ibatis.jpetstore.domain.DomainFixture;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.apache.struts.beanaction.ActionContext;
+
+import java.util.List;
+import java.util.Map;
+
+public class OrderBeanTest extends MockObjectTestCase {
+
+  public void testShouldGetCardTypes() {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    List cardList = bean.getCreditCardTypes();
+    assertEquals(3, cardList.size());
+  }
+
+  public void testListListOrdersByUsername() {
+    Mock orderServiceMock = mock(OrderService.class);
+    PaginatedArrayList orderList = new PaginatedArrayList(5);
+    orderList.add(new Order());
+    orderList.add(new Order());
+    orderList.add(new Order());
+    orderServiceMock.expects(once())
+        .method("getOrdersByUsername")
+        .with(NOT_NULL)
+        .will(returnValue(orderList));
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    AccountBean accountBean = new AccountBean();
+    accountBean.setUsername("not null");
+    sessionMap.put("accountBean", accountBean);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    assertEquals(AbstractBean.SUCCESS, bean.listOrders());
+    assertEquals(3, bean.getOrderList().size());
+  }
+
+  public void testShouldSwitchOrderListPagesBackAndForth() {
+    Mock orderServiceMock = mock(OrderService.class);
+    PaginatedArrayList orderList = new PaginatedArrayList(2);
+    orderList.add(new Order());
+    orderList.add(new Order());
+    orderList.add(new Order());
+    orderServiceMock.expects(once())
+        .method("getOrdersByUsername")
+        .with(NOT_NULL)
+        .will(returnValue(orderList));
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    AccountBean accountBean = new AccountBean();
+    accountBean.setUsername("not null");
+    sessionMap.put("accountBean", accountBean);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    bean.listOrders();
+    bean.setPageDirection("next");
+    bean.switchOrderPage();
+    assertEquals(1, bean.getOrderList().getPageIndex());
+    bean.setPageDirection("previous");
+    bean.switchOrderPage();
+    assertEquals(0, bean.getOrderList().getPageIndex());
+  }
+
+  public void testShouldResetShippingAddressRequirement() {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    bean.setShippingAddressRequired(true);
+    bean.reset();
+    assertFalse(bean.isShippingAddressRequired());
+  }
+
+  public void testShouldClearAllFields() {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    Order order = new Order();
+    bean.setOrder(order);
+    bean.setShippingAddressRequired(true);
+    bean.setOrderId(4);
+    bean.setConfirmed(true);
+    bean.setPageDirection("not null");
+    bean.clear();
+    assertFalse(bean.getOrder() == order);
+    assertFalse(bean.isShippingAddressRequired());
+    assertEquals(0, bean.getOrderId());
+    assertFalse(bean.isConfirmed());
+    assertNull(bean.getPageDirection());
+  }
+
+  public void testShouldSuccessfullyViewOrder() {
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    AccountBean accountBean = new AccountBean();
+    accountBean.setUsername("user");
+    sessionMap.put("accountBean", accountBean);
+
+    Mock orderServiceMock = mock(OrderService.class);
+    Order order = new Order();
+    order.setUsername("user");
+    orderServiceMock.expects(once())
+        .method("getOrder")
+        .with(NOT_NULL)
+        .will(returnValue(order));
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+
+    assertEquals(AbstractBean.SUCCESS, bean.viewOrder());
+    assertEquals(order, bean.getOrder());
+  }
+
+  public void testShouldFailToViewOrderDueToMismatchedUsername() {
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    AccountBean accountBean = new AccountBean();
+    accountBean.setUsername("not proper user");
+    sessionMap.put("accountBean", accountBean);
+
+    Mock orderServiceMock = mock(OrderService.class);
+    Order order = new Order();
+    order.setUsername("user");
+    orderServiceMock.expects(once())
+        .method("getOrder")
+        .with(NOT_NULL)
+        .will(returnValue(order));
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+
+    assertEquals(AbstractBean.FAILURE, bean.viewOrder());
+    assertNull(bean.getOrder());
+  }
+
+  public void 
testShouldForceSignonWhenAttemptingToCreateANewOrderWithoutBeingSignedIn () {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    assertEquals(AbstractBean.SIGNON, bean.newOrderForm());
+  }
+
+  public void testShouldFailDueToAMissingCart () {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL,NOT_NULL)
+        .will(returnValue(account));
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+    accountBean.signon();
+
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    sessionMap.put("accountBean", accountBean);
+
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    assertEquals(AbstractBean.FAILURE, bean.newOrderForm());
+  }
+
+  public void testSuccessfullyViewCart() {
+    Account account = DomainFixture.newTestAccount();
+    Mock accountServiceMock = mock(AccountService.class);
+    accountServiceMock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL,NOT_NULL)
+        .will(returnValue(account));
+    Mock catalogServiceMock = mock(CatalogService.class);
+    catalogServiceMock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+    AccountBean accountBean = new 
AccountBean((AccountService)accountServiceMock.proxy(), 
(CatalogService)catalogServiceMock.proxy());
+    accountBean.setAccount(account);
+    accountBean.signon();
+
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    sessionMap.put("accountBean", accountBean);
+    sessionMap.put("cartBean", new CartBean());
+
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+
+    assertEquals(AbstractBean.SUCCESS, bean.newOrderForm());
+  }
+
+  public void testShouldRequireShippingAddressBeforeNewOrder() {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    bean.setShippingAddressRequired(true);
+    assertEquals(AbstractBean.SHIPPING,bean.newOrder());
+  }
+
+  public void testShouldConfirmationBeforeNewOrder() {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    bean.setConfirmed(false);
+    assertEquals(AbstractBean.CONFIRM,bean.newOrder());
+  }
+
+  public void testShouldFaileDueToMissingNewOrder() {
+    Mock orderServiceMock = mock(OrderService.class);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    bean.setConfirmed(true);
+    bean.setOrder(null);
+    assertEquals(AbstractBean.FAILURE,bean.newOrder());
+  }
+
+  public void testShouldSuccessfullyCreateNewOrder() {
+    Map sessionMap = ActionContext.getActionContext().getSessionMap();
+    sessionMap.put("cartBean", new CartBean());
+
+    Mock orderServiceMock = mock(OrderService.class);
+    orderServiceMock.expects(once())
+        .method("insertOrder")
+        .with(NOT_NULL);
+    OrderBean bean = new OrderBean((OrderService)orderServiceMock.proxy());
+    bean.setConfirmed(true);
+    assertEquals(AbstractBean.SUCCESS,bean.newOrder());
+  }
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/presentation/OrderBeanTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/AccountServiceTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/AccountServiceTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/AccountServiceTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/AccountServiceTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,57 @@
+package com.ibatis.jpetstore.service;
+
+import com.ibatis.jpetstore.domain.Account;
+import com.ibatis.jpetstore.domain.DomainFixture;
+import com.ibatis.jpetstore.persistence.iface.AccountDao;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+public class AccountServiceTest extends MockObjectTestCase {
+
+  public void testShouldVerifyGetAccountIsCalledByUsername() {
+    Mock mock = mock(AccountDao.class);
+
+    mock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL)
+        .will(returnValue(new Account()));
+
+    AccountService accountService = new AccountService((AccountDao) 
mock.proxy());
+    accountService.getAccount("cbegin");
+  }
+
+  public void testShouldVerifyGetAccountIsCalledByUsernameAndPassword() {
+    Mock mock = mock(AccountDao.class);
+
+    mock.expects(once())
+        .method("getAccount")
+        .with(NOT_NULL, NOT_NULL)
+        .will(returnValue(new Account()));
+
+    AccountService accountService = new AccountService((AccountDao) 
mock.proxy());
+    accountService.getAccount("cbegin","PASSWORD");
+  }
+
+  public void testShouldVerifyInsertAccountIsCalled() {
+    Mock mock = mock(AccountDao.class);
+
+    mock.expects(once())
+        .method("insertAccount")
+        .with(NOT_NULL);
+
+    AccountService accountService = new AccountService((AccountDao) 
mock.proxy());
+    accountService.insertAccount(DomainFixture.newTestAccount());
+  }
+
+  public void testShouldVerifyUpdateAccountIsCalled() {
+    Mock mock = mock(AccountDao.class);
+
+    mock.expects(once())
+        .method("updateAccount")
+        .with(NOT_NULL);
+
+    AccountService accountService = new AccountService((AccountDao) 
mock.proxy());
+    accountService.updateAccount(DomainFixture.newTestAccount());
+  }
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/AccountServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/CatalogServiceTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/CatalogServiceTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/CatalogServiceTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/CatalogServiceTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,128 @@
+package com.ibatis.jpetstore.service;
+
+import com.ibatis.common.util.PaginatedArrayList;
+import com.ibatis.jpetstore.domain.Category;
+import com.ibatis.jpetstore.domain.Item;
+import com.ibatis.jpetstore.domain.Product;
+import com.ibatis.jpetstore.persistence.iface.CategoryDao;
+import com.ibatis.jpetstore.persistence.iface.ItemDao;
+import com.ibatis.jpetstore.persistence.iface.ProductDao;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+import java.util.ArrayList;
+
+public class CatalogServiceTest extends MockObjectTestCase {
+
+  public void testShouldCallGetCategoryOnCategoryDao() {
+
+    Mock mock = mock(CategoryDao.class);
+
+    mock.expects(once())
+        .method("getCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new Category()));
+
+    CatalogService service = new CatalogService((CategoryDao) mock.proxy(), 
null, null);
+    service.getCategory("DOGS");
+
+  }
+
+  public void testShouldCallGetCategoryListOnCategoryDao() {
+
+    Mock mock = mock(CategoryDao.class);
+
+    mock.expects(once())
+        .method("getCategoryList")
+        .withNoArguments()
+        .will(returnValue(new ArrayList()));
+
+    CatalogService service = new CatalogService((CategoryDao) mock.proxy(), 
null, null);
+    service.getCategoryList();
+
+  }
+
+  public void testShouldCallGetItemOnItemDao() {
+    Mock mock = mock(ItemDao.class);
+
+    mock.expects(once())
+        .method("getItem")
+        .with(NOT_NULL)
+        .will(returnValue(new Item()));
+
+    CatalogService service = new CatalogService(null, (ItemDao) mock.proxy(), 
null);
+    service.getItem("EST-1");
+
+  }
+
+  public void testShouldCallGetItemListByProductOnItemDao() {
+
+    Mock mock = mock(ItemDao.class);
+
+    mock.expects(once())
+        .method("getItemListByProduct")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+
+    CatalogService service = new CatalogService(null, (ItemDao) mock.proxy(), 
null);
+    service.getItemListByProduct("FI-SW-01");
+
+  }
+
+  public void testShouldCallGetProductOnProductDao() {
+
+    Mock mock = mock(ProductDao.class);
+
+    mock.expects(once())
+        .method("getProduct")
+        .with(NOT_NULL)
+        .will(returnValue(new Product()));
+
+    CatalogService service = new CatalogService(null, null, (ProductDao) 
mock.proxy());
+    service.getProduct("FI-SW-01");
+
+  }
+
+  public void testShouldCallGetProductListByCategoryOnProductDao() {
+
+    Mock mock = mock(ProductDao.class);
+
+    mock.expects(once())
+        .method("getProductListByCategory")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+
+    CatalogService service = new CatalogService(null, null, (ProductDao) 
mock.proxy());
+    service.getProductListByCategory("DOGS");
+
+  }
+
+  public void testShouldFindProductIsInStock() {
+    Mock mock = mock(ItemDao.class);
+
+    mock.expects(once())
+        .method("isItemInStock")
+        .with(NOT_NULL)
+        .will(returnValue(true));
+
+    CatalogService service = new CatalogService(null, (ItemDao) mock.proxy(), 
null);
+
+    assertTrue("Expected item to be in stock.", 
service.isItemInStock("EST-1"));
+
+  }
+
+  public void testCallSearchProductsOnProductDao() {
+    Mock mock = mock(ProductDao.class);
+
+    mock.expects(once())
+        .method("searchProductList")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+
+    CatalogService service = new CatalogService(null, null, (ProductDao) 
mock.proxy());
+    service.searchProductList("dog");
+
+  }
+
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/CatalogServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/OrderServiceTest.java
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/OrderServiceTest.java?rev=925602&view=auto
==============================================================================
--- 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/OrderServiceTest.java
 (added)
+++ 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/OrderServiceTest.java
 Sat Mar 20 13:25:33 2010
@@ -0,0 +1,100 @@
+package com.ibatis.jpetstore.service;
+
+import com.ibatis.common.util.PaginatedArrayList;
+import com.ibatis.dao.client.DaoManager;
+import com.ibatis.jpetstore.domain.DomainFixture;
+import com.ibatis.jpetstore.domain.Order;
+import com.ibatis.jpetstore.persistence.iface.ItemDao;
+import com.ibatis.jpetstore.persistence.iface.OrderDao;
+import com.ibatis.jpetstore.persistence.iface.SequenceDao;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+public class OrderServiceTest extends MockObjectTestCase {
+
+  public void testShouldCallGetOrderOnOrderDao() {
+
+    Mock orderDao = mock(OrderDao.class);
+    orderDao.expects(once())
+        .method("getOrder")
+        .with(NOT_NULL)
+        .will(returnValue(new Order()));
+
+    Mock daoManager = mock(DaoManager.class);
+    daoManager.expects(once())
+        .method("startTransaction")
+        .withNoArguments();
+
+    daoManager.expects(once())
+        .method("commitTransaction")
+        .withNoArguments();
+
+    daoManager.expects(once())
+        .method("endTransaction")
+        .withNoArguments();
+
+    OrderService service = new OrderService((DaoManager)daoManager.proxy(), 
null, (OrderDao) orderDao.proxy(), null);
+    service.getOrder(1);
+
+  }
+
+  public void testShouldCallGetOrdersByUsernameOnOrderDao() {
+    Mock orderDao = mock(OrderDao.class);
+    orderDao.expects(once())
+        .method("getOrdersByUsername")
+        .with(NOT_NULL)
+        .will(returnValue(new PaginatedArrayList(5)));
+    OrderService service = new OrderService(null, null, (OrderDao) 
orderDao.proxy(), null);
+    service.getOrdersByUsername("j2ee");
+  }
+
+  public void testShouldCallInsertOrderOnOrderDao() {
+
+    Mock seqDao = mock(SequenceDao.class);
+    seqDao.expects(once())
+        .method("getNextId")
+        .with(NOT_NULL)
+        .will(returnValue(1));
+
+    Mock orderDao = mock(OrderDao.class);
+    orderDao.expects(once())
+        .method("insertOrder")
+        .with(NOT_NULL);
+
+    Mock itemDao = mock(ItemDao.class);
+    itemDao.expects(once())
+        .method("updateAllQuantitiesFromOrder")
+        .with(NOT_NULL);
+
+    Mock daoManager = mock(DaoManager.class);
+    daoManager.expects(once())
+        .method("startTransaction")
+        .withNoArguments();
+
+    daoManager.expects(once())
+        .method("commitTransaction")
+        .withNoArguments();
+
+    daoManager.expects(once())
+        .method("endTransaction")
+        .withNoArguments();
+
+    OrderService service = new OrderService((DaoManager)daoManager.proxy(), 
(ItemDao) itemDao.proxy(), (OrderDao) orderDao.proxy(), (SequenceDao) 
seqDao.proxy());
+    service.insertOrder(DomainFixture.newTestOrder());
+
+  }
+
+  public void testShouldCallGetNextIdOnSequenceDao() {
+
+    Mock seqDao = mock(SequenceDao.class);
+    seqDao.expects(once())
+        .method("getNextId")
+        .with(NOT_NULL)
+        .will(returnValue(1));
+
+    OrderService service = new OrderService(null, null, null, (SequenceDao) 
seqDao.proxy());
+    service.getNextId("ordernum");
+
+  }
+
+}

Propchange: 
ibatis/java/jpetstore-5/trunk/jpetstore-web/src/test/java/com/ibatis/jpetstore/service/OrderServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: ibatis/java/jpetstore-5/trunk/pom.xml
URL: 
http://svn.apache.org/viewvc/ibatis/java/jpetstore-5/trunk/pom.xml?rev=925602&view=auto
==============================================================================
--- ibatis/java/jpetstore-5/trunk/pom.xml (added)
+++ ibatis/java/jpetstore-5/trunk/pom.xml Sat Mar 20 13:25:33 2010
@@ -0,0 +1,54 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.ibatis.jpetstore</groupId>
+  <artifactId>jpetstore</artifactId>
+  <packaging>pom</packaging>
+  <version>5.0-SNAPSHOT</version>
+  <name>JPetstore 5</name>
+  <url>http://maven.apache.org</url>
+  <modules>
+    <module>beanaction</module>
+    <module>jpetstore-web</module>
+  </modules>
+  <build>
+    <finalName>jpetstore</finalName>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.0.2</version>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <version>1.2.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock-cglib</artifactId>
+      <version>1.2.0</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-servlet_2.4_spec</artifactId>
+      <version>1.1.1</version>
+      <scope>provided</scope>
+    </dependency>    
+  </dependencies>
+</project>

Propchange: ibatis/java/jpetstore-5/trunk/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to