Revize 6b5f795f
Přidáno uživatelem Jakub Danek před více než 5 roky(ů)
server/src/main/java/org/danekja/ymanager/domain/RegisteredUser.java | ||
---|---|---|
48 | 48 |
public RegisteredUser() { |
49 | 49 |
} |
50 | 50 |
|
51 |
public RegisteredUser(Long id, String firstName, String lastName, Float vacationCount, Integer totalSickDayCount, Integer takenSickDayCount, LocalDateTime notification, String token, String email, String photo, LocalDateTime creationDate, UserRole role, Status status) {
|
|
52 |
super(id, vacationCount, totalSickDayCount, takenSickDayCount, notification, token, role, status);
|
|
51 |
public RegisteredUser(Long id, String firstName, String lastName, String email, String photo, LocalDateTime creationDate, UserData userData) {
|
|
52 |
super(id, userData);
|
|
53 | 53 |
this.id = id; |
54 | 54 |
this.firstName = firstName; |
55 | 55 |
this.lastName = lastName; |
56 | 56 |
this.email = email; |
57 | 57 |
this.photo = photo; |
58 | 58 |
this.creationDate = creationDate; |
59 |
this.role = role; |
|
60 |
this.status = status; |
|
61 | 59 |
} |
62 | 60 |
|
63 | 61 |
/* |
... | ... | |
66 | 64 |
@Override |
67 | 65 |
public Collection<? extends GrantedAuthority> getAuthorities() { |
68 | 66 |
//TODO do not create collection on each call |
69 |
return Collections.singleton(new SimpleGrantedAuthority(role.name()));
|
|
67 |
return Collections.singleton(new SimpleGrantedAuthority(userData.getRole().name()));
|
|
70 | 68 |
} |
71 | 69 |
|
72 | 70 |
@Override |
... | ... | |
99 | 97 |
|
100 | 98 |
@Override |
101 | 99 |
public boolean isEnabled() { |
102 |
return status == Status.ACCEPTED;
|
|
100 |
return userData.getStatus() == Status.ACCEPTED;
|
|
103 | 101 |
} |
104 | 102 |
|
105 | 103 |
/* |
... | ... | |
126 | 124 |
return photo; |
127 | 125 |
} |
128 | 126 |
|
129 |
@Override |
|
130 | 127 |
public LocalDateTime getCreationDate() { |
131 | 128 |
return creationDate; |
132 | 129 |
} |
server/src/main/java/org/danekja/ymanager/domain/User.java | ||
---|---|---|
24 | 24 |
*/ |
25 | 25 |
protected static final Logger log = LoggerFactory.getLogger(User.class); |
26 | 26 |
|
27 |
protected final UserData userData; |
|
28 |
|
|
27 | 29 |
/** |
28 | 30 |
* The user's ID. |
29 | 31 |
*/ |
30 | 32 |
protected Long id; |
31 | 33 |
|
32 |
/** |
|
33 |
* The number of user's remaining hours of an overtime. |
|
34 |
*/ |
|
35 |
protected Float vacationCount; |
|
36 |
|
|
37 |
/** |
|
38 |
* The number of user's sick days available during a year. |
|
39 |
*/ |
|
40 |
protected Integer totalSickDayCount; |
|
41 |
|
|
42 |
/** |
|
43 |
* The number of user's taken sick days. |
|
44 |
*/ |
|
45 |
protected Integer takenSickDayCount; |
|
46 |
|
|
47 |
/** |
|
48 |
* The date and time of sending an email warning about an incoming reset of remaining overtimes and sick days. |
|
49 |
*/ |
|
50 |
protected LocalDateTime notification; |
|
51 |
|
|
52 |
/** |
|
53 |
* The token for the Google oAuth. |
|
54 |
*/ |
|
55 |
protected String token; |
|
56 |
|
|
57 |
/** |
|
58 |
* The user's role. |
|
59 |
*/ |
|
60 |
protected UserRole role; |
|
61 |
|
|
62 |
/** |
|
63 |
* The user's authorization status. |
|
64 |
*/ |
|
65 |
protected Status status; |
|
66 |
|
|
67 |
public User() { |
|
34 |
protected User() { |
|
35 |
this.userData = new UserData(); |
|
68 | 36 |
} |
69 | 37 |
|
70 |
public User(Long id, Float vacationCount, Integer totalSickDayCount, Integer takenSickDayCount, LocalDateTime notification, String token, UserRole role, Status status) {
|
|
38 |
protected User(Long id, UserData userData) {
|
|
71 | 39 |
this.id = id; |
72 |
this.vacationCount = vacationCount; |
|
73 |
this.totalSickDayCount = totalSickDayCount; |
|
74 |
this.takenSickDayCount = takenSickDayCount; |
|
75 |
this.notification = notification; |
|
76 |
this.token = token; |
|
77 |
this.role = role; |
|
78 |
this.status = status; |
|
40 |
this.userData = userData; |
|
79 | 41 |
} |
80 | 42 |
|
81 | 43 |
/** |
... | ... | |
118 | 80 |
* @return the number of user's remaining hours of the overtime |
119 | 81 |
*/ |
120 | 82 |
public Float getVacationCount() { |
121 |
return this.vacationCount;
|
|
83 |
return userData.getVacationCount();
|
|
122 | 84 |
} |
123 | 85 |
|
124 | 86 |
/** |
... | ... | |
129 | 91 |
* @throws IllegalArgumentException when the given value is negative |
130 | 92 |
*/ |
131 | 93 |
public void setVacationCount(final Float vacationCount) throws IllegalArgumentException { |
132 |
User.log.debug("Setting a new number of remaining overtime: {}", vacationCount); |
|
133 |
|
|
134 |
if(vacationCount == null) { |
|
135 |
User.log.warn("The number of remaining overtime must not be null"); |
|
136 |
throw new IllegalArgumentException("vacation.null.error"); |
|
137 |
}else if (vacationCount < 0) { |
|
138 |
User.log.warn("The number of remaining overtime must not be negative"); |
|
139 |
throw new IllegalArgumentException("negative.vacation.error"); |
|
140 |
} |
|
141 | 94 |
|
142 |
this.vacationCount = vacationCount;
|
|
95 |
userData.setVacationCount(vacationCount);
|
|
143 | 96 |
} |
144 | 97 |
|
145 | 98 |
/** |
... | ... | |
150 | 103 |
* @throws IllegalArgumentException when he given parameter is null or a result of the addition is negative |
151 | 104 |
*/ |
152 | 105 |
public void addVacationCount(final Float value) { |
153 |
User.log.debug("Adding the given number of hours {} to the vacation", value); |
|
154 |
|
|
155 |
if(value == null) { |
|
156 |
User.log.warn("The given value must not be null"); |
|
157 |
throw new IllegalArgumentException("vacation.null.error"); |
|
158 |
} else if (this.vacationCount + value < 0) { |
|
159 |
User.log.warn("The number of remaining overtime must not be negative"); |
|
160 |
throw new IllegalArgumentException("negative.vacation.error"); |
|
161 |
} |
|
162 | 106 |
|
163 |
this.vacationCount += value;
|
|
107 |
userData.addVacationCount(value);
|
|
164 | 108 |
} |
165 | 109 |
|
166 | 110 |
/** |
... | ... | |
174 | 118 |
* or the times are not in order |
175 | 119 |
*/ |
176 | 120 |
public void addVacationCount(final LocalTime from, final LocalTime to) { |
177 |
User.log.debug("Adding a vacation from {} to {}", from, to); |
|
178 |
|
|
179 |
if(from == null || to == null) { |
|
180 |
User.log.warn("A vacation has to have a starting and an ending time"); |
|
181 |
throw new IllegalArgumentException("time.vacation.error"); |
|
182 |
} else if (from.compareTo(to) >= 0) { |
|
183 |
User.log.warn("A vacation must not start after it ends. from={}, to={}", from, to); |
|
184 |
throw new IllegalArgumentException("time.order.error"); |
|
185 |
} |
|
186 | 121 |
|
187 |
final float difference = from.until(to, MINUTES) / 60f; |
|
188 |
this.vacationCount += difference; |
|
122 |
userData.addVacationCount(from, to); |
|
189 | 123 |
} |
190 | 124 |
|
191 | 125 |
/** |
... | ... | |
194 | 128 |
* @return the number of user's sick days available during the year |
195 | 129 |
*/ |
196 | 130 |
public Integer getTotalSickDayCount() { |
197 |
return this.totalSickDayCount;
|
|
131 |
return userData.getTotalSickDayCount();
|
|
198 | 132 |
} |
199 | 133 |
|
200 | 134 |
/** |
... | ... | |
205 | 139 |
* @throws IllegalArgumentException when the given value is negative |
206 | 140 |
*/ |
207 | 141 |
public void setTotalSickDayCount(final Integer totalSickDayCount) throws IllegalArgumentException { |
208 |
User.log.debug("Setting a new number of user's sick days available during a year: {}", totalSickDayCount); |
|
209 |
|
|
210 |
if (totalSickDayCount != null && totalSickDayCount < 0) { |
|
211 |
User.log.warn("The number of user's available sick days must not be negative"); |
|
212 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
213 |
} |
|
214 | 142 |
|
215 |
this.totalSickDayCount = totalSickDayCount;
|
|
143 |
userData.setTotalSickDayCount(totalSickDayCount);
|
|
216 | 144 |
} |
217 | 145 |
|
218 | 146 |
/** |
... | ... | |
221 | 149 |
* @return the number of user's taken sick days |
222 | 150 |
*/ |
223 | 151 |
public Integer getTakenSickDayCount() { |
224 |
return this.takenSickDayCount;
|
|
152 |
return userData.getTakenSickDayCount();
|
|
225 | 153 |
} |
226 | 154 |
|
227 | 155 |
/** |
... | ... | |
232 | 160 |
* @throws IllegalArgumentException when the given value is negative |
233 | 161 |
*/ |
234 | 162 |
public void setTakenSickDayCount(final Integer takenSickDayCount) throws IllegalArgumentException { |
235 |
User.log.debug("Setting a new number of user's taken sick days: {}", takenSickDayCount); |
|
236 |
|
|
237 |
if (takenSickDayCount == null) { |
|
238 |
User.log.warn("The number number of user's taken sick days must not be null"); |
|
239 |
throw new IllegalArgumentException("sick.day.null.error"); |
|
240 |
} else if (takenSickDayCount < 0) { |
|
241 |
User.log.warn("The number number of user's taken sick days must not be negative"); |
|
242 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
243 |
} else if(takenSickDayCount > this.totalSickDayCount){ |
|
244 |
User.log.warn("The number number of user's taken sick days must not greater than his/her available sick days"); |
|
245 |
throw new IllegalArgumentException("taken.sick.day.count.error"); |
|
246 |
} |
|
247 | 163 |
|
248 |
this.takenSickDayCount = takenSickDayCount;
|
|
164 |
userData.setTakenSickDayCount(takenSickDayCount);
|
|
249 | 165 |
} |
250 | 166 |
|
251 | 167 |
/** |
... | ... | |
256 | 172 |
* @throws IllegalArgumentException when the given number is null or a result of the addition is negative |
257 | 173 |
*/ |
258 | 174 |
public void addTakenSickDayCount(final Integer value) throws IllegalArgumentException { |
259 |
User.log.debug("Increasing the number of remaining overtime by {}", value); |
|
260 |
|
|
261 |
if (value == null) { |
|
262 |
User.log.warn("The given value must not be null"); |
|
263 |
throw new IllegalArgumentException("vacation.null.error"); |
|
264 |
} else if (this.takenSickDayCount + value < 0) { |
|
265 |
User.log.warn("The number number of user's taken sick days must not be negative"); |
|
266 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
267 |
} else if (this.takenSickDayCount + value > this.totalSickDayCount) { |
|
268 |
User.log.warn("The number number of user's taken sick days must not greater than his/her available sick days"); |
|
269 |
throw new IllegalArgumentException("taken.sick.day.count.error"); |
|
270 |
} |
|
271 | 175 |
|
272 |
this.takenSickDayCount += value;
|
|
176 |
userData.addTakenSickDayCount(value);
|
|
273 | 177 |
} |
274 | 178 |
|
275 | 179 |
/** |
... | ... | |
278 | 182 |
* @return the date and time |
279 | 183 |
*/ |
280 | 184 |
public LocalDateTime getNotification() { |
281 |
return this.notification;
|
|
185 |
return userData.getNotification();
|
|
282 | 186 |
} |
283 | 187 |
|
284 | 188 |
/** |
... | ... | |
289 | 193 |
* @throws IllegalArgumentException when the given notification is null |
290 | 194 |
*/ |
291 | 195 |
public void setNotification(final LocalDateTime notification) throws IllegalArgumentException { |
292 |
User.log.debug("Setting a new date and time of sending an email warning: {}", notification); |
|
293 |
|
|
294 |
this.notification = notification; |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Returns the user's token for the Google oAuth. |
|
299 |
* |
|
300 |
* @return the user's token for the Google oAuth |
|
301 |
*/ |
|
302 |
public String getToken() { |
|
303 |
return this.token; |
|
304 |
} |
|
305 |
|
|
306 |
/** |
|
307 |
* Replaces the user's token for the Google oAuth with the specified string. |
|
308 |
* |
|
309 |
* @param token the new token for the Google oAuth |
|
310 |
*/ |
|
311 |
public void setToken(final String token) { |
|
312 |
User.log.debug("Setting a new token: {}", token); |
|
313 | 196 |
|
314 |
if (token == null) { |
|
315 |
User.log.warn("The given token must not be null"); |
|
316 |
throw new IllegalArgumentException("token.null.error"); |
|
317 |
} |
|
318 |
|
|
319 |
this.token = token; |
|
197 |
userData.setNotification(notification); |
|
320 | 198 |
} |
321 | 199 |
|
322 | 200 |
/** |
... | ... | |
335 | 213 |
return DEFAULT_PHOTO; |
336 | 214 |
} |
337 | 215 |
|
338 |
; |
|
339 |
|
|
340 |
|
|
341 |
/** |
|
342 |
* Returns the date and time of a user's creation. |
|
343 |
* |
|
344 |
* @return the date and time of the user's creation |
|
345 |
*/ |
|
346 |
public abstract LocalDateTime getCreationDate(); |
|
347 |
|
|
348 | 216 |
/** |
349 | 217 |
* Returns the user's role. |
350 | 218 |
* |
351 | 219 |
* @return the user's role |
352 | 220 |
*/ |
353 | 221 |
public UserRole getRole() { |
354 |
return this.role;
|
|
222 |
return userData.getRole();
|
|
355 | 223 |
} |
356 | 224 |
|
357 | 225 |
/** |
... | ... | |
362 | 230 |
* @throws IllegalArgumentException when the given role is null |
363 | 231 |
*/ |
364 | 232 |
public void setRole(final UserRole role) throws IllegalArgumentException { |
365 |
User.log.debug("Setting a new user's role: {}", role); |
|
366 |
|
|
367 |
if(role == null) { |
|
368 |
User.log.warn("The given role must not be null"); |
|
369 |
throw new IllegalArgumentException("role.null.error"); |
|
370 |
} |
|
371 |
|
|
372 |
this.role = role; |
|
233 |
userData.setRole(role); |
|
373 | 234 |
} |
374 | 235 |
|
375 | 236 |
/** |
... | ... | |
378 | 239 |
* @return the user's authorization status |
379 | 240 |
*/ |
380 | 241 |
public Status getStatus() { |
381 |
return this.status;
|
|
242 |
return userData.getStatus();
|
|
382 | 243 |
} |
383 | 244 |
|
384 | 245 |
/** |
... | ... | |
387 | 248 |
* @param status the new authorization status |
388 | 249 |
*/ |
389 | 250 |
public void setStatus(final Status status) { |
390 |
User.log.debug("Setting a new authorization status: {}", status); |
|
391 |
|
|
392 |
if(status == null) { |
|
393 |
User.log.warn("The given status must not be null"); |
|
394 |
throw new IllegalArgumentException("status.null.error"); |
|
395 |
} |
|
396 |
|
|
397 |
this.status = status; |
|
251 |
this.userData.setStatus(status); |
|
398 | 252 |
} |
399 | 253 |
|
400 | 254 |
/** |
... | ... | |
419 | 273 |
} |
420 | 274 |
|
421 | 275 |
final float difference = from.until(to, MINUTES) / 60f; |
422 |
final float tempVacationCount = this.vacationCount - difference;
|
|
276 |
final float tempVacationCount = this.userData.getVacationCount() - difference;
|
|
423 | 277 |
|
424 | 278 |
if (tempVacationCount < 0) { |
425 | 279 |
User.log.warn("Cannot take a vacation, not enough available hours"); |
426 | 280 |
throw new IllegalArgumentException("available.vacation.error"); |
427 | 281 |
} |
428 | 282 |
|
429 |
this.vacationCount = tempVacationCount;
|
|
283 |
this.userData.setVacationCount(tempVacationCount);
|
|
430 | 284 |
} |
431 | 285 |
|
432 | 286 |
/** |
... | ... | |
437 | 291 |
*/ |
438 | 292 |
public void takeSickDay() throws IllegalArgumentException { |
439 | 293 |
User.log.trace("Taking a sick day"); |
440 |
final int tempTakenSickDayCount = ++this.takenSickDayCount; |
|
441 |
|
|
442 |
if (tempTakenSickDayCount > this.totalSickDayCount) { |
|
443 |
User.log.warn("Cannot take a sick day, not enough available days"); |
|
444 |
throw new IllegalArgumentException("available.sick.day.error"); |
|
445 |
} |
|
446 | 294 |
|
447 |
this.takenSickDayCount = tempTakenSickDayCount;
|
|
295 |
this.userData.addTakenSickDayCount(1);
|
|
448 | 296 |
} |
449 | 297 |
|
450 | 298 |
/** |
... | ... | |
460 | 308 |
public String toString() { |
461 | 309 |
return "User{" + |
462 | 310 |
"id=" + id + |
463 |
", vacationCount=" + vacationCount + |
|
464 |
", totalSickDayCount=" + totalSickDayCount + |
|
465 |
", takenSickDayCount=" + takenSickDayCount + |
|
466 |
", notification=" + notification + |
|
467 |
", token='" + token + '\'' + |
|
468 |
", role=" + role + |
|
469 |
", status=" + status + |
|
311 |
", " + this.userData.toString() + |
|
470 | 312 |
'}'; |
471 | 313 |
} |
472 | 314 |
} |
server/src/main/java/org/danekja/ymanager/domain/UserData.java | ||
---|---|---|
1 |
package org.danekja.ymanager.domain; |
|
2 |
|
|
3 |
import java.time.LocalDateTime; |
|
4 |
import java.time.LocalTime; |
|
5 |
import java.time.temporal.ChronoUnit; |
|
6 |
|
|
7 |
public class UserData { |
|
8 |
/** |
|
9 |
* The number of user's remaining hours of an overtime. |
|
10 |
*/ |
|
11 |
private Float vacationCount; |
|
12 |
/** |
|
13 |
* The number of user's sick days available during a year. |
|
14 |
*/ |
|
15 |
private Integer totalSickDayCount; |
|
16 |
/** |
|
17 |
* The number of user's taken sick days. |
|
18 |
*/ |
|
19 |
private Integer takenSickDayCount; |
|
20 |
/** |
|
21 |
* The date and time of sending an email warning about an incoming reset of remaining overtimes and sick days. |
|
22 |
*/ |
|
23 |
private LocalDateTime notification; |
|
24 |
/** |
|
25 |
* The user's role. |
|
26 |
*/ |
|
27 |
private UserRole role; |
|
28 |
/** |
|
29 |
* The user's authorization status. |
|
30 |
*/ |
|
31 |
private Status status; |
|
32 |
|
|
33 |
public UserData() { |
|
34 |
} |
|
35 |
|
|
36 |
public UserData(Float vacationCount, Integer totalSickDayCount, Integer takenSickDayCount, LocalDateTime notification, UserRole role, Status status) { |
|
37 |
this.vacationCount = vacationCount; |
|
38 |
this.totalSickDayCount = totalSickDayCount; |
|
39 |
this.takenSickDayCount = takenSickDayCount; |
|
40 |
this.notification = notification; |
|
41 |
this.role = role; |
|
42 |
this.status = status; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Returns the number of user's remaining hours of an overtime. |
|
47 |
* |
|
48 |
* @return the number of user's remaining hours of the overtime |
|
49 |
*/ |
|
50 |
public Float getVacationCount() { |
|
51 |
return this.vacationCount; |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* Replaces the number of user's remaining hours of an overtime with the specified value. |
|
56 |
* If the given number is negative or null the method throws an exception. |
|
57 |
* |
|
58 |
* @param vacationCount the new number of remaining hours of the overtime. |
|
59 |
* @throws IllegalArgumentException when the given value is negative |
|
60 |
*/ |
|
61 |
public void setVacationCount(final Float vacationCount) throws IllegalArgumentException { |
|
62 |
User.log.debug("Setting a new number of remaining overtime: {}", vacationCount); |
|
63 |
|
|
64 |
if (vacationCount == null) { |
|
65 |
User.log.warn("The number of remaining overtime must not be null"); |
|
66 |
throw new IllegalArgumentException("vacation.null.error"); |
|
67 |
} else if (vacationCount < 0) { |
|
68 |
User.log.warn("The number of remaining overtime must not be negative"); |
|
69 |
throw new IllegalArgumentException("negative.vacation.error"); |
|
70 |
} |
|
71 |
|
|
72 |
this.vacationCount = vacationCount; |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Adds the given amount to the number of user's available vacations. If the given parameter is null |
|
77 |
* or a result of the addition is negative the method throws an exception. |
|
78 |
* |
|
79 |
* @param value the given amount that is going to be added |
|
80 |
* @throws IllegalArgumentException when he given parameter is null or a result of the addition is negative |
|
81 |
*/ |
|
82 |
public void addVacationCount(final Float value) { |
|
83 |
User.log.debug("Adding the given number of hours {} to the vacation", value); |
|
84 |
|
|
85 |
if (value == null) { |
|
86 |
User.log.warn("The given value must not be null"); |
|
87 |
throw new IllegalArgumentException("vacation.null.error"); |
|
88 |
} else if (this.vacationCount + value < 0) { |
|
89 |
User.log.warn("The number of remaining overtime must not be negative"); |
|
90 |
throw new IllegalArgumentException("negative.vacation.error"); |
|
91 |
} |
|
92 |
|
|
93 |
this.vacationCount += value; |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* Adds a difference of the given starting and the ending time of a vacation |
|
98 |
* to the number of user's available vacations. If some of the given parameters are null |
|
99 |
* or the times are not in order the method throws an exception. |
|
100 |
* |
|
101 |
* @param from the starting time of a vacation |
|
102 |
* @param to the ending time of a vacation |
|
103 |
* @throws IllegalArgumentException when some of the given parameters are null |
|
104 |
* or the times are not in order |
|
105 |
*/ |
|
106 |
public void addVacationCount(final LocalTime from, final LocalTime to) { |
|
107 |
User.log.debug("Adding a vacation from {} to {}", from, to); |
|
108 |
|
|
109 |
if (from == null || to == null) { |
|
110 |
User.log.warn("A vacation has to have a starting and an ending time"); |
|
111 |
throw new IllegalArgumentException("time.vacation.error"); |
|
112 |
} else if (from.compareTo(to) >= 0) { |
|
113 |
User.log.warn("A vacation must not start after it ends. from={}, to={}", from, to); |
|
114 |
throw new IllegalArgumentException("time.order.error"); |
|
115 |
} |
|
116 |
|
|
117 |
final float difference = from.until(to, ChronoUnit.MINUTES) / 60f; |
|
118 |
this.vacationCount += difference; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Returns the number of user's sick days available during a year. |
|
123 |
* |
|
124 |
* @return the number of user's sick days available during the year |
|
125 |
*/ |
|
126 |
public Integer getTotalSickDayCount() { |
|
127 |
return this.totalSickDayCount; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Replaces the number of user's sick days available during a year with the new value. |
|
132 |
* If the given number is negative or null the method throws an exception. |
|
133 |
* |
|
134 |
* @param totalSickDayCount the new number of sick days available during the year |
|
135 |
* @throws IllegalArgumentException when the given value is negative |
|
136 |
*/ |
|
137 |
public void setTotalSickDayCount(final Integer totalSickDayCount) throws IllegalArgumentException { |
|
138 |
User.log.debug("Setting a new number of user's sick days available during a year: {}", totalSickDayCount); |
|
139 |
|
|
140 |
if (totalSickDayCount != null && totalSickDayCount < 0) { |
|
141 |
User.log.warn("The number of user's available sick days must not be negative"); |
|
142 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
143 |
} |
|
144 |
|
|
145 |
this.totalSickDayCount = totalSickDayCount; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Returns the number of user's taken sick days. |
|
150 |
* |
|
151 |
* @return the number of user's taken sick days |
|
152 |
*/ |
|
153 |
public Integer getTakenSickDayCount() { |
|
154 |
return this.takenSickDayCount; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* Replaces the number of user's taken sick days with the new value. |
|
159 |
* If the given number is negative or greater than the number of available sick days or null the method throws an exception. |
|
160 |
* |
|
161 |
* @param takenSickDayCount the new number of taken sick days |
|
162 |
* @throws IllegalArgumentException when the given value is negative |
|
163 |
*/ |
|
164 |
public void setTakenSickDayCount(final Integer takenSickDayCount) throws IllegalArgumentException { |
|
165 |
User.log.debug("Setting a new number of user's taken sick days: {}", takenSickDayCount); |
|
166 |
|
|
167 |
if (takenSickDayCount == null) { |
|
168 |
User.log.warn("The number number of user's taken sick days must not be null"); |
|
169 |
throw new IllegalArgumentException("sick.day.null.error"); |
|
170 |
} else if (takenSickDayCount < 0) { |
|
171 |
User.log.warn("The number number of user's taken sick days must not be negative"); |
|
172 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
173 |
} else if (takenSickDayCount > this.totalSickDayCount) { |
|
174 |
User.log.warn("The number number of user's taken sick days must not greater than his/her available sick days"); |
|
175 |
throw new IllegalArgumentException("taken.sick.day.count.error"); |
|
176 |
} |
|
177 |
|
|
178 |
this.takenSickDayCount = takenSickDayCount; |
|
179 |
} |
|
180 |
|
|
181 |
/** |
|
182 |
* Adds the given amount to the number of user's remaining hours of an overtime. |
|
183 |
* If the given number is null or a result of the addition is negative the method throws an exception. |
|
184 |
* |
|
185 |
* @param value the given amount that is going to be added |
|
186 |
* @throws IllegalArgumentException when the given number is null or a result of the addition is negative |
|
187 |
*/ |
|
188 |
public void addTakenSickDayCount(final Integer value) throws IllegalArgumentException { |
|
189 |
User.log.debug("Increasing the number of remaining overtime by {}", value); |
|
190 |
|
|
191 |
if (value == null) { |
|
192 |
User.log.warn("The given value must not be null"); |
|
193 |
throw new IllegalArgumentException("vacation.null.error"); |
|
194 |
} else if (this.takenSickDayCount + value < 0) { |
|
195 |
User.log.warn("The number number of user's taken sick days must not be negative"); |
|
196 |
throw new IllegalArgumentException("negative.sick.day.error"); |
|
197 |
} else if (this.takenSickDayCount + value > this.totalSickDayCount) { |
|
198 |
User.log.warn("The number number of user's taken sick days must not greater than his/her available sick days"); |
|
199 |
throw new IllegalArgumentException("taken.sick.day.count.error"); |
|
200 |
} |
|
201 |
|
|
202 |
this.takenSickDayCount += value; |
|
203 |
} |
|
204 |
|
|
205 |
/** |
|
206 |
* Returns the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days. |
|
207 |
* |
|
208 |
* @return the date and time |
|
209 |
*/ |
|
210 |
public LocalDateTime getNotification() { |
|
211 |
return this.notification; |
|
212 |
} |
|
213 |
|
|
214 |
/** |
|
215 |
* Replaces the date and time of sending an email warning about an incoming reset of remaining overtimes and sick days with the given value. |
|
216 |
* If the given notification is null the method throws an exception. |
|
217 |
* |
|
218 |
* @param notification the new date and time |
|
219 |
* @throws IllegalArgumentException when the given notification is null |
|
220 |
*/ |
|
221 |
public void setNotification(final LocalDateTime notification) throws IllegalArgumentException { |
|
222 |
User.log.debug("Setting a new date and time of sending an email warning: {}", notification); |
|
223 |
|
|
224 |
this.notification = notification; |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Returns the user's role. |
|
229 |
* |
|
230 |
* @return the user's role |
|
231 |
*/ |
|
232 |
public UserRole getRole() { |
|
233 |
return this.role; |
|
234 |
} |
|
235 |
|
|
236 |
/** |
|
237 |
* Replaces the user's role with the new provided value. |
|
238 |
* If the given role is null the method throws an exception. |
|
239 |
* |
|
240 |
* @param role the new role |
|
241 |
* @throws IllegalArgumentException when the given role is null |
|
242 |
*/ |
|
243 |
public void setRole(final UserRole role) throws IllegalArgumentException { |
|
244 |
User.log.debug("Setting a new user's role: {}", role); |
|
245 |
|
|
246 |
if (role == null) { |
|
247 |
User.log.warn("The given role must not be null"); |
|
248 |
throw new IllegalArgumentException("role.null.error"); |
|
249 |
} |
|
250 |
|
|
251 |
this.role = role; |
|
252 |
} |
|
253 |
|
|
254 |
/** |
|
255 |
* Returns the user's authorization status. |
|
256 |
* |
|
257 |
* @return the user's authorization status |
|
258 |
*/ |
|
259 |
public Status getStatus() { |
|
260 |
return this.status; |
|
261 |
} |
|
262 |
|
|
263 |
/** |
|
264 |
* Replaces the authorization status with the handed value. |
|
265 |
* |
|
266 |
* @param status the new authorization status |
|
267 |
*/ |
|
268 |
public void setStatus(final Status status) { |
|
269 |
User.log.debug("Setting a new authorization status: {}", status); |
|
270 |
|
|
271 |
if (status == null) { |
|
272 |
User.log.warn("The given status must not be null"); |
|
273 |
throw new IllegalArgumentException("status.null.error"); |
|
274 |
} |
|
275 |
|
|
276 |
this.status = status; |
|
277 |
} |
|
278 |
} |
server/src/main/java/org/danekja/ymanager/repository/UserRepository.java | ||
---|---|---|
135 | 135 |
}, paramList); |
136 | 136 |
} |
137 | 137 |
|
138 |
private Map<String, Object> getUserColumns(final String token) { |
|
139 |
final List<SqlParameter> paramList = new ArrayList<>(); |
|
140 |
paramList.add(new SqlParameter(Types.LONGVARCHAR)); |
|
141 |
paramList.add(new SqlOutParameter("out_id", Types.BIGINT)); |
|
142 |
paramList.add(new SqlOutParameter("out_first_name", Types.VARCHAR)); |
|
143 |
paramList.add(new SqlOutParameter("out_last_name", Types.VARCHAR)); |
|
144 |
paramList.add(new SqlOutParameter("out_no_vacations", Types.FLOAT)); |
|
145 |
paramList.add(new SqlOutParameter("out_no_sick_days", Types.INTEGER)); |
|
146 |
paramList.add(new SqlOutParameter("out_taken_sick_days", Types.INTEGER)); |
|
147 |
paramList.add(new SqlOutParameter("out_alert", Types.TIMESTAMP)); |
|
148 |
paramList.add(new SqlOutParameter("out_token", Types.LONGVARCHAR)); |
|
149 |
paramList.add(new SqlOutParameter("out_email", Types.VARCHAR)); |
|
150 |
paramList.add(new SqlOutParameter("out_photo", Types.LONGVARCHAR)); |
|
151 |
paramList.add(new SqlOutParameter("out_creation_date", Types.TIMESTAMP)); |
|
152 |
paramList.add(new SqlOutParameter("out_role", Types.VARCHAR)); |
|
153 |
paramList.add(new SqlOutParameter("out_status", Types.VARCHAR)); |
|
154 |
|
|
155 |
return jdbc.call(con -> { |
|
156 |
final CallableStatement callableStatement = con.prepareCall("{call GetUserToken(?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"); |
|
157 |
callableStatement.setString(1, token); |
|
158 |
callableStatement.registerOutParameter(2, Types.BIGINT); |
|
159 |
callableStatement.registerOutParameter(3, Types.VARCHAR); |
|
160 |
callableStatement.registerOutParameter(4, Types.VARCHAR); |
|
161 |
callableStatement.registerOutParameter(5, Types.FLOAT); |
|
162 |
callableStatement.registerOutParameter(6, Types.INTEGER); |
|
163 |
callableStatement.registerOutParameter(7, Types.INTEGER); |
|
164 |
callableStatement.registerOutParameter(8, Types.TIMESTAMP); |
|
165 |
callableStatement.registerOutParameter(9, Types.LONGVARCHAR); |
|
166 |
callableStatement.registerOutParameter(10, Types.VARCHAR); |
|
167 |
callableStatement.registerOutParameter(11, Types.LONGVARCHAR); |
|
168 |
callableStatement.registerOutParameter(12, Types.TIMESTAMP); |
|
169 |
callableStatement.registerOutParameter(13, Types.VARCHAR); |
|
170 |
callableStatement.registerOutParameter(14, Types.VARCHAR); |
|
171 |
return callableStatement; |
|
172 |
}, paramList); |
|
173 |
} |
|
174 |
|
|
175 | 138 |
//---------------------------------- DTO ----------------------------------- |
176 | 139 |
|
177 | 140 |
/** |
... | ... | |
268 | 231 |
} |
269 | 232 |
|
270 | 233 |
public void updateUser(final User user) { |
271 |
this.jdbc.update("UPDATE end_user SET first_name = ?, last_name = ?, no_vacations = ?, taken_sick_days = ?, token = ?, email = ?, photo = ?, user_role = ?, status = ? WHERE id = ?",
|
|
272 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTakenSickDayCount(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name(), user.getId());
|
|
234 |
this.jdbc.update("UPDATE end_user SET first_name = ?, last_name = ?, no_vacations = ?, taken_sick_days = ?, email = ?, photo = ?, user_role = ?, status = ? WHERE id = ?", |
|
235 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTakenSickDayCount(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name(), user.getId()); |
|
273 | 236 |
} |
274 | 237 |
|
275 | 238 |
public void insertUser(final User user) { |
276 |
this.jdbc.update("INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, token, email, photo, user_role, status) VALUES (?,?,?,?,?,?,?,?,?,?,?)",
|
|
277 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTotalSickDayCount(), user.getTakenSickDayCount(), user.getNotification(), user.getToken(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name());
|
|
239 |
this.jdbc.update("INSERT INTO end_user (first_name, last_name, no_vacations, no_sick_days, taken_sick_days, alert, email, photo, user_role, status) VALUES (?,?,?,?,?,?,?,?,?,?,?)", |
|
240 |
user.getFirstName(), user.getLastName(), user.getVacationCount(), user.getTotalSickDayCount(), user.getTakenSickDayCount(), user.getNotification(), user.getEmail(), user.getPhoto(), user.getRole().name(), user.getStatus().name()); |
|
278 | 241 |
} |
279 | 242 |
|
280 | 243 |
public void insertSettings(final org.danekja.ymanager.domain.DefaultSettings settings) { |
server/src/main/java/org/danekja/ymanager/repository/jdbc/mappers/UserRowMapper.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.danekja.ymanager.domain.RegisteredUser; |
4 | 4 |
import org.danekja.ymanager.domain.Status; |
5 |
import org.danekja.ymanager.domain.UserData; |
|
5 | 6 |
import org.danekja.ymanager.domain.UserRole; |
6 | 7 |
import org.springframework.jdbc.core.RowMapper; |
7 | 8 |
|
... | ... | |
27 | 28 |
Timestamp date = resultSet.getTimestamp("alert"); |
28 | 29 |
LocalDateTime alert = date != null ? ((Timestamp) date).toLocalDateTime() : null; |
29 | 30 |
|
30 |
String token = resultSet.getNString("token"); |
|
31 | 31 |
String email = resultSet.getString("email"); |
32 | 32 |
String photo = resultSet.getNString("photo"); |
33 | 33 |
|
... | ... | |
36 | 36 |
UserRole role = UserRole.valueOf(resultSet.getString("user_role")); |
37 | 37 |
Status status = Status.valueOf(resultSet.getString("status")); |
38 | 38 |
|
39 |
return new RegisteredUser(id, firstName, lastName, vacations, sickDays, takenSickDays, alert, token, email, photo, creationDate, role, status); |
|
39 |
UserData userData = new UserData(vacations, sickDays, takenSickDays, alert, role, status); |
|
40 |
return new RegisteredUser(id, firstName, lastName, email, photo, creationDate, userData); |
|
40 | 41 |
} |
41 | 42 |
} |
server/src/test/java/org/danekja/ymanager/domain/RegisteredUserTest.java | ||
---|---|---|
3 | 3 |
import org.junit.jupiter.api.BeforeEach; |
4 | 4 |
import org.junit.jupiter.api.Test; |
5 | 5 |
|
6 |
import java.time.LocalDateTime; |
|
7 | 6 |
import java.time.LocalTime; |
8 | 7 |
|
9 |
import static org.junit.jupiter.api.Assertions.*; |
|
8 |
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
9 |
import static org.junit.jupiter.api.Assertions.assertThrows; |
|
10 | 10 |
|
11 | 11 |
/** |
12 | 12 |
* This class tests methods of the {@code RegisteredUser} class. |
... | ... | |
98 | 98 |
assertThrows(IllegalArgumentException.class, () -> this.user.setLastName(null)); |
99 | 99 |
} |
100 | 100 |
|
101 |
/** |
|
102 |
* Tests the method {@code setVacationCount} with common values where no problem should occur. |
|
103 |
*/ |
|
104 |
@Test |
|
105 |
void setVacationCount_valid() { |
|
106 |
this.user.setVacationCount(10f); |
|
107 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
108 |
} |
|
109 |
|
|
110 |
/** |
|
111 |
* Tests the method {@code setVacationCount} with zero which is a threshold value. |
|
112 |
*/ |
|
113 |
@Test |
|
114 |
void setVacationCount_zeroInput_valid() { |
|
115 |
this.user.setVacationCount(0f); |
|
116 |
assertEquals(0f, this.user.getVacationCount().floatValue()); |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Tests the method {@code setVacationCount} with negative one which is a threshold value. |
|
121 |
*/ |
|
122 |
@Test |
|
123 |
void setVacationCount_negativeOneInput() { |
|
124 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-1f)); |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Tests the method {@code setVacationCount} with negative value. |
|
129 |
*/ |
|
130 |
@Test |
|
131 |
void setVacationCount_negativeInput() { |
|
132 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-10f)); |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Tests the method {@code setVacationCount} with null value which should throw an exception. |
|
137 |
*/ |
|
138 |
@Test |
|
139 |
void setVacationCount_nullInput() { |
|
140 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(null)); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
145 |
*/ |
|
146 |
@Test |
|
147 |
void addVacationCount_floatInput_valid() { |
|
148 |
this.user.addVacationCount(10f); |
|
149 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
154 |
*/ |
|
155 |
@Test |
|
156 |
void addVacationCount_addFloatInput_valid() { |
|
157 |
this.user.setVacationCount(2f); |
|
158 |
this.user.addVacationCount(10f); |
|
159 |
assertEquals(12f, this.user.getVacationCount().floatValue()); |
|
160 |
} |
|
161 | 101 |
|
162 |
/** |
|
163 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
164 |
*/ |
|
165 |
@Test |
|
166 |
void addVacationCount_subtractFloatInput_valid() { |
|
167 |
this.user.setVacationCount(20f); |
|
168 |
this.user.addVacationCount(-10f); |
|
169 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
170 |
} |
|
171 |
|
|
172 |
/** |
|
173 |
* Tests the method {@code addVacationCount} with negative result of the operation which should throw an exception. |
|
174 |
*/ |
|
175 |
@Test |
|
176 |
void addVacationCount_floatInput_negativeResult() { |
|
177 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(-10f)); |
|
178 |
} |
|
179 |
|
|
180 |
/** |
|
181 |
* Tests the method {@code addVacationCount} with null value which should throw an exception. |
|
182 |
*/ |
|
183 |
@Test |
|
184 |
void addVacationCount_nullFloatInput() { |
|
185 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(null)); |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
190 |
*/ |
|
191 |
@Test |
|
192 |
void addVacationCount_timeInput_valid() { |
|
193 |
LocalTime from = LocalTime.of(10,0); |
|
194 |
LocalTime to = LocalTime.of(20,0); |
|
195 |
this.user.addVacationCount(from, to); |
|
196 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Tests the method {@code addVacationCount} with wrong order of parameters which should throw an exception. |
|
201 |
*/ |
|
202 |
@Test |
|
203 |
void addVacationCount_timeInput_order() { |
|
204 |
LocalTime from = LocalTime.of(10,0); |
|
205 |
LocalTime to = LocalTime.of(20,0); |
|
206 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(to, from)); |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Tests the method {@code addVacationCount} with null from parameter which should throw an exception. |
|
211 |
*/ |
|
212 |
@Test |
|
213 |
void addVacationCount_timeInput_nullFrom() { |
|
214 |
LocalTime to = LocalTime.of(20,0); |
|
215 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(null, to)); |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* Tests the method {@code addVacationCount} with null to parameter which should throw an exception. |
|
220 |
*/ |
|
221 |
@Test |
|
222 |
void addVacationCount_timeInput_nullTo() { |
|
223 |
LocalTime from = LocalTime.of(20,0); |
|
224 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(from, null)); |
|
225 |
} |
|
226 |
|
|
227 |
/** |
|
228 |
* Tests the method {@code addVacationCount} with null parameters which should throw an exception. |
|
229 |
*/ |
|
230 |
@Test |
|
231 |
void addVacationCount_timeNullInput() { |
|
232 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(null, null)); |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Tests the method {@code setTotalSickDayCount} with common values where no problem should occur. |
|
237 |
*/ |
|
238 |
@Test |
|
239 |
void setTotalSickDayCount_valid() { |
|
240 |
this.user.setTotalSickDayCount(10); |
|
241 |
assertEquals(10, this.user.getTotalSickDayCount().intValue()); |
|
242 |
} |
|
243 |
|
|
244 |
/** |
|
245 |
* Tests the method {@code setTotalSickDayCount} with zero which is a threshold value. |
|
246 |
*/ |
|
247 |
@Test |
|
248 |
void setTotalSickDayCount_zeroInput_valid() { |
|
249 |
this.user.setTotalSickDayCount(0); |
|
250 |
assertEquals(0, this.user.getTotalSickDayCount().intValue()); |
|
251 |
} |
|
252 |
|
|
253 |
/** |
|
254 |
* Tests the method {@code setTotalSickDayCount} with negative one which is a threshold value. |
|
255 |
*/ |
|
256 |
@Test |
|
257 |
void setTotalSickDayCount_negativeOneInput() { |
|
258 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTotalSickDayCount(-1)); |
|
259 |
} |
|
260 |
|
|
261 |
/** |
|
262 |
* Tests the method {@code setTotalSickDayCount} with negative value. |
|
263 |
*/ |
|
264 |
@Test |
|
265 |
void setTotalSickDayCount_negativeInput() { |
|
266 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTotalSickDayCount(-10)); |
|
267 |
} |
|
268 |
|
|
269 |
/** |
|
270 |
* Tests the method {@code setTotalSickDayCount} with null value. |
|
271 |
*/ |
|
272 |
@Test |
|
273 |
void setTotalSickDayCount_nullInput_valid() { |
|
274 |
this.user.setTotalSickDayCount(null); |
|
275 |
assertNull(this.user.getTotalSickDayCount()); |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* Tests the method {@code setTakenSickDayCount} with common values where no problem should occur. |
|
280 |
*/ |
|
281 |
@Test |
|
282 |
void setTakenSickDayCount_valid() { |
|
283 |
this.user.setTotalSickDayCount(20); |
|
284 |
this.user.setTakenSickDayCount(10); |
|
285 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* Tests the method {@code setTakenSickDayCount} with zero which is a threshold value. |
|
290 |
*/ |
|
291 |
@Test |
|
292 |
void setTakenSickDayCount_zeroInput_valid() { |
|
293 |
this.user.setTakenSickDayCount(0); |
|
294 |
assertEquals(0, this.user.getTakenSickDayCount().intValue()); |
|
295 |
} |
|
296 |
|
|
297 |
/** |
|
298 |
* Tests the method {@code setTakenSickDayCount} with negative one which is a threshold value. |
|
299 |
*/ |
|
300 |
@Test |
|
301 |
void setTakenSickDayCount_negativeOneInput() { |
|
302 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(-1)); |
|
303 |
} |
|
304 |
|
|
305 |
/** |
|
306 |
* Tests the method {@code setTakenSickDayCount} with negative value. |
|
307 |
*/ |
|
308 |
@Test |
|
309 |
void setTakenSickDayCount_negativeInput() { |
|
310 |
this.user.setTotalSickDayCount(10); |
|
311 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(-10)); |
|
312 |
} |
|
313 |
|
|
314 |
/** |
|
315 |
* Tests the method {@code setTakenSickDayCount} with a value that is greater than total sick days. |
|
316 |
*/ |
|
317 |
@Test |
|
318 |
void setTakenSickDayCount_over() { |
|
319 |
this.user.setTotalSickDayCount(10); |
|
320 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(20)); |
|
321 |
} |
|
322 |
|
|
323 |
/** |
|
324 |
* Tests the method {@code setTakenSickDayCount} with a value that is equals the total sick days. |
|
325 |
*/ |
|
326 |
@Test |
|
327 |
void setTakenSickDayCount_same() { |
|
328 |
this.user.setTotalSickDayCount(10); |
|
329 |
this.user.setTakenSickDayCount(10); |
|
330 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Tests the method {@code setTakenSickDayCount} with null value. |
|
335 |
*/ |
|
336 |
@Test |
|
337 |
void setTakenSickDayCount_nullInput() { |
|
338 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(null)); |
|
339 |
} |
|
340 |
|
|
341 |
/** |
|
342 |
* Tests the method {@code addTakenSickDayCount} with common values where no problem should occur. |
|
343 |
*/ |
|
344 |
@Test |
|
345 |
void addTakenSickDayCount_valid() { |
|
346 |
this.user.setTotalSickDayCount(50); |
|
347 |
this.user.addTakenSickDayCount(10); |
|
348 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
349 |
} |
|
350 |
|
|
351 |
/** |
|
352 |
* Tests the method {@code addTakenSickDayCount} with common values where no problem should occur. |
|
353 |
*/ |
|
354 |
@Test |
|
355 |
void addTakenSickDayCount_add_valid() { |
|
356 |
this.user.setTotalSickDayCount(50); |
|
357 |
this.user.setTakenSickDayCount(2); |
|
358 |
this.user.addTakenSickDayCount(10); |
|
359 |
assertEquals(12f, this.user.getTakenSickDayCount().intValue()); |
|
360 |
} |
|
361 |
|
|
362 |
/** |
|
363 |
* Tests the method {@code addTakenSickDayCount} with common values where no problem should occur. |
|
364 |
*/ |
|
365 |
@Test |
|
366 |
void addTakenSickDayCount_subtract_valid() { |
|
367 |
this.user.setTotalSickDayCount(50); |
|
368 |
this.user.setTakenSickDayCount(20); |
|
369 |
this.user.addTakenSickDayCount(-10); |
|
370 |
assertEquals(10f, this.user.getTakenSickDayCount().intValue()); |
|
371 |
} |
|
372 |
|
|
373 |
/** |
|
374 |
* Tests the method {@code addTakenSickDayCount} with negative result of the operation which should throw an exception. |
|
375 |
*/ |
|
376 |
@Test |
|
377 |
void addTakenSickDayCount_negativeResult() { |
|
378 |
assertThrows(IllegalArgumentException.class, () -> this.user.addTakenSickDayCount(-10)); |
|
379 |
} |
|
380 |
|
|
381 |
/** |
|
382 |
* Tests the method {@code addTakenSickDayCount} with null value which should throw an exception. |
|
383 |
*/ |
|
384 |
@Test |
|
385 |
void addTakenSickDayCount_nullInput() { |
|
386 |
assertThrows(IllegalArgumentException.class, () -> this.user.addTakenSickDayCount(null)); |
|
387 |
} |
|
388 |
|
|
389 |
/** |
|
390 |
* Tests the method {@code addTakenSickDayCount} with a value that is greater than total sick days. |
|
391 |
*/ |
|
392 |
@Test |
|
393 |
void addTakenSickDayCount_over() { |
|
394 |
this.user.setTotalSickDayCount(10); |
|
395 |
assertThrows(IllegalArgumentException.class, () -> this.user.addTakenSickDayCount(20)); |
|
396 |
} |
|
397 |
|
|
398 |
/** |
|
399 |
* Tests the method {@code addTakenSickDayCount} with a value that is equals the total sick days. |
|
400 |
*/ |
|
401 |
@Test |
|
402 |
void addTakenSickDayCount_same() { |
|
403 |
this.user.setTotalSickDayCount(10); |
|
404 |
this.user.addTakenSickDayCount(10); |
|
405 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
406 |
} |
|
407 |
|
|
408 |
|
|
409 |
/** |
|
410 |
* Tests the method {@code setNotification} with common values where no problem should occur. |
|
411 |
*/ |
|
412 |
@Test |
|
413 |
void setNotification_valid() { |
|
414 |
this.user.setNotification(LocalDateTime.of(2010,5,1,20,0)); |
|
415 |
assertEquals(LocalDateTime.of(2010,5,1,20,0), this.user.getNotification()); |
|
416 |
} |
|
417 |
|
|
418 |
/** |
|
419 |
* Tests the method {@code setNotification} with null value. |
|
420 |
*/ |
|
421 |
@Test |
|
422 |
void setNotification_nullInput_valid() { |
|
423 |
this.user.setNotification(null); |
|
424 |
assertNull(this.user.getNotification()); |
|
425 |
} |
|
426 |
|
|
427 |
/** |
|
428 |
* Tests the method {@code setToken} with common values where no problem should occur. |
|
429 |
*/ |
|
430 |
@Test |
|
431 |
void setToken_valid() { |
|
432 |
this.user.setToken("aaaaa"); |
|
433 |
assertEquals("aaaaa", this.user.getToken()); |
|
434 |
} |
|
435 |
|
|
436 |
/** |
|
437 |
* Tests the method {@code setToken} with null value. |
|
438 |
*/ |
|
439 |
@Test |
|
440 |
void setToken_nullInput() { |
|
441 |
assertThrows(IllegalArgumentException.class, () -> this.user.setToken(null)); |
|
442 |
} |
|
443 | 102 |
|
444 | 103 |
/** |
445 | 104 |
* Tests the method {@code setEmail} with common values where no problem should occur. |
... | ... | |
493 | 152 |
assertEquals("https://st2.depositphotos.com/9223672/12056/v/950/depositphotos_120568236-stock-illustration-male-face-avatar-logo-template.jpg", this.user.getPhoto()); |
494 | 153 |
} |
495 | 154 |
|
496 |
/** |
|
497 |
* Tests the method {@code setRole} with common values where no problem should occur. |
|
498 |
*/ |
|
499 |
@Test |
|
500 |
void setRole_valid() { |
|
501 |
this.user.setRole(UserRole.EMPLOYER); |
|
502 |
assertEquals(UserRole.EMPLOYER, this.user.getRole()); |
|
503 |
} |
|
504 |
|
|
505 |
/** |
|
506 |
* Tests the method {@code setRole} with null value. |
|
507 |
*/ |
|
508 |
@Test |
|
509 |
void setRole_nullInput() { |
|
510 |
assertThrows(IllegalArgumentException.class, () -> this.user.setRole(null)); |
|
511 |
} |
|
512 |
|
|
513 |
/** |
|
514 |
* Tests the method {@code setStatus} with common values where no problem should occur. |
|
515 |
*/ |
|
516 |
@Test |
|
517 |
void setStatus_valid() { |
|
518 |
this.user.setStatus(Status.ACCEPTED); |
|
519 |
assertEquals(Status.ACCEPTED, this.user.getStatus()); |
|
520 |
} |
|
521 |
|
|
522 |
/** |
|
523 |
* Tests the method {@code setStatus} with null value. |
|
524 |
*/ |
|
525 |
@Test |
|
526 |
void setStatus_nullInput() { |
|
527 |
assertThrows(IllegalArgumentException.class, () -> this.user.setStatus(null)); |
|
528 |
} |
|
529 |
|
|
530 | 155 |
/** |
531 | 156 |
* Tests the method {@code takeVacation} with common values where no problem should occur. |
532 | 157 |
*/ |
server/src/test/java/org/danekja/ymanager/domain/UserDataTest.java | ||
---|---|---|
1 |
package org.danekja.ymanager.domain; |
|
2 |
|
|
3 |
import org.junit.jupiter.api.BeforeEach; |
|
4 |
import org.junit.jupiter.api.Test; |
|
5 |
|
|
6 |
import java.time.LocalDateTime; |
|
7 |
import java.time.LocalTime; |
|
8 |
|
|
9 |
import static org.junit.jupiter.api.Assertions.*; |
|
10 |
|
|
11 |
public class UserDataTest { |
|
12 |
|
|
13 |
private UserData user; |
|
14 |
|
|
15 |
/** |
|
16 |
* Prepares the instance of the {@code RegisteredUser}. |
|
17 |
*/ |
|
18 |
@BeforeEach |
|
19 |
void setUp() { |
|
20 |
this.user = new UserData(); |
|
21 |
this.user.setVacationCount(0f); |
|
22 |
this.user.setTotalSickDayCount(0); |
|
23 |
this.user.setTakenSickDayCount(0); |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Tests the method {@code setVacationCount} with common values where no problem should occur. |
|
28 |
*/ |
|
29 |
@Test |
|
30 |
void setVacationCount_valid() { |
|
31 |
this.user.setVacationCount(10f); |
|
32 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
33 |
} |
|
34 |
|
|
35 |
/** |
|
36 |
* Tests the method {@code setVacationCount} with zero which is a threshold value. |
|
37 |
*/ |
|
38 |
@Test |
|
39 |
void setVacationCount_zeroInput_valid() { |
|
40 |
this.user.setVacationCount(0f); |
|
41 |
assertEquals(0f, this.user.getVacationCount().floatValue()); |
|
42 |
} |
|
43 |
|
|
44 |
/** |
|
45 |
* Tests the method {@code setVacationCount} with negative one which is a threshold value. |
|
46 |
*/ |
|
47 |
@Test |
|
48 |
void setVacationCount_negativeOneInput() { |
|
49 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-1f)); |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Tests the method {@code setVacationCount} with negative value. |
|
54 |
*/ |
|
55 |
@Test |
|
56 |
void setVacationCount_negativeInput() { |
|
57 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(-10f)); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Tests the method {@code setVacationCount} with null value which should throw an exception. |
|
62 |
*/ |
|
63 |
@Test |
|
64 |
void setVacationCount_nullInput() { |
|
65 |
assertThrows(IllegalArgumentException.class, () -> this.user.setVacationCount(null)); |
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
70 |
*/ |
|
71 |
@Test |
|
72 |
void addVacationCount_floatInput_valid() { |
|
73 |
this.user.addVacationCount(10f); |
|
74 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
79 |
*/ |
|
80 |
@Test |
|
81 |
void addVacationCount_addFloatInput_valid() { |
|
82 |
this.user.setVacationCount(2f); |
|
83 |
this.user.addVacationCount(10f); |
|
84 |
assertEquals(12f, this.user.getVacationCount().floatValue()); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
89 |
*/ |
|
90 |
@Test |
|
91 |
void addVacationCount_subtractFloatInput_valid() { |
|
92 |
this.user.setVacationCount(20f); |
|
93 |
this.user.addVacationCount(-10f); |
|
94 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
95 |
} |
|
96 |
|
|
97 |
/** |
|
98 |
* Tests the method {@code addVacationCount} with negative result of the operation which should throw an exception. |
|
99 |
*/ |
|
100 |
@Test |
|
101 |
void addVacationCount_floatInput_negativeResult() { |
|
102 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(-10f)); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Tests the method {@code addVacationCount} with null value which should throw an exception. |
|
107 |
*/ |
|
108 |
@Test |
|
109 |
void addVacationCount_nullFloatInput() { |
|
110 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(null)); |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Tests the method {@code addVacationCount} with common values where no problem should occur. |
|
115 |
*/ |
|
116 |
@Test |
|
117 |
void addVacationCount_timeInput_valid() { |
|
118 |
LocalTime from = LocalTime.of(10, 0); |
|
119 |
LocalTime to = LocalTime.of(20, 0); |
|
120 |
this.user.addVacationCount(from, to); |
|
121 |
assertEquals(10f, this.user.getVacationCount().floatValue()); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Tests the method {@code addVacationCount} with wrong order of parameters which should throw an exception. |
|
126 |
*/ |
|
127 |
@Test |
|
128 |
void addVacationCount_timeInput_order() { |
|
129 |
LocalTime from = LocalTime.of(10, 0); |
|
130 |
LocalTime to = LocalTime.of(20, 0); |
|
131 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(to, from)); |
|
132 |
} |
|
133 |
|
|
134 |
/** |
|
135 |
* Tests the method {@code addVacationCount} with null from parameter which should throw an exception. |
|
136 |
*/ |
|
137 |
@Test |
|
138 |
void addVacationCount_timeInput_nullFrom() { |
|
139 |
LocalTime to = LocalTime.of(20, 0); |
|
140 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(null, to)); |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* Tests the method {@code addVacationCount} with null to parameter which should throw an exception. |
|
145 |
*/ |
|
146 |
@Test |
|
147 |
void addVacationCount_timeInput_nullTo() { |
|
148 |
LocalTime from = LocalTime.of(20, 0); |
|
149 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(from, null)); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Tests the method {@code addVacationCount} with null parameters which should throw an exception. |
|
154 |
*/ |
|
155 |
@Test |
|
156 |
void addVacationCount_timeNullInput() { |
|
157 |
assertThrows(IllegalArgumentException.class, () -> this.user.addVacationCount(null, null)); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Tests the method {@code setTotalSickDayCount} with common values where no problem should occur. |
|
162 |
*/ |
|
163 |
@Test |
|
164 |
void setTotalSickDayCount_valid() { |
|
165 |
this.user.setTotalSickDayCount(10); |
|
166 |
assertEquals(10, this.user.getTotalSickDayCount().intValue()); |
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Tests the method {@code setTotalSickDayCount} with zero which is a threshold value. |
|
171 |
*/ |
|
172 |
@Test |
|
173 |
void setTotalSickDayCount_zeroInput_valid() { |
|
174 |
this.user.setTotalSickDayCount(0); |
|
175 |
assertEquals(0, this.user.getTotalSickDayCount().intValue()); |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Tests the method {@code setTotalSickDayCount} with negative one which is a threshold value. |
|
180 |
*/ |
|
181 |
@Test |
|
182 |
void setTotalSickDayCount_negativeOneInput() { |
|
183 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTotalSickDayCount(-1)); |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* Tests the method {@code setTotalSickDayCount} with negative value. |
|
188 |
*/ |
|
189 |
@Test |
|
190 |
void setTotalSickDayCount_negativeInput() { |
|
191 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTotalSickDayCount(-10)); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Tests the method {@code setTotalSickDayCount} with null value. |
|
196 |
*/ |
|
197 |
@Test |
|
198 |
void setTotalSickDayCount_nullInput_valid() { |
|
199 |
this.user.setTotalSickDayCount(null); |
|
200 |
assertNull(this.user.getTotalSickDayCount()); |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* Tests the method {@code setTakenSickDayCount} with common values where no problem should occur. |
|
205 |
*/ |
|
206 |
@Test |
|
207 |
void setTakenSickDayCount_valid() { |
|
208 |
this.user.setTotalSickDayCount(20); |
|
209 |
this.user.setTakenSickDayCount(10); |
|
210 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Tests the method {@code setTakenSickDayCount} with zero which is a threshold value. |
|
215 |
*/ |
|
216 |
@Test |
|
217 |
void setTakenSickDayCount_zeroInput_valid() { |
|
218 |
this.user.setTakenSickDayCount(0); |
|
219 |
assertEquals(0, this.user.getTakenSickDayCount().intValue()); |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* Tests the method {@code setTakenSickDayCount} with negative one which is a threshold value. |
|
224 |
*/ |
|
225 |
@Test |
|
226 |
void setTakenSickDayCount_negativeOneInput() { |
|
227 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(-1)); |
|
228 |
} |
|
229 |
|
|
230 |
/** |
|
231 |
* Tests the method {@code setTakenSickDayCount} with negative value. |
|
232 |
*/ |
|
233 |
@Test |
|
234 |
void setTakenSickDayCount_negativeInput() { |
|
235 |
this.user.setTotalSickDayCount(10); |
|
236 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(-10)); |
|
237 |
} |
|
238 |
|
|
239 |
/** |
|
240 |
* Tests the method {@code setTakenSickDayCount} with a value that is greater than total sick days. |
|
241 |
*/ |
|
242 |
@Test |
|
243 |
void setTakenSickDayCount_over() { |
|
244 |
this.user.setTotalSickDayCount(10); |
|
245 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(20)); |
|
246 |
} |
|
247 |
|
|
248 |
/** |
|
249 |
* Tests the method {@code setTakenSickDayCount} with a value that is equals the total sick days. |
|
250 |
*/ |
|
251 |
@Test |
|
252 |
void setTakenSickDayCount_same() { |
|
253 |
this.user.setTotalSickDayCount(10); |
|
254 |
this.user.setTakenSickDayCount(10); |
|
255 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Tests the method {@code setTakenSickDayCount} with null value. |
|
260 |
*/ |
|
261 |
@Test |
|
262 |
void setTakenSickDayCount_nullInput() { |
|
263 |
assertThrows(IllegalArgumentException.class, () -> this.user.setTakenSickDayCount(null)); |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* Tests the method {@code addTakenSickDayCount} with common values where no problem should occur. |
|
268 |
*/ |
|
269 |
@Test |
|
270 |
void addTakenSickDayCount_valid() { |
|
271 |
this.user.setTotalSickDayCount(50); |
|
272 |
this.user.addTakenSickDayCount(10); |
|
273 |
assertEquals(10, this.user.getTakenSickDayCount().intValue()); |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Tests the method {@code addTakenSickDayCount} with common values where no problem should occur. |
|
278 |
*/ |
|
279 |
@Test |
Také k dispozici: Unified diff
re #29 separate editable user-data into own class.