2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.icalendar.internal.logic;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.io.FileInputStream;
18 import java.io.IOException;
19 import java.time.Instant;
20 import java.time.LocalDate;
21 import java.time.ZoneId;
22 import java.util.List;
24 import org.junit.jupiter.api.BeforeEach;
25 import org.junit.jupiter.api.Test;
26 import org.openhab.core.library.types.DecimalType;
27 import org.openhab.core.library.types.HSBType;
28 import org.openhab.core.library.types.OnOffType;
29 import org.openhab.core.library.types.OpenClosedType;
30 import org.openhab.core.library.types.PercentType;
31 import org.openhab.core.library.types.PlayPauseType;
32 import org.openhab.core.library.types.QuantityType;
33 import org.openhab.core.library.types.RewindFastforwardType;
34 import org.openhab.core.library.types.StringType;
35 import org.openhab.core.library.types.UpDownType;
36 import org.openhab.core.types.Command;
39 * Tests for presentable calendar.
41 * @author Michael Wodniok - Initial contribution.
42 * @author Andrew Fiddian-Green - Tests for Command Tag code
43 * @author Michael Wodniok - Extended Tests for filtered Events
44 * @author Michael Wodniok - Extended Test for parallel current events
46 public class BiweeklyPresentableCalendarTest {
47 private AbstractPresentableCalendar calendar;
48 private AbstractPresentableCalendar calendar2;
49 private AbstractPresentableCalendar calendar3;
50 private AbstractPresentableCalendar calendar_issue9647;
51 private AbstractPresentableCalendar calendar_issue10808;
54 public void setUp() throws IOException, CalendarException {
55 calendar = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test.ics"));
56 calendar2 = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test2.ics"));
57 calendar3 = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test3.ics"));
58 calendar_issue9647 = new BiweeklyPresentableCalendar(
59 new FileInputStream("src/test/resources/test-issue9647.ics"));
60 calendar_issue10808 = new BiweeklyPresentableCalendar(
61 new FileInputStream("src/test/resources/test-issue10808.ics"));
65 * Tests recurrence and whether TimeZone is interpolated in a right way.
68 public void testIsEventPresent() {
70 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-08T09:04:00Z")));
71 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-08T09:08:00Z")));
72 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-08T09:11:00Z")));
74 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-09T09:04:00Z")));
75 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-09T09:08:00Z")));
76 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-09T09:11:00Z")));
78 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-10T09:04:00Z")));
79 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-10T09:08:00Z")));
80 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-10T09:11:00Z")));
82 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-11T09:04:00Z")));
83 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-11T09:08:00Z")));
84 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-11T09:11:00Z")));
86 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-12T09:04:00Z")));
87 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-12T09:08:00Z")));
88 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-12T09:11:00Z")));
90 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-13T09:04:00Z")));
91 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-13T09:08:00Z")));
92 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-13T09:11:00Z")));
94 // Test in CEST (UTC+2)
95 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-14T07:59:00Z")));
96 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-14T08:03:00Z")));
97 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-14T09:01:00Z")));
99 // Test Series with cancelled event by Davdroid
100 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-03T09:55:00Z")));
101 assertTrue(calendar2.isEventPresent(Instant.parse("2019-11-03T10:01:00Z")));
102 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-03T13:00:00Z")));
104 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-24T09:55:00Z")));
105 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-24T10:01:00Z")));
106 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-24T13:00:00Z")));
110 * This test relies on a working isEventPresent and assumes the calculation
111 * of recurrence is done the same way.
114 public void testGetCurrentEvent() {
115 Event currentEvent = calendar.getCurrentEvent(Instant.parse("2019-09-10T09:07:00Z"));
116 assertNotNull(currentEvent);
117 assertTrue("Test Series in UTC".contentEquals(currentEvent.title));
118 assertEquals(0, Instant.parse("2019-09-10T09:05:00Z").compareTo(currentEvent.start));
119 assertEquals(0, Instant.parse("2019-09-10T09:10:00Z").compareTo(currentEvent.end));
121 Event nonExistingEvent = calendar.getCurrentEvent(Instant.parse("2019-09-09T09:07:00Z"));
122 assertNull(nonExistingEvent);
124 Event currentEvent2 = calendar_issue10808.getCurrentEvent(Instant.parse("2021-06-05T17:10:05Z"));
125 assertNotNull(currentEvent2);
126 assertTrue("Test event 1".contentEquals(currentEvent2.title));
128 Event currentEvent3 = calendar_issue10808.getCurrentEvent(Instant.parse("2021-06-05T17:13:05Z"));
129 assertNotNull(currentEvent3);
130 assertTrue("Test event 2".contentEquals(currentEvent3.title));
132 Event currentEvent4 = calendar_issue10808.getCurrentEvent(Instant.parse("2021-06-05T17:18:05Z"));
133 assertNotNull(currentEvent4);
134 assertTrue("Test event 1".contentEquals(currentEvent4.title));
138 * This test relies on a working isEventPresent and assumes the calculation
139 * of recurrence is done the same way.
142 public void testGetNextEvent() {
143 // positive case: next event of series
144 Event nextEventOfSeries = calendar.getNextEvent(Instant.parse("2019-09-10T09:07:00Z"));
145 assertNotNull(nextEventOfSeries);
146 assertTrue("Test Series in UTC".contentEquals(nextEventOfSeries.title));
147 assertEquals(0, Instant.parse("2019-09-11T09:05:00Z").compareTo(nextEventOfSeries.start));
148 assertEquals(0, Instant.parse("2019-09-11T09:10:00Z").compareTo(nextEventOfSeries.end));
150 // positive case: next event after series
151 Event nextEventOutsideSeries = calendar.getNextEvent(Instant.parse("2019-09-12T09:07:00Z"));
152 assertNotNull(nextEventOutsideSeries);
153 assertTrue("Test Event in UTC+2".contentEquals(nextEventOutsideSeries.title));
154 assertEquals(0, Instant.parse("2019-09-14T08:00:00Z").compareTo(nextEventOutsideSeries.start));
155 assertEquals(0, Instant.parse("2019-09-14T09:00:00Z").compareTo(nextEventOutsideSeries.end));
157 // positive case: next event should be also set if currently none is present
158 Event nextEventIndependent = calendar.getNextEvent(Instant.parse("2019-09-13T09:07:00Z"));
159 assertTrue(nextEventOutsideSeries.equals(nextEventIndependent));
161 // negative case: after last event there is no next
162 Event nonExistingEvent = calendar.getNextEvent(Instant.parse("2019-09-14T12:00:00Z"));
163 assertNull(nonExistingEvent);
165 // mixed case: cancelled events also not show up as next
166 Event nextEventAfterCancelled = calendar2.getNextEvent(Instant.parse("2019-11-24T09:55:00Z"));
167 assertNotNull(nextEventAfterCancelled);
168 assertEquals(0, Instant.parse("2019-12-01T10:00:00Z").compareTo(nextEventAfterCancelled.start));
172 * This test checks for Events that have just begun or ended, and if so it checks for Command Tags
173 * and checks if these tags are valid
175 @SuppressWarnings("null")
177 public void testCommandTagCode() {
178 List<Event> events = null;
180 int tagsPerEvent = 8;
182 // test just begun events: first in the series
183 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"),
184 Instant.parse("2020-01-28T16:05:00Z"));
185 assertNotNull(events);
186 assertEquals(eventCount, events.size());
187 for (Event event : events) {
188 List<CommandTag> cmdTags = event.commandTags;
189 assertEquals(tagsPerEvent, cmdTags.size());
191 for (CommandTag cmdTag : cmdTags) {
192 if (cmdTag.getTagType() == CommandTagType.BEGIN) {
193 assertTrue(cmdTag.isAuthorized("abc"));
194 assertTrue(cmdTag.getItemName().matches("^\\w+$"));
195 assertTrue(cmdTag.getCommand() != null);
199 assertEquals(tagsPerEvent / 2, beginTags);
202 // test just begun events: third in the series
203 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-30T15:55:00Z"),
204 Instant.parse("2020-01-30T16:05:00Z"));
205 assertNotNull(events);
206 assertEquals(eventCount, events.size());
207 for (Event event : events) {
208 List<CommandTag> cmdTags = event.commandTags;
209 assertEquals(tagsPerEvent, cmdTags.size());
211 for (CommandTag cmdTag : cmdTags) {
212 if (cmdTag.getTagType() == CommandTagType.BEGIN) {
213 assertTrue(cmdTag.isAuthorized("abc"));
214 assertTrue(cmdTag.getItemName().matches("^\\w+$"));
215 assertTrue(cmdTag.getCommand() != null);
219 assertEquals(tagsPerEvent / 2, beginTags);
222 // test outside of window: begun events, too early
223 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:50:00Z"),
224 Instant.parse("2020-01-28T15:55:00Z"));
225 assertNotNull(events);
226 assertEquals(0, events.size());
228 // test outside of window: begun events, too late
229 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T16:05:00Z"),
230 Instant.parse("2020-01-28T16:10:00Z"));
231 assertNotNull(events);
232 assertEquals(0, events.size());
234 // test just ended events: first in the series
235 events = calendar3.getJustEndedEvents(Instant.parse("2020-01-28T16:25:00Z"),
236 Instant.parse("2020-01-28T16:35:00Z"));
237 assertNotNull(events);
238 assertEquals(eventCount, events.size());
239 for (Event event : events) {
240 List<CommandTag> cmdTags = event.commandTags;
241 assertEquals(tagsPerEvent, cmdTags.size());
243 for (CommandTag cmdTag : cmdTags) {
244 if (cmdTag.getTagType() == CommandTagType.END) {
245 assertTrue(cmdTag.isAuthorized("abc"));
246 assertTrue(cmdTag.getItemName().matches("^\\w+$"));
247 assertTrue(cmdTag.getCommand() != null);
251 assertEquals(tagsPerEvent / 2, endTags);
254 // test outside of window: ended events, too early
255 events = calendar3.getJustEndedEvents(Instant.parse("2020-01-28T16:20:00Z"),
256 Instant.parse("2020-01-28T16:25:00Z"));
257 assertNotNull(events);
258 assertEquals(0, events.size());
260 // test outside of window: ended events, too late
261 events = calendar3.getJustEndedEvents(Instant.parse("2020-01-28T16:35:00Z"),
262 Instant.parse("2020-01-28T16:40:00Z"));
263 assertNotNull(events);
264 assertEquals(0, events.size());
266 // test a valid just begun event with both good and bad authorization codes
267 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"),
268 Instant.parse("2020-01-28T16:05:00Z"));
269 assertNotNull(events);
270 assertTrue(!events.isEmpty());
271 List<CommandTag> cmdTags = events.get(0).commandTags;
272 assertTrue(!cmdTags.isEmpty());
273 CommandTag cmd = cmdTags.get(0);
274 // accept correct, empty or null configuration codes
275 assertTrue(cmd.isAuthorized("abc"));
276 assertTrue(cmd.isAuthorized(""));
277 assertTrue(cmd.isAuthorized(null));
278 // reject incorrect configuration code
279 assertFalse(cmd.isAuthorized("123"));
281 // test tag syntax: Test Series #1
282 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T19:25:00Z"),
283 Instant.parse("2020-01-28T19:35:00Z"));
284 assertNotNull(events);
285 assertEquals(1, events.size());
286 cmdTags = events.get(0).commandTags;
287 assertEquals(11, cmdTags.size());
289 // BEGIN:Calendar_Test_Color:ON:abc
290 assertEquals("Calendar_Test_Color", cmdTags.get(0).getItemName());
291 assertTrue(cmdTags.get(0).isAuthorized("abc"));
292 Command cmd0 = cmdTags.get(0).getCommand();
294 assertEquals(OnOffType.class, cmd0.getClass());
296 // BEGIN:Calendar_Test_Contact:OPEN:abc
297 Command cmd1 = cmdTags.get(1).getCommand();
299 assertEquals(OpenClosedType.class, cmd1.getClass());
301 // BEGIN:Calendar_Test_Dimmer:ON:abc
302 Command cmd2 = cmdTags.get(2).getCommand();
304 assertEquals(OnOffType.class, cmd2.getClass());
306 // BEGIN:Calendar_Test_Number:12.3:abc
307 Command cmd3 = cmdTags.get(3).getCommand();
309 assertEquals(DecimalType.class, cmd3.getClass());
311 // BEGIN:Calendar_Test_Temperature:12.3°C:abc
312 Command cmd4 = cmdTags.get(4).getCommand();
314 assertEquals(QuantityType.class, cmd4.getClass());
316 // BEGIN:Calendar_Test_Pressure:12.3hPa:abc
317 Command cmd5 = cmdTags.get(5).getCommand();
319 assertEquals(QuantityType.class, cmd5.getClass());
321 // BEGIN:Calendar_Test_Speed:12.3m/s:abc
322 Command cmd6 = cmdTags.get(6).getCommand();
324 assertEquals(QuantityType.class, cmd6.getClass());
326 // BEGIN:Calendar_Test_Player:PLAY:abc
327 Command cmd7 = cmdTags.get(7).getCommand();
329 assertEquals(PlayPauseType.class, cmd7.getClass());
331 // BEGIN:Calendar_Test_RollerShutter:UP:abc
332 Command cmd8 = cmdTags.get(8).getCommand();
334 assertEquals(UpDownType.class, cmd8.getClass());
336 // BEGIN:Calendar_Test_String:Test Series #1:abc
337 Command cmd9 = cmdTags.get(9).getCommand();
339 assertEquals(StringType.class, cmd9.getClass());
341 // BEGIN:Calendar_Test_Switch:ON:abc
342 Command cmd10 = cmdTags.get(10).getCommand();
343 assertNotNull(cmd10);
344 assertEquals(OnOffType.class, cmd10.getClass());
346 // test tag syntax: Test Series #4
347 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:10:00Z"),
348 Instant.parse("2020-01-28T20:20:00Z"));
349 assertNotNull(events);
350 assertEquals(1, events.size());
351 cmdTags = events.get(0).commandTags;
352 assertEquals(11, cmdTags.size());
354 // BEGIN:Calendar_Test_Color:0%:abc
355 cmd0 = cmdTags.get(0).getCommand();
357 assertEquals(PercentType.class, cmd0.getClass());
359 // BEGIN:Calendar_Test_Contact:CLOSED:abc
360 cmd1 = cmdTags.get(1).getCommand();
362 assertEquals(OpenClosedType.class, cmd1.getClass());
364 // BEGIN:Calendar_Test_Dimmer:0%:abc
365 cmd2 = cmdTags.get(2).getCommand();
367 assertEquals(PercentType.class, cmd2.getClass());
369 // BEGIN:Calendar_Test_Number:-12.3:abc
370 cmd3 = cmdTags.get(3).getCommand();
372 assertEquals(DecimalType.class, cmd3.getClass());
374 // BEGIN:Calendar_Test_Temperature:-12.3°C:abc
375 cmd4 = cmdTags.get(4).getCommand();
377 assertEquals(QuantityType.class, cmd4.getClass());
379 // BEGIN:Calendar_Test_Pressure:500mmHg:abc
380 cmd5 = cmdTags.get(5).getCommand();
382 assertEquals(QuantityType.class, cmd5.getClass());
384 // BEGIN:Calendar_Test_Speed:12300000mm/h:abc
385 cmd6 = cmdTags.get(6).getCommand();
387 assertEquals(QuantityType.class, cmd6.getClass());
389 // BEGIN:Calendar_Test_Player:REWIND:abc
390 cmd7 = cmdTags.get(7).getCommand();
392 assertEquals(RewindFastforwardType.class, cmd7.getClass());
394 // BEGIN:Calendar_Test_RollerShutter:100%:abc
395 cmd8 = cmdTags.get(8).getCommand();
397 assertEquals(PercentType.class, cmd8.getClass());
399 // BEGIN:Calendar_Test_String:Test Series #4:abc
400 cmd9 = cmdTags.get(9).getCommand();
402 assertEquals(StringType.class, cmd9.getClass());
404 // BEGIN:Calendar_Test_Switch:OFF:abc
405 cmd10 = cmdTags.get(10).getCommand();
406 assertNotNull(cmd10);
407 assertEquals(OnOffType.class, cmd10.getClass());
409 // test tag syntax: Test Series #5
410 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:25:00Z"),
411 Instant.parse("2020-01-28T20:35:00Z"));
412 assertNotNull(events);
413 assertEquals(1, events.size());
414 cmdTags = events.get(0).commandTags;
415 assertEquals(11, cmdTags.size());
417 // BEGIN:Calendar_Test_Color:240,100,100:abc
418 cmd0 = cmdTags.get(0).getCommand();
420 assertEquals(HSBType.class, cmd0.getClass());
422 // BEGIN:Calendar_Test_Contact:OPEN:abc
423 cmd1 = cmdTags.get(1).getCommand();
425 assertEquals(OpenClosedType.class, cmd1.getClass());
427 // BEGIN:Calendar_Test_Dimmer:50%:abc
428 cmd2 = cmdTags.get(2).getCommand();
430 assertEquals(PercentType.class, cmd2.getClass());
432 // BEGIN:Calendar_Test_Number:-0:abc
433 cmd3 = cmdTags.get(3).getCommand();
435 assertEquals(DecimalType.class, cmd3.getClass());
437 // BEGIN:Calendar_Test_Temperature:0K:abc
438 cmd4 = cmdTags.get(4).getCommand();
440 assertEquals(QuantityType.class, cmd4.getClass());
442 // BEGIN:Calendar_Test_Pressure:12.3hPa:abc
443 cmd5 = cmdTags.get(5).getCommand();
445 assertEquals(QuantityType.class, cmd5.getClass());
447 // BEGIN:Calendar_Test_Speed:12.3km/h:abc
448 cmd6 = cmdTags.get(6).getCommand();
450 assertEquals(QuantityType.class, cmd6.getClass());
452 // BEGIN:Calendar_Test_Player:PLAY:abc
453 cmd7 = cmdTags.get(7).getCommand();
455 assertEquals(PlayPauseType.class, cmd7.getClass());
457 // BEGIN:Calendar_Test_RollerShutter:50%:abc
458 cmd8 = cmdTags.get(8).getCommand();
460 assertEquals(PercentType.class, cmd8.getClass());
462 // BEGIN:Calendar_Test_String:Test Series #5:abc
463 cmd9 = cmdTags.get(9).getCommand();
465 assertEquals(StringType.class, cmd9.getClass());
467 // BEGIN:Calendar_Test_Switch:ON:abc
468 cmd10 = cmdTags.get(10).getCommand();
469 assertNotNull(cmd10);
470 assertEquals(OnOffType.class, cmd10.getClass());
472 // test bad command tag syntax: Test Series #6
473 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:40:00Z"),
474 Instant.parse("2020-01-28T20:50:00Z"));
475 assertNotNull(events);
476 assertEquals(1, events.size());
477 cmdTags = events.get(0).commandTags;
478 // Test Series #6 contains only "bad" command tags as follows..
480 // tags with wrong case prefix..
485 // tags that are missing ":" field delimiters..
488 // tags with too few field delimiters..
491 // tags with too many field delimiters..
492 // BEGIN:www:xxx:yyy:zzz
494 // tags with an invalid prefix..
495 // BEGINX:xxx:yyy:zzz
497 // BEGIN :xxx:yyy:zzz
498 // BEGIN :xxx:yyy:zzz
500 // tags with an empty Item Name
505 // tags with bad Item Name
510 // tags with an empty Target State value
515 // Note: All of the above tags must be rejected! => Assert cmdTags.size() == 0 !
517 assertEquals(0, cmdTags.size());
519 // test HTML command tag syntax: Test Series #7
520 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:55:00Z"),
521 Instant.parse("2020-01-28T21:05:00Z"));
522 assertNotNull(events);
523 assertEquals(1, events.size());
524 cmdTags = events.get(0).commandTags;
525 assertEquals(8, cmdTags.size());
527 // <p>BEGIN:Calendar_Test_Temperature:12.3°C:abc</p>
528 cmd0 = cmdTags.get(0).getCommand();
530 assertEquals(QuantityType.class, cmd0.getClass());
532 // <p>END:Calendar_Test_Temperature:23.4°C:abc</p>
533 cmd1 = cmdTags.get(1).getCommand();
535 assertEquals(QuantityType.class, cmd1.getClass());
537 // <p>BEGIN:Calendar_Test_Switch:ON:abc</p>
538 cmd2 = cmdTags.get(2).getCommand();
540 assertEquals(OnOffType.class, cmd2.getClass());
542 // <p>END:Calendar_Test_Switch:OFF:abc</p>
543 cmd3 = cmdTags.get(3).getCommand();
545 assertEquals(OnOffType.class, cmd3.getClass());
547 // <p>BEGIN:Calendar_Test_String:the quick:abc</p>
548 cmd4 = cmdTags.get(4).getCommand();
550 assertEquals(StringType.class, cmd4.getClass());
552 // <p>END:Calendar_Test_String:brown fox:abc</p>
553 cmd5 = cmdTags.get(5).getCommand();
555 assertEquals(StringType.class, cmd5.getClass());
557 // </p><p>BEGIN:Calendar_Test_Number:12.3:abc</p>
558 cmd6 = cmdTags.get(6).getCommand();
560 assertEquals(DecimalType.class, cmd6.getClass());
562 // <p>END:Calendar_Test_Number:23.4:abc</p>
563 cmd7 = cmdTags.get(7).getCommand();
565 assertEquals(DecimalType.class, cmd7.getClass());
568 @SuppressWarnings("null")
570 public void testGetFilteredEventsBetween() {
571 Event[] expectedFilteredEvents1 = new Event[] {
572 new Event("Test Series in UTC", Instant.parse("2019-09-12T09:05:00Z"),
573 Instant.parse("2019-09-12T09:10:00Z"), ""),
574 new Event("Test Event in UTC+2", Instant.parse("2019-09-14T08:00:00Z"),
575 Instant.parse("2019-09-14T09:00:00Z"), "") };
576 List<Event> realFilteredEvents1 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-12T06:00:00Z"),
577 Instant.parse("2019-09-15T06:00:00Z"), null, 3);
578 assertArrayEquals(expectedFilteredEvents1, realFilteredEvents1.toArray(new Event[0]));
580 Event[] expectedFilteredEvents2 = new Event[] {
581 new Event("Evt", Instant.parse("2019-11-10T10:00:00Z"), Instant.parse("2019-11-10T11:45:00Z"), ""),
582 new Event("Evt", Instant.parse("2019-11-17T10:00:00Z"), Instant.parse("2019-11-17T11:45:00Z"), ""),
583 new Event("Evt", Instant.parse("2019-12-01T10:00:00Z"), Instant.parse("2019-12-01T11:45:00Z"), "") };
584 List<Event> realFilteredEvents2 = calendar2.getFilteredEventsBetween(Instant.parse("2019-11-08T06:00:00Z"),
585 Instant.parse("2019-12-31T06:00:00Z"), null, 3);
586 assertArrayEquals(expectedFilteredEvents2, realFilteredEvents2.toArray(new Event[] {}));
588 Event[] expectedFilteredEvents3 = new Event[] { new Event("Test Event in UTC+2",
589 Instant.parse("2019-09-14T08:00:00Z"), Instant.parse("2019-09-14T09:00:00Z"), "") };
590 List<Event> realFilteredEvents3 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-12T06:00:00Z"),
591 Instant.parse("2019-09-15T06:00:00Z"),
592 new EventTextFilter(EventTextFilter.Field.SUMMARY, "utc+2", EventTextFilter.Type.TEXT), 3);
593 assertArrayEquals(expectedFilteredEvents3, realFilteredEvents3.toArray(new Event[] {}));
595 Event[] expectedFilteredEvents4 = new Event[] { new Event("Test Series in UTC",
596 Instant.parse("2019-09-12T09:05:00Z"), Instant.parse("2019-09-12T09:10:00Z"), "") };
597 List<Event> realFilteredEvents4 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-12T06:00:00Z"),
598 Instant.parse("2019-09-15T06:00:00Z"),
599 new EventTextFilter(EventTextFilter.Field.SUMMARY, ".*UTC$", EventTextFilter.Type.REGEX), 3);
600 assertArrayEquals(expectedFilteredEvents4, realFilteredEvents4.toArray(new Event[] {}));
602 List<Event> realFilteredEvents5 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-15T06:00:00Z"),
603 Instant.parse("2019-09-12T06:00:00Z"), null, 3);
604 assertEquals(0, realFilteredEvents5.size());
606 List<Event> realFilteredEvents6 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-15T06:00:00Z"),
607 Instant.parse("2019-12-31T00:00:00Z"), null, 3);
608 assertEquals(0, realFilteredEvents6.size());
610 List<Event> realFilteredEvents7 = calendar_issue9647.getFilteredEventsBetween(
611 LocalDate.parse("2021-01-01").atStartOfDay(ZoneId.systemDefault()).toInstant(),
612 LocalDate.parse("2021-01-02").atStartOfDay(ZoneId.systemDefault()).toInstant(), null, 3);
613 assertEquals(0, realFilteredEvents7.size());
615 Event[] expectedFilteredEvents8 = new Event[] {
616 new Event("Restabfall", LocalDate.parse("2021-01-04").atStartOfDay(ZoneId.systemDefault()).toInstant(),
617 LocalDate.parse("2021-01-05").atStartOfDay(ZoneId.systemDefault()).toInstant(), ""),
618 new Event("Gelbe Tonne", LocalDate.parse("2021-01-04").atStartOfDay(ZoneId.systemDefault()).toInstant(),
619 LocalDate.parse("2021-01-05").atStartOfDay(ZoneId.systemDefault()).toInstant(), "") };
620 List<Event> realFilteredEvents8 = calendar_issue9647.getFilteredEventsBetween(
621 LocalDate.parse("2021-01-04").atStartOfDay(ZoneId.systemDefault()).toInstant(),
622 LocalDate.parse("2021-01-05").atStartOfDay(ZoneId.systemDefault()).toInstant(), null, 3);
623 assertArrayEquals(expectedFilteredEvents8, realFilteredEvents8.toArray(new Event[] {}));