|
|
@@ -6,43 +6,96 @@
|
|
6
|
6
|
*/
|
|
7
|
7
|
package se.citerus.dddsample.scenario;
|
|
8
|
8
|
|
|
9
|
|
-import junit.framework.TestCase;
|
|
|
9
|
+import static org.hamcrest.MatcherAssert.assertThat;
|
|
|
10
|
+import static org.hamcrest.Matchers.is;
|
|
|
11
|
+import org.junit.Before;
|
|
|
12
|
+import org.junit.Test;
|
|
10
|
13
|
import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
|
|
|
14
|
+import se.citerus.dddsample.domain.model.cargo.Cargo;
|
|
|
15
|
+import se.citerus.dddsample.domain.model.cargo.CargoFactory;
|
|
11
|
16
|
import se.citerus.dddsample.domain.model.cargo.Itinerary;
|
|
12
|
17
|
import se.citerus.dddsample.domain.model.cargo.Leg;
|
|
|
18
|
+import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.MISROUTED;
|
|
|
19
|
+import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.ROUTED;
|
|
13
|
20
|
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
14
|
21
|
import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
|
|
15
|
22
|
import se.citerus.dddsample.domain.model.voyage.Voyage;
|
|
16
|
23
|
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
|
|
|
24
|
+import se.citerus.dddsample.infrastructure.persistence.inmemory.CargoRepositoryInMem;
|
|
|
25
|
+import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
|
|
17
|
26
|
|
|
18
|
27
|
import java.util.Date;
|
|
19
|
28
|
|
|
20
|
|
-public class VoyageRescheduledScenarioTest extends TestCase {
|
|
|
29
|
+public class VoyageRescheduledScenarioTest {
|
|
21
|
30
|
|
|
22
|
|
- public void testVoyageRescheduled() throws Exception {
|
|
23
|
|
- // Creating new voyages to avoid rescheduling shared ones, breaking other tests
|
|
24
|
|
- Voyage voyage1 = new Voyage(new VoyageNumber("V1"), HONGKONG_TO_NEW_YORK.schedule());
|
|
25
|
|
- Voyage voyage2 = new Voyage(new VoyageNumber("V2"), NEW_YORK_TO_DALLAS.schedule());
|
|
26
|
|
- Voyage voyage3 = new Voyage(new VoyageNumber("V3"), DALLAS_TO_HELSINKI.schedule());
|
|
|
31
|
+ Cargo cargo;
|
|
|
32
|
+ Voyage voyage1;
|
|
|
33
|
+ Voyage voyage2;
|
|
|
34
|
+ Voyage voyage3;
|
|
27
|
35
|
|
|
|
36
|
+ @Before
|
|
|
37
|
+ public void setupCargo() {
|
|
|
38
|
+ // Creating new voyages to avoid rescheduling shared ones, breaking other tests
|
|
|
39
|
+ voyage1 = new Voyage(new VoyageNumber("V1"), HONGKONG_TO_NEW_YORK.schedule());
|
|
|
40
|
+ voyage2 = new Voyage(new VoyageNumber("V2"), NEW_YORK_TO_DALLAS.schedule());
|
|
|
41
|
+ voyage3 = new Voyage(new VoyageNumber("V3"), DALLAS_TO_HELSINKI.schedule());
|
|
|
42
|
+ CargoFactory cargoFactory = new CargoFactory(new CargoRepositoryInMem(), new LocationRepositoryInMem());
|
|
|
43
|
+ cargo = cargoFactory.newCargo(HANGZOU.unLocode(), STOCKHOLM.unLocode(), toDate("2008-12-23"));
|
|
28
|
44
|
Itinerary itinerary = new Itinerary(
|
|
29
|
45
|
Leg.deriveLeg(voyage1, HANGZOU, NEWYORK),
|
|
30
|
46
|
Leg.deriveLeg(voyage2, NEWYORK, DALLAS),
|
|
31
|
47
|
Leg.deriveLeg(voyage3, DALLAS, STOCKHOLM)
|
|
32
|
48
|
);
|
|
|
49
|
+ cargo.assignToRoute(itinerary);
|
|
|
50
|
+ }
|
|
|
51
|
+
|
|
|
52
|
+ @Test
|
|
|
53
|
+ public void voyageIsRescheduledWithMaintainableRoute() {
|
|
|
54
|
+ assertThat(cargo.delivery().routingStatus(), is(ROUTED));
|
|
33
|
55
|
|
|
34
|
56
|
Date oldDepartureTime = toDate("2008-10-24", "07:00");
|
|
35
|
57
|
|
|
36
|
|
- assertEquals(itinerary.legs().get(1).loadTime(), oldDepartureTime);
|
|
37
|
|
- assertEquals(voyage2.schedule().carrierMovements().get(0).departureTime(), oldDepartureTime);
|
|
|
58
|
+ assertThat(voyage2.schedule().departureTimeAt(NEWYORK), is(oldDepartureTime));
|
|
|
59
|
+ assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(oldDepartureTime));
|
|
38
|
60
|
|
|
|
61
|
+ // Now voyage2 is rescheduled, the departure from NYC is delayed a few hours.
|
|
39
|
62
|
Date newDepartureTime = toDate("2008-10-24", "18:00");
|
|
|
63
|
+ voyage2.departureRescheduled(NEWYORK, newDepartureTime);
|
|
|
64
|
+
|
|
|
65
|
+ // The schedule of voyage2 is updated
|
|
|
66
|
+ assertThat(voyage2.schedule().departureTimeAt(NEWYORK), is(newDepartureTime));
|
|
|
67
|
+ // ...but the cargo itinerary still has the old departure time
|
|
|
68
|
+ assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(oldDepartureTime));
|
|
40
|
69
|
|
|
|
70
|
+ // Generate a new itinerary from the old one and assign the cargo to this route
|
|
|
71
|
+ Itinerary newItinerary = cargo.itinerary().withRescheduledVoyage(voyage2);
|
|
|
72
|
+ cargo.assignToRoute(newItinerary);
|
|
|
73
|
+
|
|
|
74
|
+ // Now the cargo aggregate is updated to reflect the scheduling change!
|
|
|
75
|
+ assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(newDepartureTime));
|
|
|
76
|
+ assertThat(cargo.delivery().routingStatus(), is(ROUTED));
|
|
|
77
|
+ }
|
|
|
78
|
+
|
|
|
79
|
+ @Test
|
|
|
80
|
+ public void voyageIsRescheduledWithUnmaintainableRoute() {
|
|
|
81
|
+ assertThat(cargo.delivery().routingStatus(), is(ROUTED));
|
|
|
82
|
+
|
|
|
83
|
+ // Voyage1 arrives in NYC at 2008-10-23 23:10
|
|
|
84
|
+ // Now rescheduling the departure of voyage2 to BEFORE
|
|
|
85
|
+ // voyage1 arrives in NYC. This makes it impossible to
|
|
|
86
|
+ // keep the latter part of the old itinerary, and the new itinerary
|
|
|
87
|
+ // is therefore truncated after unload in NYC.
|
|
|
88
|
+
|
|
|
89
|
+ Date newDepartureTime = toDate("2008-10-23", "18:30");
|
|
41
|
90
|
voyage2.departureRescheduled(NEWYORK, newDepartureTime);
|
|
42
|
|
- Itinerary newItinerary = itinerary.withRescheduledVoyage(voyage2);
|
|
43
|
91
|
|
|
44
|
|
- assertEquals(voyage2.schedule().carrierMovements().get(0).departureTime(), newDepartureTime);
|
|
45
|
|
- assertEquals(newItinerary.legs().get(1).loadTime(), newDepartureTime);
|
|
|
92
|
+ // Only the part of the itinerary up to and including NYC is maintainable, the rest is truncated
|
|
|
93
|
+ Itinerary truncatedItinerary = cargo.itinerary().withRescheduledVoyage(voyage2);
|
|
|
94
|
+ assertThat(truncatedItinerary.lastLeg().unloadLocation(), is(NEWYORK));
|
|
|
95
|
+
|
|
|
96
|
+ // The cargo enters MISROUTED state
|
|
|
97
|
+ cargo.assignToRoute(truncatedItinerary);
|
|
|
98
|
+ assertThat(cargo.delivery().routingStatus(), is(MISROUTED));
|
|
46
|
99
|
}
|
|
47
|
100
|
|
|
48
|
101
|
}
|