Test commentthrad
git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@270 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
0d14da9c36
commit
1c81638ceb
src/test/java/se/su/dsv/scipro/dao/jpa
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
|
||||
default-autowire="byName">
|
||||
|
||||
<bean id="entityManagerFactory"
|
||||
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
|
||||
<property name="persistenceUnitName" value="testPersistenceUnit" />
|
||||
</bean>
|
||||
|
||||
<!--
|
||||
enable the configuration of transactional behavior based on
|
||||
annotations
|
||||
-->
|
||||
<tx:annotation-driven transaction-manager="transactionManager" />
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
|
||||
|
||||
<bean id="commentDao" class="se.su.dsv.scipro.data.dao.jpa.CommentDaoJPAImp">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
<bean id="commentThreadDao" class="se.su.dsv.scipro.data.dao.jpa.CommentThreadDaoJPAImp">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
<bean id="projectDao" class="se.su.dsv.scipro.data.dao.jpa.ProjectDaoJPAImp">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
<bean id="projectClassDao" class="se.su.dsv.scipro.data.dao.jpa.ProjectClassDaoJPAImp">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
<bean id="userClassDao" class="se.su.dsv.scipro.data.dao.jpa.UserDaoJPAImp">
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory" />
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
</beans>
|
@ -0,0 +1,101 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package se.su.dsv.scipro.dao.jpa;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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 List<Comment> commentList = new ArrayList<Comment>();
|
||||
private CommentThread commentThread;
|
||||
|
||||
@Before
|
||||
public void startTransaction() {
|
||||
ProjectClass projectClass = new ProjectClass();
|
||||
projectClass.setName("Test");
|
||||
projectClass = projectClassDao.save(projectClass);
|
||||
project1 = new Project();
|
||||
project1.setProjectClass(projectClass);
|
||||
project1.setTitle("Project 1");
|
||||
project1 = projectDao.save(project1);
|
||||
|
||||
User user = new User();
|
||||
user.setFirstName("Pelle");
|
||||
user = userDao.save(user);
|
||||
comment1 = new Comment();
|
||||
comment1.setUser(user);
|
||||
comment1 = commentDao.save(comment1);
|
||||
|
||||
comment2 = new Comment();
|
||||
comment2.setUser(user);
|
||||
comment2 = commentDao.save(comment2);
|
||||
|
||||
comment3 = new Comment();
|
||||
comment3.setUser(user);
|
||||
comment3 = commentDao.save(comment3);
|
||||
|
||||
commentList.add(comment1);
|
||||
commentList.add(comment2);
|
||||
commentList.add(comment3);
|
||||
|
||||
commentThread = new CommentThread();
|
||||
commentThread.setClassId(project1.getId());
|
||||
commentThread.setClassName(project1.getClass().toString());
|
||||
commentThread.setCommentList(commentList);
|
||||
commentThread = commentThreadDao.save(commentThread);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void testGetCommentThreadByClassAndId() {
|
||||
CommentThread commentThreadNew = commentThreadDao.getCommentThreadByClassAndId(project1.getClass().toString(), project1.getId());
|
||||
Assert.assertEquals(commentThread, commentThreadNew);
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ public class TestSupervisorBoardMessageDaoJPA {
|
||||
private SupervisorBoardMessageDao hiddenMessageDao;
|
||||
|
||||
private User user, deletedUser;
|
||||
private SupervisorBoardMessage hiddenMessage, deletedHiddenMessage;
|
||||
private SupervisorBoardMessage hiddenMessage;
|
||||
|
||||
@Before
|
||||
public void startTransaction()
|
||||
|
Loading…
x
Reference in New Issue
Block a user