2 * Copyright (c) 2010-2023 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;
52 private AbstractPresentableCalendar calendar_issue11084;
55 public void setUp() throws IOException, CalendarException {
56 calendar = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test.ics"));
57 calendar2 = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test2.ics"));
58 calendar3 = new BiweeklyPresentableCalendar(new FileInputStream("src/test/resources/test3.ics"));
59 calendar_issue9647 = new BiweeklyPresentableCalendar(
60 new FileInputStream("src/test/resources/test-issue9647.ics"));
61 calendar_issue10808 = new BiweeklyPresentableCalendar(
62 new FileInputStream("src/test/resources/test-issue10808.ics"));
63 calendar_issue11084 = new BiweeklyPresentableCalendar(
64 new FileInputStream("src/test/resources/test-issue11084.ics"));
68 * Tests recurrence and whether TimeZone is interpolated in a right way.
71 public void testIsEventPresent() {
73 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-08T09:04:00Z")));
74 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-08T09:08:00Z")));
75 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-08T09:11:00Z")));
77 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-09T09:04:00Z")));
78 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-09T09:08:00Z")));
79 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-09T09:11:00Z")));
81 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-10T09:04:00Z")));
82 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-10T09:08:00Z")));
83 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-10T09:11:00Z")));
85 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-11T09:04:00Z")));
86 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-11T09:08:00Z")));
87 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-11T09:11:00Z")));
89 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-12T09:04:00Z")));
90 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-12T09:08:00Z")));
91 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-12T09:11:00Z")));
93 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-13T09:04:00Z")));
94 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-13T09:08:00Z")));
95 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-13T09:11:00Z")));
97 // Test in CEST (UTC+2)
98 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-14T07:59:00Z")));
99 assertTrue(calendar.isEventPresent(Instant.parse("2019-09-14T08:03:00Z")));
100 assertFalse(calendar.isEventPresent(Instant.parse("2019-09-14T09:01:00Z")));
102 // Test Series with cancelled event by Davdroid
103 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-03T09:55:00Z")));
104 assertTrue(calendar2.isEventPresent(Instant.parse("2019-11-03T10:01:00Z")));
105 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-03T13:00:00Z")));
107 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-24T09:55:00Z")));
108 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-24T10:01:00Z")));
109 assertFalse(calendar2.isEventPresent(Instant.parse("2019-11-24T13:00:00Z")));
113 * This test relies on a working isEventPresent and assumes the calculation
114 * of recurrence is done the same way.
117 public void testGetCurrentEvent() {
118 Event currentEvent = calendar.getCurrentEvent(Instant.parse("2019-09-10T09:07:00Z"));
119 assertNotNull(currentEvent);
120 assertTrue("Test Series in UTC".contentEquals(currentEvent.title));
121 assertEquals(0, Instant.parse("2019-09-10T09:05:00Z").compareTo(currentEvent.start));
122 assertEquals(0, Instant.parse("2019-09-10T09:10:00Z").compareTo(currentEvent.end));
124 Event nonExistingEvent = calendar.getCurrentEvent(Instant.parse("2019-09-09T09:07:00Z"));
125 assertNull(nonExistingEvent);
127 Event currentEvent2 = calendar_issue10808.getCurrentEvent(Instant.parse("2021-06-05T17:10:05Z"));
128 assertNotNull(currentEvent2);
129 assertTrue("Test event 1".contentEquals(currentEvent2.title));
131 Event currentEvent3 = calendar_issue10808.getCurrentEvent(Instant.parse("2021-06-05T17:13:05Z"));
132 assertNotNull(currentEvent3);
133 assertTrue("Test event 2".contentEquals(currentEvent3.title));
135 Event currentEvent4 = calendar_issue10808.getCurrentEvent(Instant.parse("2021-06-05T17:18:05Z"));
136 assertNotNull(currentEvent4);
137 assertTrue("Test event 1".contentEquals(currentEvent4.title));
139 Event currentEvent5 = calendar_issue11084.getCurrentEvent(Instant.parse("2021-08-16T16:30:05Z"));
140 assertNull(currentEvent5);
142 Event currentEvent6 = calendar_issue11084.getCurrentEvent(Instant.parse("2021-08-16T16:45:05Z"));
143 assertNotNull(currentEvent6);
144 assertTrue("TEST_REPEATING_EVENT_3".contentEquals(currentEvent6.title));
148 * This test relies on a working isEventPresent and assumes the calculation
149 * of recurrence is done the same way.
152 public void testGetNextEvent() {
153 // positive case: next event of series
154 Event nextEventOfSeries = calendar.getNextEvent(Instant.parse("2019-09-10T09:07:00Z"));
155 assertNotNull(nextEventOfSeries);
156 assertTrue("Test Series in UTC".contentEquals(nextEventOfSeries.title));
157 assertEquals(0, Instant.parse("2019-09-11T09:05:00Z").compareTo(nextEventOfSeries.start));
158 assertEquals(0, Instant.parse("2019-09-11T09:10:00Z").compareTo(nextEventOfSeries.end));
160 // positive case: next event after series
161 Event nextEventOutsideSeries = calendar.getNextEvent(Instant.parse("2019-09-12T09:07:00Z"));
162 assertNotNull(nextEventOutsideSeries);
163 assertTrue("Test Event in UTC+2".contentEquals(nextEventOutsideSeries.title));
164 assertEquals(0, Instant.parse("2019-09-14T08:00:00Z").compareTo(nextEventOutsideSeries.start));
165 assertEquals(0, Instant.parse("2019-09-14T09:00:00Z").compareTo(nextEventOutsideSeries.end));
167 // positive case: next event should be also set if currently none is present
168 Event nextEventIndependent = calendar.getNextEvent(Instant.parse("2019-09-13T09:07:00Z"));
169 assertTrue(nextEventOutsideSeries.equals(nextEventIndependent));
171 // negative case: after last event there is no next
172 Event nonExistingEvent = calendar.getNextEvent(Instant.parse("2019-09-14T12:00:00Z"));
173 assertNull(nonExistingEvent);
175 // mixed case: cancelled events also not show up as next
176 Event nextEventAfterCancelled = calendar2.getNextEvent(Instant.parse("2019-11-24T09:55:00Z"));
177 assertNotNull(nextEventAfterCancelled);
178 assertEquals(0, Instant.parse("2019-12-01T10:00:00Z").compareTo(nextEventAfterCancelled.start));
182 * This test checks for Events that have just begun or ended, and if so it checks for Command Tags
183 * and checks if these tags are valid
185 @SuppressWarnings("null")
187 public void testCommandTagCode() {
188 List<Event> events = null;
190 int tagsPerEvent = 8;
192 // test just begun events: first in the series
193 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"),
194 Instant.parse("2020-01-28T16:05:00Z"));
195 assertNotNull(events);
196 assertEquals(eventCount, events.size());
197 for (Event event : events) {
198 List<CommandTag> cmdTags = event.commandTags;
199 assertEquals(tagsPerEvent, cmdTags.size());
201 for (CommandTag cmdTag : cmdTags) {
202 if (cmdTag.getTagType() == CommandTagType.BEGIN) {
203 assertTrue(cmdTag.isAuthorized("abc"));
204 assertTrue(cmdTag.getItemName().matches("^\\w+$"));
205 assertTrue(cmdTag.getCommand() != null);
209 assertEquals(tagsPerEvent / 2, beginTags);
212 // test just begun events: third in the series
213 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-30T15:55:00Z"),
214 Instant.parse("2020-01-30T16:05:00Z"));
215 assertNotNull(events);
216 assertEquals(eventCount, events.size());
217 for (Event event : events) {
218 List<CommandTag> cmdTags = event.commandTags;
219 assertEquals(tagsPerEvent, cmdTags.size());
221 for (CommandTag cmdTag : cmdTags) {
222 if (cmdTag.getTagType() == CommandTagType.BEGIN) {
223 assertTrue(cmdTag.isAuthorized("abc"));
224 assertTrue(cmdTag.getItemName().matches("^\\w+$"));
225 assertTrue(cmdTag.getCommand() != null);
229 assertEquals(tagsPerEvent / 2, beginTags);
232 // test outside of window: begun events, too early
233 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:50:00Z"),
234 Instant.parse("2020-01-28T15:55:00Z"));
235 assertNotNull(events);
236 assertEquals(0, events.size());
238 // test outside of window: begun events, too late
239 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T16:05:00Z"),
240 Instant.parse("2020-01-28T16:10:00Z"));
241 assertNotNull(events);
242 assertEquals(0, events.size());
244 // test just ended events: first in the series
245 events = calendar3.getJustEndedEvents(Instant.parse("2020-01-28T16:25:00Z"),
246 Instant.parse("2020-01-28T16:35:00Z"));
247 assertNotNull(events);
248 assertEquals(eventCount, events.size());
249 for (Event event : events) {
250 List<CommandTag> cmdTags = event.commandTags;
251 assertEquals(tagsPerEvent, cmdTags.size());
253 for (CommandTag cmdTag : cmdTags) {
254 if (cmdTag.getTagType() == CommandTagType.END) {
255 assertTrue(cmdTag.isAuthorized("abc"));
256 assertTrue(cmdTag.getItemName().matches("^\\w+$"));
257 assertTrue(cmdTag.getCommand() != null);
261 assertEquals(tagsPerEvent / 2, endTags);
264 // test outside of window: ended events, too early
265 events = calendar3.getJustEndedEvents(Instant.parse("2020-01-28T16:20:00Z"),
266 Instant.parse("2020-01-28T16:25:00Z"));
267 assertNotNull(events);
268 assertEquals(0, events.size());
270 // test outside of window: ended events, too late
271 events = calendar3.getJustEndedEvents(Instant.parse("2020-01-28T16:35:00Z"),
272 Instant.parse("2020-01-28T16:40:00Z"));
273 assertNotNull(events);
274 assertEquals(0, events.size());
276 // test a valid just begun event with both good and bad authorization codes
277 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T15:55:00Z"),
278 Instant.parse("2020-01-28T16:05:00Z"));
279 assertNotNull(events);
280 assertTrue(!events.isEmpty());
281 List<CommandTag> cmdTags = events.get(0).commandTags;
282 assertTrue(!cmdTags.isEmpty());
283 CommandTag cmd = cmdTags.get(0);
284 // accept correct, empty or null configuration codes
285 assertTrue(cmd.isAuthorized("abc"));
286 assertTrue(cmd.isAuthorized(""));
287 assertTrue(cmd.isAuthorized(null));
288 // reject incorrect configuration code
289 assertFalse(cmd.isAuthorized("123"));
291 // test tag syntax: Test Series #1
292 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T19:25:00Z"),
293 Instant.parse("2020-01-28T19:35:00Z"));
294 assertNotNull(events);
295 assertEquals(1, events.size());
296 cmdTags = events.get(0).commandTags;
297 assertEquals(11, cmdTags.size());
299 // BEGIN:Calendar_Test_Color:ON:abc
300 assertEquals("Calendar_Test_Color", cmdTags.get(0).getItemName());
301 assertTrue(cmdTags.get(0).isAuthorized("abc"));
302 Command cmd0 = cmdTags.get(0).getCommand();
304 assertEquals(OnOffType.class, cmd0.getClass());
306 // BEGIN:Calendar_Test_Contact:OPEN:abc
307 Command cmd1 = cmdTags.get(1).getCommand();
309 assertEquals(OpenClosedType.class, cmd1.getClass());
311 // BEGIN:Calendar_Test_Dimmer:ON:abc
312 Command cmd2 = cmdTags.get(2).getCommand();
314 assertEquals(OnOffType.class, cmd2.getClass());
316 // BEGIN:Calendar_Test_Number:12.3:abc
317 Command cmd3 = cmdTags.get(3).getCommand();
319 assertEquals(DecimalType.class, cmd3.getClass());
321 // BEGIN:Calendar_Test_Temperature:12.3°C:abc
322 Command cmd4 = cmdTags.get(4).getCommand();
324 assertEquals(QuantityType.class, cmd4.getClass());
326 // BEGIN:Calendar_Test_Pressure:12.3hPa:abc
327 Command cmd5 = cmdTags.get(5).getCommand();
329 assertEquals(QuantityType.class, cmd5.getClass());
331 // BEGIN:Calendar_Test_Speed:12.3m/s:abc
332 Command cmd6 = cmdTags.get(6).getCommand();
334 assertEquals(QuantityType.class, cmd6.getClass());
336 // BEGIN:Calendar_Test_Player:PLAY:abc
337 Command cmd7 = cmdTags.get(7).getCommand();
339 assertEquals(PlayPauseType.class, cmd7.getClass());
341 // BEGIN:Calendar_Test_RollerShutter:UP:abc
342 Command cmd8 = cmdTags.get(8).getCommand();
344 assertEquals(UpDownType.class, cmd8.getClass());
346 // BEGIN:Calendar_Test_String:Test Series #1:abc
347 Command cmd9 = cmdTags.get(9).getCommand();
349 assertEquals(StringType.class, cmd9.getClass());
351 // BEGIN:Calendar_Test_Switch:ON:abc
352 Command cmd10 = cmdTags.get(10).getCommand();
353 assertNotNull(cmd10);
354 assertEquals(OnOffType.class, cmd10.getClass());
356 // test tag syntax: Test Series #4
357 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:10:00Z"),
358 Instant.parse("2020-01-28T20:20:00Z"));
359 assertNotNull(events);
360 assertEquals(1, events.size());
361 cmdTags = events.get(0).commandTags;
362 assertEquals(11, cmdTags.size());
364 // BEGIN:Calendar_Test_Color:0%:abc
365 cmd0 = cmdTags.get(0).getCommand();
367 assertEquals(PercentType.class, cmd0.getClass());
369 // BEGIN:Calendar_Test_Contact:CLOSED:abc
370 cmd1 = cmdTags.get(1).getCommand();
372 assertEquals(OpenClosedType.class, cmd1.getClass());
374 // BEGIN:Calendar_Test_Dimmer:0%:abc
375 cmd2 = cmdTags.get(2).getCommand();
377 assertEquals(PercentType.class, cmd2.getClass());
379 // BEGIN:Calendar_Test_Number:-12.3:abc
380 cmd3 = cmdTags.get(3).getCommand();
382 assertEquals(DecimalType.class, cmd3.getClass());
384 // BEGIN:Calendar_Test_Temperature:-12.3°C:abc
385 cmd4 = cmdTags.get(4).getCommand();
387 assertEquals(QuantityType.class, cmd4.getClass());
389 // BEGIN:Calendar_Test_Pressure:500mmHg:abc
390 cmd5 = cmdTags.get(5).getCommand();
392 assertEquals(QuantityType.class, cmd5.getClass());
394 // BEGIN:Calendar_Test_Speed:12300000mm/h:abc
395 cmd6 = cmdTags.get(6).getCommand();
397 assertEquals(QuantityType.class, cmd6.getClass());
399 // BEGIN:Calendar_Test_Player:REWIND:abc
400 cmd7 = cmdTags.get(7).getCommand();
402 assertEquals(RewindFastforwardType.class, cmd7.getClass());
404 // BEGIN:Calendar_Test_RollerShutter:100%:abc
405 cmd8 = cmdTags.get(8).getCommand();
407 assertEquals(PercentType.class, cmd8.getClass());
409 // BEGIN:Calendar_Test_String:Test Series #4:abc
410 cmd9 = cmdTags.get(9).getCommand();
412 assertEquals(StringType.class, cmd9.getClass());
414 // BEGIN:Calendar_Test_Switch:OFF:abc
415 cmd10 = cmdTags.get(10).getCommand();
416 assertNotNull(cmd10);
417 assertEquals(OnOffType.class, cmd10.getClass());
419 // test tag syntax: Test Series #5
420 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:25:00Z"),
421 Instant.parse("2020-01-28T20:35:00Z"));
422 assertNotNull(events);
423 assertEquals(1, events.size());
424 cmdTags = events.get(0).commandTags;
425 assertEquals(11, cmdTags.size());
427 // BEGIN:Calendar_Test_Color:240,100,100:abc
428 cmd0 = cmdTags.get(0).getCommand();
430 assertEquals(HSBType.class, cmd0.getClass());
432 // BEGIN:Calendar_Test_Contact:OPEN:abc
433 cmd1 = cmdTags.get(1).getCommand();
435 assertEquals(OpenClosedType.class, cmd1.getClass());
437 // BEGIN:Calendar_Test_Dimmer:50%:abc
438 cmd2 = cmdTags.get(2).getCommand();
440 assertEquals(PercentType.class, cmd2.getClass());
442 // BEGIN:Calendar_Test_Number:-0:abc
443 cmd3 = cmdTags.get(3).getCommand();
445 assertEquals(DecimalType.class, cmd3.getClass());
447 // BEGIN:Calendar_Test_Temperature:0K:abc
448 cmd4 = cmdTags.get(4).getCommand();
450 assertEquals(QuantityType.class, cmd4.getClass());
452 // BEGIN:Calendar_Test_Pressure:12.3hPa:abc
453 cmd5 = cmdTags.get(5).getCommand();
455 assertEquals(QuantityType.class, cmd5.getClass());
457 // BEGIN:Calendar_Test_Speed:12.3km/h:abc
458 cmd6 = cmdTags.get(6).getCommand();
460 assertEquals(QuantityType.class, cmd6.getClass());
462 // BEGIN:Calendar_Test_Player:PLAY:abc
463 cmd7 = cmdTags.get(7).getCommand();
465 assertEquals(PlayPauseType.class, cmd7.getClass());
467 // BEGIN:Calendar_Test_RollerShutter:50%:abc
468 cmd8 = cmdTags.get(8).getCommand();
470 assertEquals(PercentType.class, cmd8.getClass());
472 // BEGIN:Calendar_Test_String:Test Series #5:abc
473 cmd9 = cmdTags.get(9).getCommand();
475 assertEquals(StringType.class, cmd9.getClass());
477 // BEGIN:Calendar_Test_Switch:ON:abc
478 cmd10 = cmdTags.get(10).getCommand();
479 assertNotNull(cmd10);
480 assertEquals(OnOffType.class, cmd10.getClass());
482 // test bad command tag syntax: Test Series #6
483 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:40:00Z"),
484 Instant.parse("2020-01-28T20:50:00Z"));
485 assertNotNull(events);
486 assertEquals(1, events.size());
487 cmdTags = events.get(0).commandTags;
488 // Test Series #6 contains only "bad" command tags as follows..
490 // tags with wrong case prefix..
495 // tags that are missing ":" field delimiters..
498 // tags with too few field delimiters..
501 // tags with too many field delimiters..
502 // BEGIN:www:xxx:yyy:zzz
504 // tags with an invalid prefix..
505 // BEGINX:xxx:yyy:zzz
507 // BEGIN :xxx:yyy:zzz
508 // BEGIN :xxx:yyy:zzz
510 // tags with an empty Item Name
515 // tags with bad Item Name
520 // tags with an empty Target State value
525 // Note: All of the above tags must be rejected! => Assert cmdTags.size() == 0 !
527 assertEquals(0, cmdTags.size());
529 // test HTML command tag syntax: Test Series #7
530 events = calendar3.getJustBegunEvents(Instant.parse("2020-01-28T20:55:00Z"),
531 Instant.parse("2020-01-28T21:05:00Z"));
532 assertNotNull(events);
533 assertEquals(1, events.size());
534 cmdTags = events.get(0).commandTags;
535 assertEquals(8, cmdTags.size());
537 // <p>BEGIN:Calendar_Test_Temperature:12.3°C:abc</p>
538 cmd0 = cmdTags.get(0).getCommand();
540 assertEquals(QuantityType.class, cmd0.getClass());
542 // <p>END:Calendar_Test_Temperature:23.4°C:abc</p>
543 cmd1 = cmdTags.get(1).getCommand();
545 assertEquals(QuantityType.class, cmd1.getClass());
547 // <p>BEGIN:Calendar_Test_Switch:ON:abc</p>
548 cmd2 = cmdTags.get(2).getCommand();
550 assertEquals(OnOffType.class, cmd2.getClass());
552 // <p>END:Calendar_Test_Switch:OFF:abc</p>
553 cmd3 = cmdTags.get(3).getCommand();
555 assertEquals(OnOffType.class, cmd3.getClass());
557 // <p>BEGIN:Calendar_Test_String:the quick:abc</p>
558 cmd4 = cmdTags.get(4).getCommand();
560 assertEquals(StringType.class, cmd4.getClass());
562 // <p>END:Calendar_Test_String:brown fox:abc</p>
563 cmd5 = cmdTags.get(5).getCommand();
565 assertEquals(StringType.class, cmd5.getClass());
567 // </p><p>BEGIN:Calendar_Test_Number:12.3:abc</p>
568 cmd6 = cmdTags.get(6).getCommand();
570 assertEquals(DecimalType.class, cmd6.getClass());
572 // <p>END:Calendar_Test_Number:23.4:abc</p>
573 cmd7 = cmdTags.get(7).getCommand();
575 assertEquals(DecimalType.class, cmd7.getClass());
577 // issue 11084: Command tags from moved events are also executed
578 List<Event> events2 = calendar_issue11084.getJustBegunEvents(Instant.parse("2021-08-16T16:29:55Z"),
579 Instant.parse("2021-08-16T17:00:05Z"));
580 assertEquals(1, events2.size());
581 assertEquals(Instant.parse("2021-08-16T16:45:00Z"), events2.get(0).start);
583 List<Event> events3 = calendar_issue11084.getJustEndedEvents(Instant.parse("2021-08-16T16:29:55Z"),
584 Instant.parse("2021-08-16T17:00:05Z"));
585 assertEquals(1, events3.size());
586 assertEquals(Instant.parse("2021-08-16T17:00:00Z"), events3.get(0).end);
589 @SuppressWarnings("null")
591 public void testGetFilteredEventsBetween() {
592 Event[] expectedFilteredEvents1 = new Event[] {
593 new Event("Test Series in UTC", Instant.parse("2019-09-12T09:05:00Z"),
594 Instant.parse("2019-09-12T09:10:00Z"), ""),
595 new Event("Test Event in UTC+2", Instant.parse("2019-09-14T08:00:00Z"),
596 Instant.parse("2019-09-14T09:00:00Z"), "") };
597 List<Event> realFilteredEvents1 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-12T06:00:00Z"),
598 Instant.parse("2019-09-15T06:00:00Z"), null, 3);
599 assertArrayEquals(expectedFilteredEvents1, realFilteredEvents1.toArray(new Event[0]));
601 Event[] expectedFilteredEvents2 = new Event[] {
602 new Event("Evt", Instant.parse("2019-11-10T10:00:00Z"), Instant.parse("2019-11-10T11:45:00Z"), ""),
603 new Event("Evt", Instant.parse("2019-11-17T10:00:00Z"), Instant.parse("2019-11-17T11:45:00Z"), ""),
604 new Event("Evt", Instant.parse("2019-12-01T10:00:00Z"), Instant.parse("2019-12-01T11:45:00Z"), "") };
605 List<Event> realFilteredEvents2 = calendar2.getFilteredEventsBetween(Instant.parse("2019-11-08T06:00:00Z"),
606 Instant.parse("2019-12-31T06:00:00Z"), null, 3);
607 assertArrayEquals(expectedFilteredEvents2, realFilteredEvents2.toArray(new Event[] {}));
609 Event[] expectedFilteredEvents3 = new Event[] { new Event("Test Event in UTC+2",
610 Instant.parse("2019-09-14T08:00:00Z"), Instant.parse("2019-09-14T09:00:00Z"), "") };
611 List<Event> realFilteredEvents3 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-12T06:00:00Z"),
612 Instant.parse("2019-09-15T06:00:00Z"),
613 new EventTextFilter(EventTextFilter.Field.SUMMARY, "utc+2", EventTextFilter.Type.TEXT), 3);
614 assertArrayEquals(expectedFilteredEvents3, realFilteredEvents3.toArray(new Event[] {}));
616 Event[] expectedFilteredEvents4 = new Event[] { new Event("Test Series in UTC",
617 Instant.parse("2019-09-12T09:05:00Z"), Instant.parse("2019-09-12T09:10:00Z"), "") };
618 List<Event> realFilteredEvents4 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-12T06:00:00Z"),
619 Instant.parse("2019-09-15T06:00:00Z"),
620 new EventTextFilter(EventTextFilter.Field.SUMMARY, ".*UTC$", EventTextFilter.Type.REGEX), 3);
621 assertArrayEquals(expectedFilteredEvents4, realFilteredEvents4.toArray(new Event[] {}));
623 List<Event> realFilteredEvents5 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-15T06:00:00Z"),
624 Instant.parse("2019-09-12T06:00:00Z"), null, 3);
625 assertEquals(0, realFilteredEvents5.size());
627 List<Event> realFilteredEvents6 = calendar.getFilteredEventsBetween(Instant.parse("2019-09-15T06:00:00Z"),
628 Instant.parse("2019-12-31T00:00:00Z"), null, 3);
629 assertEquals(0, realFilteredEvents6.size());
631 List<Event> realFilteredEvents7 = calendar_issue9647.getFilteredEventsBetween(
632 LocalDate.parse("2021-01-01").atStartOfDay(ZoneId.systemDefault()).toInstant(),
633 LocalDate.parse("2021-01-02").atStartOfDay(ZoneId.systemDefault()).toInstant(), null, 3);
634 assertEquals(0, realFilteredEvents7.size());
636 Event[] expectedFilteredEvents8 = new Event[] {
637 new Event("Restabfall", LocalDate.parse("2021-01-04").atStartOfDay(ZoneId.systemDefault()).toInstant(),
638 LocalDate.parse("2021-01-05").atStartOfDay(ZoneId.systemDefault()).toInstant(), ""),
639 new Event("Gelbe Tonne", LocalDate.parse("2021-01-04").atStartOfDay(ZoneId.systemDefault()).toInstant(),
640 LocalDate.parse("2021-01-05").atStartOfDay(ZoneId.systemDefault()).toInstant(), "") };
641 List<Event> realFilteredEvents8 = calendar_issue9647.getFilteredEventsBetween(
642 LocalDate.parse("2021-01-04").atStartOfDay(ZoneId.systemDefault()).toInstant(),
643 LocalDate.parse("2021-01-05").atStartOfDay(ZoneId.systemDefault()).toInstant(), null, 3);
644 assertArrayEquals(expectedFilteredEvents8, realFilteredEvents8.toArray(new Event[] {}));
646 List<Event> realFilteredEvents9 = calendar_issue11084.getFilteredEventsBetween(
647 Instant.parse("2021-08-16T16:45:00.123456Z"), Instant.parse("2021-08-16T16:46:00.768643Z"), null, 3);
648 assertEquals(0, realFilteredEvents9.size());