From cdd98ef3430516c3eab7a25ee7ba0b34a28677df Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Wed, 23 Jan 2019 11:11:51 +0100 Subject: [PATCH 1/3] fixed #222: Prevent time syncing from failing if a fork has died --- .../integrity/runner/DefaultTestRunner.java | 15 +++++++-------- .../de/gebit/integrity/runner/forking/Fork.java | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/DefaultTestRunner.java b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/DefaultTestRunner.java index 72cae76e0..0c68b7a7e 100644 --- a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/DefaultTestRunner.java +++ b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/DefaultTestRunner.java @@ -864,10 +864,8 @@ protected void initializeParameterizedConstants() { String tempValue = (parameterizedConstantValues != null) ? parameterizedConstantValues.get(tempName) : null; try { - defineConstant(tempDefinition, tempValue, - (tempDefinition.eContainer() instanceof SuiteDefinition) - ? ((SuiteDefinition) tempDefinition.eContainer()) - : null); + defineConstant(tempDefinition, tempValue, (tempDefinition.eContainer() instanceof SuiteDefinition) + ? ((SuiteDefinition) tempDefinition.eContainer()) : null); } catch (ClassNotFoundException | InstantiationException | UnexecutableException exc) { // Cannot happen - parameterized constants aren't evaluated } @@ -1575,8 +1573,7 @@ protected void defineConstant(final ConstantDefinition aDefinition, Object aValu protected void defineVariable(final VariableOrConstantEntity anEntity, Object anInitialValue, final SuiteDefinition aSuite) { final Object tempInitialValue = (anInitialValue instanceof Variable) - ? variableManager.get(((Variable) anInitialValue).getName()) - : anInitialValue; + ? variableManager.get(((Variable) anInitialValue).getName()) : anInitialValue; // We need to send variable updates to forks in the main phase here. boolean tempSendToForks = (!isFork()) && shouldExecuteFixtures(); @@ -2842,8 +2839,10 @@ protected TimeSyncResultMessage distributeTimeSyncRequest(Date aStartTime, List< tempMergedResultStackTrace += "Fork '" + IntegrityDSLUtil.getQualifiedForkName(tempFork.getDefinition()) + "' failed with:\n" + tempResultMessage.getStackTrace(); } - for (TimeSyncForkResult tempSuccessResult : tempResultMessage.getResults()) { - tempResults.put(tempSuccessResult.getForkName(), tempSuccessResult); + if (tempResultMessage != null) { + for (TimeSyncForkResult tempSuccessResult : tempResultMessage.getResults()) { + tempResults.put(tempSuccessResult.getForkName(), tempSuccessResult); + } } } diff --git a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java index 190f211cb..e6fa8183d 100644 --- a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java +++ b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/forking/Fork.java @@ -581,16 +581,23 @@ public TimeSyncResultMessage injectTestTimeState(long aRealtimeOffset, long aRea while (timeSyncResult == null) { long tempTimeLeft = TimeUnit.SECONDS.toMillis(getForkTimesyncTimeout()) - TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - tempStart); - if (tempTimeLeft > 0) { + if (tempTimeLeft > 0 && isConnected()) { + long tempWait = Math.min(1000, tempTimeLeft); try { - timeSyncResultSyncObject.wait(tempTimeLeft); + timeSyncResultSyncObject.wait(tempWait); } catch (InterruptedException exc) { // ignored } } else { - throw new RuntimeException( - "Timed out while waiting to receive time sync confirmation from fork '" - + IntegrityDSLUtil.getQualifiedForkName(getDefinition()) + "'!"); + if (!isConnected()) { + // The fork has disconnected in the mean time, which means it has either crashed or ended + // normally. In both cases, time syncing is no longer necessary. + return null; + } else { + throw new RuntimeException( + "Timed out while waiting to receive time sync confirmation from fork '" + + IntegrityDSLUtil.getQualifiedForkName(getDefinition()) + "'!"); + } } } From a74388a6ea1e067977dd5c9c2656ac8864dc2061 Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Fri, 25 Jan 2019 13:29:58 +0100 Subject: [PATCH 2/3] fixes #220: Add warning for redundant "inlined" statements --- .../integrity/validation/DSLJavaValidator.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/validation/DSLJavaValidator.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/validation/DSLJavaValidator.java index 7ea66e6ed..1a33c12c8 100644 --- a/de.gebit.integrity.dsl/src/de/gebit/integrity/validation/DSLJavaValidator.java +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/validation/DSLJavaValidator.java @@ -51,6 +51,7 @@ import de.gebit.integrity.dsl.Parameter; import de.gebit.integrity.dsl.ParameterTableHeader; import de.gebit.integrity.dsl.ParameterTableValue; +import de.gebit.integrity.dsl.Suite; import de.gebit.integrity.dsl.SuiteDefinition; import de.gebit.integrity.dsl.SuiteParameterDefinition; import de.gebit.integrity.dsl.SuiteReturnDefinition; @@ -340,6 +341,19 @@ public void checkForPrivateConstantInSuite(ConstantDefinition anEntity) { } } + /** + * Checks for redundant suite inline statements. + * + * @param aSuiteStatement + */ + @Check + public void checkSuiteStatement(Suite aSuiteStatement) { + if (aSuiteStatement.getInlined() != null && aSuiteStatement.getDefinition().getInlined() != null) { + warning("Redundant inline statement: the invoked suite is already defined as 'inlined'", + DslPackage.Literals.SUITE__INLINED); + } + } + /** * Checks for missing parameters. * From 86e68034efe0ee9be44fda96b1a50255cf3edd2d Mon Sep 17 00:00:00 2001 From: Rene Schneider Date: Fri, 25 Jan 2019 17:07:25 +0100 Subject: [PATCH 3/3] fixes #209: Add conversions for Java 8 Date/Time API --- .../DefaultModularValueConverter.java | 28 ++ .../dates/DateAndTimeValueToInstant.java | 38 +++ .../dates/DateAndTimeValueToLocalDate.java | 42 +++ .../DateAndTimeValueToLocalDateTime.java | 40 +++ .../dates/DateAndTimeValueToLocalTime.java | 42 +++ .../DateAndTimeValueToZonedDateTime.java | 39 +++ .../integrity/dates/DateValueToInstant.java | 38 +++ .../integrity/dates/DateValueToLocalDate.java | 40 +++ .../dates/DateValueToLocalDateTime.java | 40 +++ .../dates/DateValueToZonedDateTime.java | 39 +++ .../integrity/dates/TimeValueToInstant.java | 38 +++ .../dates/TimeValueToLocalDateTime.java | 39 +++ .../integrity/dates/TimeValueToLocalTime.java | 39 +++ .../dates/TimeValueToZonedDateTime.java | 39 +++ .../comparator/DefaultResultComparator.java | 86 +++++- .../integrity/fixtures/NoOpFixture.integrity | 12 + .../dates/europeanDateAndTimeValues.integrity | 66 +++++ .../dates/isoDateAndTimeValues.integrity | 51 ++++ .../dates/EuropeanDateAndTimeValues.java | 18 ++ .../basic/dates/IsoDateAndTimeValues.java | 18 ++ ...tes.europeanDateAndTimeValuesWithJava8.xml | 264 ++++++++++++++++++ ...ic.dates.isoDateAndTimeValuesWithJava8.xml | 240 ++++++++++++++++ .../tests/fixtures/basic/NoOpFixture.java | 24 ++ 23 files changed, 1318 insertions(+), 2 deletions(-) create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToInstant.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDate.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDateTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToZonedDateTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToInstant.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDate.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDateTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToZonedDateTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToInstant.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalDateTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalTime.java create mode 100644 de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToZonedDateTime.java create mode 100644 de.gebit.integrity.tests/results/integrity.basic.dates.europeanDateAndTimeValuesWithJava8.xml create mode 100644 de.gebit.integrity.tests/results/integrity.basic.dates.isoDateAndTimeValuesWithJava8.xml diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/DefaultModularValueConverter.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/DefaultModularValueConverter.java index 70d3c6318..757fd8dee 100644 --- a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/DefaultModularValueConverter.java +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/DefaultModularValueConverter.java @@ -15,24 +15,37 @@ import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToCalendar; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToDate; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToFormattedString; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToInstant; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToLocalDate; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToLocalDateTime; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToLocalTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToSQLDate; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToSQLTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToString; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToTimestamp; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateAndTimeValueToZonedDateTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToCalendar; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToDate; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToFormattedString; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToInstant; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToLocalDate; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToLocalDateTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToSQLDate; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToSQLTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToString; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToTimestamp; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.DateValueToZonedDateTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToCalendar; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToDate; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToFormattedString; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToInstant; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToLocalDateTime; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToLocalTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToSQLDate; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToSQLTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToString; import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToTimestamp; +import de.gebit.integrity.parameter.conversion.conversions.integrity.dates.TimeValueToZonedDateTime; import de.gebit.integrity.parameter.conversion.conversions.integrity.javaconstants.JavaConstantToAnything; import de.gebit.integrity.parameter.conversion.conversions.integrity.javaconstants.JavaConstantToMap; import de.gebit.integrity.parameter.conversion.conversions.integrity.nestedobjects.NestedObjectToBean; @@ -308,6 +321,21 @@ protected void initializeConversions() { addConversion(TimeValueToSQLTime.class); addConversion(TimeValueToTimestamp.class); + // Java8 date/time conversions, Integrity -> Java + addConversion(DateAndTimeValueToInstant.class); + addConversion(DateAndTimeValueToLocalDateTime.class); + addConversion(DateAndTimeValueToZonedDateTime.class); + addConversion(DateAndTimeValueToLocalDate.class); + addConversion(DateAndTimeValueToLocalTime.class); + addConversion(DateValueToInstant.class); + addConversion(DateValueToLocalDate.class); + addConversion(DateValueToLocalDateTime.class); + addConversion(DateValueToZonedDateTime.class); + addConversion(TimeValueToInstant.class); + addConversion(TimeValueToLocalDateTime.class); + addConversion(TimeValueToLocalTime.class); + addConversion(TimeValueToZonedDateTime.class); + // nested objects, Integrity -> Java addConversion(NestedObjectToMap.class); addConversion(NestedObjectToString.class); diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToInstant.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToInstant.java new file mode 100644 index 000000000..c6170aef3 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToInstant.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.Instant; +import java.util.Date; + +import de.gebit.integrity.dsl.DateAndTimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateAndTimeValueToInstant extends Conversion { + + @Override + public Instant convert(DateAndTimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return DateUtil.convertDateAndTimeValue(aSource).toInstant(); + } catch (ParseException exc) { + throw new ConversionFailedException(DateAndTimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDate.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDate.java new file mode 100644 index 000000000..1c6a1983e --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDate.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.DateAndTimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateAndTimeValueToLocalDate extends Conversion { + + @Override + public LocalDate convert(DateAndTimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalDateTime + .from(DateUtil.convertDateAndTimeValue(aSource).toInstant().atZone(ZoneId.systemDefault())) + .toLocalDate(); + } catch (ParseException exc) { + throw new ConversionFailedException(DateAndTimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDateTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDateTime.java new file mode 100644 index 000000000..2d53afe87 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalDateTime.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.DateAndTimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateAndTimeValueToLocalDateTime extends Conversion { + + @Override + public LocalDateTime convert(DateAndTimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalDateTime + .from(DateUtil.convertDateAndTimeValue(aSource).toInstant().atZone(ZoneId.systemDefault())); + } catch (ParseException exc) { + throw new ConversionFailedException(DateAndTimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalTime.java new file mode 100644 index 000000000..124eb4300 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToLocalTime.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.DateAndTimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateAndTimeValueToLocalTime extends Conversion { + + @Override + public LocalTime convert(DateAndTimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalDateTime + .from(DateUtil.convertDateAndTimeValue(aSource).toInstant().atZone(ZoneId.systemDefault())) + .toLocalTime(); + } catch (ParseException exc) { + throw new ConversionFailedException(DateAndTimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToZonedDateTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToZonedDateTime.java new file mode 100644 index 000000000..0a78c4290 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateAndTimeValueToZonedDateTime.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.ZonedDateTime; +import java.util.Date; +import java.util.GregorianCalendar; + +import de.gebit.integrity.dsl.DateAndTimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateAndTimeValueToZonedDateTime extends Conversion { + + @Override + public ZonedDateTime convert(DateAndTimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return ((GregorianCalendar) DateUtil.convertDateAndTimeValue(aSource)).toZonedDateTime(); + } catch (ParseException exc) { + throw new ConversionFailedException(DateAndTimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToInstant.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToInstant.java new file mode 100644 index 000000000..6e2517a3a --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToInstant.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.Instant; +import java.util.Date; + +import de.gebit.integrity.dsl.DateValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateValueToInstant extends Conversion { + + @Override + public Instant convert(DateValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return DateUtil.convertDateValue(aSource).getTime().toInstant(); + } catch (ParseException exc) { + throw new ConversionFailedException(DateValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDate.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDate.java new file mode 100644 index 000000000..bc9c77a72 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDate.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalDate; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.DateValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateValueToLocalDate extends Conversion { + + @Override + public LocalDate convert(DateValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalDate + .from(DateUtil.convertDateValue(aSource).getTime().toInstant().atZone(ZoneId.systemDefault())); + } catch (ParseException exc) { + throw new ConversionFailedException(DateValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDateTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDateTime.java new file mode 100644 index 000000000..b8a6e432a --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToLocalDateTime.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.DateValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateValueToLocalDateTime extends Conversion { + + @Override + public LocalDateTime convert(DateValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalDateTime + .from(DateUtil.convertDateValue(aSource).getTime().toInstant().atZone(ZoneId.systemDefault())); + } catch (ParseException exc) { + throw new ConversionFailedException(DateValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToZonedDateTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToZonedDateTime.java new file mode 100644 index 000000000..e8e8c45bb --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/DateValueToZonedDateTime.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.ZonedDateTime; +import java.util.Date; +import java.util.GregorianCalendar; + +import de.gebit.integrity.dsl.DateValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class DateValueToZonedDateTime extends Conversion { + + @Override + public ZonedDateTime convert(DateValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return ((GregorianCalendar) DateUtil.convertDateValue(aSource)).toZonedDateTime(); + } catch (ParseException exc) { + throw new ConversionFailedException(DateValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToInstant.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToInstant.java new file mode 100644 index 000000000..ffed496cc --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToInstant.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.Instant; +import java.util.Date; + +import de.gebit.integrity.dsl.TimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class TimeValueToInstant extends Conversion { + + @Override + public Instant convert(TimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return DateUtil.convertTimeValue(aSource).toInstant(); + } catch (ParseException exc) { + throw new ConversionFailedException(TimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalDateTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalDateTime.java new file mode 100644 index 000000000..8825c329c --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalDateTime.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.TimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class TimeValueToLocalDateTime extends Conversion { + + @Override + public LocalDateTime convert(TimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalDateTime.from(DateUtil.convertTimeValue(aSource).toInstant().atZone(ZoneId.systemDefault())); + } catch (ParseException exc) { + throw new ConversionFailedException(TimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalTime.java new file mode 100644 index 000000000..2a5b2b058 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToLocalTime.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.LocalTime; +import java.time.ZoneId; +import java.util.Date; + +import de.gebit.integrity.dsl.TimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class TimeValueToLocalTime extends Conversion { + + @Override + public LocalTime convert(TimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return LocalTime.from(DateUtil.convertTimeValue(aSource).toInstant().atZone(ZoneId.systemDefault())); + } catch (ParseException exc) { + throw new ConversionFailedException(TimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToZonedDateTime.java b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToZonedDateTime.java new file mode 100644 index 000000000..a67539c47 --- /dev/null +++ b/de.gebit.integrity.dsl/src/de/gebit/integrity/parameter/conversion/conversions/integrity/dates/TimeValueToZonedDateTime.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2013 Rene Schneider, GEBIT Solutions GmbH and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package de.gebit.integrity.parameter.conversion.conversions.integrity.dates; + +import java.text.ParseException; +import java.time.ZonedDateTime; +import java.util.Date; +import java.util.GregorianCalendar; + +import de.gebit.integrity.dsl.TimeValue; +import de.gebit.integrity.parameter.conversion.Conversion; +import de.gebit.integrity.parameter.conversion.ConversionContext; +import de.gebit.integrity.parameter.conversion.ConversionFailedException; +import de.gebit.integrity.utils.DateUtil; + +/** + * A default Integrity conversion. + * + * @author Rene Schneider - initial API and implementation + * + */ +public class TimeValueToZonedDateTime extends Conversion { + + @Override + public ZonedDateTime convert(TimeValue aSource, Class aTargetType, + ConversionContext aConversionContext) throws ConversionFailedException { + try { + return ((GregorianCalendar) DateUtil.convertTimeValue(aSource)).toZonedDateTime(); + } catch (ParseException exc) { + throw new ConversionFailedException(TimeValue.class, Date.class, null, exc); + } + } + +} diff --git a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/comparator/DefaultResultComparator.java b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/comparator/DefaultResultComparator.java index 732b84840..9c67e3cd6 100644 --- a/de.gebit.integrity.runner/src/de/gebit/integrity/runner/comparator/DefaultResultComparator.java +++ b/de.gebit.integrity.runner/src/de/gebit/integrity/runner/comparator/DefaultResultComparator.java @@ -8,6 +8,13 @@ package de.gebit.integrity.runner.comparator; import java.lang.reflect.Array; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.temporal.Temporal; import java.util.Arrays; import java.util.Date; import java.util.HashSet; @@ -99,7 +106,8 @@ public ComparisonResult compareResult(Object aFixtureResult, ValueOrEnumValueOrO tempMethodName, aPropertyName); } else { tempConversionTargetType = aFixtureResult.getClass().isArray() - ? aFixtureResult.getClass().getComponentType() : aFixtureResult.getClass(); + ? aFixtureResult.getClass().getComponentType() + : aFixtureResult.getClass(); } if (anExpectedResult.getMoreValues().size() > 0) { @@ -306,6 +314,9 @@ protected ComparisonResult performEqualityCheck(Object aConvertedResult, Object if (aConvertedResult instanceof Date && aConvertedExpectedResult instanceof Date) { return performEqualityCheckForDates((Date) aConvertedResult, (Date) aConvertedExpectedResult, aRawExpectedResult); + } else if (aConvertedResult instanceof Temporal && aConvertedExpectedResult instanceof Temporal) { + return performEqualityCheckForJava8Dates((Temporal) aConvertedResult, + (Temporal) aConvertedExpectedResult, aRawExpectedResult); } else if (aConvertedResult instanceof Map && aConvertedExpectedResult instanceof Map) { return performEqualityCheckForMaps((Map) aConvertedResult, (Map) aConvertedExpectedResult, aRawExpectedResult); @@ -452,7 +463,8 @@ protected MapComparisonResult performEqualityCheckForMaps(Map aResult, Map ComparisonResult tempInnerResult = performEqualityCheck(tempActualValue, tempConvertedReferenceValue, (tempReferenceValue instanceof ValueOrEnumValueOrOperation) - ? (ValueOrEnumValueOrOperation) tempReferenceValue : null); + ? (ValueOrEnumValueOrOperation) tempReferenceValue + : null); if (!tempInnerResult.isSuccessful()) { tempSuccess = false; @@ -499,6 +511,76 @@ protected ComparisonResult performEqualityCheckForDates(Date aResult, Date anExp } } + protected ComparisonResult performEqualityCheckForJava8Dates(Temporal aResult, Temporal anExpectedResult, + Object aRawExpectedResult) { + if (aRawExpectedResult instanceof DateValue) { + // compare only the date part + if (aResult instanceof LocalTime) { + throw new IllegalArgumentException("Cannot compare a LocalTime, which has no date part, to a date"); + } else if (aResult instanceof LocalDate) { + return SimpleComparisonResult.valueOf(((LocalDate) aResult).equals(((LocalDate) anExpectedResult))); + } else if (aResult instanceof LocalDateTime) { + return SimpleComparisonResult.valueOf(((LocalDateTime) aResult).toLocalDate() + .equals(((LocalDateTime) anExpectedResult).toLocalDate())); + } else if (aResult instanceof ZonedDateTime) { + return SimpleComparisonResult + .valueOf((((ZonedDateTime) aResult).withZoneSameInstant(ZoneId.systemDefault()).toLocalDate()) + .equals(((ZonedDateTime) anExpectedResult).withZoneSameInstant(ZoneId.systemDefault()) + .toLocalDate())); + } else if (aResult instanceof Instant) { + return SimpleComparisonResult.valueOf(((Instant) aResult).atZone(ZoneId.systemDefault()).toLocalDate() + .equals(((Instant) anExpectedResult).atZone(ZoneId.systemDefault()).toLocalDate())); + } else { + throw new UnsupportedOperationException( + "Cannot compare '" + aResult.getClass() + "' and '" + anExpectedResult.getClass() + "'"); + } + } else if (aRawExpectedResult instanceof TimeValue) { + // compare only the time part + if (aResult instanceof LocalDate) { + throw new IllegalArgumentException("Cannot compare a LocalDate, which has no time part, to a time"); + } else if (aResult instanceof LocalTime) { + return SimpleComparisonResult.valueOf(((LocalTime) aResult).equals(((LocalTime) anExpectedResult))); + } else if (aResult instanceof LocalDateTime) { + return SimpleComparisonResult.valueOf(((LocalDateTime) aResult).toLocalTime() + .equals(((LocalDateTime) anExpectedResult).toLocalTime())); + } else if (aResult instanceof ZonedDateTime) { + // In this case, we consider two times equal if they mark the same point in time, even though the zones + // might differ + return SimpleComparisonResult + .valueOf((((ZonedDateTime) aResult).withZoneSameInstant(ZoneId.systemDefault()).toLocalTime()) + .equals(((ZonedDateTime) anExpectedResult).withZoneSameInstant(ZoneId.systemDefault()) + .toLocalTime())); + } else if (aResult instanceof Instant) { + return SimpleComparisonResult.valueOf(((Instant) aResult).atZone(ZoneId.systemDefault()).toLocalTime() + .equals(((Instant) anExpectedResult).atZone(ZoneId.systemDefault()).toLocalTime())); + } else { + throw new UnsupportedOperationException( + "Cannot compare '" + aResult.getClass() + "' and '" + anExpectedResult.getClass() + "'"); + } + } else { + // compare both parts + if (aResult instanceof LocalDate) { + return SimpleComparisonResult.NOT_EQUAL; + } else if (aResult instanceof LocalTime) { + return SimpleComparisonResult.NOT_EQUAL; + } else if (aResult instanceof LocalDateTime) { + return SimpleComparisonResult + .valueOf(((LocalDateTime) aResult).equals(((LocalDateTime) anExpectedResult))); + } else if (aResult instanceof ZonedDateTime) { + // In this case, we consider two times equal if they mark the same point in time, even though the zones + // might differ + return SimpleComparisonResult.valueOf( + (((ZonedDateTime) aResult).toInstant()).equals(((ZonedDateTime) anExpectedResult).toInstant())); + } else if (aResult instanceof Instant) { + return SimpleComparisonResult.valueOf(((Instant) aResult).atZone(ZoneId.systemDefault()) + .equals(((Instant) anExpectedResult).atZone(ZoneId.systemDefault()))); + } else { + throw new UnsupportedOperationException( + "Cannot compare '" + aResult.getClass() + "' and '" + anExpectedResult.getClass() + "'"); + } + } + } + /** * Compare two objects. At this point it is expected that the previous stages have done all conversion work, * iteration through arrays etc. diff --git a/de.gebit.integrity.tests/integrity/fixtures/NoOpFixture.integrity b/de.gebit.integrity.tests/integrity/fixtures/NoOpFixture.integrity index 6a64b69cc..f237d6c49 100644 --- a/de.gebit.integrity.tests/integrity/fixtures/NoOpFixture.integrity +++ b/de.gebit.integrity.tests/integrity/fixtures/NoOpFixture.integrity @@ -54,6 +54,18 @@ packagedef integrity.fixtures.basic.noop with calldef echoCalendar uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoCalendar testdef echoCalendarTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoCalendar + calldef echoLocalDate uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoLocalDate + testdef echoLocalDateTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoLocalDate + + calldef echoLocalTime uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoLocalTime + testdef echoLocalTimeTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoLocalTime + + calldef echoLocalDateTime uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoLocalDateTime + testdef echoLocalDateTimeTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoLocalDateTime + + calldef echoZonedDateTime uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoZonedDateTime + testdef echoZonedDateTimeTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoZonedDateTime + calldef echoMap uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap testdef echoMapTest uses de.gebit.integrity.tests.fixtures.basic.NoOpFixture#echoMap diff --git a/de.gebit.integrity.tests/integrity/suites/basic/dates/europeanDateAndTimeValues.integrity b/de.gebit.integrity.tests/integrity/suites/basic/dates/europeanDateAndTimeValues.integrity index 464447888..16327b7ca 100644 --- a/de.gebit.integrity.tests/integrity/suites/basic/dates/europeanDateAndTimeValues.integrity +++ b/de.gebit.integrity.tests/integrity/suites/basic/dates/europeanDateAndTimeValues.integrity @@ -67,4 +67,70 @@ packagedef integrity.basic.dates with suiteend + + suitedef europeanDateAndTimeValuesWithJava8 with + + + // European format - date only + + test echoLocalDateTest date: 01.01.1970 = 01.01.1970 + test echoLocalDateTest date: 01.01.0001 = 01.01.0001 + + variable tempDate + call echoLocalDate date: 30.12.2012 -> tempDate + test echoLocalDateTest date: tempDate = 30.12.2012 + + + // 24hrs format - time only + + test echoLocalTimeTest date: 15:30:10 = 15:30:11 + test echoLocalTimeTest date: 02:00 = 02:00:00 + test echoLocalTimeTest date: 02:00:00.123 = 02:00:00.123 + + + // 12hrs format - time only + + test echoLocalTimeTest date: 10:30:10am = 10:30:10pm + test echoLocalTimeTest date: 02:00am = 02:00:00am + test echoLocalTimeTest date: 02:00:00.123am = 02:00:00.123am + + + // 12hrs and 24hrs mixed - time only + + test echoLocalTimeTest date: 10:30:10am = 10:30:10 + test echoLocalTimeTest date: 02:00pm = 14:00:00 + test echoLocalTimeTest date: 02:00:00.123pm = 14:00:00.123 + + + // European 24hrs format - date and time + + // this must return equality since it should only check the time portion + test echoLocalDateTimeTest date: 02.10.2010 01:00 = 01:00 + + // this must return equality since it should only check the time portion + test echoLocalDateTimeTest date: 02.01.2010 01:00:00 = 01:00 + + // this must return unequality since it should check date and time + test echoLocalDateTimeTest date: 01:00 = 02.01.2010 01:00 + + // this must return equality, since it should only check the date + test echoLocalDateTimeTest date: 01.01.1980 01:00 = 01.01.1980 + + // this must return unequality, since it should check date and time + test echoLocalDateTimeTest date: 01.01.1980 12:31 = 01.01.1980 12:30 + + + // European 12hrs format - date and time + + // this must return equality since it should only check the time portion + test echoLocalDateTimeTest date: 02.10.2010 01:00pm = 01:00pm + + // this must return unequality since it should check date and time + test echoLocalDateTimeTest date: 01:00am = 02.01.2010 01:00am + + // this must return unequality, since it should check date and time + test echoLocalDateTimeTest date: 01.01.1980 12:31pm = 01.01.1980 12:30pm + + suiteend + packageend \ No newline at end of file diff --git a/de.gebit.integrity.tests/integrity/suites/basic/dates/isoDateAndTimeValues.integrity b/de.gebit.integrity.tests/integrity/suites/basic/dates/isoDateAndTimeValues.integrity index 1e4d7d33e..a3560434d 100644 --- a/de.gebit.integrity.tests/integrity/suites/basic/dates/isoDateAndTimeValues.integrity +++ b/de.gebit.integrity.tests/integrity/suites/basic/dates/isoDateAndTimeValues.integrity @@ -51,4 +51,55 @@ packagedef integrity.basic.dates with suiteend + + suitedef isoDateAndTimeValuesWithJava8 with + + // ISO8601 format - date only + + test echoLocalDateTest date: 1970-01-01 = 1970-01-01 + test echoLocalDateTest date: 0001-01-01 = 0001-01-01 + + variable tempDate + call echoLocalDate date: 2012-12-30 -> tempDate + test echoLocalDateTest date: tempDate = 2012-12-30 + + + // ISO8601 format - time only + + // a few simple cases (the T forces Integrity to use the ISO time format handling internally) + test echoLocalTimeTest date: T12:30:10 = T12:30:11 + test echoLocalTimeTest date: T02:00 = T02:00:00 + test echoLocalTimeTest date: T02:00:00.123 = T02:00:00.123 + + // this must be equal because of time zones + test echoLocalTimeTest date: 02:00Z = 01:00:00-0100 + test echoZonedDateTimeTest date: 02:00Z = 01:00:00-0100 + + // ISO8601 format - date and time + + // this must return equality since it should only check the time portion + test echoLocalDateTimeTest date: 2010-10-02T01:00 = 01:00 + test echoLocalTimeTest date: 2010-10-02T01:00 = 01:00 + + // this must return equality since it should only check the time portion + test echoLocalDateTimeTest date: 2010-01-02T01:00 = 01:00 + + // this must return unequality since it should check date and time + test echoLocalDateTimeTest date: 01:00 = 2010-01-02T01:00 + + // this must return equality, since it should only check the date + test echoLocalDateTimeTest date: 1970-01-01T12:30+01:00 = 1970-01-01 + test echoLocalDateTest date: 1970-01-01T12:30+01:00 = 1970-01-01 + + // this must return unequality, since it should check date and time + test echoLocalDateTimeTest date: 1970-01-01T12:31 = 1970-01-01T12:30 + + // this must be equal because of the timezone offsets + test echoLocalDateTimeTest date: 1970-01-01T12:00+02:00 = 1970-01-01T10:00Z + test echoZonedDateTimeTest date: 1970-01-01T12:00+02:00 = 1970-01-01T10:00Z + + // issue #45: 2013-06-24T10:00:00+0000 is not accepted as valid time + test echoDateTest date: 2013-06-24T10:00:00+0000 = 2013-06-24T10:00:00Z + + suiteend packageend \ No newline at end of file diff --git a/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/EuropeanDateAndTimeValues.java b/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/EuropeanDateAndTimeValues.java index 3744ebf90..666584f8c 100644 --- a/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/EuropeanDateAndTimeValues.java +++ b/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/EuropeanDateAndTimeValues.java @@ -44,4 +44,22 @@ public void test() throws ModelLoadException, IOException, JDOMException { assertDocumentMatchesReference(tempResult); } + /** + * Performs a suite which does fixture calls with date/time values and checks the resulting XML document. + * + * @throws ModelLoadException + * @throws IOException + * @throws JDOMException + */ + @Test + public void testJava8() throws ModelLoadException, IOException, JDOMException { + // test with german locale, regardless of system settings + Locale.setDefault(Locale.GERMAN); + + Document tempResult = executeIntegritySuite( + new String[] { "integrity/suites/basic/dates/europeanDateAndTimeValues.integrity" }, + "integrity.basic.dates.europeanDateAndTimeValuesWithJava8", null); + assertDocumentMatchesReference(tempResult); + } + } diff --git a/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/IsoDateAndTimeValues.java b/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/IsoDateAndTimeValues.java index 8b548ea40..e84680830 100644 --- a/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/IsoDateAndTimeValues.java +++ b/de.gebit.integrity.tests/junit/de/gebit/integrity/tests/junit/basic/dates/IsoDateAndTimeValues.java @@ -44,4 +44,22 @@ public void test() throws ModelLoadException, IOException, JDOMException { assertDocumentMatchesReference(tempResult); } + /** + * Performs a suite which does fixture calls with date/time values and checks the resulting XML document. + * + * @throws ModelLoadException + * @throws IOException + * @throws JDOMException + */ + @Test + public void testJava8() throws ModelLoadException, IOException, JDOMException { + // test with english locale, regardless of system settings + Locale.setDefault(Locale.ENGLISH); + + Document tempResult = executeIntegritySuite( + new String[] { "integrity/suites/basic/dates/isoDateAndTimeValues.integrity" }, + "integrity.basic.dates.isoDateAndTimeValuesWithJava8", null); + assertDocumentMatchesReference(tempResult); + } + } diff --git a/de.gebit.integrity.tests/results/integrity.basic.dates.europeanDateAndTimeValuesWithJava8.xml b/de.gebit.integrity.tests/results/integrity.basic.dates.europeanDateAndTimeValuesWithJava8.xml new file mode 100644 index 000000000..a962f0591 --- /dev/null +++ b/de.gebit.integrity.tests/results/integrity.basic.dates.europeanDateAndTimeValuesWithJava8.xml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/de.gebit.integrity.tests/results/integrity.basic.dates.isoDateAndTimeValuesWithJava8.xml b/de.gebit.integrity.tests/results/integrity.basic.dates.isoDateAndTimeValuesWithJava8.xml new file mode 100644 index 000000000..97d031cbe --- /dev/null +++ b/de.gebit.integrity.tests/results/integrity.basic.dates.isoDateAndTimeValuesWithJava8.xml @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/NoOpFixture.java b/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/NoOpFixture.java index 63af77b89..38f040593 100644 --- a/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/NoOpFixture.java +++ b/de.gebit.integrity.tests/src/de/gebit/integrity/tests/fixtures/basic/NoOpFixture.java @@ -9,6 +9,10 @@ import java.math.BigDecimal; import java.math.BigInteger; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Date; import java.util.Map; @@ -128,6 +132,26 @@ public Calendar echoCalendar(@FixtureParameter(name = "calendar") Calendar aCale return aCalendarToEcho; } + @FixtureMethod(description = "Echo the LocalDate '$date$'") + public LocalDate echoLocalDate(@FixtureParameter(name = "date") LocalDate aDateToEcho) { + return aDateToEcho; + } + + @FixtureMethod(description = "Echo the LocalTime '$date$'") + public LocalTime echoLocalTime(@FixtureParameter(name = "date") LocalTime aDateToEcho) { + return aDateToEcho; + } + + @FixtureMethod(description = "Echo the LocalDateTime '$date$'") + public LocalDateTime echoLocalDateTime(@FixtureParameter(name = "date") LocalDateTime aDateToEcho) { + return aDateToEcho; + } + + @FixtureMethod(description = "Echo the ZonedDateTime '$date$'") + public ZonedDateTime echoZonedDateTime(@FixtureParameter(name = "date") ZonedDateTime aDateToEcho) { + return aDateToEcho; + } + @FixtureMethod(description = "Echo the map array '$map$'") public Map[] echoMapArray(@FixtureParameter(name = "map") Map[] aMapToEcho) { return aMapToEcho;