| At line 321 added 1 line. |
|
| At line 343 added 66 lines. |
| !CategoryDaoTest |
|
| Next, create an ''CategoryDaoTest.java'' class in ''test/dao/**/dao''. |
|
| [{Java2HtmlPlugin |
|
| package org.appfuse.dao; |
|
| import org.appfuse.model.Category; |
| import org.springframework.dao.DataAccessException; |
|
| public class CategoryDaoTest extends BaseDaoTestCase { |
| |
| private CategoryDAO catdao = null; |
| private Category category = null; |
| |
| protected void setUp() throws Exception { |
| super.setUp(); |
| catdao = (CategoryDAO) ctx.getBean("categoryDAO"); |
| } |
| |
| protected void tearDown() throws Exception { |
| super.tearDown(); |
| catdao = null; |
| } |
| |
| public void testGetCategory() throws Exception { |
| category = catdao.getCategory(new Long(1)); |
|
| assertNotNull(category); |
| assertEquals("Struts v. Spring MVC", category.getCategoryName()); |
| } |
| |
| public void testUpdateCategory() throws Exception { |
| category = catdao.getCategory(new Long(2)); |
| category.setCategoryName("Testing update category"); |
| catdao.saveCategory(category); |
| |
| assertEquals("Testing update category", category.getCategoryName()); |
| } |
| |
| public void testAddAndRemoveCategory() throws Exception { |
| category = new Category(); |
| category.setCategoryName("Spaceman Biff"); |
| category.setCategoryDescription("Paying homage to Calvin's alter ego!"); |
| |
| catdao.saveCategory(category); |
| |
| assertNotNull(category.getCategoryDescription()); |
| assertEquals("Spaceman Biff", category.getCategoryName()); |
| |
| catdao.removeCategory(category.getCategoryId()); |
| |
| try { |
| category = catdao.getCategory(category.getCategoryId()); |
| fail("saveCategory didn't throw DataAccessException"); |
| } catch (DataAccessException d) { |
| assertNotNull(d); |
| } |
| |
| } |
|
| } |
|
| }] |
|