1 package dst.ass1.jpa.tests;
3 import static org.hamcrest.core.IsCollectionContaining.hasItems;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertThat;
6 import static org.junit.Assert.assertTrue;
8 import java.util.Collection;
10 import java.util.GregorianCalendar;
12 import javax.persistence.EntityTransaction;
14 import org.junit.Before;
15 import org.junit.Test;
17 import dst.ass1.jpa.dao.ICourseDAO;
18 import dst.ass1.jpa.model.CourseStatus;
19 import dst.ass1.jpa.model.ICourse;
21 public class Ass1_2_3b_02Test extends Ass1_TestBase {
23 private ICourseDAO dao;
26 public void setUp() throws Exception {
27 dao = daoFactory.createCourseDAO();
29 EntityTransaction tx = em.getTransaction();
31 ICourse course1 = dao.findById(testData.course1Id);
32 course1.setStatus(CourseStatus.CANCELLED);
39 public void testFindNonCancelledCoursesBetweenStartAndFinish() {
40 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(null, null);
42 assertThat(map(courses, e -> e.getId()), hasItems(
48 public void testFindEventsForStatusFinishedBetweenStartAndFinish2() {
49 Date start = createDate(2017, 1, 1, 1, 1);
50 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, null);
52 assertThat(map(courses, e -> e.getId()), hasItems(
58 public void testFindEventsForStatusFinishedBetweenStartAndFinish3() {
59 Date end = dao.findById(testData.course2Id).getEnd();
60 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(null, end);
61 assertNotNull(courses);
62 assertTrue(courses.isEmpty());
65 private Date createDate(int year, int month, int day, int hours, int minutes) {
66 return new GregorianCalendar(year, month, day, hours, minutes).getTime();