From 07718045946a6bbb6a222034839be23f00d27c57 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Tue, 30 Jun 2020 18:21:58 +0200 Subject: [PATCH] Fix #838 TimeZone-less DTSTART and DTEND not changed to GMT in native mode with GraalVM 20.1.0+ --- .../component/dataformat/it/ICalUtils.java | 18 +++------------ .../dataformat/it/DataformatTest.java | 22 ++++++++++++++++--- .../dataformat/src/test/resources/test.ics | 6 ++--- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java b/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java index 7cfc018e832b..b13ec412f8a2 100644 --- a/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java +++ b/integration-tests/dataformat/src/main/java/org/apache/camel/quarkus/component/dataformat/it/ICalUtils.java @@ -22,11 +22,9 @@ import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.DateTime; import net.fortuna.ical4j.model.PropertyList; -import net.fortuna.ical4j.model.TimeZone; import net.fortuna.ical4j.model.TimeZoneRegistry; import net.fortuna.ical4j.model.TimeZoneRegistryFactory; import net.fortuna.ical4j.model.component.VEvent; -import net.fortuna.ical4j.model.component.VTimeZone; import net.fortuna.ical4j.model.parameter.Cn; import net.fortuna.ical4j.model.parameter.Role; import net.fortuna.ical4j.model.property.Attendee; @@ -36,6 +34,7 @@ import net.fortuna.ical4j.model.property.DtStart; import net.fortuna.ical4j.model.property.ProdId; import net.fortuna.ical4j.model.property.Summary; +import net.fortuna.ical4j.model.property.TzId; import net.fortuna.ical4j.model.property.Uid; import net.fortuna.ical4j.model.property.Version; @@ -45,8 +44,6 @@ protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime // Create a TimeZone TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); String tzId = start.getZone().getId(); - TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId); - VTimeZone tz = timezone.getVTimeZone(); // Create the event PropertyList propertyList = new PropertyList(); @@ -59,7 +56,7 @@ protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime VEvent meeting = new VEvent(propertyList); // add timezone info.. - meeting.getProperties().add(tz.getTimeZoneId()); + meeting.getProperties().add(new TzId(tzId)); // generate unique identifier.. meeting.getProperties().add(new Uid("00000000")); @@ -82,16 +79,7 @@ protected static Calendar createTestCalendar(ZonedDateTime start, ZonedDateTime } static DateTime toDateTime(ZonedDateTime zonedDateTime, TimeZoneRegistry registry) { - final String tzId = zonedDateTime.getZone().getId(); - final TimeZone timezone = registry.getTimeZone(tzId.equals("Z") ? "UTC" : tzId); - // workaround for https://github.com/apache/camel-quarkus/issues/838 - final DateTime result = new DateTime(); - result.setTimeZone(timezone); - result.setTime(zonedDateTime.toInstant().toEpochMilli()); - // To reproduce https://github.com/apache/camel-quarkus/issues/838 comment the above, enable the following - // and remove the TZ from DTSTART and DTEND in src/test/resources/test.ics - // final DateTime result = new DateTime(zonedDateTime.toInstant().toEpochMilli()); - return result; + return new DateTime(zonedDateTime.toInstant().toEpochMilli()); } } diff --git a/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java b/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java index 147cb35f01c4..5556571bfae6 100644 --- a/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java +++ b/integration-tests/dataformat/src/test/java/org/apache/camel/quarkus/component/dataformat/it/DataformatTest.java @@ -19,7 +19,10 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.stream.Stream; import io.quarkus.test.junit.QuarkusTest; @@ -59,10 +62,15 @@ public void snakeYaml(String route) { @Test public void ical() throws ParseException, IOException { - final ZonedDateTime START = ZonedDateTime.parse("2007-12-03T10:15:30+01:00[Europe/Paris]"); - final ZonedDateTime END = ZonedDateTime.parse("2007-12-03T11:16:31+01:00[Europe/Paris]"); + final ZonedDateTime START = LocalDateTime.of(2007, 12, 3, 10, 15, 30).atZone(ZoneId.systemDefault()); + final ZonedDateTime END = LocalDateTime.of(2007, 12, 03, 11, 16, 31).atZone(ZoneId.systemDefault()); - final String icalString = IOUtils.toString(getClass().getResourceAsStream("/test.ics"), StandardCharsets.UTF_8); + final String icsTemplate = IOUtils.toString(getClass().getResourceAsStream("/test.ics"), StandardCharsets.UTF_8); + final String icalString = String.format( + icsTemplate, + toFormatedLocalDateTime(START), + toFormatedLocalDateTime(END), + START.getZone().getId()); final String actualIcal = RestAssured .given() @@ -87,4 +95,12 @@ public void ical() throws ParseException, IOException { Assertions.assertEquals(icalString, body.replace("\r", "")); } + static String toFormatedLocalDateTime(ZonedDateTime zonedDateTime) { + String result = zonedDateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd'T'hhmmss")); + if (zonedDateTime.getZone().getId().equals("Etc/UTC")) { + result += "Z"; + } + return result; + } + } diff --git a/integration-tests/dataformat/src/test/resources/test.ics b/integration-tests/dataformat/src/test/resources/test.ics index 6bb9d714fae0..c730b9af1104 100644 --- a/integration-tests/dataformat/src/test/resources/test.ics +++ b/integration-tests/dataformat/src/test/resources/test.ics @@ -4,10 +4,10 @@ PRODID:-//Events Calendar//iCal4j 1.0//EN CALSCALE:GREGORIAN BEGIN:VEVENT DTSTAMP:19700101T000000Z -DTSTART;TZID=Europe/Paris:20071203T101530 -DTEND;TZID=Europe/Paris:20071203T111631 +DTSTART:%s +DTEND:%s SUMMARY:Progress Meeting -TZID:Europe/Paris +TZID:%s UID:00000000 ATTENDEE;ROLE=REQ-PARTICIPANT;CN=dev1@mycompany:mailto:dev1@mycompany END:VEVENT