Return-Path: X-Original-To: apmail-zest-commits-archive@minotaur.apache.org Delivered-To: apmail-zest-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 10E0817E29 for ; Fri, 17 Apr 2015 16:08:15 +0000 (UTC) Received: (qmail 48156 invoked by uid 500); 17 Apr 2015 16:08:15 -0000 Delivered-To: apmail-zest-commits-archive@zest.apache.org Received: (qmail 48127 invoked by uid 500); 17 Apr 2015 16:08:15 -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 48052 invoked by uid 99); 17 Apr 2015 16:08:14 -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; Fri, 17 Apr 2015 16:08:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CE8F4E0280; Fri, 17 Apr 2015 16:08:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: niclas@apache.org To: commits@zest.apache.org Date: Fri, 17 Apr 2015 16:08:44 -0000 Message-Id: <2e61fc9dbb4841e3ae9e75a7e53f1ef2@git.apache.org> In-Reply-To: <2da16a2ab3144bd6bd2beabd68134615@git.apache.org> References: <2da16a2ab3144bd6bd2beabd68134615@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [32/50] [abbrv] zest-qi4j git commit: Replaced Joda Time with Java 8 Time API. http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/booking/BuildDeliverySnapshotTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/booking/BuildDeliverySnapshotTest.java b/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/booking/BuildDeliverySnapshotTest.java index bb5c1e2..7b646cc 100644 --- a/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/booking/BuildDeliverySnapshotTest.java +++ b/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/booking/BuildDeliverySnapshotTest.java @@ -17,7 +17,8 @@ */ package org.qi4j.sample.dcicargo.sample_a.context.shipping.booking; -import java.util.Date; +import java.time.LocalTime; +import java.time.ZonedDateTime; import org.junit.Before; import org.junit.Test; import org.qi4j.api.unitofwork.UnitOfWork; @@ -37,9 +38,16 @@ import org.qi4j.sample.dcicargo.sample_a.data.shipping.itinerary.Itinerary; import org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location; import org.qi4j.sample.dcicargo.sample_a.data.shipping.voyage.Voyage; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEventType.*; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEventType.CLAIM; +import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEventType.CUSTOMS; +import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEventType.LOAD; +import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEventType.UNLOAD; /** * Tests of the Build Delivery Snapshot subfunction use case. @@ -53,9 +61,9 @@ import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingE * FIXME: Test methods call each other to allow ordered execution, ie. tests are not indepedants ! */ public class BuildDeliverySnapshotTest - extends TestApplication + extends TestApplication { - final Date TODAY = new Date(); + final ZonedDateTime TODAY = ZonedDateTime.now().with( LocalTime.MIDNIGHT ); private Location HONGKONG; private Location STOCKHOLM; @@ -105,51 +113,55 @@ public class BuildDeliverySnapshotTest leg( V200T, NEWYORK, DALLAS, day( 9 ), day( 12 ) ), leg( V300A, DALLAS, STOCKHOLM, day( 13 ), day( 16 ) ) ); - - } // DERIVE WITH ROUTE SPECIFICATION ============================================================================== - @Test( expected = RouteException.class ) - public void deviation_2a_InvalidRouteSpecification_sameLocations() throws Exception + @Test(expected = RouteException.class) + public void deviation_2a_InvalidRouteSpecification_sameLocations() + throws Exception { RouteSpecification routeSpec = routeSpecification( HONGKONG, HONGKONG, day( 20 ) ); new BuildDeliverySnapshot( routeSpec ).get(); } - @Test( expected = RouteException.class ) - public void deviation_2b_InvalidRouteSpecification_tooEarlyDeadline() throws Exception + @Test(expected = RouteException.class) + public void deviation_2b_InvalidRouteSpecification_tooEarlyDeadline() + throws Exception { RouteSpecification routeSpec = routeSpecification( HONGKONG, STOCKHOLM, TODAY ); new BuildDeliverySnapshot( routeSpec ).get(); } @Test - public void deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification() throws Exception + public void deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification() + throws Exception { RouteSpecification routeSpec = routeSpecification( HONGKONG, STOCKHOLM, day( 20 ) ); Delivery delivery = new BuildDeliverySnapshot( routeSpec ).get(); - assertThat( delivery.timestamp().get().after( TODAY ), is( equalTo( true ) ) ); // TODAY is set first - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.NOT_ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.NOT_RECEIVED ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( HandlingEventType.RECEIVE ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( null ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.timestamp().get().isAfter( TODAY.toInstant() ), equalTo( true ) ); // TODAY is set first + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.NOT_ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.NOT_RECEIVED ) ); + assertThat( delivery.nextExpectedHandlingEvent() + .get() + .handlingEventType() + .get(), equalTo( HandlingEventType.RECEIVE ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( HONGKONG ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), nullValue() ); + assertThat( delivery.lastHandlingEvent().get(), nullValue() ); + assertThat( delivery.lastKnownLocation().get(), nullValue() ); + assertThat( delivery.currentVoyage().get(), nullValue() ); + assertThat( delivery.eta().get(), nullValue() ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); } - // DERIVE WITH NON-ROUTED CARGO ============================================================================== @Test - public void deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo() throws Exception + public void deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo() + throws Exception { deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification(); @@ -160,25 +172,28 @@ public class BuildDeliverySnapshotTest Cargo cargo = CARGOS.createCargo( routeSpec, delivery, "ABCD" ); // Same as previous test (just build from cargo instead) - assertThat( delivery.timestamp().get().after( TODAY ), is( equalTo( true ) ) ); // TODAY is set first - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.NOT_ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.NOT_RECEIVED ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( HandlingEventType.RECEIVE ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( null ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.timestamp().get().isAfter( TODAY.toInstant() ), equalTo( true ) ); // TODAY is set first + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.NOT_ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.NOT_RECEIVED ) ); + assertThat( delivery.nextExpectedHandlingEvent() + .get() + .handlingEventType() + .get(), equalTo( HandlingEventType.RECEIVE ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( HONGKONG ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), nullValue() ); + assertThat( delivery.lastHandlingEvent().get(), nullValue() ); + assertThat( delivery.lastKnownLocation().get(), nullValue() ); + assertThat( delivery.currentVoyage().get(), nullValue() ); + assertThat( delivery.eta().get(), nullValue() ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); } - // DERIVE WITH ROUTE SPECIFICATION + ITINERARY (Routed cargo) ============================================== @Test - public void deviation_2d_UnsatisfyingItinerary_wrongOrigin() throws Exception + public void deviation_2d_UnsatisfyingItinerary_wrongOrigin() + throws Exception { deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo(); @@ -195,12 +210,13 @@ public class BuildDeliverySnapshotTest Delivery delivery = new BuildDeliverySnapshot( cargo ).get(); // Route specification not satisfied by itinerary - assertThat( itinerary.firstLeg().loadLocation().get(), is( not( equalTo( routeSpec.origin().get() ) ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.MISROUTED ) ) ); + assertThat( itinerary.firstLeg().loadLocation().get(), not( equalTo( routeSpec.origin().get() ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.MISROUTED ) ); } @Test - public void deviation_2d_UnsatisfyingItinerary_wrongDestination() throws Exception + public void deviation_2d_UnsatisfyingItinerary_wrongDestination() + throws Exception { deviation_2d_UnsatisfyingItinerary_wrongOrigin(); @@ -210,12 +226,13 @@ public class BuildDeliverySnapshotTest Delivery delivery = new BuildDeliverySnapshot( cargo ).get(); // Route specification not satisfied by itinerary - assertThat( itinerary.lastLeg().unloadLocation().get(), is( not( equalTo( routeSpec.destination().get() ) ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.MISROUTED ) ) ); + assertThat( itinerary.lastLeg().unloadLocation().get(), not( equalTo( routeSpec.destination().get() ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.MISROUTED ) ); } @Test - public void deviation_2d_UnsatisfyingItinerary_missedDeadline() throws Exception + public void deviation_2d_UnsatisfyingItinerary_missedDeadline() + throws Exception { deviation_2d_UnsatisfyingItinerary_wrongDestination(); @@ -225,46 +242,50 @@ public class BuildDeliverySnapshotTest Delivery delivery = new BuildDeliverySnapshot( cargo ).get(); // Route specification not satisfied by itinerary - assertFalse( routeSpec.arrivalDeadline().get().after( itinerary.finalArrivalDate() ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.MISROUTED ) ) ); + assertFalse( routeSpec.arrivalDeadline().get().isAfter( itinerary.finalArrivalDate() ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.MISROUTED ) ); } @Test - public void deviation_3a_CargoHasNoHandlingHistory() throws Exception + public void deviation_3a_CargoHasNoHandlingHistory() + throws Exception { deviation_2d_UnsatisfyingItinerary_missedDeadline(); - Date arrival = day( 16 ); - Date deadline = day( 20 ); + ZonedDateTime arrival = day( 16 ); + ZonedDateTime deadline = day( 20 ); // Itinerary will satisfy route specification RouteSpecification routeSpec = routeSpecification( HONGKONG, STOCKHOLM, deadline ); cargo.routeSpecification().set( routeSpec ); Delivery delivery = new BuildDeliverySnapshot( cargo ).get(); // Route specification satisfied by itinerary - assertThat( itinerary.firstLeg().loadLocation().get(), is( equalTo( routeSpec.origin().get() ) ) ); - assertThat( itinerary.lastLeg().unloadLocation().get(), is( equalTo( routeSpec.destination().get() ) ) ); - assertTrue( routeSpec.arrivalDeadline().get().after( itinerary.finalArrivalDate() ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - - assertThat( delivery.timestamp().get().after( TODAY ), is( equalTo( true ) ) ); // TODAY is set first - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.NOT_RECEIVED ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( HandlingEventType.RECEIVE ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( null ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( arrival ) ) ); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( itinerary.firstLeg().loadLocation().get(), equalTo( routeSpec.origin().get() ) ); + assertThat( itinerary.lastLeg().unloadLocation().get(), equalTo( routeSpec.destination().get() ) ); + assertTrue( routeSpec.arrivalDeadline().get().isAfter( itinerary.finalArrivalDate() ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + + assertThat( delivery.timestamp().get().isAfter( TODAY.toInstant() ), equalTo( true ) ); // TODAY is set first + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.NOT_RECEIVED ) ); + assertThat( delivery.nextExpectedHandlingEvent() + .get() + .handlingEventType() + .get(), equalTo( HandlingEventType.RECEIVE ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( HONGKONG ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), nullValue() ); + assertThat( delivery.lastHandlingEvent().get(), nullValue() ); + assertThat( delivery.lastKnownLocation().get(), nullValue() ); + assertThat( delivery.currentVoyage().get(), nullValue() ); + assertThat( delivery.eta().get(), equalTo( arrival ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); } - // DERIVE WITH ROUTE SPECIFICATION + ITINERARY + LAST HANDLING EVENT ============================================ @Test - public void deviation_4a_RECEIVE_1a_UnexpectedPort() throws Exception + public void deviation_4a_RECEIVE_1a_UnexpectedPort() + throws Exception { deviation_3a_CargoHasNoHandlingHistory(); @@ -275,22 +296,23 @@ public class BuildDeliverySnapshotTest Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); // We don't know what's next for a misdirected cargo - assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( true ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), nullValue() ); + assertThat( delivery.eta().get(), nullValue() ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( SHANGHAI ) ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( SHANGHAI ) ); // Cargo is still routed - but it should be re-routed according to new (unexpected) location. - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.currentVoyage().get(), nullValue() ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); } @Test - public void deviation_4a_RECEIVE_1b_ExpectedPort() throws Exception + public void deviation_4a_RECEIVE_1b_ExpectedPort() + throws Exception { deviation_4a_RECEIVE_1a_UnexpectedPort(); @@ -300,21 +322,21 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, HandlingEventType.RECEIVE, HONGKONG, null ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( HONGKONG ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( HONGKONG ) ); // We expect the cargo to be loaded on voyage V100S in Hong Kong - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( LOAD ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( V100S ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( LOAD ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( HONGKONG ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( V100S ) ); } - @Test - public void deviation_4b_LOAD_2a_UnexpectedPort() throws Exception + public void deviation_4b_LOAD_2a_UnexpectedPort() + throws Exception { deviation_4a_RECEIVE_1b_ExpectedPort(); @@ -324,19 +346,20 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, LOAD, TOKYO, V100S ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( true ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), nullValue() ); + assertThat( delivery.eta().get(), nullValue() ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.ONBOARD_CARRIER ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( TOKYO ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( V100S ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.ONBOARD_CARRIER ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( TOKYO ) ); + assertThat( delivery.currentVoyage().get(), equalTo( V100S ) ); } @Test - public void deviation_4b_LOAD_2b_ExpectedPort() throws Exception + public void deviation_4b_LOAD_2b_ExpectedPort() + throws Exception { deviation_4b_LOAD_2a_UnexpectedPort(); @@ -346,21 +369,22 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, LOAD, HONGKONG, V100S ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.ONBOARD_CARRIER ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( V100S ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.ONBOARD_CARRIER ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( HONGKONG ) ); + assertThat( delivery.currentVoyage().get(), equalTo( V100S ) ); // We expect the cargo to be unloaded from voyage V100S in New York - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( UNLOAD ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( NEWYORK ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( V100S ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( UNLOAD ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( NEWYORK ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( V100S ) ); } @Test - public void deviation_4b_LOAD_2c_UnexpectedVoyageNotFromItinerary() throws Exception + public void deviation_4b_LOAD_2c_UnexpectedVoyageNotFromItinerary() + throws Exception { deviation_4b_LOAD_2b_ExpectedPort(); @@ -370,19 +394,20 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 1 ), trackingId, LOAD, HONGKONG, V400S ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( true ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), nullValue() ); + assertThat( delivery.eta().get(), nullValue() ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.ONBOARD_CARRIER ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( V400S ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.ONBOARD_CARRIER ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( HONGKONG ) ); + assertThat( delivery.currentVoyage().get(), equalTo( V400S ) ); } @Test - public void deviation_4b_LOAD_2c_ExpectedButLaterVoyageInItinerary() throws Exception + public void deviation_4b_LOAD_2c_ExpectedButLaterVoyageInItinerary() + throws Exception { deviation_4b_LOAD_2c_UnexpectedVoyageNotFromItinerary(); @@ -395,23 +420,23 @@ public class BuildDeliverySnapshotTest Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); // Should have been true, but we accept it for now... - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.ONBOARD_CARRIER ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( NEWYORK ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( V200T ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.ONBOARD_CARRIER ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( NEWYORK ) ); + assertThat( delivery.currentVoyage().get(), equalTo( V200T ) ); // We expect the cargo to be unloaded from voyage V200T in Dallas - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( UNLOAD ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( DALLAS ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( V200T ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( UNLOAD ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( DALLAS ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( V200T ) ); } - @Test - public void deviation_4c_UNLOAD_1a_UnexpectedPort() throws Exception + public void deviation_4c_UNLOAD_1a_UnexpectedPort() + throws Exception { deviation_4b_LOAD_2c_ExpectedButLaterVoyageInItinerary(); @@ -423,18 +448,18 @@ public class BuildDeliverySnapshotTest Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); cargo.delivery().set( delivery ); - assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( true ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), nullValue() ); + assertThat( delivery.eta().get(), nullValue() ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastHandlingEvent().get().handlingEventType().get(), is( equalTo( UNLOAD ) ) ); - assertThat( delivery.lastHandlingEvent().get().voyage().get(), is( equalTo( V100S ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( TOKYO ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastHandlingEvent().get().handlingEventType().get(), equalTo( UNLOAD ) ); + assertThat( delivery.lastHandlingEvent().get().voyage().get(), equalTo( V100S ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( TOKYO ) ); + assertThat( delivery.currentVoyage().get(), nullValue() ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); // Cargo needs to be rerouted @@ -445,34 +470,34 @@ public class BuildDeliverySnapshotTest cargo.delivery().set( delivery ); // Old itinerary will not satisfy new route specification - assertThat( itinerary.firstLeg().loadLocation().get(), is( not( equalTo( routeSpec.origin().get() ) ) ) ); - assertThat( itinerary.lastLeg().unloadLocation().get(), is( equalTo( routeSpec.destination().get() ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.MISROUTED ) ) ); + assertThat( itinerary.firstLeg().loadLocation().get(), not( equalTo( routeSpec.origin().get() ) ) ); + assertThat( itinerary.lastLeg().unloadLocation().get(), equalTo( routeSpec.destination().get() ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.MISROUTED ) ); // Old planned arrival time is still satisfying new deadline - assertTrue( routeSpec.arrivalDeadline().get().after( itinerary.finalArrivalDate() ) ); + assertTrue( routeSpec.arrivalDeadline().get().isAfter( itinerary.finalArrivalDate() ) ); // We don't know what's next before a new itinerary has been chosen - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), equalTo( null ) ); + assertThat( delivery.eta().get(), equalTo( null ) ); // Cargo is still misdirected (in unexpected location) according to old itinerary - assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( true ) ); // Last known data - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastHandlingEvent().get().handlingEventType().get(), is( equalTo( UNLOAD ) ) ); - assertThat( delivery.lastHandlingEvent().get().voyage().get(), is( equalTo( V100S ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( TOKYO ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastHandlingEvent().get().handlingEventType().get(), equalTo( UNLOAD ) ); + assertThat( delivery.lastHandlingEvent().get().voyage().get(), equalTo( V100S ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( TOKYO ) ); + assertThat( delivery.currentVoyage().get(), equalTo( null ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); // New itinerary that satisfy the new route specification. New origin departure from Tokyo. - Date arrival= day( 19 ); + ZonedDateTime arrival = day( 19 ); itinerary = itinerary( - leg( V400S, TOKYO, HAMBURG, day( 9 ), day( 16 ) ), - leg( V500S, HAMBURG, STOCKHOLM, day( 17 ), arrival ) + leg( V400S, TOKYO, HAMBURG, day( 9 ), day( 16 ) ), + leg( V500S, HAMBURG, STOCKHOLM, day( 17 ), arrival ) ); // Customer reroutes cargo. This is a possible step in the cargo booking process. @@ -480,31 +505,32 @@ public class BuildDeliverySnapshotTest delivery = cargo.delivery().get(); // Cargo is on track again - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastHandlingEvent().get().handlingEventType().get(), is( equalTo( UNLOAD ) ) ); - assertThat( delivery.lastHandlingEvent().get().voyage().get(), is( equalTo( V100S ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( TOKYO ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( arrival ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastHandlingEvent().get().handlingEventType().get(), equalTo( UNLOAD ) ); + assertThat( delivery.lastHandlingEvent().get().voyage().get(), equalTo( V100S ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( TOKYO ) ); + assertThat( delivery.currentVoyage().get(), equalTo( null ) ); + assertThat( delivery.eta().get(), equalTo( arrival ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); // When a cargo is rerouted the (often misdirected) last handling event is flagged as disregarded // since it doesn't have to be part of the new itinerary (this isn't in the Citerus version). // We now expect the cargo to be loaded onto voyage V400S in Tokyo heading to Hamburg - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( LOAD ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( TOKYO ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( V400S ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( LOAD ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( TOKYO ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( V400S ) ); // Cargo is not misdirected anymore according to new itinerary. Cargo location is now expected to be in Tokyo. } @Test - public void deviation_4c_UNLOAD_1b_ExpectedMidpointLocation() throws Exception + public void deviation_4c_UNLOAD_1b_ExpectedMidpointLocation() + throws Exception { deviation_4c_UNLOAD_1a_UnexpectedPort(); @@ -515,22 +541,23 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 8 ), day( 8 ), trackingId, UNLOAD, HAMBURG, V400S ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( HAMBURG ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( HAMBURG ) ); + assertThat( delivery.currentVoyage().get(), nullValue() ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); // We expect the cargo to be loaded onto voyage V200T in New York heading for Dallas - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( LOAD ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( HAMBURG ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( V500S ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( LOAD ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( HAMBURG ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( V500S ) ); } @Test - public void deviation_4c_UNLOAD_1c_Destination() throws Exception + public void deviation_4c_UNLOAD_1c_Destination() + throws Exception { deviation_4c_UNLOAD_1b_ExpectedMidpointLocation(); @@ -541,25 +568,25 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 16 ), day( 16 ), trackingId, UNLOAD, STOCKHOLM, V500S ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( STOCKHOLM ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( STOCKHOLM ) ); + assertThat( delivery.currentVoyage().get(), equalTo( null ) ); // Cargo has arrived at destination location - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( true ) ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( true ) ); // We expect the cargo to be claimed by customer - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( CLAIM ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( STOCKHOLM ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( null ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( CLAIM ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( STOCKHOLM ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( null ) ); } - @Test - public void deviation_4d_CUSTOMS_1a_CargoIsInDestinationPort() throws Exception + public void deviation_4d_CUSTOMS_1a_CargoIsInDestinationPort() + throws Exception { deviation_4c_UNLOAD_1c_Destination(); @@ -570,23 +597,23 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 16 ), day( 16 ), trackingId, CUSTOMS, STOCKHOLM, null ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.IN_PORT ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( STOCKHOLM ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.IN_PORT ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( STOCKHOLM ) ); + assertThat( delivery.currentVoyage().get(), equalTo( null ) ); // Cargo might be at destination, but the last handling event wasn't unloading - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( true ) ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( true ) ); // Shouldn't we expect the cargo to be claimed by the customer now ? - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), equalTo( null ) ); } - @Test - public void deviation_4e_CLAIM_1a_CargoIsNotInDestinationPort() throws Exception + public void deviation_4e_CLAIM_1a_CargoIsNotInDestinationPort() + throws Exception { deviation_4d_CUSTOMS_1a_CargoIsInDestinationPort(); @@ -597,22 +624,23 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 1 ), day( 16 ), trackingId, CLAIM, HELSINKI, null ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( true ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); - assertThat( delivery.eta().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( true ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), equalTo( null ) ); + assertThat( delivery.eta().get(), equalTo( null ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.CLAIMED ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( HELSINKI ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.CLAIMED ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( HELSINKI ) ); + assertThat( delivery.currentVoyage().get(), equalTo( null ) ); // Cargo is claimed but has not arrived yet in destination port - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); } @Test - public void deviation_4e_CLAIM_1b_CargoIsInDestinationPort() throws Exception + public void deviation_4e_CLAIM_1b_CargoIsInDestinationPort() + throws Exception { deviation_4e_CLAIM_1a_CargoIsNotInDestinationPort(); @@ -623,17 +651,17 @@ public class BuildDeliverySnapshotTest HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent( day( 16 ), day( 16 ), trackingId, CLAIM, STOCKHOLM, null ); Delivery delivery = new BuildDeliverySnapshot( cargo, handlingEvent ).get(); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.CLAIMED ) ) ); - assertThat( delivery.lastHandlingEvent().get(), is( equalTo( handlingEvent ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( STOCKHOLM ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( null ) ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.CLAIMED ) ); + assertThat( delivery.lastHandlingEvent().get(), equalTo( handlingEvent ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( STOCKHOLM ) ); + assertThat( delivery.currentVoyage().get(), equalTo( null ) ); // Cargo is claimed in destination port - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( true ) ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( true ) ); // No more expected handling events - assertThat( delivery.nextExpectedHandlingEvent().get(), is( equalTo( null ) ) ); + assertThat( delivery.nextExpectedHandlingEvent().get(), equalTo( null ) ); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/handling/RegisterHandlingEventTest.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/handling/RegisterHandlingEventTest.java b/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/handling/RegisterHandlingEventTest.java index fba4edc..964b299 100644 --- a/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/handling/RegisterHandlingEventTest.java +++ b/samples/dci-cargo/dcisample_a/src/test/java/org/qi4j/sample/dcicargo/sample_a/context/shipping/handling/RegisterHandlingEventTest.java @@ -17,7 +17,7 @@ */ package org.qi4j.sample.dcicargo.sample_a.context.shipping.handling; -import java.util.Date; +import java.time.ZonedDateTime; import org.junit.Before; import org.junit.Test; import org.qi4j.api.unitofwork.UnitOfWork; @@ -35,7 +35,6 @@ import org.qi4j.sample.dcicargo.sample_a.data.shipping.location.Location; import org.qi4j.sample.dcicargo.sample_a.data.shipping.voyage.Voyage; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEventType.UNLOAD; @@ -45,12 +44,12 @@ import static org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingE * Test method names describe the test purpose. The prefix refers to the step in the use case. */ public class RegisterHandlingEventTest - extends TestApplication + extends TestApplication { - Date time; + ZonedDateTime time; String trackId; String msg; - private Date arrival; + private ZonedDateTime arrival; private Cargo cargo; private TrackingId trackingId; private Cargos CARGOS; @@ -63,9 +62,11 @@ public class RegisterHandlingEventTest private Voyage V300A; @Before - public void beforeEachTest() throws Exception { + public void beforeEachTest() + throws Exception + { UnitOfWork uow = module.currentUnitOfWork(); - CARGOS = uow.get(Cargos.class, CargosEntity.CARGOS_ID ); + CARGOS = uow.get( Cargos.class, CargosEntity.CARGOS_ID ); HONGKONG = uow.get( Location.class, CNHKG.code().get() ); STOCKHOLM = uow.get( Location.class, SESTO.code().get() ); NEWYORK = uow.get( Location.class, USNYC.code().get() ); @@ -76,10 +77,10 @@ public class RegisterHandlingEventTest trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 17 ) ).createCargo( "ABC" ); cargo = uow.get( Cargo.class, trackingId.id().get() ); Itinerary itinerary = itinerary( - leg( V100S, HONGKONG, NEWYORK, day( 1 ), day( 8 ) ), - leg( V200T, NEWYORK, DALLAS, day( 9 ), day( 12 ) ), - leg( V300A, DALLAS, STOCKHOLM, day( 13 ), - arrival = day( 16 ) ) + leg( V100S, HONGKONG, NEWYORK, day( 1 ), day( 8 ) ), + leg( V200T, NEWYORK, DALLAS, day( 9 ), day( 12 ) ), + leg( V300A, DALLAS, STOCKHOLM, day( 13 ), + arrival = day( 16 ) ) ); new BookNewCargo( cargo, itinerary ).assignCargoToRoute(); time = day( 1 ); @@ -89,147 +90,165 @@ public class RegisterHandlingEventTest // INPUT EXISTENCE VALIDATION ================================================================== @Test - public void deviation_2a_MissingRegistrationTime() throws Exception + public void deviation_2a_MissingRegistrationTime() + throws Exception { msg = register( null, time, trackId, "RECEIVE", "CNHKG", null ); - assertThat( msg, is( equalTo( "Registration time was null. All parameters have to be passed." ) ) ); + assertThat( msg, equalTo( "Registration time was null. All parameters have to be passed." ) ); } + @Test - public void deviation_2a_MissingCompletionTime() throws Exception + public void deviation_2a_MissingCompletionTime() + throws Exception { msg = register( time, null, trackId, "RECEIVE", "CNHKG", null ); - assertThat( msg, is( equalTo( "Completion time was null. All parameters have to be passed." ) ) ); + assertThat( msg, equalTo( "Completion time was null. All parameters have to be passed." ) ); } @Test - public void deviation_2a_MissingTrackingId() throws Exception + public void deviation_2a_MissingTrackingId() + throws Exception { msg = register( time, time, null, "RECEIVE", "CNHKG", null ); - assertThat( msg, is( equalTo( "Tracking id was null. All parameters have to be passed." ) ) ); + assertThat( msg, equalTo( "Tracking id was null. All parameters have to be passed." ) ); } @Test - public void deviation_2a_EmptyTrackingId() throws Exception + public void deviation_2a_EmptyTrackingId() + throws Exception { msg = register( time, time, "", "RECEIVE", "CNHKG", null ); - assertThat( msg, is( equalTo( "Tracking id cannot be empty." ) ) ); + assertThat( msg, equalTo( "Tracking id cannot be empty." ) ); } @Test - public void deviation_2a_MissingEventType() throws Exception + public void deviation_2a_MissingEventType() + throws Exception { msg = register( time, time, trackId, null, "CNHKG", null ); - assertThat( msg, is( equalTo( "Event type was null. All parameters have to be passed." ) ) ); + assertThat( msg, equalTo( "Event type was null. All parameters have to be passed." ) ); } @Test - public void deviation_2a_EmptyEventType() throws Exception + public void deviation_2a_EmptyEventType() + throws Exception { msg = register( time, time, trackId, "", "CNHKG", null ); - assertThat( msg, is( equalTo( "Event type cannot be empty." ) ) ); + assertThat( msg, equalTo( "Event type cannot be empty." ) ); } @Test - public void deviation_2a_MissingUnlocode() throws Exception + public void deviation_2a_MissingUnlocode() + throws Exception { msg = register( time, time, trackId, "RECEIVE", null, null ); - assertThat( msg, is( equalTo( "UnLocode was null. All parameters have to be passed." ) ) ); + assertThat( msg, equalTo( "UnLocode was null. All parameters have to be passed." ) ); } @Test - public void deviation_2a_EmptyUnlocode() throws Exception + public void deviation_2a_EmptyUnlocode() + throws Exception { msg = register( time, time, trackId, "RECEIVE", "", null ); - assertThat( msg, is( equalTo( "UnLocode cannot be empty." ) ) ); + assertThat( msg, equalTo( "UnLocode cannot be empty." ) ); } @Test - public void step_2_CompleteData__Receive_in_Hong_Kong() throws Exception + public void step_2_CompleteData__Receive_in_Hong_Kong() + throws Exception { new RegisterHandlingEvent( time, time, trackId, "RECEIVE", "CNHKG", null ).register(); } - // INPUT VALIDATION ================================================================== @Test - public void deviation_3a_HandlingTypeNotRecognized() throws Exception + public void deviation_3a_HandlingTypeNotRecognized() + throws Exception { msg = register( time, time, trackId, "RECEIPT", "CNHKG", null ); - assertThat( msg, is( equalTo( - "'RECEIPT' is not a valid handling event type. Valid types are: [RECEIVE, LOAD, UNLOAD, CUSTOMS, CLAIM]" ) ) ); + assertThat( msg, equalTo( + "'RECEIPT' is not a valid handling event type. Valid types are: [RECEIVE, LOAD, UNLOAD, CUSTOMS, CLAIM]" ) ); } @Test - public void deviation_3b_NoCargoWithTrackingId() throws Exception + public void deviation_3b_NoCargoWithTrackingId() + throws Exception { msg = register( time, time, "XXX", "RECEIVE", "CNHKG", null ); - assertThat( msg, is( equalTo( "Found no cargo with tracking id 'XXX'." ) ) ); + assertThat( msg, equalTo( "Found no cargo with tracking id 'XXX'." ) ); } @Test - public void deviation_3c_CargoNotRoutedYet() throws Exception + public void deviation_3c_CargoNotRoutedYet() + throws Exception { TrackingId nonRoutedTrackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 17 ) ).createCargo( "NonRoutedCargo" ); String nonRouted = nonRoutedTrackingId.id().get(); msg = register( time, time, nonRouted, "RECEIVE", "CNHKG", null ); - assertThat( msg, is( equalTo( "Can't create handling event for non-routed cargo '" + nonRouted + "'." ) ) ); + assertThat( msg, equalTo( "Can't create handling event for non-routed cargo '" + nonRouted + "'." ) ); } @Test - public void deviation_3d_NoLocationWithUnlocode() throws Exception + public void deviation_3d_NoLocationWithUnlocode() + throws Exception { msg = register( time, time, trackId, "RECEIVE", "ZZZZZ", null ); - assertThat( msg, is( equalTo( "Unknown location: ZZZZZ" ) ) ); + assertThat( msg, equalTo( "Unknown location: ZZZZZ" ) ); } @Test - public void deviation_3e_1a_MissingVoyageNumber() throws Exception + public void deviation_3e_1a_MissingVoyageNumber() + throws Exception { msg = register( time, time, trackId, "LOAD", "CNHKG", null ); - assertThat( msg, is( equalTo( "Handling event LOAD requires a voyage. No voyage number submitted." ) ) ); + assertThat( msg, equalTo( "Handling event LOAD requires a voyage. No voyage number submitted." ) ); } @Test - public void deviation_3e_1b_MissingVoyage() throws Exception + public void deviation_3e_1b_MissingVoyage() + throws Exception { msg = register( time, time, trackId, "LOAD", "CNHKG", "V600S" ); - assertThat( msg, is( equalTo( "Found no voyage with voyage number 'V600S'." ) ) ); + assertThat( msg, equalTo( "Found no voyage with voyage number 'V600S'." ) ); } @Test - public void deviation_3f_SkipVoyageNumberSilentlyWhenProhibited() throws Exception + public void deviation_3f_SkipVoyageNumberSilentlyWhenProhibited() + throws Exception { new RegisterHandlingEvent( time, time, trackId, "RECEIVE", "CNHKG", "V100S" ).register(); - assertThat( cargo.delivery().get().currentVoyage().get(), is( equalTo( null ) ) ); + assertThat( cargo.delivery().get().currentVoyage().get(), equalTo( null ) ); } @Test - public void step_3_to_5_ValidRegistration__Load_in_Hong_Kong() throws Exception + public void step_3_to_5_ValidRegistration__Load_in_Hong_Kong() + throws Exception { new RegisterHandlingEvent( time, time, trackId, "LOAD", "CNHKG", "V100S" ).register(); Delivery delivery = cargo.delivery().get(); - assertThat( delivery.routingStatus().get(), is( equalTo( RoutingStatus.ROUTED ) ) ); - assertThat( delivery.transportStatus().get(), is( equalTo( TransportStatus.ONBOARD_CARRIER ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is( equalTo( UNLOAD ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), is( equalTo( NEWYORK ) ) ); - assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), is( equalTo( V100S ) ) ); - assertThat( delivery.lastKnownLocation().get(), is( equalTo( HONGKONG ) ) ); - assertThat( delivery.currentVoyage().get(), is( equalTo( V100S ) ) ); - assertThat( delivery.eta().get(), is( equalTo( arrival ) ) ); - assertThat( delivery.isMisdirected().get(), is( equalTo( false ) ) ); - assertThat( delivery.isUnloadedAtDestination().get(), is( equalTo( false ) ) ); + assertThat( delivery.routingStatus().get(), equalTo( RoutingStatus.ROUTED ) ); + assertThat( delivery.transportStatus().get(), equalTo( TransportStatus.ONBOARD_CARRIER ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), equalTo( UNLOAD ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().location().get(), equalTo( NEWYORK ) ); + assertThat( delivery.nextExpectedHandlingEvent().get().voyage().get(), equalTo( V100S ) ); + assertThat( delivery.lastKnownLocation().get(), equalTo( HONGKONG ) ); + assertThat( delivery.currentVoyage().get(), equalTo( V100S ) ); + assertThat( delivery.eta().get(), equalTo( arrival ) ); + assertThat( delivery.isMisdirected().get(), equalTo( false ) ); + assertThat( delivery.isUnloadedAtDestination().get(), equalTo( false ) ); } - - private String register( Date registrationTime, - Date completionTime, + private String register( ZonedDateTime registrationTime, + ZonedDateTime completionTime, String trackingIdString, String eventTypeString, String unLocodeString, - String voyageNumberString ) throws Exception + String voyageNumberString + ) + throws Exception { try { @@ -240,7 +259,7 @@ public class RegisterHandlingEventTest unLocodeString, voyageNumberString ).register(); } - catch (IllegalArgumentException e) + catch( IllegalArgumentException e ) { return e.getMessage(); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/GraphTraversalService.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/GraphTraversalService.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/GraphTraversalService.java index 7fc9dbf..6918b12 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/GraphTraversalService.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/GraphTraversalService.java @@ -19,7 +19,8 @@ package org.qi4j.sample.dcicargo.pathfinder_b.api; import java.rmi.Remote; import java.rmi.RemoteException; -import java.util.Date; +import java.time.LocalDate; +import java.time.ZonedDateTime; import java.util.List; /** @@ -38,7 +39,7 @@ public interface GraphTraversalService extends Remote * * @throws RemoteException RMI problem */ - List findShortestPath( Date departureDate, String originUnLocode, String destinationUnLocode ) + List findShortestPath( ZonedDateTime departureDate, String originUnLocode, String destinationUnLocode ) throws RemoteException; List getVoyages() http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/TransitEdge.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/TransitEdge.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/TransitEdge.java index 111c941..8adee9d 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/TransitEdge.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/api/TransitEdge.java @@ -18,7 +18,8 @@ package org.qi4j.sample.dcicargo.pathfinder_b.api; import java.io.Serializable; -import java.util.Date; +import java.time.LocalDate; +import java.time.ZonedDateTime; /** * Represents an edge in a path through a graph, @@ -30,8 +31,8 @@ public final class TransitEdge implements Serializable private final String voyageNumber; private final String fromUnLocode; private final String toUnLocode; - private final Date fromDate; - private final Date toDate; + private final ZonedDateTime fromDate; + private final ZonedDateTime toDate; /** * Constructor. @@ -45,8 +46,8 @@ public final class TransitEdge implements Serializable public TransitEdge( final String voyageNumber, final String fromUnLocode, final String toUnLocode, - final Date fromDate, - final Date toDate + final ZonedDateTime fromDate, + final ZonedDateTime toDate ) { this.voyageNumber = voyageNumber; @@ -71,12 +72,12 @@ public final class TransitEdge implements Serializable return toUnLocode; } - public Date getFromDate() + public ZonedDateTime getFromDate() { return fromDate; } - public Date getToDate() + public ZonedDateTime getToDate() { return toDate; } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphDAO.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphDAO.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphDAO.java index 15e86ea..d5c450b 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphDAO.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphDAO.java @@ -17,10 +17,11 @@ */ package org.qi4j.sample.dcicargo.pathfinder_b.internal; +import java.time.LocalDate; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Random; import org.qi4j.sample.dcicargo.pathfinder_b.api.TransitEdge; @@ -50,7 +51,7 @@ public class GraphDAO return voyages; } - Date departureDate = new Date(); + ZonedDateTime departureDate = ZonedDateTime.now(); for( int i = 0; i < 50; i++ ) { List locations = getRandomChunkOfLocations( listLocations() ); @@ -61,9 +62,9 @@ public class GraphDAO String from = locations.remove( 0 ); String destination = locations.remove( 0 ); - Date date = nextDate( departureDate ); - Date fromDate; - Date toDate; + ZonedDateTime date = nextDate( departureDate ); + ZonedDateTime fromDate; + ZonedDateTime toDate; // Carrier movements for( final String to : locations ) @@ -92,9 +93,9 @@ public class GraphDAO return voyages; } - private Date nextDate( Date date ) + private ZonedDateTime nextDate( ZonedDateTime date ) { - return new Date( date.getTime() + ONE_DAY_MS + ( random.nextInt( 1000 ) - 500 ) * ONE_MIN_MS ); + return date.plusDays( 1 + random.nextInt( 30 ) ); } private List getRandomChunkOfLocations( List allLocations ) http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphTraversalServiceImpl.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphTraversalServiceImpl.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphTraversalServiceImpl.java index 2c59c53..3f87839 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphTraversalServiceImpl.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/pathfinder_b/internal/GraphTraversalServiceImpl.java @@ -18,9 +18,9 @@ package org.qi4j.sample.dcicargo.pathfinder_b.internal; import java.rmi.RemoteException; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Collections; -import java.util.Date; import java.util.List; import java.util.Random; import org.qi4j.sample.dcicargo.pathfinder_b.api.GraphTraversalService; @@ -40,7 +40,7 @@ public class GraphTraversalServiceImpl } // Combine existing voyages to create a route. - public List findShortestPath( final Date departureDate, + public List findShortestPath( final ZonedDateTime departureDate, final String originUnLocode, final String destinationUnLocode ) @@ -54,7 +54,7 @@ public class GraphTraversalServiceImpl do { String expectedDeparture = originUnLocode; - Date lastArrivalTime = departureDate; + ZonedDateTime lastArrivalTime = departureDate; // Transit edges (itinerary legs) final List routeEdges = new ArrayList(); @@ -83,13 +83,13 @@ public class GraphTraversalServiceImpl final String departure = voyageEdge.getFromUnLocode(); final String arrival = voyageEdge.getToUnLocode(); - final Date departureTime = voyageEdge.getFromDate(); - final Date arrivalTime = voyageEdge.getToDate(); + final ZonedDateTime departureTime = voyageEdge.getFromDate(); + final ZonedDateTime arrivalTime = voyageEdge.getToDate(); boolean expectsDeparture = departure.equals( expectedDeparture ); boolean uniqueDeparture = !oldDepartures.contains( departure ); boolean uniqueArrival = !oldDepartures.contains( arrival ); - boolean afterLastArrivalTime = departureTime.after( lastArrivalTime ); + boolean afterLastArrivalTime = departureTime.isAfter( lastArrivalTime ); if( expectsDeparture && uniqueDeparture && uniqueArrival && afterLastArrivalTime ) { http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/DCISampleApplication_b.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/DCISampleApplication_b.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/DCISampleApplication_b.java index 4e5a36f..262bbbc 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/DCISampleApplication_b.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/DCISampleApplication_b.java @@ -17,7 +17,6 @@ */ package org.qi4j.sample.dcicargo.sample_b.bootstrap; -import java.util.Date; import org.apache.wicket.ConverterLocator; import org.apache.wicket.Page; import org.apache.wicket.datetime.PatternDateConverter; @@ -54,9 +53,6 @@ public class DCISampleApplication_b // Show/hide wicket tags in html code getMarkupSettings().setStripWicketTags( true ); - - // Default date format (we don't care for now about the hour of the day) - ( (ConverterLocator) getConverterLocator() ).set( Date.class, new PatternDateConverter( "yyyy-MM-dd", true ) ); } private void mountPages() http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/BaseData.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/BaseData.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/BaseData.java index dc2c669..1cba6bf 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/BaseData.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/BaseData.java @@ -17,9 +17,11 @@ */ package org.qi4j.sample.dcicargo.sample_b.bootstrap.sampledata; +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Date; import java.util.List; import org.qi4j.api.structure.Module; import org.qi4j.api.value.ValueBuilder; @@ -71,7 +73,7 @@ public abstract class BaseData return unlocode.newInstance(); } - protected CarrierMovement carrierMovement( Location depLoc, Location arrLoc, Date depTime, Date arrTime ) + protected CarrierMovement carrierMovement( Location depLoc, Location arrLoc, ZonedDateTime depTime, ZonedDateTime arrTime ) { ValueBuilder carrierMovement = module.newValueBuilder( CarrierMovement.class ); carrierMovement.prototype().departureLocation().set( depLoc ); @@ -90,7 +92,7 @@ public abstract class BaseData return schedule.newInstance(); } - protected Leg leg( Voyage voyage, Location load, Location unload, Date loadTime, Date unloadTime ) + protected Leg leg( Voyage voyage, Location load, Location unload, ZonedDateTime loadTime, ZonedDateTime unloadTime ) { ValueBuilder leg = module.newValueBuilder( Leg.class ); leg.prototype().voyage().set( voyage ); @@ -116,13 +118,13 @@ public abstract class BaseData Boolean isUnloadedAtDestination, RoutingStatus routingStatus, Boolean isMisdirected, - Date eta, + ZonedDateTime eta, Integer itineraryProgressIndex, NextHandlingEvent nextHandlingEvent ) { ValueBuilder delivery = module.newValueBuilder( Delivery.class ); - delivery.prototype().timestamp().set( new Date() ); + delivery.prototype().timestamp().set( Instant.now() ); delivery.prototype().lastHandlingEvent().set( lastHandlingEvent ); delivery.prototype().transportStatus().set( transportStatus ); delivery.prototype().isUnloadedAtDestination().set( isUnloadedAtDestination ); @@ -135,7 +137,7 @@ public abstract class BaseData } // Delivery with only mandatory values - protected Delivery delivery( Date date, + protected Delivery delivery( Instant date, TransportStatus transportStatus, RoutingStatus routingStatus, Integer itineraryProgressIndex @@ -151,7 +153,7 @@ public abstract class BaseData protected NextHandlingEvent nextHandlingEvent( HandlingEventType handlingEventType, Location location, - Date time, + ZonedDateTime time, Voyage voyage ) { @@ -163,8 +165,8 @@ public abstract class BaseData return nextHandlingEvent.newInstance(); } - protected ParsedHandlingEventData parsedHandlingEventData( Date registrationTime, - Date completionTime, + protected ParsedHandlingEventData parsedHandlingEventData( ZonedDateTime registrationTime, + ZonedDateTime completionTime, String trackingIdString, HandlingEventType handlingEventType, String unLocodeString, @@ -182,11 +184,4 @@ public abstract class BaseData return attempt.newInstance(); } - - protected static Date day( int days ) - { - Date today = new Date(); - long aDay = 24 * 60 * 60 * 1000; - return new Date( today.getTime() + days * aDay ); - } } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/SampleDataService.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/SampleDataService.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/SampleDataService.java index 753e232..fd2d57d 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/SampleDataService.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/bootstrap/sampledata/SampleDataService.java @@ -17,14 +17,12 @@ */ package org.qi4j.sample.dcicargo.sample_b.bootstrap.sampledata; +import java.time.LocalDate; +import java.time.ZonedDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Random; import java.util.UUID; -import org.joda.time.DateTime; -import org.joda.time.LocalDate; -import org.joda.time.LocalTime; import org.qi4j.api.activation.ActivatorAdapter; import org.qi4j.api.activation.Activators; import org.qi4j.api.injection.scope.Service; @@ -133,7 +131,7 @@ public interface SampleDataService routeSpec.print(); NextHandlingEvent nextEvent = null; - Date time = null; + ZonedDateTime time = null; String port = null; String voyageNumber = null; Voyage voyage; @@ -168,8 +166,7 @@ public interface SampleDataService } final RouteSpecification unsatisfiedRouteSpec = - routeSpecFactory.build( origin, badDest, new Date(), new DateTime().plusDays( 25 ) - .toDate() ); + routeSpecFactory.build( origin, badDest, ZonedDateTime.now(), ZonedDateTime.now().plusDays( 25 ) ); cargo.routeSpecification().set( unsatisfiedRouteSpec ); new InspectUnhandledCargo( cargo ).inspect(); @@ -180,7 +177,7 @@ public interface SampleDataService { nextEvent = cargo.delivery().get().nextHandlingEvent().get(); port = nextEvent.location().get().getCode(); - final Date mockTime = new Date(); + final ZonedDateTime mockTime = ZonedDateTime.now(); registerEvent( mockTime, mockTime, trackingId, RECEIVE, port, null ); } @@ -358,7 +355,7 @@ public interface SampleDataService Location origin; Location destination; Random random = new Random(); - Date deadline; + ZonedDateTime deadline; String uuid; String id; try @@ -374,9 +371,7 @@ public interface SampleDataService } while( destination.equals( origin ) ); - deadline = new LocalDate().plusDays( 35 + random.nextInt( 10 ) ) - .toDateTime( new LocalTime() ) - .toDate(); + deadline = ZonedDateTime.now().plusDays( 35 + random.nextInt( 10 ) ); // Build sortable random tracking ids uuid = UUID.randomUUID().toString().toUpperCase(); @@ -393,8 +388,8 @@ public interface SampleDataService } } - private void registerEvent( Date registrationTime, - Date completionTime, + private void registerEvent( ZonedDateTime registrationTime, + ZonedDateTime completionTime, String trackingIdString, HandlingEventType handlingEventType, String unLocodeString, http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/query/dto/HandlingEventDTO.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/query/dto/HandlingEventDTO.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/query/dto/HandlingEventDTO.java index 08a9ea2..6386e16 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/query/dto/HandlingEventDTO.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/query/dto/HandlingEventDTO.java @@ -17,7 +17,7 @@ */ package org.qi4j.sample.dcicargo.sample_b.communication.query.dto; -import java.util.Date; +import java.time.ZonedDateTime; import org.qi4j.api.common.Optional; import org.qi4j.api.property.Property; import org.qi4j.library.conversion.values.Unqualified; @@ -37,7 +37,7 @@ import org.qi4j.sample.dcicargo.sample_b.infrastructure.conversion.DTO; @Unqualified public interface HandlingEventDTO extends DTO { - Property completionTime(); + Property completionTime(); Property trackingId(); http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/BookNewCargoPage.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/BookNewCargoPage.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/BookNewCargoPage.java index 8c71905..c75ff8a 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/BookNewCargoPage.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/BookNewCargoPage.java @@ -17,7 +17,8 @@ */ package org.qi4j.sample.dcicargo.sample_b.communication.web.booking; -import java.util.Date; +import java.time.LocalDate; +import java.time.ZonedDateTime; import java.util.List; import org.apache.wicket.Session; import org.apache.wicket.ajax.AjaxRequestTarget; @@ -27,7 +28,6 @@ import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.panel.ComponentFeedbackPanel; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.request.mapper.parameter.PageParameters; -import org.joda.time.LocalDate; import org.qi4j.sample.dcicargo.sample_b.communication.query.CommonQueries; import org.qi4j.sample.dcicargo.sample_b.context.interaction.booking.BookNewCargo; import org.qi4j.sample.dcicargo.sample_b.data.structure.tracking.TrackingId; @@ -57,7 +57,7 @@ public class BookNewCargoPage extends BookingBasePage { // Set by Wicket property resolvers: private String origin, destination; - private Date deadline; + private ZonedDateTime deadline; public BookNewCargoForm() { @@ -107,7 +107,7 @@ public class BookNewCargoPage extends BookingBasePage // Deadline final DateTextFieldWithPicker deadlineField = new DateTextFieldWithPicker( "deadline", "Arrival deadline", this ); - deadlineField.earliestDate( new LocalDate().plusDays( 1 ) ); + deadlineField.earliestDate( LocalDate.now().plusDays( 1 ) ); final ComponentFeedbackPanel deadlineFeedback = new ComponentFeedbackPanel( "deadlineFeedback", deadlineField ); http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoDetailsPage.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoDetailsPage.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoDetailsPage.java index eafd5fe..7067bbc 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoDetailsPage.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoDetailsPage.java @@ -161,14 +161,16 @@ public class CargoDetailsPage extends BookingBasePage Leg leg = item.getModelObject(); item.add( new Label( "loadLocation", leg.loadLocation().get().getCode() ) ); - item.add( new Label( "loadTime", new Model( leg.loadTime().get() ) ) ); + Date loadTime = new Date( leg.loadTime().get().toInstant().toEpochMilli() ); + item.add( new Label( "loadTime", new Model( loadTime ) ) ); item.add( new Label( "voyage", leg.voyage().get().voyageNumber().get().number().get() ) ); Boolean isMisrouted = routingStatus == MISROUTED && item.getIndex() == ( getList().size() - 1 ); item.add( new Label( "unloadLocation", leg.unloadLocation().get().getCode() ) .add( new ErrorColor( isMisrouted ) ) ); - item.add( new Label( "unloadTime", new Model( leg.unloadTime().get() ) ) ); + Date unloadTime = new Date( leg.unloadTime().get().toInstant().toEpochMilli() ); + item.add( new Label( "unloadTime", new Model( unloadTime ) ) ); } } ); } http://git-wip-us.apache.org/repos/asf/zest-qi4j/blob/b71c878d/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoListPage.java ---------------------------------------------------------------------- diff --git a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoListPage.java b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoListPage.java index dc569bb..65ac141 100644 --- a/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoListPage.java +++ b/samples/dci-cargo/dcisample_b/src/main/java/org/qi4j/sample/dcicargo/sample_b/communication/web/booking/CargoListPage.java @@ -72,7 +72,7 @@ public class CargoListPage extends BookingBasePage // Route specification RouteSpecification routeSpec = cargo.routeSpecification().get(); String destination = routeSpec.destination().get().getCode(); - Date deadline = routeSpec.arrivalDeadline().get(); + Date deadline = new Date( routeSpec.arrivalDeadline().get().toInstant().toEpochMilli() ); // Routing status Delivery delivery = cargo.delivery().get();