Search in sources :

Example 6 with RouteSpecification

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_missedDeadline.

@Test
public void deviation_2d_UnsatisfyingItinerary_missedDeadline() throws Exception {
    deviation_2d_UnsatisfyingItinerary_wrongDestination();
    // Arrival on day 12 according to itinerary is not meeting deadline
    RouteSpecification routeSpec = routeSpecification(HONGKONG, STOCKHOLM, day(14));
    cargo.routeSpecification().set(routeSpec);
    Delivery delivery = new BuildDeliverySnapshot(cargo).get();
    // Route specification not satisfied by itinerary
    assertFalse(routeSpec.arrivalDeadline().get().after(itinerary.finalArrivalDate()));
    assertThat(delivery.routingStatus().get(), is(equalTo(RoutingStatus.MISROUTED)));
}
Also used : RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) Delivery(org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery) Test(org.junit.Test)

Example 7 with RouteSpecification

use of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification in project qi4j-sdk by Qi4j.

the class BuildDeliverySnapshotTest method deviation_2a_InvalidRouteSpecification_sameLocations.

// DERIVE WITH ROUTE SPECIFICATION ==============================================================================
@Test(expected = RouteException.class)
public void deviation_2a_InvalidRouteSpecification_sameLocations() throws Exception {
    RouteSpecification routeSpec = routeSpecification(HONGKONG, HONGKONG, day(20));
    new BuildDeliverySnapshot(routeSpec).get();
}
Also used : RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) Test(org.junit.Test)

Example 8 with RouteSpecification

use of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification in project qi4j-sdk by Qi4j.

the class BuildDeliverySnapshotTest method deviation_2b_InvalidRouteSpecification_tooEarlyDeadline.

@Test(expected = RouteException.class)
public void deviation_2b_InvalidRouteSpecification_tooEarlyDeadline() throws Exception {
    RouteSpecification routeSpec = routeSpecification(HONGKONG, STOCKHOLM, TODAY);
    new BuildDeliverySnapshot(routeSpec).get();
}
Also used : RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) Test(org.junit.Test)

Example 9 with RouteSpecification

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_wrongDestination.

@Test
public void deviation_2d_UnsatisfyingItinerary_wrongDestination() throws Exception {
    deviation_2d_UnsatisfyingItinerary_wrongOrigin();
    // Helsinki not in itinerary last leg
    RouteSpecification routeSpec = routeSpecification(HONGKONG, HELSINKI, day(20));
    cargo.routeSpecification().set(routeSpec);
    Delivery delivery = new BuildDeliverySnapshot(cargo).get();
    // Route specification not satisfied by itinerary
    assertThat(itinerary.lastLeg().unloadLocation().get(), is(not(equalTo(routeSpec.destination().get()))));
    assertThat(delivery.routingStatus().get(), is(equalTo(RoutingStatus.MISROUTED)));
}
Also used : RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) Delivery(org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery) Test(org.junit.Test)

Example 10 with RouteSpecification

use of org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification in project qi4j-sdk by Qi4j.

the class BuildDeliverySnapshotTest method deviation_4c_UNLOAD_1a_UnexpectedPort.

@Test
public void deviation_4c_UNLOAD_1a_UnexpectedPort() throws Exception {
    deviation_4b_LOAD_2c_ExpectedButLaterVoyageInItinerary();
    UnitOfWork uow = module.currentUnitOfWork();
    HandlingEventsEntity HANDLING_EVENTS = uow.get(HandlingEventsEntity.class, HandlingEventsEntity.HANDLING_EVENTS_ID);
    // Unexpected unload in Tokyo
    HandlingEvent handlingEvent = HANDLING_EVENTS.createHandlingEvent(day(5), day(5), trackingId, UNLOAD, TOKYO, V100S);
    Delivery delivery = new BuildDeliverySnapshot(cargo, handlingEvent).get();
    cargo.delivery().set(delivery);
    assertThat(delivery.isMisdirected().get(), is(equalTo(true)));
    assertThat(delivery.nextExpectedHandlingEvent().get(), is(equalTo(null)));
    assertThat(delivery.eta().get(), is(equalTo(null)));
    assertThat(delivery.routingStatus().get(), is(equalTo(RoutingStatus.ROUTED)));
    assertThat(delivery.transportStatus().get(), is(equalTo(TransportStatus.IN_PORT)));
    assertThat(delivery.lastHandlingEvent().get(), is(equalTo(handlingEvent)));
    assertThat(delivery.lastHandlingEvent().get().handlingEventType().get(), is(equalTo(UNLOAD)));
    assertThat(delivery.lastHandlingEvent().get().voyage().get(), is(equalTo(V100S)));
    assertThat(delivery.lastKnownLocation().get(), is(equalTo(TOKYO)));
    assertThat(delivery.currentVoyage().get(), is(equalTo(null)));
    assertThat(delivery.isUnloadedAtDestination().get(), is(equalTo(false)));
    // Cargo needs to be rerouted
    // Customer specifies a new route
    RouteSpecification routeSpec = routeSpecification(TOKYO, STOCKHOLM, day(20));
    cargo.routeSpecification().set(routeSpec);
    delivery = new BuildDeliverySnapshot(cargo).get();
    cargo.delivery().set(delivery);
    // Old itinerary will not satisfy new route specification
    assertThat(itinerary.firstLeg().loadLocation().get(), is(not(equalTo(routeSpec.origin().get()))));
    assertThat(itinerary.lastLeg().unloadLocation().get(), is(equalTo(routeSpec.destination().get())));
    assertThat(delivery.routingStatus().get(), is(equalTo(RoutingStatus.MISROUTED)));
    // Old planned arrival time is still satisfying new deadline
    assertTrue(routeSpec.arrivalDeadline().get().after(itinerary.finalArrivalDate()));
    // We don't know what's next before a new itinerary has been chosen
    assertThat(delivery.nextExpectedHandlingEvent().get(), is(equalTo(null)));
    assertThat(delivery.eta().get(), is(equalTo(null)));
    // Cargo is still misdirected (in unexpected location) according to old itinerary
    assertThat(delivery.isMisdirected().get(), is(equalTo(true)));
    // Last known data
    assertThat(delivery.transportStatus().get(), is(equalTo(TransportStatus.IN_PORT)));
    assertThat(delivery.lastHandlingEvent().get(), is(equalTo(handlingEvent)));
    assertThat(delivery.lastHandlingEvent().get().handlingEventType().get(), is(equalTo(UNLOAD)));
    assertThat(delivery.lastHandlingEvent().get().voyage().get(), is(equalTo(V100S)));
    assertThat(delivery.lastKnownLocation().get(), is(equalTo(TOKYO)));
    assertThat(delivery.currentVoyage().get(), is(equalTo(null)));
    assertThat(delivery.isUnloadedAtDestination().get(), is(equalTo(false)));
    // New itinerary that satisfy the new route specification. New origin departure from Tokyo.
    Date arrival = day(19);
    itinerary = itinerary(leg(V400S, TOKYO, HAMBURG, day(9), day(16)), leg(V500S, HAMBURG, STOCKHOLM, day(17), arrival));
    // Customer reroutes cargo. This is a possible step in the cargo booking process.
    new BookNewCargo(cargo, itinerary).assignCargoToRoute();
    delivery = cargo.delivery().get();
    // Cargo is on track again
    assertThat(delivery.isMisdirected().get(), is(equalTo(false)));
    assertThat(delivery.routingStatus().get(), is(equalTo(RoutingStatus.ROUTED)));
    assertThat(delivery.transportStatus().get(), is(equalTo(TransportStatus.IN_PORT)));
    assertThat(delivery.lastHandlingEvent().get(), is(equalTo(handlingEvent)));
    assertThat(delivery.lastHandlingEvent().get().handlingEventType().get(), is(equalTo(UNLOAD)));
    assertThat(delivery.lastHandlingEvent().get().voyage().get(), is(equalTo(V100S)));
    assertThat(delivery.lastKnownLocation().get(), is(equalTo(TOKYO)));
    assertThat(delivery.currentVoyage().get(), is(equalTo(null)));
    assertThat(delivery.eta().get(), is(equalTo(arrival)));
    assertThat(delivery.isUnloadedAtDestination().get(), is(equalTo(false)));
    // When a cargo is rerouted the (often misdirected) last handling event is flagged as disregarded
    // since it doesn't have to be part of the new itinerary (this isn't in the Citerus version).
    // We now expect the cargo to be loaded onto voyage V400S in Tokyo heading to Hamburg
    assertThat(delivery.isMisdirected().get(), is(equalTo(false)));
    assertThat(delivery.nextExpectedHandlingEvent().get().handlingEventType().get(), is(equalTo(LOAD)));
    assertThat(delivery.nextExpectedHandlingEvent().get().location().get(), is(equalTo(TOKYO)));
    assertThat(delivery.nextExpectedHandlingEvent().get().voyage().get(), is(equalTo(V400S)));
// Cargo is not misdirected anymore according to new itinerary. Cargo location is now expected to be in Tokyo.
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) HandlingEvent(org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEvent) Delivery(org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery) Date(java.util.Date) HandlingEventsEntity(org.qi4j.sample.dcicargo.sample_a.data.entity.HandlingEventsEntity) Test(org.junit.Test)

Aggregations

RouteSpecification (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification)10 Test (org.junit.Test)9 Delivery (org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery)7 Date (java.util.Date)3 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)2 DateMidnight (org.joda.time.DateMidnight)1 HandlingEventsEntity (org.qi4j.sample.dcicargo.sample_a.data.entity.HandlingEventsEntity)1 Cargo (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargo)1 Cargos (org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargos)1 HandlingEvent (org.qi4j.sample.dcicargo.sample_a.data.shipping.handling.HandlingEvent)1 Itinerary (org.qi4j.sample.dcicargo.sample_a.data.shipping.itinerary.Itinerary)1