Search in sources :

Example 11 with Forum

use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.

the class ForumPersistenceImplTest method testGetForum.

/**
	 * Tests getForum method
	 * @throws Exception to JUnit
	 */
public void testGetForum() throws Exception {
    List forums = persistence.getAllForums();
    for (Iterator it = forums.iterator(); it.hasNext(); ) {
        Forum forum = (Forum) it.next();
        Forum forum1 = persistence.getForum(forum.getId());
        checkForum(forum, forum1);
    }
}
Also used : Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Forum(cn.edu.zju.acm.onlinejudge.bean.Forum)

Example 12 with Forum

use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.

the class ForumPersistenceImplTest 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;
}
Also used : Forum(cn.edu.zju.acm.onlinejudge.bean.Forum)

Example 13 with Forum

use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.

the class SubmissionPersistenceImplTest 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;
}
Also used : Forum(cn.edu.zju.acm.onlinejudge.bean.Forum)

Example 14 with Forum

use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.

the class ForumPersistenceImplTest 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
    }
}
Also used : PersistenceException(cn.edu.zju.acm.onlinejudge.persistence.PersistenceException) Forum(cn.edu.zju.acm.onlinejudge.bean.Forum)

Example 15 with Forum

use of cn.edu.zju.acm.onlinejudge.bean.Forum in project zoj by licheng.

the class ForumPersistenceImplTest 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());
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) Forum(cn.edu.zju.acm.onlinejudge.bean.Forum)

Aggregations

Forum (cn.edu.zju.acm.onlinejudge.bean.Forum)19 ArrayList (java.util.ArrayList)5 PersistenceException (cn.edu.zju.acm.onlinejudge.persistence.PersistenceException)4 Iterator (java.util.Iterator)4 List (java.util.List)4 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2