Author: schof
Date: Wed Aug 2 15:48:54 2006
New Revision: 428181
URL: http://svn.apache.org/viewvc?rev=428181&view=rev
Log:
moved all data setup code to the listener
Modified:
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/InventoryService.java
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/impl/InventoryServiceImpl.java
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/web/DataPopListener.java
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/domain/CategoryTest.java
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/service/impl/InventoryServiceImplTest.java
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/TreeBackerTest.java
Modified:
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/InventoryService.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/InventoryService.java?rev=428181&r1=428180&r2=428181&view=diff
==============================================================================
---
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/InventoryService.java
(original)
+++
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/InventoryService.java
Wed Aug 2 15:48:54 2006
@@ -45,9 +45,8 @@
public void setPetDao(PetDao petDao);
/**
- * Creates test inventory data in the datastore. This method is only
necessary b/c petstore is configured to
- * use an in memory database. In a real world application your schema and
data would already exist in the
- * database and you just point your hibernate data source at the real db.
+ * Stores a Category in the datastore.
+ * @param category
*/
- public void createTestData();
+ public void storeCategory(Category category);
}
Modified:
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/impl/InventoryServiceImpl.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/impl/InventoryServiceImpl.java?rev=428181&r1=428180&r2=428181&view=diff
==============================================================================
---
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/impl/InventoryServiceImpl.java
(original)
+++
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/service/impl/InventoryServiceImpl.java
Wed Aug 2 15:48:54 2006
@@ -53,27 +53,12 @@
this.petDao = petDao;
}
- public void createTestData() {
-
- Category cats = new Category("Cats");
-
- Category dogs = new Category("Dogs");
- Category terriers = new Category("Terriers");
- dogs.addChildCategory(terriers);
- Pet bostonTerrier = new Pet("0100", "Boston Terrier");
- Pet wheatonTerrier = new Pet("0101", "Wheaton Terrier");
- terriers.addPet(bostonTerrier);
- terriers.addPet(wheatonTerrier);
- Category retrievers = new Category("Retrievers");
- dogs.addChildCategory(retrievers);
- Category birds = new Category("Birds");
- Category fish = new Category("Fish");
- Category reptiles = new Category( "Reptiles");
-
- categoryDao.store(dogs);
- categoryDao.store(cats);
- categoryDao.store(birds);
- categoryDao.store(fish);
- categoryDao.store(reptiles);
+ /**
+ * Stores a Category in the datastore.
+ *
+ * @param category
+ */
+ public void storeCategory(Category category) {
+ categoryDao.store(category);
}
}
Modified:
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/web/DataPopListener.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/web/DataPopListener.java?rev=428181&r1=428180&r2=428181&view=diff
==============================================================================
---
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/web/DataPopListener.java
(original)
+++
shale/sandbox/shale-petstore/src/main/java/org/apache/shale/petstore/web/DataPopListener.java
Wed Aug 2 15:48:54 2006
@@ -17,6 +17,8 @@
package org.apache.shale.petstore.web;
import org.apache.shale.petstore.service.InventoryService;
+import org.apache.shale.petstore.domain.Category;
+import org.apache.shale.petstore.domain.Pet;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.context.ApplicationContext;
@@ -38,8 +40,35 @@
ApplicationContext applicationContext =
(ApplicationContext)servletContextEvent.getServletContext().
getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
- InventoryService inventoryService =
(InventoryService)applicationContext.getBean("inventoryService");
- inventoryService.createTestData();
+
createTestData((InventoryService)applicationContext.getBean("inventoryService"));
+ }
+
+ /**
+ * Use the service provided to create some test data.
+ * @param inventoryService
+ */
+ private void createTestData(InventoryService inventoryService) {
+
+ Category cats = new Category("Cats");
+ Category dogs = new Category("Dogs");
+ Category terriers = new Category("Terriers");
+ dogs.addChildCategory(terriers);
+ Pet bostonTerrier = new Pet("0100", "Boston Terrier", 675.00, 8);
+ Pet wheatonTerrier = new Pet("0101", "Wheaton Terrier", 625.00, 12);
+ terriers.addPet(bostonTerrier);
+ terriers.addPet(wheatonTerrier);
+ Category retrievers = new Category("Retrievers");
+ dogs.addChildCategory(retrievers);
+ Category birds = new Category("Birds");
+ Category fish = new Category("Fish");
+ Category reptiles = new Category( "Reptiles");
+
+ // now store each of the top level categories
+ inventoryService.storeCategory(dogs);
+ inventoryService.storeCategory(cats);
+ inventoryService.storeCategory(birds);
+ inventoryService.storeCategory(fish);
+ inventoryService.storeCategory(reptiles);
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
Modified:
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/domain/CategoryTest.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/domain/CategoryTest.java?rev=428181&r1=428180&r2=428181&view=diff
==============================================================================
---
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/domain/CategoryTest.java
(original)
+++
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/domain/CategoryTest.java
Wed Aug 2 15:48:54 2006
@@ -29,8 +29,7 @@
private Category barCategory;
protected void setUp() throws Exception {
- pet = new Pet();
- pet.setProductId("003201233");
+ pet = new Pet("003201233", "foo pet");
fooCategory = new Category("foo category");
barCategory = new Category("bar category");
}
Modified:
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/service/impl/InventoryServiceImplTest.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/service/impl/InventoryServiceImplTest.java?rev=428181&r1=428180&r2=428181&view=diff
==============================================================================
---
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/service/impl/InventoryServiceImplTest.java
(original)
+++
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/service/impl/InventoryServiceImplTest.java
Wed Aug 2 15:48:54 2006
@@ -19,6 +19,7 @@
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
import org.apache.shale.petstore.persistence.CategoryDao;
+import org.apache.shale.petstore.domain.Category;
/**
* @author Sean Schofield
@@ -27,13 +28,13 @@
private InventoryServiceImpl inventoryService;
private Mock mockDao;
+ private Mock mockCategory;
public void setUp() throws Exception {
super.setUp();
- inventoryService = new InventoryServiceImpl();
- // setup mock
mockDao = mock(CategoryDao.class);
- // inject mock
+ mockCategory = mock(Category.class);
+ inventoryService = new InventoryServiceImpl();
inventoryService.setCategoryDao((CategoryDao)mockDao.proxy());
}
@@ -42,8 +43,8 @@
inventoryService.getInventory();
}
- public void testCreateTestData() {
- mockDao.expects(atLeastOnce()).method("store");
- inventoryService.createTestData();
+ public void testStoreCategory() {
+ mockDao.expects(once()).method("store");
+ inventoryService.storeCategory((Category)mockCategory.proxy());
}
}
Modified:
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/TreeBackerTest.java
URL:
http://svn.apache.org/viewvc/shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/TreeBackerTest.java?rev=428181&r1=428180&r2=428181&view=diff
==============================================================================
---
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/TreeBackerTest.java
(original)
+++
shale/sandbox/shale-petstore/src/test/java/org/apache/shale/petstore/view/backing/TreeBackerTest.java
Wed Aug 2 15:48:54 2006
@@ -36,13 +36,14 @@
private static final Category DOGS = new Category("dogs");
private static final Category TERRIERS = new Category("terriers");
- private static final Pet BOSTON_TERRIER = new Pet("1001", "boton terrier");
- private static final Pet WHEATON_TERRIER = new Pet("1002", "wheaton
terrier");
+ private static final Pet BOSTON_TERRIER = new Pet("1001", "boton terrier",
1000.00, 10);
+ private static final Pet WHEATON_TERRIER = new Pet("1002", "wheaton
terrier", 850.00, 0);
private static final Category RETRIEVERS = new Category("retrievers");
private static final Category CATS = new Category("cats");
private static final Category FISH = new Category("fish");
private TreeBacker treeBacker;
+
//private Mock mockDao;
public void setUp() throws Exception {
@@ -90,7 +91,8 @@
}
/**
- * Mock class used to generate sample data.
+ * Mock class used to generate sample data. Its not sufficient to use a
proxy from JMock because we'd like
+ * to verify that the tree nodes are being ordererd exactly as we expect.
*/
private static final class MockInventoryService implements
InventoryService {
@@ -113,6 +115,10 @@
}
public void createTestData() {
+ throw new UnsupportedOperationException("method should not be
called from test case");
+ }
+
+ public void storeCategory(Category category) {
throw new UnsupportedOperationException("method should not be
called from test case");
}
}