]> git.somenet.org - pub/jan/dst18.git/blob - ass1-jpa/src/test/java/dst/ass1/jpa/tests/Ass1_2_3b_01Test.java
Add template for assignment 1
[pub/jan/dst18.git] / ass1-jpa / src / test / java / dst / ass1 / jpa / tests / Ass1_2_3b_01Test.java
1 package dst.ass1.jpa.tests;
2
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;
7
8 import java.util.Collection;
9 import java.util.Date;
10 import java.util.GregorianCalendar;
11
12 import org.junit.Before;
13 import org.junit.Test;
14
15 import dst.ass1.jpa.dao.ICourseDAO;
16 import dst.ass1.jpa.model.ICourse;
17
18 public class Ass1_2_3b_01Test extends Ass1_TestBase {
19
20     private ICourseDAO dao;
21
22     @Before
23     public void setUp() throws Exception {
24         dao = daoFactory.createCourseDAO();
25     }
26
27     @Test
28     public void testFindNonCancelledCoursesBetweenStartAndFinish() {
29         Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(null, null);
30
31         assertThat(map(courses, e -> e.getId()), hasItems(
32                 testData.course1Id,
33                 testData.course2Id
34         ));
35     }
36
37     @Test
38     public void testFindEventsForStatusFinishedBetweenStartAndFinish2() {
39         Date start = createDate(2017, 1, 1, 1, 1);
40         Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, null);
41         Collection<Long> courseIds = map(courses, ICourse::getId);
42         assertThat(courseIds, hasItems(testData.course1Id, testData.course2Id));
43
44         assertThat(map(courses, e -> e.getId()), hasItems(
45                 testData.course1Id,
46                 testData.course2Id
47         ));
48     }
49
50     @Test
51     public void testFindEventsForStatusFinishedBetweenStartAndFinish3() {
52         Date start = dao.findById(testData.course1Id).getStart();
53         Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, null);
54
55         assertThat(map(courses, e -> e.getId()), hasItems(
56                 testData.course2Id
57         ));
58     }
59
60     @Test
61     public void testFindEventsForStatusFinishedBetweenStartAndFinish4() {
62         Date end = dao.findById(testData.course2Id).getEnd();
63         Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(null, end);
64
65         assertThat(map(courses, e -> e.getId()), hasItems(
66                 testData.course1Id
67         ));
68     }
69
70     @Test
71     public void testFindEventsForStatusFinishedBetweenStartAndFinish5() {
72         Date start = dao.findById(testData.course1Id).getEnd();
73         Date end = dao.findById(testData.course2Id).getEnd();
74         Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, end);
75
76         assertNotNull(courses);
77         assertTrue(courses.isEmpty());
78     }
79
80     private Date createDate(int year, int month, int day, int hours, int minutes) {
81         return new GregorianCalendar(year, month, day, hours, minutes).getTime();
82     }
83
84 }