Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1708F200B28 for ; Sun, 12 Jun 2016 08:24:06 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 16036160A54; Sun, 12 Jun 2016 06:24:06 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8F313160A61 for ; Sun, 12 Jun 2016 08:24:03 +0200 (CEST) Received: (qmail 85619 invoked by uid 500); 12 Jun 2016 06:24:02 -0000 Mailing-List: contact commits-help@zest.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zest.apache.org Delivered-To: mailing list commits@zest.apache.org Received: (qmail 85571 invoked by uid 99); 12 Jun 2016 06:24:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Jun 2016 06:24:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 62BF6ED30B; Sun, 12 Jun 2016 06:24:02 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: niclas@apache.org To: commits@zest.apache.org Date: Sun, 12 Jun 2016 06:24:08 -0000 Message-Id: <6374de85d75e49f4bb45d98404485bbc@git.apache.org> In-Reply-To: <8b4aae01b1084ae388404c4f2fdf06cf@git.apache.org> References: <8b4aae01b1084ae388404c4f2fdf06cf@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [7/7] zest-java git commit: ZEST-124 - Replaced Joda Time API with Java Time API, and I also removed the java.util.Date support and all uses except where required when interfacing with other systems. archived-at: Sun, 12 Jun 2016 06:24:06 -0000 ZEST-124 - Replaced Joda Time API with Java Time API, and I also removed the java.util.Date support and all uses except where required when interfacing with other systems. Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/37910017 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/37910017 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/37910017 Branch: refs/heads/develop Commit: 379100175b78ea5867387dde8141bee5417f2f01 Parents: d83eae7 Author: Niclas Hedhman Authored: Sun Jun 12 14:23:23 2016 +0800 Committer: Niclas Hedhman Committed: Sun Jun 12 14:23:27 2016 +0800 ---------------------------------------------------------------------- build.gradle | 1 - core/api/build.gradle | 1 - .../zest/api/composite/PropertyMapper.java | 96 +++- .../java/org/apache/zest/api/util/Dates.java | 104 ----- .../runtime/property/PropertyEqualityTest.java | 67 +-- .../apache/zest/runtime/query/model/Person.java | 4 +- .../org/apache/zest/spi/entity/EntityState.java | 1 + .../entitystore/helpers/DefaultEntityState.java | 8 +- .../spi/value/ValueDeserializerAdapter.java | 29 +- .../zest/spi/value/ValueSerializerAdapter.java | 43 +- .../test/entity/AbstractEntityStoreTest.java | 48 +- .../zest/test/indexing/AbstractQueryTest.java | 97 ++-- .../org/apache/zest/test/indexing/TestData.java | 24 +- .../apache/zest/test/indexing/model/Person.java | 12 +- .../test/value/AbstractJsonDateFormatTest.java | 108 ++++- .../AbstractPlainValueSerializationTest.java | 43 +- ...AbstractValueCompositeSerializationTest.java | 50 +-- def.xml | 334 ++++++++++++++ .../rdf/query/internal/RdfQueryParserImpl.java | 21 +- .../solr/internal/SolrEntityIndexerMixin.java | 3 +- .../index/sql/support/common/QNameInfo.java | 18 +- .../postgresql/PostgreSQLTypeHelper.java | 9 +- .../support/skeletons/AbstractSQLStartup.java | 26 +- .../jackson/JacksonValueDeserializer.java | 4 +- libraries.gradle | 2 - .../apache/zest/library/alarm/AlarmEvent.java | 4 +- .../apache/zest/library/alarm/AlarmStatus.java | 6 +- .../apache/zest/library/alarm/AlarmSystem.java | 4 +- .../alarm/ExtendedAlarmModelService.java | 6 +- .../library/alarm/SimpleAlarmModelService.java | 6 +- .../alarm/StandardAlarmModelService.java | 6 +- .../library/alarm/ExtendedAlarmModelTest.java | 4 +- .../library/alarm/SimpleAlarmModelTest.java | 4 +- .../library/alarm/StandardAlarmModelTest.java | 4 +- .../zest/library/appbrowser/AppBrowserTest.java | 1 - .../library/circuitbreaker/CircuitBreaker.java | 26 +- .../circuitbreaker/jmx/CircuitBreakerJMX.java | 11 +- .../conversion/values/EntityToValueTest.java | 9 +- .../library/conversion/values/TestModel.java | 34 +- .../conversion/values/ValueToEntityTest.java | 4 +- .../rest/server/DomainEventSourceResource.java | 16 +- .../application/api/ApplicationEvent.java | 4 +- .../factory/ApplicationEventFactoryService.java | 5 +- .../replay/ApplicationEventPlayerService.java | 12 +- .../source/helper/ApplicationEvents.java | 53 +-- .../domain/api/UnitOfWorkDomainEventsValue.java | 3 +- .../factory/UnitOfWorkNotificationConcern.java | 3 +- .../domain/replay/DomainEventPlayerService.java | 109 +++-- .../domain/source/helper/Events.java | 12 - .../domain/source/helper/EventRouterTest.java | 5 +- .../domain/source/helper/EventsTest.java | 5 +- .../source/helper/UnitOfWorkRouterTest.java | 5 +- .../rdf/entity/EntityTypeSerializer.java | 28 +- .../zest/library/rest/client/ClientCache.java | 209 +++++---- .../responsereader/TableResponseReader.java | 22 +- .../library/rest/common/table/TableBuilder.java | 442 ++++++++++--------- .../rest/server/api/ResourceValidity.java | 40 +- .../requestreader/DefaultRequestReader.java | 37 +- .../responsewriter/TableResponseWriter.java | 13 +- .../zest/library/rest/admin/EntityResource.java | 11 +- .../zest/library/rest/admin/RestTest.java | 3 +- libraries/scheduler/dev-status.xml | 2 +- .../zest/library/scheduler/CronSchedule.java | 13 +- .../zest/library/scheduler/OnceSchedule.java | 9 +- .../apache/zest/library/scheduler/Schedule.java | 8 +- .../zest/library/scheduler/ScheduleFactory.java | 7 +- .../zest/library/scheduler/Scheduler.java | 6 +- .../defaults/DefaultScheduleFactoryMixin.java | 10 +- .../library/scheduler/internal/Execution.java | 32 +- .../scheduler/internal/ScheduleTime.java | 9 +- .../scheduler/internal/SchedulerMixin.java | 27 +- .../library/scheduler/timeline/Timeline.java | 3 +- .../timeline/TimelineForScheduleConcern.java | 3 +- .../scheduler/timeline/TimelineRecord.java | 3 +- .../timeline/TimelineScheduleMixin.java | 27 +- .../timeline/TimelineSchedulerServiceMixin.java | 3 +- .../library/scheduler/CronScheduleTest.java | 12 +- .../zest/library/scheduler/SchedulerTest.java | 20 +- .../manual/recipes/createEntity/Accident.java | 6 +- .../dcicargo/pathfinder_a/api/TransitEdge.java | 14 +- .../internal/GraphTraversalServiceImpl.java | 18 +- .../bootstrap/DCISampleApplication_a.java | 12 +- .../sample_a/bootstrap/sampledata/BaseData.java | 23 +- .../bootstrap/sampledata/BaseDataService.java | 98 ++-- .../bootstrap/sampledata/SampleDataService.java | 49 +- .../communication/query/TrackingQueries.java | 2 +- .../query/dto/HandlingEventDTO.java | 4 +- .../web/booking/BookNewCargoPage.java | 8 +- .../web/booking/CargoDetailsPage.java | 13 +- .../web/booking/CargoListPage.java | 19 +- .../communication/web/booking/RoutePanel.java | 8 +- .../web/handling/RegisterHandlingEventPage.java | 14 +- .../web/tracking/HandlingHistoryPanel.java | 3 +- .../web/tracking/NextHandlingEventPanel.java | 5 +- .../web/tracking/TrackCargoPage.java | 17 +- .../context/shipping/booking/BookNewCargo.java | 20 +- .../shipping/booking/BuildDeliverySnapshot.java | 45 +- .../handling/RegisterHandlingEvent.java | 32 +- .../context/support/ApplicationEvents.java | 12 +- .../context/support/FoundNoRoutesException.java | 8 +- .../RegisterHandlingEventAttemptDTO.java | 6 +- .../context/support/RoutingService.java | 7 +- .../data/shipping/cargo/RouteSpecification.java | 6 +- .../data/shipping/delivery/Delivery.java | 7 +- .../delivery/ExpectedHandlingEvent.java | 4 +- .../data/shipping/handling/HandlingEvent.java | 6 +- .../data/shipping/handling/HandlingEvents.java | 14 +- .../data/shipping/itinerary/Itinerary.java | 26 +- .../sample_a/data/shipping/itinerary/Leg.java | 7 +- .../data/shipping/voyage/CarrierMovement.java | 6 +- .../wicket/form/DateTextFieldWithPicker.java | 33 +- .../wicket/prevnext/PrevNext.java | 5 +- .../web/booking/CargoDetailsPage.html | 4 +- .../communication/web/booking/RoutePanel.html | 4 +- .../shipping/booking/BookNewCargoTest.java | 61 ++- .../booking/BuildDeliverySnapshotTest.java | 135 +++--- .../handling/RegisterHandlingEventTest.java | 54 +-- .../pathfinder_b/api/GraphTraversalService.java | 4 +- .../dcicargo/pathfinder_b/api/TransitEdge.java | 24 +- .../dcicargo/pathfinder_b/api/TransitPath.java | 5 +- .../pathfinder_b/internal/GraphDAO.java | 30 +- .../internal/GraphTraversalServiceImpl.java | 12 +- .../bootstrap/DCISampleApplication_b.java | 4 +- .../sample_b/bootstrap/sampledata/BaseData.java | 44 +- .../bootstrap/sampledata/SampleDataService.java | 54 +-- .../communication/query/TrackingQueries.java | 2 +- .../query/dto/HandlingEventDTO.java | 4 +- .../web/booking/BookNewCargoPage.java | 7 +- .../web/booking/CargoDetailsPage.java | 14 +- .../web/booking/CargoListPage.java | 12 +- .../communication/web/booking/RoutePanel.java | 10 +- .../IncidentLoggingApplicationMockupPage.java | 16 +- .../web/tracking/HandlingHistoryPanel.java | 10 +- .../web/tracking/NextHandlingEventPanel.java | 5 +- .../web/tracking/TrackCargoPage.java | 7 +- .../interaction/booking/BookNewCargo.java | 13 +- .../booking/routing/AssignCargoToRoute.java | 43 +- .../DeriveUpdatedRouteSpecification.java | 14 +- .../inspection/event/InspectArrivedCargo.java | 24 +- .../inspection/event/InspectCargoInCustoms.java | 4 +- .../inspection/event/InspectClaimedCargo.java | 8 +- .../inspection/event/InspectLoadedCargo.java | 49 +- .../inspection/event/InspectReceivedCargo.java | 30 +- .../inspection/event/InspectUnhandledCargo.java | 6 +- .../inspection/event/InspectUnloadedCargo.java | 28 +- .../parsing/ParseHandlingEventData.java | 17 +- .../parsing/dto/ParsedHandlingEventData.java | 27 +- .../registration/RegisterHandlingEvent.java | 4 +- .../CannotRegisterHandlingEventException.java | 11 +- .../exception/ChronologicalException.java | 6 +- .../context/service/routing/RoutingService.java | 11 +- .../exception/FoundNoRoutesException.java | 8 +- .../data/factory/HandlingEventFactory.java | 14 +- .../RouteSpecificationFactoryService.java | 23 +- .../structure/cargo/RouteSpecification.java | 31 +- .../data/structure/delivery/Delivery.java | 7 +- .../structure/delivery/NextHandlingEvent.java | 4 +- .../data/structure/handling/HandlingEvent.java | 27 +- .../data/structure/itinerary/Itinerary.java | 26 +- .../sample_b/data/structure/itinerary/Leg.java | 6 +- .../data/structure/voyage/CarrierMovement.java | 6 +- .../sample_b/data/structure/voyage/Voyage.java | 5 +- .../wicket/form/DateTextFieldWithPicker.java | 31 +- .../web/booking/CargoDetailsPage.html | 4 +- .../communication/web/booking/RoutePanel.html | 4 +- .../bootstrap/test/TestApplication.java | 112 ++--- .../booking/routing/AssignCargoToRouteTest.java | 6 +- .../event/InspectArrivedCargoTest.java | 4 +- .../event/InspectCargoInCustomsTest.java | 4 +- .../event/InspectClaimedCargoTest.java | 8 +- .../event/InspectLoadedCargoTest.java | 6 +- .../event/InspectReceivedCargoTest.java | 2 +- .../event/InspectUnhandledCargoTest.java | 4 +- .../event/InspectUnloadedCargoTest.java | 6 +- .../parsing/ParseHandlingEventDataTest.java | 22 +- .../registration/RegisterHandlingEventTest.java | 8 +- .../sample/forum/context/view/ViewPost.java | 20 +- .../zest/sample/forum/data/entity/Post.java | 4 +- .../zest/sample/rental/domain/Booking.java | 6 +- .../apache/zest/sample/rental/domain/Car.java | 6 +- .../zest/sample/rental/domain/Period.java | 6 +- .../zest/sample/rental/domain/RentalShop.java | 33 +- .../sample/rental/domain/dev/InitialData.java | 71 ++- .../apache/zest/sample/rental/web/MainPage.java | 8 +- tools/shell/src/dist/bin/zest-boot | 2 + .../demo/thirtyminutes/ThirtyMinutesDocs.java | 14 +- 186 files changed, 2471 insertions(+), 1964 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 67f1ad9..0591ba7 100644 --- a/build.gradle +++ b/build.gradle @@ -164,7 +164,6 @@ allprojects { options.noTimestamp = true options.links = [ 'http://docs.oracle.com/javase/7/docs/api/', - 'http://www.joda.org/joda-time/apidocs/', 'http://www.json.org/javadoc/', 'http://junit.org/javadoc/latest/' ] http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/api/build.gradle ---------------------------------------------------------------------- diff --git a/core/api/build.gradle b/core/api/build.gradle index 595b47d..f9e42b8 100644 --- a/core/api/build.gradle +++ b/core/api/build.gradle @@ -23,7 +23,6 @@ jar { manifest { name = "Apache Zestâ„¢ Core API"}} dependencies { compile project( ':org.apache.zest.core:org.apache.zest.core.io' ) - compile libraries.jodatime testCompile project( ':org.apache.zest.core:org.apache.zest.core.testsupport' ) testCompile project( ':org.apache.zest.libraries:org.apache.zest.library.constraints' ) http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/api/src/main/java/org/apache/zest/api/composite/PropertyMapper.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/composite/PropertyMapper.java b/core/api/src/main/java/org/apache/zest/api/composite/PropertyMapper.java index e23683b..63911ac 100644 --- a/core/api/src/main/java/org/apache/zest/api/composite/PropertyMapper.java +++ b/core/api/src/main/java/org/apache/zest/api/composite/PropertyMapper.java @@ -28,9 +28,15 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.Period; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collection; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -41,7 +47,6 @@ import org.apache.zest.api.ZestAPI; import org.apache.zest.api.property.GenericPropertyInfo; import org.apache.zest.api.property.Property; import org.apache.zest.api.util.Classes; -import org.apache.zest.api.util.Dates; import org.apache.zest.api.value.ValueComposite; /** @@ -63,7 +68,13 @@ public final class PropertyMapper STRATEGY.put( Character.class, new CharMapper() ); STRATEGY.put( Float.class, new FloatMapper() ); STRATEGY.put( Double.class, new DoubleMapper() ); - STRATEGY.put( Date.class, new DateMapper() ); + STRATEGY.put( LocalDate.class, new LocalDateMapper() ); + STRATEGY.put( LocalDateTime.class, new LocalDateTimeMapper() ); + STRATEGY.put( ZonedDateTime.class, new ZonedDateTimeMapper() ); + STRATEGY.put( OffsetDateTime.class, new OffsetDateTimeMapper() ); + STRATEGY.put( Instant.class, new InstantMapper() ); + STRATEGY.put( Duration.class, new DurationMapper() ); + STRATEGY.put( Period.class, new PeriodMapper() ); STRATEGY.put( Boolean.class, new BooleanMapper() ); STRATEGY.put( BigDecimal.class, new BigDecimalMapper() ); STRATEGY.put( BigInteger.class, new BigIntegerMapper() ); @@ -140,7 +151,7 @@ public final class PropertyMapper { strategy = STRATEGY.get( type ); } - if( strategy == null ) // If null, try with the ValueComposite Mapper... + if( strategy == null ) // If null, try with the ValueComposite Mapper... { strategy = STRATEGY.get( ValueComposite.class ); } @@ -446,13 +457,73 @@ public final class PropertyMapper } } - private static class DateMapper + private static class LocalDateMapper implements MappingStrategy { @Override public Object map( Composite composite, Type type, String value ) { - return Dates.fromString( value.trim() ); + return LocalDate.parse( value.trim() ); + } + } + + private static class LocalDateTimeMapper + implements MappingStrategy + { + @Override + public Object map( Composite composite, Type type, String value ) + { + return LocalDateTime.parse( value.trim() ); + } + } + + private static class ZonedDateTimeMapper + implements MappingStrategy + { + @Override + public Object map( Composite composite, Type type, String value ) + { + return ZonedDateTime.parse( value.trim() ); + } + } + + private static class OffsetDateTimeMapper + implements MappingStrategy + { + @Override + public Object map( Composite composite, Type type, String value ) + { + return OffsetDateTime.parse( value.trim() ); + } + } + + private static class InstantMapper + implements MappingStrategy + { + @Override + public Object map( Composite composite, Type type, String value ) + { + return Instant.parse( value.trim() ); + } + } + + private static class DurationMapper + implements MappingStrategy + { + @Override + public Object map( Composite composite, Type type, String value ) + { + return Duration.parse( value.trim() ); + } + } + + private static class PeriodMapper + implements MappingStrategy + { + @Override + public Object map( Composite composite, Type type, String value ) + { + return Period.parse( value.trim() ); } } @@ -463,7 +534,10 @@ public final class PropertyMapper @SuppressWarnings( "unchecked" ) public Object map( Composite composite, Type type, String value ) { - return ZestAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ).module().instance().newValueFromSerializedState( (Class) type, value ); + return ZestAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply( composite ) + .module() + .instance() + .newValueFromSerializedState( (Class) type, value ); } } @@ -471,7 +545,7 @@ public final class PropertyMapper implements MappingStrategy { @Override - @SuppressWarnings( {"raw", "unchecked"} ) + @SuppressWarnings( { "raw", "unchecked" } ) public Object map( final Composite composite, Type type, String value ) { final Class arrayType = ( (Class) type ).getComponentType(); @@ -502,7 +576,7 @@ public final class PropertyMapper implements MappingStrategy { @Override - @SuppressWarnings( {"raw", "unchecked"} ) + @SuppressWarnings( { "raw", "unchecked" } ) public Object map( final Composite composite, Type type, String value ) { final Type dataType = ( (ParameterizedType) type ).getActualTypeArguments()[ 0 ]; @@ -523,7 +597,7 @@ public final class PropertyMapper implements MappingStrategy { @Override - @SuppressWarnings( {"raw", "unchecked"} ) + @SuppressWarnings( { "raw", "unchecked" } ) public Object map( final Composite composite, Type type, String value ) { final Type dataType = ( (ParameterizedType) type ).getActualTypeArguments()[ 0 ]; @@ -544,7 +618,7 @@ public final class PropertyMapper implements MappingStrategy { @Override - @SuppressWarnings( {"raw", "unchecked"} ) + @SuppressWarnings( { "raw", "unchecked" } ) public Object map( final Composite composite, Type generictype, String value ) { ParameterizedType type = (ParameterizedType) generictype; http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/api/src/main/java/org/apache/zest/api/util/Dates.java ---------------------------------------------------------------------- diff --git a/core/api/src/main/java/org/apache/zest/api/util/Dates.java b/core/api/src/main/java/org/apache/zest/api/util/Dates.java deleted file mode 100644 index edd5392..0000000 --- a/core/api/src/main/java/org/apache/zest/api/util/Dates.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * - */ -package org.apache.zest.api.util; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; - -/** - * Useful methods for handling Dates. - */ -public final class Dates -{ - // Formatters are not thread-safe. Create one per thread - private static final ThreadLocal ISO8601 = new ThreadLocal() - { - @Override - protected DateFormat initialValue() - { - return new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZ" ); - } - }; - - private static final ThreadLocal ISO8601_UTC = new ThreadLocal() - { - @Override - protected DateFormat initialValue() - { - SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" ); - dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); - return dateFormat; - } - }; - - /** - * @param stringDate a string representing a date as either ISO8601, @millis@ or /Date() formats - * @return a Date - */ - public static Date fromString( String stringDate ) - { - try - { - Date date = ISO8601_UTC.get().parse( stringDate ); - return date; - } - catch( ParseException e ) - { - try - { - Date date = ISO8601.get().parse( stringDate ); - return date; - } - catch( ParseException e1 ) - { - // @millis@ format - if( stringDate.startsWith( "@" ) && stringDate.endsWith( "@" ) ) - { - long time = Long.parseLong( stringDate.substring( 1, stringDate.length() - 1 ) ); - Date date = new Date( time ); - return date; - } - else if( stringDate.startsWith( "/Date(" ) && stringDate.endsWith( ")/" ) ) // Microsoft format - { - long time = Long.parseLong( stringDate.substring( 6, stringDate.length() - 2 ) ); - Date date = new Date( time ); - return date; - } - throw new IllegalStateException( "Illegal date:" + stringDate ); - } - } - } - - /** - * @param date a Date - * @return String representation in ISO8601 UTC - */ - public static String toUtcString( Date date ) - { - return ISO8601_UTC.get().format( date ); - } - - private Dates() - { - } -} http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/runtime/src/test/java/org/apache/zest/runtime/property/PropertyEqualityTest.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/property/PropertyEqualityTest.java b/core/runtime/src/test/java/org/apache/zest/runtime/property/PropertyEqualityTest.java index 2cf33d5..56bf92e 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/property/PropertyEqualityTest.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/property/PropertyEqualityTest.java @@ -21,26 +21,25 @@ package org.apache.zest.runtime.property; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Date; -import org.apache.zest.api.value.ValueBuilderFactory; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; -import org.junit.Test; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; import org.apache.zest.api.common.Optional; import org.apache.zest.api.property.Property; import org.apache.zest.api.property.PropertyDescriptor; -import org.apache.zest.api.structure.Module; import org.apache.zest.api.value.ValueBuilder; +import org.apache.zest.api.value.ValueBuilderFactory; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.test.AbstractZestTest; +import org.junit.Test; +import static java.time.ZoneOffset.UTC; import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; -import static org.joda.time.DateTimeZone.UTC; import static org.junit.Assert.assertThat; /** @@ -60,7 +59,7 @@ public class PropertyEqualityTest module.values( PrimitivesValue.class, Some.class, AnotherSome.class, Other.class ); } - public enum AnEnum + private enum AnEnum { BAZAR, CATHEDRAL @@ -101,9 +100,9 @@ public class PropertyEqualityTest Property bigDecimalProperty(); - Property dateProperty(); + Property instantProperty(); - Property dateTimeProperty(); + Property dateTimeProperty(); Property localDateProperty(); @@ -127,7 +126,7 @@ public class PropertyEqualityTest @Test public void givenValuesOfTheSameTypeWhenTestingPropertyDescriptorEqualityExpectEquals() { - Some some = buildSomeValue(valueBuilderFactory); + Some some = buildSomeValue( valueBuilderFactory ); ValueDescriptor someDescriptor = zest.api().valueDescriptorFor( some ); PropertyDescriptor someCharPropDesc = someDescriptor.state().findPropertyModelByName( "characterProperty" ); @@ -152,7 +151,8 @@ public class PropertyEqualityTest PrimitivesValue primitive = buildPrimitivesValue( valueBuilderFactory ); ValueDescriptor primitiveDescriptor = zest.api().valueDescriptorFor( primitive ); - PropertyDescriptor primitiveCharPropDesc = primitiveDescriptor.state().findPropertyModelByName( "characterProperty" ); + PropertyDescriptor primitiveCharPropDesc = primitiveDescriptor.state() + .findPropertyModelByName( "characterProperty" ); assertThat( "PropertyDescriptors equal", someCharPropDesc, @@ -297,7 +297,7 @@ public class PropertyEqualityTest return primitive; } - public static PrimitivesValue buildPrimitivesValueWithDifferentState( ValueBuilderFactory vbf ) + private static PrimitivesValue buildPrimitivesValueWithDifferentState( ValueBuilderFactory vbf ) { PrimitivesValue primitive; { @@ -317,10 +317,12 @@ public class PropertyEqualityTest return primitive; } - public static Some buildSomeValue(ValueBuilderFactory vbf) + public static Some buildSomeValue( ValueBuilderFactory vbf ) { Some some; { + ZonedDateTime refDate = ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 0, UTC ); + ValueBuilder builder = vbf.newValueBuilder( Some.class ); builder.prototype().characterProperty().set( 'q' ); builder.prototype().stringProperty().set( "foo" ); @@ -334,10 +336,10 @@ public class PropertyEqualityTest builder.prototype().enumProperty().set( AnEnum.BAZAR ); builder.prototype().bigIntegerProperty().set( new BigInteger( "42" ) ); builder.prototype().bigDecimalProperty().set( new BigDecimal( "42.23" ) ); - builder.prototype().dateProperty().set( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ); - builder.prototype().dateTimeProperty().set( new DateTime( "2020-03-04T13:24:35", UTC ) ); - builder.prototype().localDateProperty().set( new LocalDate( "2020-03-04" ) ); - builder.prototype().localDateTimeProperty().set( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ); + builder.prototype().instantProperty().set( refDate.toInstant() ); + builder.prototype().dateTimeProperty().set( refDate ); + builder.prototype().localDateProperty().set( LocalDate.of( 2020, 3, 4 ) ); + builder.prototype().localDateTimeProperty().set( LocalDateTime.of( 2020, 3, 4, 13, 23, 0 ) ); some = builder.newInstance(); } return some; @@ -347,6 +349,7 @@ public class PropertyEqualityTest { Some some; { + ZonedDateTime refDate = ZonedDateTime.of( 2030, 2, 8, 9, 9, 9, 0, UTC ); ValueBuilder builder = vbf.newValueBuilder( Some.class ); builder.prototype().characterProperty().set( 'i' ); builder.prototype().stringProperty().set( "bar" ); @@ -360,10 +363,10 @@ public class PropertyEqualityTest builder.prototype().enumProperty().set( AnEnum.CATHEDRAL ); builder.prototype().bigIntegerProperty().set( new BigInteger( "23" ) ); builder.prototype().bigDecimalProperty().set( new BigDecimal( "23.42" ) ); - builder.prototype().dateProperty().set( new DateTime( "2030-02-08T09:09:09", UTC ).toDate() ); - builder.prototype().dateTimeProperty().set( new DateTime( "2030-02-08T09:09:09", UTC ) ); - builder.prototype().localDateProperty().set( new LocalDate( "2030-02-08" ) ); - builder.prototype().localDateTimeProperty().set( new LocalDateTime( "2030-02-08T09:09:09", UTC ) ); + builder.prototype().instantProperty().set( refDate.toInstant() ); + builder.prototype().dateTimeProperty().set( refDate ); + builder.prototype().localDateProperty().set( LocalDate.of( 2030, 2, 8 ) ); + builder.prototype().localDateTimeProperty().set( LocalDateTime.of( 2030, 2, 8, 9, 9, 9 ) ); some = builder.newInstance(); } return some; @@ -373,6 +376,7 @@ public class PropertyEqualityTest { AnotherSome anotherSome; { + ZonedDateTime refDate = ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 0, UTC ); ValueBuilder builder = vbf.newValueBuilder( AnotherSome.class ); builder.prototype().characterProperty().set( 'q' ); builder.prototype().stringProperty().set( "foo" ); @@ -386,10 +390,10 @@ public class PropertyEqualityTest builder.prototype().enumProperty().set( AnEnum.BAZAR ); builder.prototype().bigIntegerProperty().set( new BigInteger( "42" ) ); builder.prototype().bigDecimalProperty().set( new BigDecimal( "42.23" ) ); - builder.prototype().dateProperty().set( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ); - builder.prototype().dateTimeProperty().set( new DateTime( "2020-03-04T13:24:35", UTC ) ); - builder.prototype().localDateProperty().set( new LocalDate( "2020-03-04" ) ); - builder.prototype().localDateTimeProperty().set( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ); + builder.prototype().instantProperty().set( refDate.toInstant() ); + builder.prototype().dateTimeProperty().set( refDate ); + builder.prototype().localDateProperty().set( refDate.toLocalDate() ); + builder.prototype().localDateTimeProperty().set( LocalDateTime.of( 2020, 3, 4, 13, 23, 0 ) ); anotherSome = builder.newInstance(); } return anotherSome; @@ -412,10 +416,11 @@ public class PropertyEqualityTest builder.prototype().enumProperty().set( AnEnum.CATHEDRAL ); builder.prototype().bigIntegerProperty().set( new BigInteger( "23" ) ); builder.prototype().bigDecimalProperty().set( new BigDecimal( "23.42" ) ); - builder.prototype().dateProperty().set( new DateTime( "2030-02-08T09:09:09", UTC ).toDate() ); - builder.prototype().dateTimeProperty().set( new DateTime( "2030-02-08T09:09:09", UTC ) ); - builder.prototype().localDateProperty().set( new LocalDate( "2030-02-08" ) ); - builder.prototype().localDateTimeProperty().set( new LocalDateTime( "2030-02-08T09:09:09", UTC ) ); + ZonedDateTime refDate = ZonedDateTime.of( 2030, 2, 8, 9, 9, 9, 0, UTC ); + builder.prototype().instantProperty().set( refDate.toInstant() ); + builder.prototype().dateTimeProperty().set( refDate ); + builder.prototype().localDateProperty().set( LocalDate.of( 2030, 2, 8 ) ); + builder.prototype().localDateTimeProperty().set( LocalDateTime.of( 2030, 2, 8, 9, 9, 9 ) ); anotherSome = builder.newInstance(); } return anotherSome; http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/runtime/src/test/java/org/apache/zest/runtime/query/model/Person.java ---------------------------------------------------------------------- diff --git a/core/runtime/src/test/java/org/apache/zest/runtime/query/model/Person.java b/core/runtime/src/test/java/org/apache/zest/runtime/query/model/Person.java index a4eff58..8f1b842 100644 --- a/core/runtime/src/test/java/org/apache/zest/runtime/query/model/Person.java +++ b/core/runtime/src/test/java/org/apache/zest/runtime/query/model/Person.java @@ -19,7 +19,7 @@ */ package org.apache.zest.runtime.query.model; -import java.util.Date; +import java.time.LocalDate; import java.util.List; import java.util.Map; import org.apache.zest.api.association.Association; @@ -50,7 +50,7 @@ public interface Person Property email(); @Optional - Property> datesToRemember(); + Property> datesToRemember(); @Optional Property> tags(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/spi/src/main/java/org/apache/zest/spi/entity/EntityState.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/spi/entity/EntityState.java b/core/spi/src/main/java/org/apache/zest/spi/entity/EntityState.java index 6031851..95b13f2 100644 --- a/core/spi/src/main/java/org/apache/zest/spi/entity/EntityState.java +++ b/core/spi/src/main/java/org/apache/zest/spi/entity/EntityState.java @@ -19,6 +19,7 @@ */ package org.apache.zest.spi.entity; +import java.time.Instant; import org.apache.zest.api.common.QualifiedName; import org.apache.zest.api.entity.EntityDescriptor; import org.apache.zest.api.entity.EntityReference; http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/DefaultEntityState.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/DefaultEntityState.java b/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/DefaultEntityState.java index a95fa57..3375670 100644 --- a/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/DefaultEntityState.java +++ b/core/spi/src/main/java/org/apache/zest/spi/entitystore/helpers/DefaultEntityState.java @@ -61,10 +61,10 @@ public final class DefaultEntityState identity, EntityStatus.NEW, entityDescriptor, - new HashMap(), - new HashMap(), - new HashMap>(), - new HashMap>() ); + new HashMap<>(), + new HashMap<>(), + new HashMap<>(), + new HashMap<>() ); } public DefaultEntityState( String version, http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java index a3c72e1..93a8d7e 100644 --- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java +++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java @@ -24,11 +24,18 @@ import java.io.InputStream; import java.io.ObjectInputStream; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.Period; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Base64; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; @@ -44,14 +51,10 @@ import org.apache.zest.api.type.MapType; import org.apache.zest.api.type.Serialization; import org.apache.zest.api.type.ValueCompositeType; import org.apache.zest.api.type.ValueType; -import org.apache.zest.api.util.Dates; import org.apache.zest.api.value.ValueBuilder; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.api.value.ValueDeserializer; import org.apache.zest.api.value.ValueSerializationException; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; import static org.apache.zest.functional.Iterables.empty; @@ -80,8 +83,8 @@ import static org.apache.zest.functional.Iterables.empty; *
  • BigInteger and BigDecimal depends on {@link org.apache.zest.api.value.ValueSerializer.Options};
  • *
  • Date as String in ISO-8601, {@literal @millis@} or {@literal /Date(..)} Microsoft format;
  • *
  • DateTime (JodaTime) as a ISO-8601 String with optional timezone offset;
  • - *
  • LocalDateTime (JodaTime) as whatever {@link LocalDateTime#LocalDateTime(java.lang.Object)} accept as {@literal instant};
  • - *
  • LocalDate (JodaTime) as whatever {@link LocalDate#LocalDate(java.lang.Object)} accept as {@literal instant};
  • + *
  • LocalDateTime (JodaTime) as whatever {@link LocalDateTime#parse} accept as {@literal instant};
  • + *
  • LocalDate (JodaTime) as whatever {@link LocalDate#parse} accept as {@literal instant};
  • * * * @param Implementor pull-parser type @@ -157,10 +160,14 @@ public abstract class ValueDeserializerAdapter registerDeserializer( BigInteger.class, input -> new BigInteger( input.toString() ) ); // Date types - registerDeserializer( Date.class, input -> Dates.fromString( input.toString() ) ); - registerDeserializer( DateTime.class, input -> DateTime.parse( input.toString() ) ); - registerDeserializer( LocalDateTime.class, LocalDateTime::new ); - registerDeserializer( LocalDate.class, LocalDate::new ); + registerDeserializer( Instant.class, input -> Instant.parse( input.toString() ) ); + registerDeserializer( ZonedDateTime.class, input -> ZonedDateTime.parse( input.toString() ) ); + registerDeserializer( OffsetDateTime.class, input -> OffsetDateTime.parse( input.toString() ) ); + registerDeserializer( LocalDateTime.class, input -> LocalDateTime.parse( input.toString() ) ); + registerDeserializer( LocalDate.class, input -> LocalDate.parse( input.toString() )); + registerDeserializer( LocalTime.class, input -> LocalTime.parse( input.toString() )); + registerDeserializer( Duration.class, input -> Duration.parse( input.toString() )); + registerDeserializer( Period.class, input -> Period.parse( input.toString() )); // Other supported types registerDeserializer( EntityReference.class, input -> EntityReference.parseEntityReference( input.toString() ) ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java index 6e0a2ad..e428f4e 100644 --- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java +++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java @@ -24,8 +24,15 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.Period; +import java.time.ZonedDateTime; import java.util.Base64; -import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.function.BiFunction; @@ -39,14 +46,10 @@ import org.apache.zest.api.composite.CompositeInstance; import org.apache.zest.api.entity.EntityComposite; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.property.Property; -import org.apache.zest.api.util.Dates; import org.apache.zest.api.value.ValueComposite; import org.apache.zest.api.value.ValueDescriptor; import org.apache.zest.api.value.ValueSerializationException; import org.apache.zest.api.value.ValueSerializer; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; /** * Adapter for pull-parsing capable ValueSerializers. @@ -83,7 +86,7 @@ public abstract class ValueSerializerAdapter implements ValueSerializer { - public static interface ComplexSerializer + public interface ComplexSerializer { void serialize( Options options, T object, OutputType output ) throws Exception; @@ -128,25 +131,29 @@ public abstract class ValueSerializerAdapter public ValueSerializerAdapter() { // Primitive Value types - registerSerializer( String.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Character.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Boolean.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Integer.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Long.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Short.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Byte.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Float.class, ValueSerializerAdapter.identitySerializer() ); - registerSerializer( Double.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( String.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Character.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Boolean.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Integer.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Long.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Short.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Byte.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Float.class, ValueSerializerAdapter.identitySerializer() ); + registerSerializer( Double.class, ValueSerializerAdapter.identitySerializer() ); // Number types registerSerializer( BigDecimal.class, ( options, bigDecimal ) -> bigDecimal.toString() ); registerSerializer( BigInteger.class, ( options, bigInteger ) -> bigInteger.toString() ); // Date types - registerSerializer( Date.class, ( options, date ) -> Dates.toUtcString( date ) ); - registerSerializer( DateTime.class, ( options, date ) -> date.toString() ); + registerSerializer( Instant.class, ( options, date ) -> date.toString() ); + registerSerializer( Duration.class, ( options, date ) -> date.toString() ); + registerSerializer( Period.class, ( options, date ) -> date.toString() ); + registerSerializer( ZonedDateTime.class, ( options, date ) -> date.toString() ); + registerSerializer( OffsetDateTime.class, ( options, date ) -> date.toString() ); registerSerializer( LocalDateTime.class, ( options, date ) -> date.toString() ); registerSerializer( LocalDate.class, ( options, date ) -> date.toString() ); + registerSerializer( LocalTime.class, ( options, date ) -> date.toString() ); // Other supported types registerSerializer( EntityReference.class, ( options, ref ) -> ref.toString() ); @@ -155,7 +162,7 @@ public abstract class ValueSerializerAdapter @Override public final Function serialize() { - return object -> serialize( object ); + return this::serialize; } @Override http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java b/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java index 73455ec..b050570 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/entity/AbstractEntityStoreTest.java @@ -21,17 +21,13 @@ package org.apache.zest.test.entity; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Date; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.structure.Module; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; -import org.junit.After; -import org.junit.Test; import org.apache.zest.api.association.Association; import org.apache.zest.api.association.ManyAssociation; import org.apache.zest.api.association.NamedAssociation; @@ -40,7 +36,9 @@ import org.apache.zest.api.common.UseDefaults; import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityComposite; import org.apache.zest.api.injection.scope.Service; +import org.apache.zest.api.injection.scope.Structure; import org.apache.zest.api.property.Property; +import org.apache.zest.api.structure.Module; import org.apache.zest.api.unitofwork.ConcurrentEntityModificationException; import org.apache.zest.api.unitofwork.NoSuchEntityException; import org.apache.zest.api.unitofwork.UnitOfWork; @@ -52,11 +50,13 @@ import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.spi.entitystore.EntityStore; import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; import org.apache.zest.test.AbstractZestTest; +import org.junit.After; +import org.junit.Test; +import static java.time.ZoneOffset.UTC; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; -import static org.joda.time.DateTimeZone.UTC; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -72,6 +72,7 @@ public abstract class AbstractEntityStoreTest @Structure private Module moduleInstance; + private ZonedDateTime refDate = ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 0, UTC ); @Override public void assemble( ModuleAssembly module ) @@ -96,7 +97,7 @@ public abstract class AbstractEntityStoreTest { // Create entity EntityBuilder builder = unitOfWork.newEntityBuilder( TestEntity.class ); - builder.instance().dateValue().set( new Date() ); + builder.instance().instantValue().set( Instant.now() ); TestEntity instance = builder.newInstance(); instance.name().set( "Test" ); @@ -107,10 +108,10 @@ public abstract class AbstractEntityStoreTest instance.booleanValue().set( Boolean.TRUE ); instance.bigIntegerValue().set( new BigInteger( "42" ) ); instance.bigDecimalValue().set( new BigDecimal( "42" ) ); - instance.dateValue().set( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ); - instance.dateTimeValue().set( new DateTime( "2020-03-04T13:24:35", UTC ) ); - instance.localDateTimeValue().set( new LocalDateTime( "2020-03-04T13:23:00" ) ); - instance.localDateValue().set( new LocalDate( "2020-03-04" ) ); + instance.instantValue().set( refDate.toInstant() ); + instance.dateTimeValue().set( refDate ); + instance.localDateTimeValue().set( LocalDateTime.of( 2020, 3, 4, 13, 23, 00 ) ); + instance.localDateValue().set( LocalDate.of( 2020, 3, 4 ) ); instance.association().set( instance ); ValueBuilder valueBuilder4 = moduleInstance.newValueBuilder( Tjabba.class ); @@ -192,21 +193,21 @@ public abstract class AbstractEntityStoreTest instance.bigDecimalValue().get(), equalTo( new BigDecimal( "42" ) ) ); - assertThat( "property 'dateValue' has correct value", - instance.dateValue().get(), - equalTo( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ) ); + assertThat( "property 'instantValue' has correct value", + instance.instantValue().get(), + equalTo( refDate.toInstant() ) ); assertThat( "property 'dateTimeValue' has correct value", instance.dateTimeValue().get(), - equalTo( new DateTime( "2020-03-04T13:24:35", UTC ) ) ); + equalTo( refDate ) ); assertThat( "property 'localDateTimeValue' has correct value", instance.localDateTimeValue().get(), - equalTo( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ) ); + equalTo( LocalDateTime.of( 2020, 3, 4, 13, 23, 0 ) ) ); assertThat( "property 'localDateValue' has correct value", instance.localDateValue().get(), - equalTo( new LocalDate( "2020-03-04" ) ) ); + equalTo( LocalDate.of( 2020, 3, 4 ) ) ); assertThat( "property 'name' has correct value", instance.name().get(), @@ -506,10 +507,10 @@ public abstract class AbstractEntityStoreTest Property bigDecimalValue(); @Optional - Property dateValue(); + Property instantValue(); @Optional - Property dateTimeValue(); + Property dateTimeValue(); @Optional Property localDateTimeValue(); @@ -580,7 +581,6 @@ public abstract class AbstractEntityStoreTest public interface TestValue2 extends ValueComposite { - Property stringValue(); Property anotherValue(); @@ -588,8 +588,6 @@ public abstract class AbstractEntityStoreTest public enum TestEnum { - VALUE1, VALUE2, VALUE3 } - } http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractQueryTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractQueryTest.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractQueryTest.java index 9b40b62..8a0dc57 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractQueryTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/AbstractQueryTest.java @@ -22,19 +22,18 @@ package org.apache.zest.test.indexing; import java.io.IOException; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; import java.util.HashMap; import java.util.Map; import org.apache.zest.api.injection.scope.Structure; -import org.apache.zest.api.structure.Module; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; -import org.junit.Ignore; -import org.junit.Test; import org.apache.zest.api.query.NotQueryableException; import org.apache.zest.api.query.Query; import org.apache.zest.api.query.QueryBuilder; import org.apache.zest.api.query.grammar.OrderBy; +import org.apache.zest.api.structure.Module; import org.apache.zest.spi.query.EntityFinderException; import org.apache.zest.spi.query.IndexExporter; import org.apache.zest.test.indexing.model.Account; @@ -46,12 +45,10 @@ import org.apache.zest.test.indexing.model.Male; import org.apache.zest.test.indexing.model.Nameable; import org.apache.zest.test.indexing.model.Person; import org.apache.zest.test.indexing.model.QueryParam; +import org.junit.Ignore; +import org.junit.Test; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.joda.time.DateTimeZone.UTC; -import static org.joda.time.DateTimeZone.forID; -import static org.junit.Assert.assertThat; +import static java.time.ZoneOffset.UTC; import static org.apache.zest.api.query.QueryExpressions.and; import static org.apache.zest.api.query.QueryExpressions.contains; import static org.apache.zest.api.query.QueryExpressions.containsName; @@ -70,6 +67,9 @@ import static org.apache.zest.api.query.QueryExpressions.orderBy; import static org.apache.zest.api.query.QueryExpressions.templateFor; import static org.apache.zest.test.indexing.NameableAssert.verifyOrderedResults; import static org.apache.zest.test.indexing.NameableAssert.verifyUnorderedResults; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; /** * Abstract satisfiedBy with tests for simple queries against Index/Query engines. @@ -79,7 +79,7 @@ public abstract class AbstractQueryTest { @Structure Module moduleInstance; - + private ZonedDateTime refDate; @Test public void showNetwork() @@ -117,7 +117,7 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Nameable.class ); Query query = unitOfWork.newQuery( qb ); System.out.println( "*** script03: " + query ); - verifyUnorderedResults( query, "Felix", "Joe Doe", "Ann Doe", "Jack Doe", "Penang", "Kuala Lumpur", "Cooking", "Gaming", + verifyUnorderedResults( query, "Felix", "Joe Doe", "Ann Doe", "Jack Doe", "Penang", "Kuala Lumpur", "Cooking", "Gaming", "Programming", "Cars" ); } @@ -152,10 +152,10 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( eq( person.mother() - .get() - .placeOfBirth() - .get() - .name(), "Kuala Lumpur" ) ) + .get() + .placeOfBirth() + .get() + .name(), "Kuala Lumpur" ) ) ); System.out.println( "*** script05: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -441,10 +441,10 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( eq( person.personalWebsite() - .get() - .protocol() - .get() - .value(), "http" ) ) + .get() + .protocol() + .get() + .value(), "http" ) ) ); System.out.println( "*** script29: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -573,8 +573,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + refDate = ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, UTC ); Query query = unitOfWork.newQuery( qb.where( - eq( person.dateValue(), new DateTime( "2010-03-04T13:24:35", UTC ).toDate() ) ) ); + eq( person.instantValue(), refDate.toInstant() ) ) ); System.out.println( "*** script40_Date: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -586,7 +587,7 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( - ne( person.dateValue(), new DateTime( "2010-03-04T13:24:35", UTC ).toDate() ) ) ); + ne( person.instantValue(), refDate.toInstant() ) ) ); System.out.println( "*** script41_Date: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -597,8 +598,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime cetTime = ZonedDateTime.of( 2010, 3, 4, 14, 24, 35, 0, ZoneId.of( "CET" ) ); Query query = unitOfWork.newQuery( qb.where( - ne( person.dateValue(), new DateTime( "2010-03-04T14:24:35", forID( "CET" ) ).toDate() ) ) ); + ne( person.instantValue(), cetTime.toInstant() ) ) ); System.out.println( "*** script42_Date: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -609,9 +611,11 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime start = ZonedDateTime.of( 2005, 3, 4, 13, 24, 35, 0, UTC ); + ZonedDateTime end = ZonedDateTime.of( 2015, 3, 4, 13, 24, 35, 0, UTC ); Query query = unitOfWork.newQuery( qb.where( - and( gt( person.dateValue(), new DateTime( "2005-03-04T13:24:35", UTC ).toDate() ), - lt( person.dateValue(), new DateTime( "2015-03-04T13:24:35", UTC ).toDate() ) ) ) ); + and( gt( person.instantValue(), start.toInstant() ), + lt( person.instantValue(), end.toInstant() ) ) ) ); System.out.println( "*** script43_Date: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -622,8 +626,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime time = ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, UTC ); Query query = unitOfWork.newQuery( qb.where( - eq( person.dateTimeValue(), new DateTime( "2010-03-04T13:24:35", UTC ) ) ) ); + eq( person.dateTimeValue(), time ) ) ); System.out.println( "*** script40_DateTime: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -634,8 +639,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime time = ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, UTC ); Query query = unitOfWork.newQuery( qb.where( - ne( person.dateTimeValue(), new DateTime( "2010-03-04T13:24:35", UTC ) ) ) ); + ne( person.dateTimeValue(), time ) ) ); System.out.println( "*** script41_DateTime: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -646,8 +652,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime time = ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, ZoneId.of( "CET" ) ); Query query = unitOfWork.newQuery( qb.where( - ne( person.dateTimeValue(), new DateTime( "2010-03-04T14:24:35", forID( "CET" ) ) ) ) ); + ne( person.dateTimeValue(), time ) ) ); System.out.println( "*** script42_DateTime: " + query ); verifyUnorderedResults( query, "Jack Doe", "Joe Doe" ); @@ -658,9 +665,11 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime start = ZonedDateTime.of( 2005, 3, 4, 13, 24, 35, 0, UTC ); + ZonedDateTime end = ZonedDateTime.of( 2015, 3, 4, 13, 24, 35, 0, UTC ); Query query = unitOfWork.newQuery( qb.where( - and( gt( person.dateTimeValue(), new DateTime( "2005-03-04T13:24:35", UTC ) ), - lt( person.dateTimeValue(), new DateTime( "2015-03-04T13:24:35", UTC ) ) ) ) ); + and( gt( person.dateTimeValue(), start ), + lt( person.dateTimeValue(), end ) ) ) ); System.out.println( "*** script43_DateTime: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -672,7 +681,7 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( - eq( person.localDateTimeValue(), new LocalDateTime( "2010-03-04T13:23:00", UTC ) ) ) ); + eq( person.localDateTimeValue(), LocalDateTime.of( 2010, 3, 4, 13, 23, 0 ) ) ) ); System.out.println( "*** script40_LocalDateTime: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -684,7 +693,7 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( - ne( person.localDateTimeValue(), new LocalDateTime( "2010-03-04T13:23:00", UTC ) ) ) ); + ne( person.localDateTimeValue(), LocalDateTime.of( 2010, 3, 4, 13, 23, 0 ) ) ) ); System.out.println( "*** script41_LocalDateTime: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -695,8 +704,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + ZonedDateTime time = ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, ZoneId.of( "CET" ) ); Query query = unitOfWork.newQuery( qb.where( - ne( person.localDateTimeValue(), new LocalDateTime( "2010-03-04T13:23:00", forID( "CET" ) ) ) ) ); + ne( person.localDateTimeValue(), time.toLocalDateTime() ) ) ); System.out.println( "*** script42_LocalDateTime: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -707,9 +717,11 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + LocalDateTime start = ZonedDateTime.of( 2005, 3, 4, 13, 24, 35, 0, UTC ).toLocalDateTime(); + LocalDateTime end = ZonedDateTime.of( 2015, 3, 4, 13, 24, 35, 0, UTC ).toLocalDateTime(); Query query = unitOfWork.newQuery( qb.where( - and( gt( person.localDateTimeValue(), new LocalDateTime( "2005-03-04T13:24:35", UTC ) ), - lt( person.localDateTimeValue(), new LocalDateTime( "2015-03-04T13:24:35", UTC ) ) ) ) ); + and( gt( person.localDateTimeValue(), start ), + lt( person.localDateTimeValue(), end ) ) ) ); System.out.println( "*** script43_LocalDateTime: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -721,7 +733,7 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( - eq( person.localDateValue(), new LocalDate( "2010-03-04", UTC ) ) ) ); + eq( person.localDateValue(), LocalDate.of( 2010,3,4 ) ) ) ); System.out.println( "*** script40_LocalDate: " + query ); verifyUnorderedResults( query, "Jack Doe" ); @@ -733,7 +745,7 @@ public abstract class AbstractQueryTest QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); Query query = unitOfWork.newQuery( qb.where( - ne( person.localDateValue(), new LocalDate( "2010-03-04", UTC ) ) ) ); + ne( person.localDateValue(), LocalDate.of( 2010,3,4 ) ) ) ); System.out.println( "*** script41_LocalDate: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -744,8 +756,9 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + LocalDate time = ZonedDateTime.of(2010,3,4,13,24,35,0, ZoneId.of("CET")).toLocalDate(); Query query = unitOfWork.newQuery( qb.where( - ne( person.localDateValue(), new LocalDate( "2010-03-04", forID( "CET" ) ) ) ) ); + ne( person.localDateValue(), time ) ) ); System.out.println( "*** script42_LocalDate: " + query ); verifyUnorderedResults( query, "Joe Doe" ); @@ -756,9 +769,11 @@ public abstract class AbstractQueryTest { QueryBuilder qb = this.moduleInstance.newQueryBuilder( Person.class ); Person person = templateFor( Person.class ); + LocalDate start = ZonedDateTime.of(2010,3,4,13,24,35,0,UTC).toLocalDate(); + LocalDate end = ZonedDateTime.of(2010,3,4,13,24,35,0,UTC).toLocalDate(); Query query = unitOfWork.newQuery( qb.where( - and( gt( person.localDateValue(), new LocalDate( "2005-03-04", UTC ) ), - lt( person.localDateValue(), new LocalDate( "2015-03-04", UTC ) ) ) ) ); + and( gt( person.localDateValue(), start), + lt( person.localDateValue(), end ) ) ) ); System.out.println( "*** script43_LocalDate: " + query ); verifyUnorderedResults( query, "Jack Doe" ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/testsupport/src/main/java/org/apache/zest/test/indexing/TestData.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/TestData.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/TestData.java index 7c5d2fa..8d20a6e 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/TestData.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/TestData.java @@ -21,6 +21,9 @@ package org.apache.zest.test.indexing; import java.math.BigDecimal; import java.math.BigInteger; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; import org.apache.zest.api.entity.EntityBuilder; @@ -39,11 +42,8 @@ import org.apache.zest.test.indexing.model.Person; import org.apache.zest.test.indexing.model.Protocol; import org.apache.zest.test.indexing.model.QueryParam; import org.apache.zest.test.indexing.model.URL; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; -import static org.joda.time.DateTimeZone.UTC; +import static java.time.ZoneOffset.UTC; /** * Utility class to populate Index/Query tests data. @@ -176,10 +176,10 @@ public class TestData joeDoe.address().set( address ); joeDoe.bigInteger().set( new BigInteger( "23232323232323232323232323" ) ); joeDoe.bigDecimal().set( new BigDecimal( "23.4276931348623157e+309" ) ); - joeDoe.dateValue().set( new DateTime( "2020-03-04T13:24:35", UTC ).toDate() ); - joeDoe.dateTimeValue().set( new DateTime( "2020-03-04T13:24:35", UTC ) ); - joeDoe.localDateTimeValue().set( new LocalDateTime( "2020-03-04T13:23:00" ) ); - joeDoe.localDateValue().set( new LocalDate( "2020-03-04" ) ); + joeDoe.instantValue().set( ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 0, UTC ).toInstant() ); + joeDoe.dateTimeValue().set( ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 0, UTC ) ); + joeDoe.localDateTimeValue().set( LocalDateTime.of( 2020, 3, 4, 13, 23, 0 ) ); + joeDoe.localDateValue().set( LocalDate.of( 2020, 3, 4 ) ); NameableAssert.trace( joeDoe ); } @@ -201,10 +201,10 @@ public class TestData jackDoe.address().set( address ); jackDoe.bigInteger().set( new BigInteger( "42424242424242424242424242" ) ); jackDoe.bigDecimal().set( new BigDecimal( "42.2376931348623157e+309" ) ); - jackDoe.dateValue().set( new DateTime( "2010-03-04T13:24:35", UTC ).toDate() ); - jackDoe.dateTimeValue().set( new DateTime( "2010-03-04T13:24:35", UTC ) ); - jackDoe.localDateTimeValue().set( new LocalDateTime( "2010-03-04T13:23:00" ) ); - jackDoe.localDateValue().set( new LocalDate( "2010-03-04" ) ); + jackDoe.instantValue().set( ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, UTC ).toInstant() ); + jackDoe.dateTimeValue().set( ZonedDateTime.of( 2010, 3, 4, 13, 24, 35, 0, UTC ) ); + jackDoe.localDateTimeValue().set( LocalDateTime.of( 2010, 3, 4, 13, 23, 0 ) ); + jackDoe.localDateValue().set( LocalDate.of( 2010, 3, 4 ) ); ValueBuilder urlBuilder = module.newValueBuilder( URL.class ); ValueBuilder protocolBuilder = module.newValueBuilder( Protocol.class ); http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/testsupport/src/main/java/org/apache/zest/test/indexing/model/Person.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/indexing/model/Person.java b/core/testsupport/src/main/java/org/apache/zest/test/indexing/model/Person.java index e9bfd11..1046879 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/indexing/model/Person.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/indexing/model/Person.java @@ -21,11 +21,11 @@ package org.apache.zest.test.indexing.model; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Date; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.Map; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; import org.apache.zest.api.association.Association; import org.apache.zest.api.association.ManyAssociation; import org.apache.zest.api.association.NamedAssociation; @@ -86,10 +86,10 @@ public interface Person Property bigDecimal(); @Optional - Property dateValue(); + Property instantValue(); @Optional - Property dateTimeValue(); + Property dateTimeValue(); @Optional Property localDateTimeValue(); http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractJsonDateFormatTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractJsonDateFormatTest.java b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractJsonDateFormatTest.java index 3ad92cc..4cb33ba 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractJsonDateFormatTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractJsonDateFormatTest.java @@ -19,12 +19,17 @@ */ package org.apache.zest.test.value; -import java.util.Date; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.Period; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import java.util.List; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.Before; -import org.junit.Test; import org.apache.zest.api.injection.scope.Service; import org.apache.zest.api.type.CollectionType; import org.apache.zest.api.type.ValueType; @@ -32,8 +37,10 @@ import org.apache.zest.api.value.ValueDeserializer; import org.apache.zest.bootstrap.AssemblyException; import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.test.AbstractZestTest; +import org.junit.Test; -import static org.junit.Assert.*; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; /** * Assert that a JSON ValueDeserializer support various date formats. @@ -43,7 +50,14 @@ public class AbstractJsonDateFormatTest extends AbstractZestTest { - private final ValueType dateType = new ValueType( Date.class ); + private final ValueType offsetDateTimeType = new ValueType( OffsetDateTime.class ); + private final ValueType zonedDateTimeType = new ValueType( ZonedDateTime.class ); + private final ValueType localDateTimeType = new ValueType( LocalDateTime.class ); + private final ValueType localTimeType = new ValueType( LocalTime.class ); + private final ValueType localDateType = new ValueType( LocalDate.class ); + private final ValueType instantType = new ValueType( Instant.class ); + private final ValueType durationType = new ValueType( Duration.class ); + private final ValueType periodType = new ValueType( Period.class ); @Override public void assemble( ModuleAssembly module ) @@ -55,31 +69,83 @@ public class AbstractJsonDateFormatTest protected ValueDeserializer valueDeserializer; @Test - public void givenISO6801DateFormatWhenConvertingFromSerializedStateExpectValidDate() + public void givenLocalDateTimeFormatWhenConvertingFromSerializedStateExpectValidDate() + throws Exception + { + CollectionType collectionType = new CollectionType( List.class, localDateTimeType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"2009-08-12T14:54:27\"]" ); + LocalDateTime expected = LocalDateTime.of( 2009, 8, 12, 14, 54, 27 ); + assertThat( value.get( 0 ), equalTo( expected ) ); + } + + @Test + public void givenLocalDateFormatWhenConvertingFromSerializedStateExpectValidDate() + throws Exception + { + CollectionType collectionType = new CollectionType( List.class, localDateType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"2009-08-12\"]" ); + LocalDate expected = LocalDate.of( 2009, 8, 12 ); + assertThat( value.get( 0 ), equalTo( expected ) ); + } + + @Test + public void givenLocalTimeFormatWhenConvertingFromSerializedStateExpectValidDate() + throws Exception + { + CollectionType collectionType = new CollectionType( List.class, localTimeType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"14:54:27\"]" ); + LocalTime expected = LocalTime.of( 14, 54, 27 ); + assertThat( value.get( 0 ), equalTo( expected ) ); + } + + @Test + public void givenOffsetDateTimeFormatWhenConvertingFromSerializedStateExpectValidDate() + throws Exception + { + CollectionType collectionType = new CollectionType( List.class, offsetDateTimeType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"2009-08-12T14:54:27.895+08:00\"]" ); + OffsetDateTime expected = OffsetDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000, ZoneOffset.ofHours( 8 ) ); + assertThat( value.get( 0 ), equalTo( expected ) ); + } + + @Test + public void givenZonedDateTimeFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception { - CollectionType collectionType = new CollectionType( List.class, dateType ); - List value = valueDeserializer.deserialize( module, collectionType, "[\"2009-08-12T14:54:27.895+0800\"]" ); - assertEquals( new DateTime( "2009-08-12T06:54:27.895Z", DateTimeZone.UTC ).toDate(), value.get( 0 ) ); + CollectionType collectionType = new CollectionType( List.class, zonedDateTimeType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"2009-08-12T14:54:27.895+02:00[CET]\"]" ); + ZonedDateTime expected = ZonedDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000, ZoneId.of( "CET" ) ); + assertThat( value.get( 0 ), equalTo( expected ) ); } @Test - public void givenAtDateFormatWhenConvertingFromSerializedStateExpectValidDate() + public void givenInstantFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception { - long tstamp = System.currentTimeMillis(); - CollectionType collectionType = new CollectionType( List.class, dateType ); - List value = valueDeserializer.deserialize( module, collectionType, "[\"@" + tstamp + "@\"]" ); - assertEquals( new Date( tstamp ), value.get( 0 ) ); + CollectionType collectionType = new CollectionType( List.class, instantType); + List value = valueDeserializer.deserialize( module, collectionType, "[\"2016-06-11T08:47:12.620Z\"]" ); + Instant expected = Instant.parse("2016-06-11T08:47:12.620Z" ); + assertThat( value.get( 0 ), equalTo( expected ) ); } @Test - public void givenMicrosoftDateFormatWhenConvertingFromSerializedStateExpectValidDate() + public void givenDurationFormatWhenConvertingFromSerializedStateExpectValidDate() throws Exception { - long tstamp = System.currentTimeMillis(); - CollectionType collectionType = new CollectionType( List.class, dateType ); - List value = valueDeserializer.deserialize( module, collectionType, "[\"/Date(" + tstamp + ")/\"]" ); - assertEquals( new Date( tstamp ), value.get( 0 ) ); + CollectionType collectionType = new CollectionType( List.class, durationType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"PT3.5S\"]" ); + Duration expected = Duration.ofMillis( 3500 ); + assertThat( value.get( 0 ), equalTo( expected ) ); } + + @Test + public void givenPeriodFormatWhenConvertingFromSerializedStateExpectValidDate() + throws Exception + { + CollectionType collectionType = new CollectionType( List.class, periodType ); + List value = valueDeserializer.deserialize( module, collectionType, "[\"P3Y5M13D\"]" ); + Period expected = Period.of( 3, 5, 13); + assertThat( value.get( 0 ), equalTo( expected ) ); + } + } http://git-wip-us.apache.org/repos/asf/zest-java/blob/37910017/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractPlainValueSerializationTest.java ---------------------------------------------------------------------- diff --git a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractPlainValueSerializationTest.java b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractPlainValueSerializationTest.java index f00af68..3ac1039 100644 --- a/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractPlainValueSerializationTest.java +++ b/core/testsupport/src/main/java/org/apache/zest/test/value/AbstractPlainValueSerializationTest.java @@ -21,7 +21,11 @@ package org.apache.zest.test.value; import java.math.BigDecimal; import java.math.BigInteger; -import java.util.Date; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.time.ZonedDateTime; import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityReference; import org.apache.zest.api.injection.scope.Service; @@ -35,16 +39,10 @@ import org.apache.zest.bootstrap.ModuleAssembly; import org.apache.zest.entitystore.memory.MemoryEntityStoreService; import org.apache.zest.spi.uuid.UuidIdentityGeneratorService; import org.apache.zest.test.AbstractZestTest; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalDateTime; import org.junit.Test; import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; -import static org.joda.time.DateTimeZone.UTC; -import static org.joda.time.DateTimeZone.forID; -import static org.joda.time.DateTimeZone.forOffsetHours; import static org.junit.Assert.assertThat; /** @@ -194,46 +192,33 @@ public abstract class AbstractPlainValueSerializationTest } @Test - public void givenDateValueWhenSerializingAndDeserializingExpectEquals() - { - String serialized = valueSerialization.serialize( new DateTime( "2020-03-04T13:24:35", forID( "CET" ) ).toDate() ); - assertThat( serialized, equalTo( "2020-03-04T12:24:35.000Z" ) ); - - Date deserialized = valueSerialization.deserialize( module, Date.class, serialized ); - assertThat( deserialized, equalTo( new DateTime( "2020-03-04T13:24:35", forID( "CET" ) ).toDate() ) ); - assertThat( deserialized, equalTo( new DateTime( "2020-03-04T12:24:35", UTC ).toDate() ) ); - } - - @Test public void givenDateTimeValueWhenSerializingAndDeserializingExpectEquals() { - // We specify the TimeZone explicitely here so that serialized/deserialized is equals - // See https://github.com/JodaOrg/joda-time/issues/106 - String serialized = valueSerialization.serialize( new DateTime( "2020-03-04T13:24:35", forOffsetHours( 1 ) ) ); - assertThat( serialized, equalTo( "2020-03-04T13:24:35.000+01:00" ) ); - DateTime deserialized = valueSerialization.deserialize( module, DateTime.class, serialized ); - assertThat( deserialized, equalTo( new DateTime( "2020-03-04T13:24:35", forOffsetHours( 1 ) ) ) ); + String serialized = valueSerialization.serialize( OffsetDateTime.of( 2020, 3, 4, 13, 24, 35, 123000000, ZoneOffset.ofHours( 1 ) ) ); + assertThat( serialized, equalTo( "2020-03-04T13:24:35.123+01:00" ) ); + ZonedDateTime deserialized = valueSerialization.deserialize( module, ZonedDateTime.class, serialized ); + assertThat( deserialized, equalTo( ZonedDateTime.of( 2020, 3, 4, 13, 24, 35, 123000000, ZoneOffset.ofHours( 1 ) ) ) ); } @Test public void givenLocalDateTimeValueWhenSerializingAndDeserializingExpectEquals() { // Serialized without TimeZone - String serialized = valueSerialization.serialize( new LocalDateTime( "2020-03-04T13:23:00", forID( "CET" ) ) ); - assertThat( serialized, equalTo( "2020-03-04T13:23:00.000" ) ); + String serialized = valueSerialization.serialize( LocalDateTime.of( 2020, 3, 4, 13, 23, 12 ) ); + assertThat( serialized, equalTo( "2020-03-04T13:23:12" ) ); LocalDateTime deserialized = valueSerialization.deserialize( module, LocalDateTime.class, serialized ); - assertThat( deserialized, equalTo( new LocalDateTime( "2020-03-04T13:23:00", UTC ) ) ); + assertThat( deserialized, equalTo( LocalDateTime.of( 2020, 3, 4, 13, 23, 12 ) ) ); } @Test public void givenLocalDateValueWhenSerializingAndDeserializingExpectEquals() { - String serialized = valueSerialization.serialize( new LocalDate( "2020-03-04" ) ); + String serialized = valueSerialization.serialize( LocalDate.of( 2020, 3, 4 ) ); assertThat( serialized, equalTo( "2020-03-04" ) ); LocalDate deserialized = valueSerialization.deserialize( module, LocalDate.class, serialized ); - assertThat( deserialized, equalTo( new LocalDate( "2020-03-04" ) ) ); + assertThat( deserialized, equalTo( LocalDate.of( 2020,3,4 ) ) ); } @Test