use of org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery in project qi4j-sdk by Qi4j.
the class BookNewCargoTest method step_2_CreateNewCargo.
@Test
public void step_2_CreateNewCargo() throws Exception {
UnitOfWork uow = module.currentUnitOfWork();
Location HONGKONG = uow.get(Location.class, CNHKG.code().get());
Location STOCKHOLM = uow.get(Location.class, SESTO.code().get());
Cargos CARGOS = uow.get(Cargos.class, CargosEntity.CARGOS_ID);
// Create cargo with valid input from customer
TrackingId trackingId = new BookNewCargo(CARGOS, HONGKONG, STOCKHOLM, day(17)).book();
// Retrieve created cargo from store
Cargo cargo = uow.get(Cargo.class, trackingId.id().get());
// Test cargo data
assertThat(cargo.trackingId().get(), is(equalTo(trackingId)));
assertThat(cargo.origin().get(), is(equalTo(HONGKONG)));
// Test route specification
assertThat(cargo.routeSpecification().get().destination().get(), is(equalTo(STOCKHOLM)));
// day(17) here is calculated a few milliseconds after initial day(17), so it will be later...
assertThat(cargo.routeSpecification().get().arrivalDeadline().get(), equalTo(day(17)));
// (Itinerary is not assigned yet)
// Test derived delivery snapshot
Delivery delivery = cargo.delivery().get();
// TODAY is set first
assertThat(delivery.timestamp().get().after(TODAY), is(equalTo(true)));
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)));
// Is set when itinerary is assigned
assertThat(delivery.eta().get(), is(equalTo(null)));
assertThat(delivery.isMisdirected().get(), is(equalTo(false)));
assertThat(delivery.isUnloadedAtDestination().get(), is(equalTo(false)));
}
use of org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery in project qi4j-sdk by Qi4j.
the class BookNewCargoTest method step_5_AssignCargoToRoute.
@Test
public void step_5_AssignCargoToRoute() throws Exception {
UnitOfWork uow = module.currentUnitOfWork();
Location HONGKONG = uow.get(Location.class, CNHKG.code().get());
Location STOCKHOLM = uow.get(Location.class, SESTO.code().get());
Cargos CARGOS = uow.get(Cargos.class, CargosEntity.CARGOS_ID);
// Create valid cargo
Date deadline = day(30);
TrackingId trackingId = new BookNewCargo(CARGOS, HONGKONG, STOCKHOLM, deadline).book();
Cargo cargo = uow.get(Cargo.class, trackingId.id().get());
List<Itinerary> routeCandidates = new BookNewCargo(cargo).routeCandidates();
// Get first route found
// Would normally be found with an Itinerary id from customer selection
Itinerary itinerary = routeCandidates.get(0);
// Use case step 5 - System assigns cargo to route
new BookNewCargo(cargo, itinerary).assignCargoToRoute();
assertThat("Itinerary has been assigned to cargo.", itinerary, is(equalTo(cargo.itinerary().get())));
// BuildDeliverySnapshot will check if itinerary is valid. No need to check it here.
// Check values set in new delivery snapshot
Delivery delivery = cargo.delivery().get();
assertThat(delivery.routingStatus().get(), is(equalTo(RoutingStatus.ROUTED)));
// ETA (= Unload time of last Leg) is before Deadline (set in previous test)
assertTrue(delivery.eta().get().before(deadline));
}
use of org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery in project qi4j-sdk by Qi4j.
the class BuildDeliverySnapshotTest method deviation_3a_CargoHasNoHandlingHistory.
@Test
public void deviation_3a_CargoHasNoHandlingHistory() throws Exception {
deviation_2d_UnsatisfyingItinerary_missedDeadline();
Date arrival = day(16);
Date 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)));
// TODAY is set first
assertThat(delivery.timestamp().get().after(TODAY), is(equalTo(true)));
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)));
}
use of org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery in project qi4j-sdk by Qi4j.
the class BuildDeliverySnapshotTest method deviation_4c_UNLOAD_1b_ExpectedMidpointLocation.
@Test
public void deviation_4c_UNLOAD_1b_ExpectedMidpointLocation() throws Exception {
deviation_4c_UNLOAD_1a_UnexpectedPort();
UnitOfWork uow = module.currentUnitOfWork();
HandlingEventsEntity HANDLING_EVENTS = uow.get(HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID);
// Unload at midpoint location of itinerary
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)));
// 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)));
}
use of org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery in project qi4j-sdk by Qi4j.
the class InspectCargoTest method deviation_3a_CargoIsMisdirected.
@Test
public void deviation_3a_CargoIsMisdirected() throws Exception {
// Create misdirected handling event for cargo (receipt in Shanghai is unexpected)
UnitOfWork uow = module.currentUnitOfWork();
HandlingEventsEntity HANDLING_EVENTS = uow.get(HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID);
handlingEvent = HANDLING_EVENTS.createHandlingEvent(day(0), day(0), trackingId, HandlingEventType.RECEIVE, SHANGHAI, null);
Delivery delivery = new BuildDeliverySnapshot(cargo, handlingEvent).get();
cargo.delivery().set(delivery);
assertThat(cargo.delivery().get().isMisdirected().get(), is(equalTo(true)));
logger.info(" Handling cargo 'ABC' (misdirected):");
new InspectCargo(handlingEvent).inspect();
// Assert that notification of misdirection has been sent (see console output).
}
Aggregations