commentthread

This commit is contained in:
joha-asc 2011-07-21 16:31:14 +02:00
parent c7b8d1a9d1
commit ff8d5d09db

@ -0,0 +1,111 @@
/**
*
*/
package se.su.dsv.scipro.dao.jpa;
import java.util.SortedSet;
import java.util.TreeSet;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import se.su.dsv.scipro.data.dao.interfaces.CommentDao;
import se.su.dsv.scipro.data.dao.interfaces.CommentThreadDao;
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
import se.su.dsv.scipro.data.dao.interfaces.UserDao;
import se.su.dsv.scipro.data.dataobjects.Comment;
import se.su.dsv.scipro.data.dataobjects.CommentThread;
import se.su.dsv.scipro.data.dataobjects.Project;
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
import se.su.dsv.scipro.data.dataobjects.User;
/**
* @author Johan Aschan - aschan@dsv.su.se
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class TestCommentThreadDaoJPA {
@Autowired
private CommentDao commentDao;
@Autowired
private CommentThreadDao commentThreadDao;
@Autowired
private ProjectDao projectDao;
@Autowired
private ProjectClassDao projectClassDao;
@Autowired
private UserDao userDao;
private Project project1;
private Comment comment1, comment2, comment3;
private SortedSet<Comment> comments = new TreeSet<Comment>();
private CommentThread commentThread;
private User user;
@Before
public void startTransaction() {
ProjectClass projectClass = new ProjectClass(ProjectClass.BACHELOR,"Bachelor","Bachelor degree thesis project");
projectClass = projectClassDao.save(projectClass);
project1 = new Project();
project1.setProjectClass(projectClass);
project1.setTitle("Project 1");
project1 = projectDao.save(project1);
user = new User();
user.setFirstName("Pelle");
user = userDao.save(user);
commentThread = new CommentThread(project1);
commentThread = commentThreadDao.save(commentThread);
comment1 = new Comment(user,commentThread);
comment1 = commentDao.save(comment1);
comment2 = new Comment(user,commentThread);
comment2 = commentDao.save(comment2);
comment3 = new Comment(user,commentThread);
comment3 = commentDao.save(comment3);
comments.add(comment1);
comments.add(comment2);
comments.add(comment3);
commentThread.setComments(comments);
commentThread = commentThreadDao.save(commentThread);
}
@Test
@Transactional
@Rollback
public void testGetCommentThreadByClassAndId() {
CommentThread commentThreadNew = commentThreadDao.getCommentThread(project1);
Assert.assertEquals(commentThread, commentThreadNew);
}
@Test
@Transactional
@Rollback
public void testGetCommentThreadSize() {
int commentThreadSize = commentThreadDao.getCommentThreadSize(project1);
Assert.assertEquals(3, commentThreadSize);
}
}