You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2016/10/23 14:23:44 UTC
[03/28] zest-java git commit: ZEST-180, ZEST-186, ZEST-187,
ZEST-188 Big Identity refactoring UnitOfWorkFactory is auto added to
all modules that doesn't declare one IdentityGenerator is auto-added to all
modules that deosn't declare one. Removed DCI/DDD
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/BookNewCargoTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/BookNewCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/BookNewCargoTest.java
deleted file mode 100644
index 58c8e42..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/BookNewCargoTest.java
+++ /dev/null
@@ -1,220 +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.sample.dcicargo.sample_b.context.test.booking;
-
-import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.Cargo;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.constraint.ConstraintViolationException;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.BookNewCargo;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.factory.exception.CannotCreateCargoException;
-import org.apache.zest.sample.dcicargo.sample_b.data.factory.exception.CannotCreateRouteSpecificationException;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE;
-
-/**
- * {@link BookNewCargo} tests
- *
- * FIXME: Every test method call the one above to allow ordered execution, ie. tests are not indepedants !
- */
-public class BookNewCargoTest extends TestApplication
-{
-
- private CargoAggregateRoot CARGOS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
- }
-
- @Test
- public void deviation_2a_OriginAndDestinationSame()
- throws Exception
- {
- try
- {
- thrown.expect( CannotCreateRouteSpecificationException.class, "Origin location can't be same as destination location." );
- new BookNewCargo( CARGOS, HONGKONG, HONGKONG, DAY24 ).getTrackingId();
- }
- catch( Exception ex )
- {
- ex.printStackTrace();
- throw ex;
- }
- }
-
- @Test
- public void deviation_2b_DeadlineInThePastNotAccepted()
- throws Exception
- {
- deviation_2a_OriginAndDestinationSame();
- thrown.expect( CannotCreateRouteSpecificationException.class, "Arrival deadline is in the past or Today." );
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( -1 ) ).getTrackingId();
- }
-
- @Test
- public void deviation_2b_DeadlineTodayIsTooEarly()
- throws Exception
- {
- deviation_2b_DeadlineInThePastNotAccepted();
- thrown.expect( CannotCreateRouteSpecificationException.class, "Arrival deadline is in the past or Today." );
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, day( 0 ) ).getTrackingId();
- }
-
- @Test
- public void deviation_2b_DeadlineTomorrowIsOkay()
- throws Exception
- {
- deviation_2b_DeadlineTodayIsTooEarly();
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY1 ).getTrackingId();
- }
-
- @Test
- public void step_2_CanCreateRouteSpecification()
- throws Exception
- {
- deviation_2b_DeadlineTomorrowIsOkay();
- UnitOfWork uow = uowf.currentUnitOfWork();
- trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).getTrackingId();
- cargo = uow.get( Cargo.class, trackingId.id().get() );
- assertThat( cargo.routeSpecification().get().origin().get(), is( equalTo( HONGKONG ) ) );
- assertThat( cargo.routeSpecification().get().destination().get(), is( equalTo( STOCKHOLM ) ) );
- assertThat( cargo.routeSpecification().get().arrivalDeadline().get(), is( equalTo( DAY24 ) ) );
- }
-
- @Test
- public void step_3_CanDeriveInitialDeliveryData()
- throws Exception
- {
- step_2_CanCreateRouteSpecification();
- UnitOfWork uow = uowf.currentUnitOfWork();
- trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).getTrackingId();
- cargo = uow.get( Cargo.class, trackingId.id().get() );
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- RECEIVE, HONGKONG, noSpecificDate, noVoyage );
- }
-
- @Test
- public void deviation_4a_TrackingIdTooShort()
- throws Exception
- {
- step_3_CanDeriveInitialDeliveryData();
- thrown.expect( ConstraintViolationException.class, "for value 'no'" );
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "no" );
- }
-
- @Test
- public void deviation_4a_TrackingIdNotTooShort()
- throws Exception
- {
- deviation_4a_TrackingIdTooShort();
- UnitOfWork uow = uowf.currentUnitOfWork();
- trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "yes" );
- cargo = uow.get( Cargo.class, trackingId.id().get() );
- assertThat( cargo.trackingId().get().id().get(), is( equalTo( "yes" ) ) );
- }
-
- @Test
- public void deviation_4a_TrackingIdTooLong()
- throws Exception
- {
- deviation_4a_TrackingIdNotTooShort();
- thrown.expect( ConstraintViolationException.class, "for value '1234567890123456789012345678901'" );
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "1234567890123456789012345678901" );
- }
-
- @Test
- public void deviation_4a_TrackingIdNotTooLong()
- throws Exception
- {
- deviation_4a_TrackingIdTooLong();
- UnitOfWork uow = uowf.currentUnitOfWork();
- trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "123456789012345678901234567890" );
- cargo = uow.get( Cargo.class, trackingId.id().get() );
- assertThat( cargo.trackingId().get().id().get(), is( equalTo( "123456789012345678901234567890" ) ) );
- }
-
- @Test
- public void deviation_4a_TrackingIdWithWrongCharacter()
- throws Exception
- {
- deviation_4a_TrackingIdNotTooLong();
- thrown.expect( ConstraintViolationException.class, "for value 'G�teborg1234'" );
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "G�teborg1234" );
- }
-
- @Test
- public void deviation_4b_TrackingIdNotUnique()
- throws Exception
- {
- deviation_4a_TrackingIdWithWrongCharacter();
- thrown.expect( CannotCreateCargoException.class, "Tracking id 'yes' is not unique." );
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "yes" );
- }
-
- @Test
- public void step_4_CanAutoCreateTrackingIdFromEmptyString()
- throws Exception
- {
- deviation_4b_TrackingIdNotUnique();
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "" );
- }
-
- @Test
- public void step_4_CanAutoCreateTrackingIdFromNull()
- throws Exception
- {
- step_4_CanAutoCreateTrackingIdFromEmptyString();
- new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( null );
- }
-
- @Test
- public void success_BookNewCargo()
- throws Exception
- {
- step_4_CanAutoCreateTrackingIdFromNull();
- UnitOfWork uow = uowf.currentUnitOfWork();
- trackingId = new BookNewCargo( CARGOS, HONGKONG, STOCKHOLM, DAY24 ).withTrackingId( "ABC" );
- cargo = uow.get( Cargo.class, trackingId.id().get() );
-
- assertThat( cargo.trackingId().get(), is( equalTo( trackingId ) ) );
- assertThat( cargo.trackingId().get().id().get(), is( equalTo( "ABC" ) ) );
- assertThat( cargo.origin().get(), is( equalTo( HONGKONG ) ) );
-
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- RECEIVE, HONGKONG, noSpecificDate, noVoyage );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/AssignCargoToRouteTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/AssignCargoToRouteTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/AssignCargoToRouteTest.java
deleted file mode 100644
index 9c38ae6..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/AssignCargoToRouteTest.java
+++ /dev/null
@@ -1,198 +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.sample.dcicargo.sample_b.context.test.booking.routing;
-
-import java.time.LocalDate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.exception.RoutingException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.exception.UnsatisfyingRouteException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.routing.AssignCargoToRoute;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Itinerary;
-
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.CLAIMED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CUSTOMS;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD;
-
-/**
- * {@link AssignCargoToRoute} tests
- *
- * FIXME: Every test method call the one above to allow ordered execution, ie. tests are not independent!
- */
-public class AssignCargoToRouteTest extends TestApplication
-{
- private static Itinerary itinerary2;
- private HandlingEventAggregateRoot HANDLING_EVENTS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
-
- // Create new cargo
- routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 );
- delivery = delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, unknownLeg );
- cargo = CARGOS.createCargo( routeSpec, delivery, "ABC" );
- trackingId = cargo.trackingId().get();
- delivery = cargo.delivery().get();
- }
-
- @Test
- public void precondition_x1_CannotReRouteClaimedCargo()
- throws Exception
- {
- cargo.delivery().set( delivery( TODAY, CLAIMED, ROUTED, unknownLeg ) );
- thrown.expect( RoutingException.class, "Can't re-route claimed cargo" );
- new AssignCargoToRoute( cargo, itinerary ).assign();
- }
-
- @Test
- public void deviation_1a_UnsatisfyingItinerary()
- throws Exception
- {
- precondition_x1_CannotReRouteClaimedCargo();
-
- cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, unknownLeg ) );
- thrown.expect( UnsatisfyingRouteException.class, "Route specification was not satisfied with itinerary" );
- new AssignCargoToRoute( cargo, wrongItinerary ).assign();
- }
-
- @Test
- public void deviation_3a_Routing_UnhandledCargo()
- throws Exception
- {
- deviation_1a_UnsatisfyingItinerary();
-
- cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, unknownLeg ) );
- new AssignCargoToRoute( cargo, itinerary ).assign();
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- RECEIVE, HONGKONG, noSpecificDate, noVoyage );
- }
-
- @Test
- public void deviation_3b_ReRouting_OnBoard()
- throws Exception
- {
- deviation_3a_Routing_UnhandledCargo();
-
- // Load cargo
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, LOAD, CHICAGO, V201 );
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, DAY23, leg2,
- nextHandlingEvent( UNLOAD, NEWYORK, DAY6, V201 ) ) );
-
- // New itinerary with arrival location of current carrier movement
- // Earliest departure date is after carrier arrival
- itinerary2 = itinerary( leg( V202, NEWYORK, STOCKHOLM, DAY8, DAY17 ) );
-
- // Re-route cargo while on board a carrier
- new AssignCargoToRoute( cargo, itinerary2 ).assign();
- assertDelivery( LOAD, CHICAGO, DAY5, V201,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary2.eta(), leg1,
- UNLOAD, NEWYORK, DAY6, V201 ); // from old itinerary!
- }
-
- @Test
- public void deviation_3c_ReRouting_InPort_Received()
- throws Exception
- {
- deviation_3b_ReRouting_OnBoard();
-
- // Receive cargo
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, unknownETA, unknownLeg,
- nextHandlingEvent( LOAD, HONGKONG, DAY1, V201 ) ) );
-
- // New itinerary going from current port
- itinerary2 = itinerary( leg( V202, HONGKONG, STOCKHOLM, DAY3, DAY17 ) );
-
- // Re-route cargo after receipt in port
- new AssignCargoToRoute( cargo, itinerary2 ).assign();
- assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary2.eta(), leg1,
- LOAD, HONGKONG, DAY3, V202 ); // from new itinerary!
- }
-
- @Test
- public void deviation_3c_ReRouting_InPort_Unloaded()
- throws Exception
- {
- deviation_3c_ReRouting_InPort_Received();
-
- // Unload cargo
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, unknownETA, leg2,
- nextHandlingEvent( UNLOAD, NEWYORK, DAY6, V201 ) ) );
-
- // Re-route cargo unloaded in port
- itinerary2 = itinerary( leg( V202, CHICAGO, STOCKHOLM, DAY6, DAY19 ) );
- new AssignCargoToRoute( cargo, itinerary2 ).assign();
- assertDelivery( UNLOAD, CHICAGO, DAY5, V201,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary2.eta(), leg1,
- LOAD, CHICAGO, DAY6, V202 );
- }
-
- @Test
- public void deviation_3c_ReRouting_InPort_InCustoms()
- throws Exception
- {
- deviation_3c_ReRouting_InPort_Unloaded();
-
- // Receive cargo
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY6, DAY6, trackingId, CUSTOMS, NEWYORK, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, unknownETA, leg3,
- unknownNextHandlingEvent ) );
-
- // Re-route cargo while in customs
- itinerary2 = itinerary( leg( V202, NEWYORK, STOCKHOLM, DAY8, DAY18 ) );
- new AssignCargoToRoute( cargo, itinerary2 ).assign();
- assertDelivery( CUSTOMS, NEWYORK, DAY6, noVoyage,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary2.eta(), leg1,
- LOAD, NEWYORK, DAY8, V202 );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/RegisterNewDestinationTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/RegisterNewDestinationTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/RegisterNewDestinationTest.java
deleted file mode 100644
index 1f84e3d..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/routing/RegisterNewDestinationTest.java
+++ /dev/null
@@ -1,316 +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.sample.dcicargo.sample_b.context.test.booking.routing;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.exception.ChangeDestinationException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.routing.RegisterNewDestination;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisroutedException;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-
-import static org.junit.Assert.fail;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.CLAIMED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CUSTOMS;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD;
-
-/**
- * {@link RegisterNewDestination} tests
- *
- * FIXME: Every test method call the one above to allow ordered execution, ie. tests are not indepedants !
- */
-public class RegisterNewDestinationTest extends TestApplication
-{
- private HandlingEventAggregateRoot HANDLING_EVENTS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
-
- // Create new cargo
- routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, TODAY, deadline = DAY24 );
- delivery = delivery( TODAY, NOT_RECEIVED, NOT_ROUTED, leg1 );
- cargo = CARGOS.createCargo( routeSpec, delivery, "ABC" );
- trackingId = cargo.trackingId().get();
- delivery = cargo.delivery().get();
- }
-
- @Test
- public void precondition_x1_CannotChangeDestinationOfClaimedCargo()
- throws Exception
- {
- cargo.delivery().set( delivery( DAY1, CLAIMED, ROUTED, leg1 ) );
- thrown.expect( ChangeDestinationException.class, "Can't change destination of claimed cargo" );
- new RegisterNewDestination( cargo ).to( "USCHI" );
- }
-
- @Test
- public void deviation_1a_UnrecognizedLocation()
- throws Exception
- {
- precondition_x1_CannotChangeDestinationOfClaimedCargo();
-
- cargo.delivery().set( delivery( DAY1, IN_PORT, ROUTED, leg1 ) );
- thrown.expect( ChangeDestinationException.class, "Didn't recognize location 'XXXXX'" );
- new RegisterNewDestination( cargo ).to( "XXXXX" );
- }
-
- @Test
- public void deviation_1b_NewDestinationSameAsOldDestination()
- throws Exception
- {
- deviation_1a_UnrecognizedLocation();
-
- cargo.delivery().set( delivery( DAY1, IN_PORT, ROUTED, leg1 ) );
- thrown.expect( ChangeDestinationException.class, "New destination is same as old destination." );
- new RegisterNewDestination( cargo ).to( "SESTO" );
- }
-
- @Test
- public void step_2_NotRouted()
- throws Exception
- {
- deviation_1b_NewDestinationSameAsOldDestination();
-
- cargo.routeSpecification().set( routeSpec );
- cargo.delivery().set( delivery( DAY1, NOT_RECEIVED, NOT_ROUTED, leg1 ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
-
- new RegisterNewDestination( cargo ).to( "CNSHA" );
-
- assertRouteSpec( HONGKONG, SHANGHAI, TODAY, DAY24 );
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- RECEIVE, HONGKONG, noSpecificDate, noVoyage );
- }
-
- @Test
- public void step_2_NotReceived()
- throws Exception
- {
- step_2_NotRouted();
-
- cargo.routeSpecification().set( routeSpec );
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( null, NOT_RECEIVED, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( RECEIVE, HONGKONG, noSpecificDate, noVoyage ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
-
- // No last handling event
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- RECEIVE, HONGKONG, noSpecificDate, noVoyage );
-
- new RegisterNewDestination( cargo ).to( "CNSHA" );
-
- // Destination changed, deadline is the same
- assertRouteSpec( HONGKONG, SHANGHAI, TODAY, DAY24 );
-
- /**
- * Delivery status was updated in {@link InspectUnhandledCargo}
- * Still expects receipt in cargo origin (Hong Kong).
- * */
- assertDelivery( null, null, null, null,
- NOT_RECEIVED, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- RECEIVE, HONGKONG, noSpecificDate, noVoyage );
- }
-
- @Test
- public void step_2_Received()
- throws Exception
- {
- step_2_NotReceived();
-
- cargo.routeSpecification().set( routeSpec );
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( LOAD, HONGKONG, DAY1, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
- assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- LOAD, HONGKONG, DAY1, V201 );
-
- new RegisterNewDestination( cargo ).to( "CNSHA" );
-
- assertRouteSpec( HONGKONG, // Unchanged
- SHANGHAI, // New destination
- DAY1, // Completion time of last handling event
- DAY24 ); // Unchanged
-
- /**
- * Delivery status was updated in {@link InspectReceivedCargo}
- * Before cargo has been re-routed we don't know which voyage the cargo is going with next.
- * */
- assertDelivery( RECEIVE, HONGKONG, DAY1, noVoyage,
- IN_PORT, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
-
- @Test
- public void deviation_2a_OnBoardCarrier()
- throws Exception
- {
- step_2_Received();
-
- cargo.routeSpecification().set( routeSpec );
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( UNLOAD, CHICAGO, DAY5, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- UNLOAD, CHICAGO, DAY5, V201 );
- try
- {
- new RegisterNewDestination( cargo ).to( "CNSHA" );
- fail();
- }
- catch( CargoMisroutedException e )
- {
- assertMessage( e, "MISROUTED! Route specification is not satisfied with itinerary" );
- assertRouteSpec( CHICAGO, // Arrival location of current carrier movement
- SHANGHAI, // New destination
- DAY5, // Arrival time of current carrier movement
- DAY24 ); // Unchanged
-
- /**
- * Delivery status was updated in {@link InspectLoadedCargo}
- * We still expect unload in Chicago
- * */
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- UNLOAD, CHICAGO, DAY5, V201 );
- }
- }
-
- @Test
- public void deviation_2b_InPort_Unloaded()
- throws Exception
- {
- deviation_2a_OnBoardCarrier();
-
- cargo.routeSpecification().set( routeSpec );
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- nextHandlingEvent( LOAD, CHICAGO, DAY5, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
- assertDelivery( UNLOAD, CHICAGO, DAY5, V201,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- LOAD, CHICAGO, DAY5, V201 );
- try
- {
- new RegisterNewDestination( cargo ).to( "CNSHA" );
- fail();
- }
- catch( CargoMisroutedException e )
- {
- assertMessage( e, "MISROUTED! Route specification is not satisfied with itinerary" );
- assertRouteSpec( CHICAGO, // Current location
- SHANGHAI, // New destination
- DAY5, // Last completion time
- DAY24 ); // Unchanged
-
- /**
- * Delivery status was updated in {@link InspectUnloadedCargo}
- * We still expect unload in Chicago
- * */
- assertDelivery( UNLOAD, CHICAGO, DAY5, V201,
- IN_PORT, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
- }
-
- @Test
- public void deviation_2b_InPort_InCustoms()
- throws Exception
- {
- deviation_2b_InPort_Unloaded();
-
- cargo.routeSpecification().set( routeSpec );
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, CUSTOMS, CHICAGO, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- unknownNextHandlingEvent ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
- assertDelivery( CUSTOMS, CHICAGO, DAY5, noVoyage,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- unknownNextHandlingEvent );
-
- new RegisterNewDestination( cargo ).to( "CNSHA" );
-
- assertRouteSpec( CHICAGO, // Current location
- SHANGHAI, // New destination
- DAY5, // Last completion time
- DAY24 ); // Unchanged
-
- /**
- * Delivery status was updated in {@link InspectCargoInCustoms}
- * We still expect unload in Chicago
- */
- assertDelivery( CUSTOMS, CHICAGO, DAY5, noVoyage,
- IN_PORT, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/specification/DeriveUpdatedRouteSpecTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/specification/DeriveUpdatedRouteSpecTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/specification/DeriveUpdatedRouteSpecTest.java
deleted file mode 100644
index a907b1a..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/booking/specification/DeriveUpdatedRouteSpecTest.java
+++ /dev/null
@@ -1,160 +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.sample.dcicargo.sample_b.context.test.booking.specification;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.booking.specification.DeriveUpdatedRouteSpecification;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.NOT_RECEIVED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.RECEIVE;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD;
-
-public class DeriveUpdatedRouteSpecTest extends TestApplication
-{
- private HandlingEventAggregateRoot HANDLING_EVENTS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
-
- // Create new cargo
- routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, TODAY, deadline = DAY24 );
- delivery = delivery( TODAY, NOT_RECEIVED, ROUTED, unknownLeg );
- cargo = CARGOS.createCargo( routeSpec, delivery, "ABC" );
- cargo.itinerary().set( itinerary );
- trackingId = cargo.trackingId().get();
- }
-
- @Test
- public void deviation_1a_Destination_changed()
- throws Exception
- {
- cargo.routeSpecification().set( routeSpec );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( LOAD, HONGKONG, DAY1, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
-
- newRouteSpec = new DeriveUpdatedRouteSpecification( cargo, ROTTERDAM ).getRouteSpec();
- cargo.routeSpecification().set( newRouteSpec );
-
- assertRouteSpec( HONGKONG, // Unchanged
- ROTTERDAM, // New destination
- DAY1, // Completion time of last handling event
- DAY24 ); // Unchanged
- }
-
- @Test
- public void step_1_Destination_unchanged()
- throws Exception
- {
- cargo.routeSpecification().set( routeSpec );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, RECEIVE, HONGKONG, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( LOAD, HONGKONG, DAY1, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
-
- newRouteSpec = new DeriveUpdatedRouteSpecification( cargo ).getRouteSpec();
- cargo.routeSpecification().set( newRouteSpec );
-
- assertRouteSpec( HONGKONG, // Unchanged
- STOCKHOLM, // Unchanged
- DAY1, // Completion time of last handling event
- DAY24 ); // Unchanged
- }
-
- @Test
- public void deviation_2a_NotReceived()
- throws Exception
- {
- cargo.routeSpecification().set( routeSpec );
- cargo.delivery().set( delivery( TODAY, NOT_RECEIVED, ROUTED, unknownLeg ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
-
- newRouteSpec = new DeriveUpdatedRouteSpecification( cargo ).getRouteSpec();
- cargo.routeSpecification().set( newRouteSpec );
-
- assertRouteSpec( HONGKONG, // Unchanged
- STOCKHOLM, // Unchanged
- TODAY, // Unchanged
- DAY24 ); // Unchanged
- }
-
- @Test
- public void deviation_2b_OnBoardCarrier()
- throws Exception
- {
- cargo.routeSpecification().set( routeSpec );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( UNLOAD, CHICAGO, DAY5, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
-
- newRouteSpec = new DeriveUpdatedRouteSpecification( cargo ).getRouteSpec();
- cargo.routeSpecification().set( newRouteSpec );
-
- assertRouteSpec( CHICAGO, // Arrival location of current carrier movement
- STOCKHOLM, // Unchanged
- DAY5, // Arrival time of current carrier movement
- DAY24 ); // Unchanged
- }
-
- @Test
- public void step_3_InPort()
- throws Exception
- {
- cargo.routeSpecification().set( routeSpec );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY5, DAY5, trackingId, UNLOAD, CHICAGO, V201 );
- cargo.delivery().set( delivery( handlingEvent, IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- nextHandlingEvent( LOAD, CHICAGO, DAY5, V201 ) ) );
-
- assertRouteSpec( HONGKONG, STOCKHOLM, TODAY, DAY24 );
-
- newRouteSpec = new DeriveUpdatedRouteSpecification( cargo ).getRouteSpec();
- cargo.routeSpecification().set( newRouteSpec );
-
- assertRouteSpec( CHICAGO, // Current location
- STOCKHOLM, // Unchanged
- DAY5, // Last completion time
- DAY24 ); // Unchanged
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectArrivedCargoTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectArrivedCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectArrivedCargoTest.java
deleted file mode 100644
index 1661406..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectArrivedCargoTest.java
+++ /dev/null
@@ -1,140 +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.sample.dcicargo.sample_b.context.test.handling.inspection.event;
-
-import java.time.LocalDate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectArrivedCargo;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoArrivedException;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-
-import static org.junit.Assert.fail;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CLAIM;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD;
-
-/**
- * {@link InspectArrivedCargo} tests
- */
-public class InspectArrivedCargoTest extends TestApplication
-{
- private HandlingEventAggregateRoot HANDLING_EVENTS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
-
- // Create new cargo
- routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 );
- delivery = delivery( TODAY, IN_PORT, ROUTED, leg5 );
- cargo = CARGOS.createCargo( routeSpec, delivery, "Arrived_CARGO" );
- trackingId = cargo.trackingId().get();
- }
-
- @Test
- public void deviation_2a_NotRouted_MissingItinerary_UnloadedInFinalDestination()
- throws Exception
- {
- // Cargo not routed
- cargo.itinerary().set( null );
- cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, NOT_ROUTED, leg5 ) );
-
- // Unload in final destination (with no itinerary!)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY23, DAY23, trackingId, UNLOAD, STOCKHOLM, V203 );
- try
- {
- new InspectArrivedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoArrivedException e )
- {
- assertMessage( e, "Cargo 'Arrived_CARGO' has arrived in destination Stockholm (SESTO)" );
-
- // An unexpected unload shouldn't be considered an itinerary progress - legIndex stays unchanged
- assertDelivery( UNLOAD, STOCKHOLM, DAY23, V203,
- IN_PORT, arrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- CLAIM, STOCKHOLM, DAY23, noVoyage );
- }
- }
-
- @Test
- public void deviation_2b_Misrouted_WrongItineraryWithoutCurrentUnloadLocation_UnloadedInFinalDestination()
- throws Exception
- {
- // Misroute cargo - assign unsatisfying itinerary not going to Stockholm
- cargo.itinerary().set( wrongItinerary );
- cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, MISROUTED, leg5 ) );
-
- // Unload in final destination (with wrong itinerary)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY23, DAY23, trackingId, UNLOAD, STOCKHOLM, V203 );
- try
- {
- new InspectArrivedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoArrivedException e )
- {
- assertMessage( e, "Cargo 'Arrived_CARGO' has arrived in destination Stockholm (SESTO)" );
- assertDelivery( UNLOAD, STOCKHOLM, DAY23, V203,
- IN_PORT, arrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- CLAIM, STOCKHOLM, DAY23, noVoyage );
- }
- }
-
- @Test
- public void success_UnloadInDestination()
- throws Exception
- {
- // Assign satisfying route going to Stockholm
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg5 ) );
-
- // Unload in final destination (with satisfying itinerary)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY23, DAY23, trackingId, UNLOAD, STOCKHOLM, V203 );
- try
- {
- new InspectArrivedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoArrivedException e )
- {
- assertMessage( e, "Cargo 'Arrived_CARGO' has arrived in destination Stockholm (SESTO)" );
- assertDelivery( UNLOAD, STOCKHOLM, DAY23, V203,
- IN_PORT, arrived,
- ROUTED, directed, itinerary.eta(), leg5,
- CLAIM, STOCKHOLM, DAY23, noVoyage );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectCargoInCustomsTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectCargoInCustomsTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectCargoInCustomsTest.java
deleted file mode 100644
index 44c931e..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectCargoInCustomsTest.java
+++ /dev/null
@@ -1,138 +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.sample.dcicargo.sample_b.context.test.handling.inspection.event;
-
-import java.time.LocalDate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectCargoInCustoms;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-
-import static org.junit.Assert.fail;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CUSTOMS;
-
-/**
- * {@link InspectCargoInCustoms} tests
- */
-public class InspectCargoInCustomsTest extends TestApplication
-{
- private HandlingEventAggregateRoot HANDLING_EVENTS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
-
- // Create new cargo
- routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(), deadline = DAY24 );
- delivery = delivery( TODAY, IN_PORT, ROUTED, leg1 );
- cargo = CARGOS.createCargo( routeSpec, delivery, "CARGO_in_customs" );
- trackingId = cargo.trackingId().get();
- }
-
- @Test
- public void precondition_CustomsHandlingNotOnBoardCarrier()
- throws Exception
- {
- cargo.itinerary().set( itinerary );
-
- // No customs handling on board a carrier...
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, CUSTOMS, STOCKHOLM, noVoyage );
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent ) );
- try
- {
- new InspectCargoInCustoms( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( InspectionFailedException e )
- {
- assertMessage( e, "INTERNAL ERROR: Cannot handle cargo in customs on board a carrier." );
- }
- }
-
- @Test
- public void deviation_2a_NotRouted_CustomsLocation_FinalDestination()
- throws Exception
- {
- // Cargo not routed
- cargo.itinerary().set( null );
- cargo.delivery().set( delivery( TODAY, IN_PORT, NOT_ROUTED, leg5 ) );
-
- // Handle in customs (without itinerary!)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, CUSTOMS, STOCKHOLM, noVoyage );
- new InspectCargoInCustoms( cargo, handlingEvent ).inspect();
-
- assertDelivery( CUSTOMS, STOCKHOLM, DAY1, noVoyage,
- IN_PORT, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
-
- @Test
- public void deviation_2b_Misrouted_CustomsLocation_DestinationOfWrongItinerary()
- throws Exception
- {
- // Misroute cargo - assign unsatisfying itinerary not going to Stockholm
- cargo.itinerary().set( wrongItinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, MISROUTED, leg3 ) );
-
- // Handle in customs (with wrong itinerary)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY20, DAY20, trackingId, CUSTOMS, MELBOURNE, noVoyage );
- new InspectCargoInCustoms( cargo, handlingEvent ).inspect();
-
- assertDelivery( CUSTOMS, MELBOURNE, DAY20, noVoyage,
- IN_PORT, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
-
- @Test
- public void step_2_Routed_CustomsLocation_FinalDestination()
- throws Exception
- {
- // Assign satisfying route going to Stockholm
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, MISROUTED, leg5 ) );
-
- // Handle in customs (without itinerary!)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY24, DAY24, trackingId, CUSTOMS, STOCKHOLM, noVoyage );
- new InspectCargoInCustoms( cargo, handlingEvent ).inspect();
-
- assertDelivery( CUSTOMS, STOCKHOLM, DAY24, noVoyage,
- IN_PORT, notArrived,
- ROUTED, directed, itinerary.eta(), leg5,
- unknownNextHandlingEvent );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectClaimedCargoTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectClaimedCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectClaimedCargoTest.java
deleted file mode 100644
index 570b3f7..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectClaimedCargoTest.java
+++ /dev/null
@@ -1,133 +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.sample.dcicargo.sample_b.context.test.handling.inspection.event;
-
-import java.time.LocalDate;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectClaimedCargo;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.CLAIMED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.CLAIM;
-
-/**
- * {@link InspectClaimedCargo} tests
- */
-public class InspectClaimedCargoTest extends TestApplication
-{
- private HandlingEventAggregateRoot HANDLING_EVENTS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- CargoAggregateRoot CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
-
- // Create new cargo
- routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, LocalDate.now(),deadline = DAY24 );
- delivery = delivery( TODAY, IN_PORT, ROUTED, leg1 );
- cargo = CARGOS.createCargo( routeSpec, delivery, "Claimed_CARGO" );
- trackingId = cargo.trackingId().get();
- }
-
- @Test
- public void deviation_2a_NotRouted_ClaimInFinalDestination()
- throws Exception
- {
- // Cargo not routed
- cargo.itinerary().set( null );
- cargo.delivery().set( delivery( TODAY, IN_PORT, NOT_ROUTED, leg5 ) );
-
- // Claim in final destination (without itinerary!)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, CLAIM, STOCKHOLM, noVoyage );
-
- new InspectClaimedCargo( cargo, handlingEvent ).inspect();
-
- assertDelivery( CLAIM, STOCKHOLM, DAY1, noVoyage,
- CLAIMED, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
-
- @Test
- public void deviation_2b_Misrouted_ClaimInDestinationOfWrongItinerary()
- throws Exception
- {
- // Misroute cargo - assign unsatisfying itinerary not going to Stockholm
- cargo.itinerary().set( wrongItinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, MISROUTED, leg3 ) );
-
- // Claim in final destination (with wrong itinerary)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY20, DAY20, trackingId, CLAIM, MELBOURNE, noVoyage );
- new InspectClaimedCargo( cargo, handlingEvent ).inspect();
-
- assertDelivery( CLAIM, MELBOURNE, DAY20, noVoyage,
- CLAIMED, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
-
- @Test
- public void step_2_Routed_ClaimInMidpointLocation()
- throws Exception
- {
- // Assign satisfying route going to Stockholm
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Claim in midpoint before arrival at final destination
- // Should this really be considered misdirected?!
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY9, DAY9, trackingId, CLAIM, DALLAS, noVoyage );
- new InspectClaimedCargo( cargo, handlingEvent ).inspect();
-
- assertDelivery( CLAIM, DALLAS, DAY9, noVoyage,
- CLAIMED, notArrived,
- ROUTED, misdirected, itinerary.eta(), leg3,
- unknownNextHandlingEvent );
- }
-
- @Test
- public void step_2_Routed_ClaimInFinalDestination()
- throws Exception
- {
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg5 ) );
-
- // Claim in final destination
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY24, DAY24, trackingId, CLAIM, STOCKHOLM, noVoyage );
- new InspectClaimedCargo( cargo, handlingEvent ).inspect();
-
- assertDelivery( CLAIM, STOCKHOLM, DAY24, noVoyage,
- CLAIMED, notArrived,
- ROUTED, directed, itinerary.eta(), leg5,
- unknownNextHandlingEvent );
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/103c59cb/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectLoadedCargoTest.java
----------------------------------------------------------------------
diff --git a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectLoadedCargoTest.java b/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectLoadedCargoTest.java
deleted file mode 100644
index 2dd657a..0000000
--- a/samples/dci-cargo/dcisample_b/src/test/java/org/apache/zest/sample/dcicargo/sample_b/context/test/handling/inspection/event/InspectLoadedCargoTest.java
+++ /dev/null
@@ -1,515 +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.sample.dcicargo.sample_b.context.test.handling.inspection.event;
-
-import java.time.LocalDate;
-import org.junit.Before;
-import org.junit.Test;
-import org.apache.zest.api.unitofwork.UnitOfWork;
-import org.apache.zest.sample.dcicargo.sample_b.bootstrap.test.TestApplication;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.event.InspectLoadedCargo;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoHijackedException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisdirectedException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoMisroutedException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.CargoNotRoutedException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.InspectionFailedException;
-import org.apache.zest.sample.dcicargo.sample_b.context.interaction.handling.inspection.exception.UnexpectedCarrierException;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.CargoAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.aggregateroot.HandlingEventAggregateRoot;
-import org.apache.zest.sample.dcicargo.sample_b.data.structure.cargo.RouteSpecification;
-import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.Delivery;
-import org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus;
-import org.apache.zest.sample.dcicargo.sample_b.data.structure.itinerary.Leg;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.MISROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.NOT_ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.RoutingStatus.ROUTED;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.IN_PORT;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.delivery.TransportStatus.ONBOARD_CARRIER;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.LOAD;
-import static org.apache.zest.sample.dcicargo.sample_b.data.structure.handling.HandlingEventType.UNLOAD;
-
-/**
- * {@link InspectLoadedCargo} tests
- *
- * FIXME: Every test method call the one above to allow ordered execution, ie. tests are not indepedants !
- */
-public class InspectLoadedCargoTest extends TestApplication
-{
- private HandlingEventAggregateRoot HANDLING_EVENTS;
- private CargoAggregateRoot CARGOS;
-
- @Before
- public void prepareTest()
- throws Exception
- {
- super.prepareTest();
- UnitOfWork uow = uowf.currentUnitOfWork();
- CARGOS = uow.get( CargoAggregateRoot.class, CargoAggregateRoot.CARGOS_ID );
- HANDLING_EVENTS = uow.get( HandlingEventAggregateRoot.class, HandlingEventAggregateRoot.HANDLING_EVENTS_ID );
- // Create new cargo
- RouteSpecification routeSpec = routeSpecFactory.build( HONGKONG, STOCKHOLM, TODAY, deadline = DAY24 );
- Delivery delivery = delivery( TODAY, IN_PORT, ROUTED, leg1 );
- cargo = CARGOS.createCargo( routeSpec, delivery, "Loaded_CARGO" );
- trackingId = cargo.trackingId().get();
-// delivery = cargo.delivery().get();
- }
-
- @Test
- public void deviation_2a_WrongCarrierSchedule()
- throws Exception
- {
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg1 ) );
-
- // V202 doesn't expect a load in Hongkong - can't determine much more before we get a correct voyage schedule
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V202 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( UnexpectedCarrierException e )
- {
- assertMessage( e, "Carrier of voyage V202 didn't expect a load in Hongkong (CNHKG)" );
- assertDelivery( LOAD, HONGKONG, DAY1, V202,
- ONBOARD_CARRIER, notArrived,
- ROUTED, misdirected, unknownETA, unknownLeg,
- unknownNextHandlingEvent );
- }
- }
-
- @Test
- public void deviation_2a_CarrierOnTime_ArrivalDate_Planned()
- throws Exception
- {
- deviation_2a_WrongCarrierSchedule();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg1 ) );
-
- //
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- UNLOAD, CHICAGO, DAY5, V201 ); // Arrival date 1 is planned
- }
-
- @Test
- public void deviation_2a_CarrierDelayed_ArrivalDate_Estimated()
- throws Exception
- {
- deviation_2a_CarrierOnTime_ArrivalDate_Planned();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg1 ) );
-
- //
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY2, DAY2, trackingId, LOAD, HONGKONG, V201 );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- assertDelivery( LOAD, HONGKONG, DAY2, V201,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- UNLOAD, CHICAGO, DAY6, V201 ); // Arrival date has been postponed 1 day
- }
-
- @Test
- public void deviation_3a_NotRouted_MissingItinerary()
- throws Exception
- {
- deviation_2a_CarrierDelayed_ArrivalDate_Estimated();
-
- // Cargo not routed
- cargo.itinerary().set( null );
- cargo.delivery().set( delivery( TODAY, IN_PORT, NOT_ROUTED, leg1 ) );
-
- // Load cargo in Hong Kong (without an itinerary!)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoNotRoutedException e )
- {
- assertMessage( e, "NOT ROUTED while being handled!" );
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- NOT_ROUTED, directed, unknownETA, unknownLeg,
- UNLOAD, CHICAGO, DAY5, V201 );
- }
- }
-
- @Test
- public void deviation_3b_Misrouted_LoadLocationOfWrongItinerary_Origin()
- throws Exception
- {
- deviation_3a_NotRouted_MissingItinerary();
-
- // Misroute cargo - assign unsatisfying itinerary not going to Stockholm
- cargo.itinerary().set( wrongItinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, MISROUTED, leg1 ) );
-
- // Load cargo in Hong Kong (with wrong itinerary)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
- try
- {
- // Load in any location is unexpected when itinerary is wrong
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoMisroutedException e )
- {
- assertMessage( e, "MISROUTED! Route specification is not satisfied with itinerary" );
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- MISROUTED, directed, unknownETA, unknownLeg,
- UNLOAD, CHICAGO, DAY5, V201 );
- }
- }
-
- @Test
- public void deviation_3b_Misrouted_LoadLocationOfWrongItinerary_Midpoint()
- throws Exception
- {
- deviation_3b_Misrouted_LoadLocationOfWrongItinerary_Origin();
-
- cargo.itinerary().set( wrongItinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, MISROUTED, leg1 ) );
-
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, NEWYORK, V201 );
- thrown.expect( CargoMisroutedException.class, "MISROUTED! Route specification is not satisfied with itinerary" );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- }
-
- @Test
- public void deviation_3b_Misrouted_LoadLocationOfWrongItinerary_UnplannedLocation()
- throws Exception
- {
- deviation_3b_Misrouted_LoadLocationOfWrongItinerary_Midpoint();
-
- cargo.itinerary().set( wrongItinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, MISROUTED, leg1 ) );
-
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, ROTTERDAM, V205 );
- thrown.expect( CargoMisroutedException.class, "MISROUTED! Route specification is not satisfied with itinerary" );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- }
-
- @Test
- public void step_3_Routed()
- throws Exception
- {
- deviation_3b_Misrouted_LoadLocationOfWrongItinerary_UnplannedLocation();
-
- // Assign satisfying route going to Stockholm
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg1 ) );
-
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
-
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- UNLOAD, CHICAGO, DAY5, V201 );
- }
-
- @Test
- public void deviation_4x_InternalError_InvalidItineraryProgressIndex()
- throws Exception
- {
- step_3_Routed();
-
- cargo.itinerary().set( itinerary );
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HONGKONG, V201 );
-
- Integer badLegIndex = 7;
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, unknownETA, badLegIndex, unknownNextHandlingEvent ) );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( InspectionFailedException e )
- {
- assertMessage( e, "INTERNAL ERROR: Itinerary progress index '7' is invalid!" );
- assertDelivery( LOAD, HONGKONG, DAY1, V201,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, unknownETA, badLegIndex, unknownNextHandlingEvent );
- }
- }
-
- @Test
- public void deviation_4a_Misdirected_UnexpectedLoadLocation()
- throws Exception
- {
- deviation_4x_InternalError_InvalidItineraryProgressIndex();
-
- // Move the cargo ahead on the route. Third leg of itinerary expects load in Dallas.
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Unexpected load in previous load location of itinerary (onto expected voyage) - can't go back in time.
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY5, trackingId, LOAD, ROTTERDAM, V202 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoMisdirectedException e )
- {
- assertMessage( e, "MISDIRECTED! Itinerary expected load in New York (USNYC)" );
- assertDelivery( LOAD, ROTTERDAM, DAY5, V202, // Itinerary expected: LOAD, NEWYORK, DAY7, V202
- ONBOARD_CARRIER, notArrived,
- ROUTED, misdirected, itinerary.eta(), leg3,
- unknownNextHandlingEvent ); // When location is wrong we have to investigate...
- }
- }
-
- @Test
- public void deviation_4b_Misdirected_UnexpectedLoadVoyage_PreviousInItinerary()
- throws Exception
- {
- deviation_4a_Misdirected_UnexpectedLoadLocation();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Unexpected load onto previous voyage (in expected location) - can't go back in time.
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, LOAD, NEWYORK, V201 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoMisdirectedException e )
- {
- assertMessage( e, "MISDIRECTED! Itinerary expected load onto voyage V202" );
- assertDelivery( LOAD, NEWYORK, DAY7, V201, // Itinerary expected: LOAD, NEWYORK, DAY7, V202
- ONBOARD_CARRIER, notArrived,
- ROUTED, misdirected, itinerary.eta(), leg3,
- UNLOAD, GOTHENBURG, DAY13, V201 ); // Itinerary expected: UNLOAD, DALLAS, DAY8, V202
- }
- }
-
- @Test
- public void deviation_4b_Misdirected_UnexpectedLoadVoyage_NextInItinerary()
- throws Exception
- {
- deviation_4b_Misdirected_UnexpectedLoadVoyage_PreviousInItinerary();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Unexpected load onto future voyage (in expected location) - can't jump ahead in route plan.
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, LOAD, NEWYORK, V203 );
- thrown.expect( CargoMisdirectedException.class, "MISDIRECTED! Itinerary expected load onto voyage V202" );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- }
-
- @Test
- public void deviation_4b_Misdirected_UnexpectedLoadVoyage_VoyageNotInItinerary()
- throws Exception
- {
- deviation_4b_Misdirected_UnexpectedLoadVoyage_NextInItinerary();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Unexpected load onto voyage not in itinerary
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, LOAD, NEWYORK, V204 );
- thrown.expect( CargoMisdirectedException.class, "MISDIRECTED! Itinerary expected load onto voyage V202" );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- }
-
- @Test
- public void deviation_4c_Misdirected_UnexpectedLoadVoyage_Unplanned_ButGoingToWantedLocation()
- throws Exception
- {
- deviation_4b_Misdirected_UnexpectedLoadVoyage_VoyageNotInItinerary();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Unexpected load onto voyage not in itinerary - but the carrier is going to our expected arrival location!
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY9, DAY9, trackingId, LOAD, NEWYORK, V205 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoMisdirectedException e )
- {
- assertMessage( e, "MISDIRECTED! Cargo is heading to expected arrival location USDAL but on unexpected voyage V205" );
- assertDelivery( LOAD, NEWYORK, DAY9, V205, // Itinerary expected: LOAD, NEWYORK, DAY7, V202
- ONBOARD_CARRIER, notArrived,
- ROUTED, misdirected, itinerary.eta(), leg3,
- UNLOAD, DALLAS, DAY10, V205 ); // Itinerary expected: UNLOAD, DALLAS, DAY8, V202
- }
- }
-
- @Test
- public void deviation_4d_Misdirected_ExpectedLoadVoyage_UnexpectedNewVoyageSchedule()
- throws Exception
- {
- deviation_4c_Misdirected_UnexpectedLoadVoyage_Unplanned_ButGoingToWantedLocation();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Unexpected voyage schedule change
- V202 = voyage( "V202", schedule(
- carrierMovement( CHICAGO, NEWYORK, DAY3, DAY5 ),
- carrierMovement( NEWYORK, HAMBURG, DAY7, DAY15 ),
- carrierMovement( HAMBURG, ROTTERDAM, DAY16, DAY17 ),
- carrierMovement( ROTTERDAM, GOTHENBURG, DAY17, DAY19 )
- ) );
-
- // Expected load onto voyage - but carrier has changed arrival location!
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, LOAD, NEWYORK, V202 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- fail();
- }
- catch( CargoMisdirectedException e )
- {
- assertMessage( e, "MISDIRECTED! Itinerary expects voyage V202 to arrive in USDAL but carrier is now going to DEHAM" );
- assertDelivery( LOAD, NEWYORK, DAY7, V202, // Itinerary expected: LOAD, NEWYORK, DAY7, V202
- ONBOARD_CARRIER, notArrived,
- ROUTED, misdirected, itinerary.eta(), leg3,
- UNLOAD, HAMBURG, DAY15, V202 ); // Itinerary expected: UNLOAD, DALLAS, DAY8, V202
- }
- }
-
- @Test
- public void success_Load()
- throws Exception
- {
- deviation_4d_Misdirected_ExpectedLoadVoyage_UnexpectedNewVoyageSchedule();
-
- cargo.itinerary().set( itinerary );
- cargo.delivery().set( delivery( TODAY, IN_PORT, ROUTED, leg3 ) );
-
- // Restore expected voyage schedule change
- V202 = voyage( "V202", schedule(
- carrierMovement( CHICAGO, NEWYORK, DAY3, DAY5 ),
- carrierMovement( NEWYORK, DALLAS, DAY7, DAY8 ),
- carrierMovement( DALLAS, ROTTERDAM, DAY10, DAY17 ),
- carrierMovement( ROTTERDAM, GOTHENBURG, DAY17, DAY19 )
- ) );
-
- // Expected load (leg 3)
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY7, DAY7, trackingId, LOAD, NEWYORK, V202 );
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
-
- Leg currentCarrierMovement = itinerary.leg( delivery.itineraryProgressIndex().get() );
- assertThat( currentCarrierMovement.unloadLocation().get(), is( equalTo( DALLAS ) ) );
- assertThat( currentCarrierMovement.unloadDate().get(), is( equalTo( DAY8 ) ) );
- assertThat( currentCarrierMovement.voyage().get(), is( equalTo( V202 ) ) );
-
- assertDelivery( LOAD, NEWYORK, DAY7, V202,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg3,
- UNLOAD, DALLAS, DAY8, V202 );
- }
-
- @Test
- public void riskZoneDestination()
- throws Exception
- {
- success_Load();
-
- // Risk zone destination
- routeSpec = routeSpecFactory.build( HANGZHOU, ROTTERDAM, LocalDate.now(),deadline = DAY24 );
- delivery = delivery( TODAY, ONBOARD_CARRIER, ROUTED, leg1 );
- cargo = CARGOS.createCargo( routeSpec, delivery, "Naive" );
- trackingId = cargo.trackingId().get();
- itinerary = itinerary(
- leg( V205, HANGZHOU, MOGADISHU, DAY1, DAY2 ),
- leg( V205, MOGADISHU, ROTTERDAM, DAY2, DAY4 )
- );
- cargo.itinerary().set( itinerary );
-
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY1, DAY1, trackingId, LOAD, HANGZHOU, V205 );
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- nextHandlingEvent( UNLOAD, MOGADISHU, DAY2, V205 ) ) );
-
- assertDelivery( LOAD, HANGZHOU, DAY1, V205,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- UNLOAD, MOGADISHU, DAY2, V205 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- }
- catch( CargoHijackedException e )
- {
- assertMessage( e, "Cargo 'Naive' was hijacked." );
- assertDelivery( LOAD, HANGZHOU, DAY1, V205,
- TransportStatus.UNKNOWN, notArrived,
- ROUTED, directed, itinerary.eta(), leg1,
- UNLOAD, MOGADISHU, DAY2, V205 );
- }
- }
-
- @Test
- public void riskZoneDeparture()
- throws Exception
- {
- riskZoneDestination();
-
- // Risk zone departure (they know you now, so risk is higher)
- cargo = CARGOS.createCargo( routeSpec, delivery, "Hopeful" );
- trackingId = cargo.trackingId().get();
- cargo.itinerary().set( itinerary ); // Risky itinerary
-
- handlingEvent = HANDLING_EVENTS.createHandlingEvent( DAY2, DAY2, trackingId, LOAD, MOGADISHU, V205 );
- cargo.delivery().set( delivery( handlingEvent, ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- nextHandlingEvent( UNLOAD, ROTTERDAM, DAY4, V205 ) ) );
-
- assertDelivery( LOAD, MOGADISHU, DAY2, V205,
- ONBOARD_CARRIER, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- UNLOAD, ROTTERDAM, DAY4, V205 );
- try
- {
- new InspectLoadedCargo( cargo, handlingEvent ).inspect();
- }
- catch( CargoHijackedException e )
- {
- assertMessage( e, "Cargo 'Hopeful' was hijacked." );
- assertDelivery( LOAD, MOGADISHU, DAY2, V205,
- TransportStatus.UNKNOWN, notArrived,
- ROUTED, directed, itinerary.eta(), leg2,
- UNLOAD, ROTTERDAM, DAY4, V205 );
- }
- }
-}