blob: 2cb54f84aa550fef75090b767aebf683d485c9e7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dao;
import static org.junit.Assert.*;
import at.ac.tuwien.sepm.assignment.groupphase.exception.PersistenceException;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Employee.EducationLevel;
import at.ac.tuwien.sepm.assignment.groupphase.missioncontrol.dto.Registration;
import at.ac.tuwien.sepm.assignment.groupphase.util.JdbcTestCase;
import java.time.Instant;
import java.time.LocalDate;
import java.util.HashSet;
import java.util.Set;
import org.dbunit.dataset.IDataSet;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class RegistrationDAOTest extends JdbcTestCase {
private RegistrationDAO registrationDAO;
public RegistrationDAOTest() throws PersistenceException {
this.registrationDAO =
new RegistrationDatabaseDAO(
getJdbcConnectionManager(),
new EmployeeDatabaseDAO(getJdbcConnectionManager()));
}
@Override
protected IDataSet getDataSet() throws Exception {
return getDataSet("registrationTestBaseData.xml");
}
@Rule public ExpectedException thrown = ExpectedException.none();
@Test
public void addRegistrationsShouldSucceed() throws PersistenceException {
Set<Registration> registrations = new HashSet<>();
Employee employee1 =
Employee.builder()
.id(1)
.name("John Doe")
.birthday(LocalDate.now()) // incorrect, but should be irrelevant
.educationLevel(EducationLevel.RS)
.isDriver(true)
.isPilot(true)
.build();
Employee employee2 =
Employee.builder()
.id(2)
.name("Nick \"Kage\" Verily")
.birthday(LocalDate.now()) // incorrect, but should be irrelevant
.educationLevel(EducationLevel.NKV)
.isDriver(true)
.isPilot(false)
.build();
Employee employee3 =
Employee.builder()
.id(3)
.name("Nicht Arzt")
.birthday(LocalDate.now()) // incorrect, but should be irrelevant
.educationLevel(EducationLevel.NA)
.isDriver(false)
.isPilot(false)
.build();
Registration registration1 =
Registration.builder()
.start(Instant.now()) // incorrect, but should be irrelevant to outcome
.end(Instant.now()) // same
.employee(employee1)
.build();
Registration registration2 =
Registration.builder()
.start(Instant.now()) // incorrect, but should be irrelevant to outcome
.end(Instant.now()) // same
.employee(employee2)
.build();
Registration registration3 =
Registration.builder()
.start(Instant.now()) // incorrect, but should be irrelevant to outcome
.end(Instant.now()) // same
.employee(employee3)
.build();
registrations.add(registration1);
registrations.add(registration2);
registrations.add(registration3);
Set<Long> returnvalues = registrationDAO.add(1, registrations);
assertFalse(returnvalues.isEmpty()); // can be improved...
}
@Test
public void addRegistrationToInexistentVehicleShouldFail() throws PersistenceException {
thrown.expect(PersistenceException.class);
Set<Registration> registrations = new HashSet<>();
Employee employee =
Employee.builder()
.id(1)
.name("John Doe")
.birthday(LocalDate.now()) // incorrect, but should be irrelevant
.educationLevel(EducationLevel.RS)
.isDriver(true)
.isPilot(true)
.build();
Registration registration =
Registration.builder()
.start(Instant.now())
.end(Instant.now())
.employee(employee)
.build();
registrations.add(registration);
registrationDAO.add(200, registrations);
}
}
|