Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_cn
Articles_de
Articles_pt
Articles_zh
HibernateRelationshi...




JSPWiki v2.2.33

[RSS]


Hide Menu

HibernateRelationships


Difference between version 47 and version 46:

At line 1628 added 1 line.
[{Java2HtmlPlugin
At line 1630 added 1 line.
package org.appfuse.dao;
At line 1632 added 105 lines.
import java.util.Date;
import org.appfuse.Constants;
import org.appfuse.model.Address;
import org.appfuse.model.Weblog;
import org.appfuse.model.User;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
/**
* @author Rance Shields
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class WeblogDaoTest extends BaseDaoTestCase {
private WeblogDAO wldao = null;
private Weblog weblog = null;
private UserDAO udao = null;
private User user = null;
protected void setUp() throws Exception {
super.setUp();
wldao = (WeblogDAO) ctx.getBean("weblogDAO");
udao = (UserDAO) ctx.getBean("userDAO");
}
protected void tearDown() throws Exception {
super.tearDown();
wldao = null;
}
public void testGetWeblogInvalid() throws Exception {
try {
weblog = wldao.getWeblog(new Long(3000));
fail("weblogId found in database, failing test...");
} catch (DataAccessException d) {
assertTrue(d != null);
}
}
public void testGetWeblog() throws Exception {
weblog = wldao.getWeblog(new Long(1));
assertNotNull(weblog);
assertEquals(2, weblog.getUsers().size());
}
public void testUpdateWeblog() throws Exception {
weblog = wldao.getWeblog(new Long(2));
weblog.setBlogTitle("Testing Update Weblog");
wldao.saveWeblog(weblog);
assertEquals("Testing Update Weblog", weblog.getBlogTitle());
}
public void testAddWeblogUser() throws Exception {
weblog = wldao.getWeblog(new Long(2));
assertEquals(1, weblog.getUsers().size());
user = udao.getUser("tomcat");
weblog.addUser(user);
wldao.saveWeblog(weblog);
assertEquals(2, weblog.getUsers().size());
//add the same user twice - should result in no additional user
weblog.addUser(user);
wldao.saveWeblog(weblog);
assertEquals("more than 2 of the same users", 2, weblog.getUsers().size());
weblog.getUsers().remove(user);
wldao.saveWeblog(weblog);
assertEquals(1, weblog.getUsers().size());
}
public void testAddAndRemoveWeblog() throws Exception {
weblog = new Weblog();
weblog.setBlogTitle("A new test for adding and then deleting a weblog");
weblog.setDateCreated(new Date(2005-04-17));
weblog.setUsername("Cartman");
wldao.saveWeblog(weblog);
assertNotNull(weblog.getBlogTitle());
assertEquals("Cartman", weblog.getUsername());
wldao.removeWeblog(weblog.getWeblogId());
try {
weblog = wldao.getWeblog(weblog.getWeblogId());
fail("saveWeblog didn't throw DataAccessException");
} catch (DataAccessException d) {
assertNotNull(d);
}
}
}
}]

Back to HibernateRelationships, or to the Page History.