testing, one method doesnt seem to work
This commit is contained in:
parent
335125dc32
commit
68f76ae00b
206
src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java
Normal file
206
src/test/java/se/su/dsv/scipro/springdata/TestChecklist.java
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
package se.su.dsv.scipro.springdata;
|
||||||
|
|
||||||
|
|
||||||
|
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.CheckListAnswerDao;
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.CheckListQuestionDao;
|
||||||
|
import se.su.dsv.scipro.data.dao.interfaces.ProjectDao;
|
||||||
|
import se.su.dsv.scipro.data.dataobjects.*;
|
||||||
|
import se.su.dsv.scipro.data.enums.CheckListQuestionAnswer;
|
||||||
|
import se.su.dsv.scipro.match.facade.ApplicationPeriodFacade;
|
||||||
|
import se.su.dsv.scipro.springdata.services.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(inheritLocations = false, locations = {
|
||||||
|
"classpath:test-applicationContext.xml"
|
||||||
|
})
|
||||||
|
public class TestChecklist {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private ProjectIdeaService projectIdeaService;
|
||||||
|
@Autowired
|
||||||
|
private ProjectClassService projectClassService;
|
||||||
|
@Autowired
|
||||||
|
private RoleService roleService;
|
||||||
|
@Autowired
|
||||||
|
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||||
|
@Autowired
|
||||||
|
private MatchService matchService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProjectDao projectDao;
|
||||||
|
@Autowired
|
||||||
|
private ChecklistService checklistService;
|
||||||
|
@Autowired
|
||||||
|
private CheckListQuestionDao checkListQuestionDao;
|
||||||
|
@Autowired
|
||||||
|
private CheckListAnswerDao checkListAnswerDao;
|
||||||
|
|
||||||
|
private User employee1;
|
||||||
|
private Employee employee1Role;
|
||||||
|
private ProjectClass bachelor;
|
||||||
|
private Project project;
|
||||||
|
|
||||||
|
private List<CheckList> checkLists;
|
||||||
|
private CheckList checkList;
|
||||||
|
|
||||||
|
private List<CheckListQuestion> checkListQuestions;
|
||||||
|
private CheckListQuestion checkListQuestion;
|
||||||
|
|
||||||
|
private List<CheckListAnswer> checkListAnswers;
|
||||||
|
private CheckListAnswer checkListAnswer;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void startTransaction() throws Exception {
|
||||||
|
|
||||||
|
employee1 = new User();
|
||||||
|
employee1 = userService.save(employee1);
|
||||||
|
|
||||||
|
employee1Role = new Employee();
|
||||||
|
employee1Role.setUser(employee1);
|
||||||
|
employee1Role = (Employee) roleService.save(employee1Role);
|
||||||
|
|
||||||
|
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
|
||||||
|
bachelor = projectClassService.save(bachelor);
|
||||||
|
|
||||||
|
project = new Project();
|
||||||
|
project.setHeadSupervisor(employee1Role);
|
||||||
|
project.setTitle("project");
|
||||||
|
project.setProjectClass(bachelor);
|
||||||
|
project = projectDao.save(project);
|
||||||
|
|
||||||
|
checkListAnswers = new ArrayList<CheckListAnswer>();
|
||||||
|
checkListAnswer = new CheckListAnswer();
|
||||||
|
checkListAnswer.setAnswer(CheckListQuestionAnswer.GREEN);
|
||||||
|
checkListAnswer.setUser(employee1);
|
||||||
|
checkListAnswer = checkListAnswerDao.save(checkListAnswer);
|
||||||
|
checkListAnswers.add(checkListAnswer);
|
||||||
|
|
||||||
|
checkListQuestions = new ArrayList<CheckListQuestion>();
|
||||||
|
checkListQuestion = new CheckListQuestion();
|
||||||
|
checkListQuestion.setQuestion("question?");
|
||||||
|
checkListQuestion.setQuestionNumber(1);
|
||||||
|
checkListQuestion.setAnswers(checkListAnswers);
|
||||||
|
checkListQuestion = checkListQuestionDao.save(checkListQuestion);
|
||||||
|
checkListQuestions.add(checkListQuestion);
|
||||||
|
|
||||||
|
checkLists = new ArrayList<CheckList>();
|
||||||
|
checkList = new CheckList();
|
||||||
|
checkList.setName("checklist");
|
||||||
|
checkList.setProject(project);
|
||||||
|
checkList.setQuestions(checkListQuestions);
|
||||||
|
checkList = checklistService.save(checkList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testStuff() {
|
||||||
|
Assert.assertTrue(
|
||||||
|
checkList.getQuestions()!=null
|
||||||
|
&& !checkList.getQuestions().isEmpty()
|
||||||
|
&& checkList.getQuestions().get(0)!=null
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers() != null
|
||||||
|
&& !checkList.getQuestions().get(0).getAnswers().isEmpty()
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers().get(0) != null
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers().get(0).getAnswer() != null
|
||||||
|
&& checkList.getQuestions().get(0).getAnswers().get(0).getAnswer().equals(CheckListQuestionAnswer.GREEN)
|
||||||
|
&& checkList.getUserLastOpenDate().get(employee1) == null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we run method, the date should get updated.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testupdateUserLastOpenDate() {
|
||||||
|
/**
|
||||||
|
* Since the date is null ATM, we need to put a new date and save the checklist.
|
||||||
|
*/
|
||||||
|
Date oldDate = new Date();
|
||||||
|
checkList.getUserLastOpenDate().put(employee1, oldDate);
|
||||||
|
checkList = checklistService.save(checkList);
|
||||||
|
/**
|
||||||
|
* Then we run the method, which should update the date to a newer date.
|
||||||
|
*/
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Date newDate = checkList.getUserLastOpenDate().get(employee1);
|
||||||
|
/**
|
||||||
|
* The old date should now be before the new date.
|
||||||
|
*/
|
||||||
|
Assert.assertTrue(oldDate.before(newDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we run method with user, getUserLastOpenUpdate for user should no longer be null.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate1() {
|
||||||
|
checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1);
|
||||||
|
Assert.assertNotSame(null, checkList.getUserLastOpenDate().get(employee1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User has not yet opened the checklist with the new functionality. We have no way of knowing
|
||||||
|
* when the user last opened the checklist, so method should return false.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate2() {
|
||||||
|
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We run the update method. Since the updated date will be newer than the lastModified of
|
||||||
|
* the checklistanswer, the method should return false.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate3() {
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
@Rollback
|
||||||
|
public void testhasChangedSinceUserLastOpenDate4() {
|
||||||
|
// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1)==null); true
|
||||||
|
|
||||||
|
// Date lastModified = checkListAnswer.getLastModified();
|
||||||
|
// Assert.assertTrue(lastModified!=null); true
|
||||||
|
|
||||||
|
// checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1)!=null); true
|
||||||
|
|
||||||
|
checkList = checklistService.updateUserLastOpenDate(checkList, employee1);
|
||||||
|
Date newDate = new Date();
|
||||||
|
checkListAnswer.setLastModified(newDate);
|
||||||
|
|
||||||
|
// Assert.assertTrue(checkList.getUserLastOpenDate().get(employee1).before(newDate)); true
|
||||||
|
|
||||||
|
Assert.assertFalse(checklistService.hasChangedSinceUserLastOpenDate(checkList, employee1));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user