Added a method for cleaning up old setup data before running a test.
This commit is contained in:
parent
42c3496e17
commit
554f479947
@ -54,8 +54,6 @@ public class TestApplicationPeriodDao {
|
||||
@Autowired
|
||||
private ProjectIdeaDao projectIdeaDao;
|
||||
|
||||
private ProjectClass bachelor;
|
||||
|
||||
private ApplicationPeriod applicationPeriod;
|
||||
|
||||
private ApplicationPeriod applicationPeriod2;
|
||||
@ -64,18 +62,18 @@ public class TestApplicationPeriodDao {
|
||||
|
||||
private ProjectIdea projectIdea2;
|
||||
|
||||
private ProjectIdea projectIdea3;
|
||||
|
||||
private Project project;
|
||||
|
||||
private SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
|
||||
|
||||
private ProjectClass master;
|
||||
|
||||
private ProjectIdea projectIdea3;
|
||||
private ProjectClass bachelor;
|
||||
|
||||
private ProjectClass phd;
|
||||
|
||||
private ApplicationPeriodDao target;
|
||||
|
||||
private ProjectIdea createProjectIdea(final ApplicationPeriod applicationPeriod1, final ProjectClass projectClass) {
|
||||
ProjectIdea projectIdea = new ProjectIdea();
|
||||
projectIdea.setProjectClass(projectClass);
|
||||
@ -115,16 +113,11 @@ public class TestApplicationPeriodDao {
|
||||
|
||||
Set<ProjectClass> projectClassSet = new HashSet<ProjectClass>();
|
||||
projectClassSet.add(bachelor);
|
||||
projectClassSet.add(master);
|
||||
ApplicationPeriod applicationPeriod1 = applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(projectClassSet, null, null));
|
||||
projectIdea1 = createProjectIdea(applicationPeriod1, bachelor);
|
||||
projectIdea2 = createProjectIdea(applicationPeriod1, bachelor);
|
||||
projectIdea3 = createProjectIdea(applicationPeriod1, bachelor);
|
||||
projectClassSet.clear();
|
||||
projectClassSet.add(bachelor);
|
||||
applicationPeriod = applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(projectClassSet, date("2011-06-14"), date("2011-07-01")));
|
||||
applicationPeriod2 =applicationPeriodDao.save( ApplicationPeriodFacade.createApplicationPeriod(projectClassSet, date("2011-07-15"), date("2011-08-01")));
|
||||
target = applicationPeriodDao;
|
||||
projectIdea1 = createProjectIdea(applicationPeriod, bachelor);
|
||||
projectIdea2 = createProjectIdea(applicationPeriod, bachelor);
|
||||
projectIdea3 = createProjectIdea(applicationPeriod, bachelor);
|
||||
}
|
||||
|
||||
private Date date(String dateString) {
|
||||
@ -141,7 +134,7 @@ public class TestApplicationPeriodDao {
|
||||
public void testShouldReturnAllProjectIdeasForApplicationPeriod() {
|
||||
projectIdea1.setDateCreated(date("2011-07-02"));
|
||||
projectIdea2.setDateCreated(date("2011-06-12"));
|
||||
List<ProjectIdea> projectIdeas = target.getProjectIdeas(applicationPeriod);
|
||||
List<ProjectIdea> projectIdeas = applicationPeriodDao.getProjectIdeas(applicationPeriod);
|
||||
Assert.assertEquals(Arrays.asList(new ProjectIdea[] { projectIdea2 }), projectIdeas);
|
||||
}
|
||||
|
||||
@ -155,7 +148,7 @@ public class TestApplicationPeriodDao {
|
||||
projectIdea3.setDateCreated(date("2011-06-12"));
|
||||
projectIdea3.setProjectClass(phd);
|
||||
applicationPeriod.getProjectClass().add(phd);
|
||||
List<ProjectIdea> projectIdeas = target.getProjectIdeas(applicationPeriod);
|
||||
List<ProjectIdea> projectIdeas = applicationPeriodDao.getProjectIdeas(applicationPeriod);
|
||||
Assert.assertEquals(Arrays.asList(new ProjectIdea[] { projectIdea1, projectIdea3 }), projectIdeas);
|
||||
}
|
||||
|
||||
@ -166,7 +159,7 @@ public class TestApplicationPeriodDao {
|
||||
projectIdea1.setDateCreated(date("2011-07-01"));
|
||||
projectIdea1.setProject(project);
|
||||
projectIdea2.setDateCreated(date("2011-07-01"));
|
||||
List<ProjectIdea> projectIdeas = target.getProjectIdeas(applicationPeriod);
|
||||
List<ProjectIdea> projectIdeas = applicationPeriodDao.getProjectIdeas(applicationPeriod);
|
||||
Assert.assertEquals(Arrays.asList(new ProjectIdea[] { projectIdea2 }), projectIdeas);
|
||||
}
|
||||
|
||||
@ -175,7 +168,7 @@ public class TestApplicationPeriodDao {
|
||||
@Rollback
|
||||
public void testShouldOnlyReturnCurrentPeriods() {
|
||||
Date currentTime = date("2011-07-20");
|
||||
List<ApplicationPeriod> periods = target.getCurrentPeriods(currentTime);
|
||||
List<ApplicationPeriod> periods = applicationPeriodDao.getCurrentPeriods(currentTime);
|
||||
Assert.assertEquals(Arrays.asList(new ApplicationPeriod[] { applicationPeriod2 }), periods);
|
||||
}
|
||||
|
||||
@ -184,16 +177,25 @@ public class TestApplicationPeriodDao {
|
||||
@Rollback
|
||||
public void testShouldReturnNextPeriod() {
|
||||
Date currentTime = date("2011-07-02");
|
||||
ApplicationPeriod ap = target.getNextPeriodByClass(bachelor, currentTime);
|
||||
ApplicationPeriod ap = applicationPeriodDao.getNextPeriodByClass(bachelor, currentTime);
|
||||
Assert.assertEquals(applicationPeriod2, ap);
|
||||
}
|
||||
|
||||
private void cleanUpDatabase() {
|
||||
projectIdeaDao.delete(projectIdea1);
|
||||
projectIdeaDao.delete(projectIdea2);
|
||||
projectIdeaDao.delete(projectIdea3);
|
||||
applicationPeriodDao.delete(applicationPeriod);
|
||||
applicationPeriodDao.delete(applicationPeriod2);
|
||||
}
|
||||
|
||||
/* create an application period with the start date before the date of TODAY but the end date is irrelevant, then it should NOT be possible to remove the application period, */
|
||||
/* create an application period with the start date before TODAY
|
||||
but the end date is irrelevant, it should NOT be possible to remove the application period, */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void notAbleToRemovePeriod() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@ -207,17 +209,19 @@ public class TestApplicationPeriodDao {
|
||||
}
|
||||
|
||||
|
||||
/* create an application period with the both the start-date and the end-date after the date of "TODAY", then it should be possible to remove the period */
|
||||
/* create an application period with the the start-date after TODAY,
|
||||
it should be possible to remove the period */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void canRemovePeriod() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.MONTH, 2);
|
||||
cal.add(Calendar.DAY_OF_WEEK, 1);
|
||||
final Date startDate1 = cal.getTime();
|
||||
cal.add(Calendar.MONTH, 3);
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
final Date endDate1 = cal.getTime();
|
||||
ApplicationPeriod applicationPeriod = applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(myBachelorSet, startDate1, endDate1));
|
||||
boolean periodRemoved = applicationPeriodFacade.removeApplicationPeriod(applicationPeriod);
|
||||
@ -225,58 +229,42 @@ public class TestApplicationPeriodDao {
|
||||
}
|
||||
|
||||
|
||||
/* 1. create an application period from TODAY and one month forward, the PROJECT CLASSES are THE SAME,
|
||||
2. test if there exists any OPEN application period for the project class */
|
||||
/* create a "bachelor" application period from TODAY and a month forward,,
|
||||
there should exist an OPEN "bachelor"application period */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void applicationPeriodExists() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
final Date startDate1 = cal.getTime();
|
||||
cal.set(2012, Calendar.APRIL, 2);
|
||||
cal.add(Calendar.MONTH, 1);
|
||||
final Date endDate1 = cal.getTime();
|
||||
applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(myBachelorSet, startDate1, endDate1));
|
||||
boolean exists = applicationPeriodFacade.openApplicationPeriodsExists(bachelor);
|
||||
Assert.assertTrue(exists); // should exist
|
||||
}
|
||||
|
||||
/* 1. create an application period from TODAY and one month forward, the PROJECT CLASSES are DIFFERENT
|
||||
2. test if there exists any OPEN application period for the project class */
|
||||
/* create a "master" application period from TODAY and two months forward,
|
||||
there should NOT exist any OPEN "bachelor" application period */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void missingApplicationPeriod_1() {
|
||||
/* Set<ProjectClass> myMasterSet = new HashSet<ProjectClass>();
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myMasterSet = new HashSet<ProjectClass>();
|
||||
myMasterSet.add(master);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
final Date startDate1 = cal.getTime();
|
||||
cal.set(2012, Calendar.APRIL, 2);
|
||||
cal.add(Calendar.MONTH, 2);
|
||||
final Date endDate1 = cal.getTime();
|
||||
applicationPeriodDao.save(createApplicationPeriod(myMasterSet, startDate1, endDate1));
|
||||
applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(myMasterSet, startDate1, endDate1));
|
||||
boolean exists = applicationPeriodFacade.openApplicationPeriodsExists(bachelor);
|
||||
Assert.assertFalse(exists); // should NOT exist*/
|
||||
Assert.assertFalse(exists); // should NOT exist
|
||||
}
|
||||
|
||||
/* 1. create an application period from ONE DAY AFTER TODAY and one month forward, the PROJECT CLASSES are SAME
|
||||
2. test if there exists any OPEN application period for the project class */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void missingApplicationPeriod_2() {
|
||||
/* Set<ProjectClass> myMasterSet = new HashSet<ProjectClass>();
|
||||
myMasterSet.add(master);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
final Date startDate1 = cal.getTime();
|
||||
cal.set(2012, Calendar.APRIL, 2);
|
||||
final Date endDate1 = cal.getTime();
|
||||
applicationPeriodDao.save(createApplicationPeriod(myMasterSet, startDate1, endDate1));
|
||||
boolean exists = applicationPeriodFacade.openApplicationPeriodsExists(bachelor);
|
||||
Assert.assertFalse(exists); // should NOT exist*/
|
||||
}
|
||||
|
||||
/* the same project classes, the same date, the first period: 10.00 - 11.59,
|
||||
the second period: 12.00 - 13.59,
|
||||
should NOT overlap. */
|
||||
@ -296,6 +284,7 @@ should NOT overlap. */
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void notOverlappingBasedOnDatePeriods() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@ -313,37 +302,38 @@ should NOT overlap. */
|
||||
Assert.assertFalse(periodOverlap); // should NOT overlap
|
||||
}
|
||||
|
||||
/* the same project classes, first create an application period and save it,
|
||||
then try to edit the new period, it should NOT overlap even if the start or end date and/or project class are the same */
|
||||
/* Test for checking if it possible to edit an application period: first create bachelor-application period and save it,
|
||||
then try to edit the new period by adding a "master" class and changing end date,
|
||||
it should NOT overlap (itself) even if the start or end date and/or project class are the same */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void notOverlappingWhenUpdating() {
|
||||
/* Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
public void notOverlappingWhenEditing() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2012, Calendar.MARCH, 2);
|
||||
final Date startDate1 = cal.getTime();
|
||||
|
||||
cal.set(2012, Calendar.APRIL, 2);
|
||||
final Date endDate1 = cal.getTime();
|
||||
|
||||
ApplicationPeriod applicationPeriod1 = applicationPeriodDao.save(createApplicationPeriod(myBachelorSet, startDate1, endDate1));
|
||||
ApplicationPeriod applicationPeriod1 = applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(myBachelorSet, startDate1, endDate1));
|
||||
// edit the period
|
||||
applicationPeriod1.getProjectClass().add(master);
|
||||
cal.set(2012, Calendar.MAY, 2);
|
||||
final Date changedEndDate = cal.getTime();
|
||||
applicationPeriod1.setEndDate(changedEndDate);
|
||||
boolean periodOverlap = applicationPeriodFacade.doesPeriodOverlap(applicationPeriod1);
|
||||
Assert.assertFalse(periodOverlap); // should NOT overlap*/
|
||||
Assert.assertFalse(periodOverlap); // should NOT overlap
|
||||
}
|
||||
|
||||
/* same time periods, with different project classes, should NOT overlap */
|
||||
/*same time periods, with different project classes, should NOT overlap */
|
||||
@Test
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void notOverlappingDifferentProjectClasses() {
|
||||
/*Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(2012, Calendar.MARCH, 2);
|
||||
@ -353,11 +343,11 @@ should NOT overlap. */
|
||||
final Date endDate = cal.getTime();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 14);
|
||||
final Date endDate2 = cal.getTime();
|
||||
applicationPeriodDao.save(createApplicationPeriod(myBachelorSet, startDate, endDate));
|
||||
applicationPeriodDao.save(ApplicationPeriodFacade.createApplicationPeriod(myBachelorSet, startDate, endDate));
|
||||
Set<ProjectClass> myMasterSet = new HashSet<ProjectClass>();
|
||||
myMasterSet.add(master);
|
||||
boolean periodOverlap = applicationPeriodFacade.doesPeriodOverlap(createApplicationPeriod(myMasterSet, startDate, endDate2));
|
||||
Assert.assertFalse(periodOverlap); // should NOT overlap*/
|
||||
boolean periodOverlap = applicationPeriodFacade.doesPeriodOverlap(ApplicationPeriodFacade.createApplicationPeriod(myMasterSet, startDate, endDate2));
|
||||
Assert.assertFalse(periodOverlap); // should NOT overlap
|
||||
}
|
||||
|
||||
|
||||
@ -366,6 +356,7 @@ should NOT overlap. */
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void overlappingPeriods() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@ -387,6 +378,7 @@ should NOT overlap. */
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void overlappingSameProjectClasses() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
@ -406,6 +398,7 @@ should NOT overlap. */
|
||||
@Transactional
|
||||
@Rollback
|
||||
public void overlappingMultipleProjectClasses() {
|
||||
cleanUpDatabase();
|
||||
Set<ProjectClass> myBachelorSet = new HashSet<ProjectClass>();
|
||||
myBachelorSet.add(bachelor);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
Loading…
x
Reference in New Issue
Block a user