Search in sources :

Example 1 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_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)));
}
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 2 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_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)));
}
Also used : UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Cargo(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargo) Cargos(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.Cargos) 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 3 with RouteSpecification

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();
}
Also used : DateMidnight(org.joda.time.DateMidnight) RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) Date(java.util.Date)

Example 4 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_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)));
}
Also used : Itinerary(org.qi4j.sample.dcicargo.sample_a.data.shipping.itinerary.Itinerary) 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 5 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_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)));
}
Also used : RouteSpecification(org.qi4j.sample.dcicargo.sample_a.data.shipping.cargo.RouteSpecification) Delivery(org.qi4j.sample.dcicargo.sample_a.data.shipping.delivery.Delivery) Date(java.util.Date) 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