| At line 271 added 71 lines. |
| !EntryDaoTest |
|
| Now, create an ''EntryDaoTest.java'' class. Again, create this class in ''test/dao/**/dao'' and fill it with the following code. |
|
| [{Java2HtmlPlugin |
|
| package org.appfuse.dao; |
|
| import java.sql.Timestamp; |
|
| import org.appfuse.model.Entry; |
| import org.springframework.dao.DataAccessException; |
|
| public class EntryDaoTest extends BaseDaoTestCase { |
| |
| private EntryDAO edao = null; |
| private Entry entry = null; |
| |
| protected void setUp() throws Exception { |
| super.setUp(); |
| edao = (EntryDAO) ctx.getBean("entryDAO"); |
| } |
| |
| protected void tearDown() throws Exception { |
| super.tearDown(); |
| edao = null; |
| } |
| |
| public void testGetEntry() throws Exception { |
| entry = edao.getEntry(new Long(1)); |
|
| assertNotNull(entry); |
| assertEquals("Testing", entry.getText()); |
| } |
| |
| public void testUpdateEntry() throws Exception { |
| entry = edao.getEntry(new Long(2)); |
| entry.setText("Testing update entry"); |
| entry.setCategoryId(new Long(2)); |
| edao.saveEntry(entry); |
| |
| assertEquals("Testing update entry", entry.getText()); |
| } |
| |
| public void testAddAndRemoveEntry() throws Exception { |
| entry = new Entry(); |
| entry.setText("Testing add a new entry"); |
| entry.setTimeCreated(new Timestamp(2004-04-02)); |
| entry.setCategoryId(new Long(3)); |
| entry.setWeblogId(new Long(1)); |
| |
| edao.saveEntry(entry); |
| |
| assertNotNull(entry.getText()); |
| assertEquals("Testing add a new entry", entry.getText()); |
| |
| edao.removeEntry(entry.getEntryId()); |
| |
| try { |
| entry = edao.getEntry(entry.getEntryId()); |
| fail("saveEntry didn't throw DataAccessException"); |
| } catch (DataAccessException d) { |
| assertNotNull(d); |
| } |
| |
| } |
|
| } |
|
| }] |
|