use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class ForumPersistenceImpl method getAllForums.
/**
* <p>
* Get all forums in persistence layer.
* </p>
*
* @return a list of Forum instances containing all forums in persistence layer
* @throws PersistenceException
* wrapping a persistence implementation specific exception
*/
public List<Forum> getAllForums() throws PersistenceException {
Connection conn = null;
try {
conn = Database.createConnection();
PreparedStatement ps = null;
try {
ps = conn.prepareStatement(ForumPersistenceImpl.GET_ALL_FORUMS);
ResultSet rs = ps.executeQuery();
List<Forum> forums = new ArrayList<Forum>();
while (rs.next()) {
Forum forum = new Forum();
forum.setId(rs.getLong(DatabaseConstants.FORUM_FORUM_ID));
forum.setName(rs.getString(DatabaseConstants.FORUM_NAME));
forum.setDescription(rs.getString(DatabaseConstants.FORUM_DESCRIPTION));
forums.add(forum);
}
return forums;
} finally {
Database.dispose(ps);
}
} catch (SQLException e) {
throw new PersistenceException("Failed to get all forums", e);
} finally {
Database.dispose(conn);
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testCreateForum1.
/**
* Tests createForum method
* @throws Exception to JUnit
*/
public void testCreateForum1() throws Exception {
Forum forum = new Forum();
forum.setName("name");
forum.setDescription("desc");
persistence.createForum(forum, 1);
Forum forum1 = persistence.getForum(forum.getId());
checkForum(forum, forum1);
}
use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class ContestPersistenceImplTest method newForum.
/**
* Creates a new forum.
* @param id the id
* @return a new forum instance
*/
private Forum newForum(long id) {
Forum forum = new Forum();
forum.setId(id);
forum.setName("forum" + id);
forum.setDescription("forum" + id + " description");
return forum;
}
use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testGetAllForums.
/**
* Tests getAllForums method
* @throws Exception to JUnit
*/
public void testGetAllForums() throws Exception {
List forums = persistence.getAllForums();
assertEquals("size is wrong", 3, forums.size());
Set nameSet = new HashSet(Arrays.asList(new String[] { "forum1", "forum2", "forum3" }));
Set descSet = new HashSet(Arrays.asList(new String[] { "forum1 description", "forum2 description", "forum3 description" }));
for (Iterator it = forums.iterator(); it.hasNext(); ) {
Forum forum = (Forum) it.next();
assertTrue("wrong name", nameSet.contains(forum.getName()));
assertTrue("wrong description", descSet.contains(forum.getDescription()));
nameSet.remove(forum.getName());
descSet.remove(forum.getDescription());
}
}
use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.
the class AuthorizationPersistenceImplTest method testUpdateForum2.
/**
* Tests updateForum method
* @throws Exception to JUnit
*/
public void testUpdateForum2() throws Exception {
try {
Forum forum = new Forum();
forum.setName("foo");
forum.setDescription("bar");
persistence.updateForum(forum, 1);
fail("PersistenceException should be thrown");
} catch (PersistenceException pe) {
// ok
}
}
Aggregations