use of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification in project qi4j-sdk by Qi4j.
the class BuildDeliverySnapshotTest method deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification.
@Test
public void deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification() throws Exception {
RouteSpecification routeSpec = routeSpecification(HONGKONG, STOCKHOLM, day(20));
Delivery delivery = new BuildDeliverySnapshot(routeSpec).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)));
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.cargo.RouteSpecification in project qi4j-sdk by Qi4j.
the class BuildDeliverySnapshotTest method deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo.
// DERIVE WITH NON-ROUTED CARGO ==============================================================================
@Test
public void deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo() throws Exception {
deviation_2c_ItineraryIsUnknown_buildFromRouteSpecification();
UnitOfWork uow = module.currentUnitOfWork();
RouteSpecification routeSpec = routeSpecification(HONGKONG, STOCKHOLM, day(20));
Cargos CARGOS = uow.get(Cargos.class, CargosEntity.CARGOS_ID);
Delivery delivery = new BuildDeliverySnapshot(routeSpec).get();
Cargo cargo = CARGOS.createCargo(routeSpec, delivery, "ABCD");
// Same as previous test (just build from cargo instead)
// 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)));
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.cargo.RouteSpecification in project qi4j-sdk by Qi4j.
the class BookNewCargo method buildRouteSpecification.
public RouteSpecification buildRouteSpecification(ValueBuilderFactory vbf, Location origin, Location destination, Date deadline) {
if (origin == destination) {
throw new RouteException("Origin location can't be same as destination location.");
}
if (deadline == null) {
throw new RouteException("Arrival deadline cannot be null.");
}
Date endOfToday = new DateMidnight().plusDays(1).toDate();
if (deadline.before(endOfToday)) {
throw new RouteException("Arrival deadline is in the past or Today." + "\nDeadline " + deadline + "\nToday (midnight) " + endOfToday);
}
ValueBuilder<RouteSpecification> routeSpec = vbf.newValueBuilder(RouteSpecification.class);
routeSpec.prototype().origin().set(origin);
routeSpec.prototype().destination().set(destination);
routeSpec.prototype().arrivalDeadline().set(deadline);
return routeSpec.newInstance();
}
use of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification in project qi4j-sdk by Qi4j.
the class BuildDeliverySnapshotTest method deviation_2d_UnsatisfyingItinerary_wrongOrigin.
// DERIVE WITH ROUTE SPECIFICATION + ITINERARY (Routed cargo) ==============================================
@Test
public void deviation_2d_UnsatisfyingItinerary_wrongOrigin() throws Exception {
deviation_2c_ItineraryIsUnknown_buildFromNonRoutedCargo();
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), day(16)));
// Hangzhou not in itinerary first leg
RouteSpecification routeSpec = routeSpecification(HANGZHOU, STOCKHOLM, day(20));
cargo.itinerary().set(itinerary);
cargo.routeSpecification().set(routeSpec);
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)));
}
use of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification 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)));
}
Aggregations