peter_backlund 17 年之前
父節點
當前提交
061958fdaa

+ 0
- 421
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/scenario/CargoLifecycleScenarioTest.java 查看文件

@@ -1,421 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.scenario;
2
-
3
-import static org.hamcrest.core.Is.is;
4
-import static org.junit.Assert.*;
5
-import org.junit.Test;
6
-import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
7
-import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
8
-import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.*;
9
-import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.*;
10
-import se.citerus.dddsample.tracking.core.domain.model.handling.*;
11
-import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
12
-import se.citerus.dddsample.tracking.core.domain.model.location.Location;
13
-import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
14
-import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
15
-import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
16
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
17
-import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
18
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage.NONE;
19
-import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
20
-import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
21
-import se.citerus.dddsample.tracking.core.domain.service.RoutingService;
22
-import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.*;
23
-
24
-import java.util.Arrays;
25
-import java.util.Date;
26
-import java.util.List;
27
-
28
-public class CargoLifecycleScenarioTest {
29
-
30
-  /**
31
-   * Repository implementations are part of the infrastructure layer,
32
-   * which in this test is stubbed out by in-memory replacements.
33
-   */
34
-  HandlingEventRepository handlingEventRepository = new HandlingEventRepositoryInMem();
35
-  CargoRepository cargoRepository = new CargoRepositoryInMem();
36
-  LocationRepository locationRepository = new LocationRepositoryInMem();
37
-  VoyageRepository voyageRepository = new VoyageRepositoryInMem();
38
-
39
-  HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
40
-  TrackingIdFactory trackingIdFactory = new TrackingIdFactoryInMem();
41
-
42
-  /**
43
-   * This is a domain service interface, whose implementation
44
-   * is part of the infrastructure layer (re mote call to external system).
45
-   * <p/>
46
-   * It is stubbed in this test.
47
-   */
48
-  RoutingService routingService = new ScenarioStubRoutingService();
49
-
50
-  TrackingId trackingId;
51
-
52
-  @Test
53
-  public void cargoIsCorrectlyDelivered() throws Exception {
54
-    bookCargoFromHongkongToStockholm();
55
-    checkDeliveryAfterBooking();
56
-
57
-    // Route: Hongkong - Long Beach - New York - Stockholm
58
-    routeCargoFromHongkongToStockholm();
59
-    checkDeliveryAfterRouting();
60
-
61
-
62
-    receiveInHongkong();
63
-    checkDeliveryAfterReceiveInHongkong();
64
-
65
-    loadInHongkong();
66
-    checkDeliveryAfterLoadInHongKong();
67
-
68
-    unloadInLongBeach();
69
-    checkDeliveryAfterUnloadInLongBeach();
70
-
71
-    loadInLongBeach();
72
-    checkDeliveryAfterLoadInLongBeach();
73
-
74
-    unloadInNewYork();
75
-    checkDeliveryAfterUnloadInNewYork();
76
-
77
-    loadInNewYork();
78
-    checkDeliveryAfterLoadInNewYork();
79
-
80
-    unloadInStockholmOffOf(v200);
81
-    checkDeliveryAfterUnloadInStockholm();
82
-
83
-    claimInStockholm();
84
-    checkDeliveryAfterClaimInStockholm();
85
-  }
86
-
87
-  private void unloadInLongBeach() throws CannotCreateHandlingEventException {
88
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-06"), v100, LONGBEACH, UNLOAD);
89
-  }
90
-
91
-  private void checkDeliveryAfterUnloadInLongBeach() {
92
-    Cargo cargo = cargoRepository.find(trackingId);
93
-
94
-    assertThat(cargo.currentVoyage(), is(NONE));
95
-    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
96
-    assertThat(cargo.transportStatus(), is(IN_PORT));
97
-    assertFalse(cargo.isMisdirected());
98
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, LONGBEACH, v250)));
99
-  }
100
-
101
-  private void loadInLongBeach() throws CannotCreateHandlingEventException {
102
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-07"), v250, LONGBEACH, LOAD);
103
-  }
104
-
105
-  private void checkDeliveryAfterLoadInLongBeach() {
106
-    Cargo cargo = cargoRepository.find(trackingId);
107
-
108
-    assertThat(cargo.currentVoyage(), is(v250));
109
-    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
110
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
111
-    assertFalse(cargo.isMisdirected());
112
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, NEWYORK, v250)));
113
-  }
114
-
115
-  private void unloadInNewYork() throws CannotCreateHandlingEventException {
116
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), v250, NEWYORK, UNLOAD);
117
-  }
118
-
119
-  private void checkDeliveryAfterUnloadInNewYork() {
120
-    Cargo cargo = cargoRepository.find(trackingId);
121
-
122
-    assertThat(cargo.currentVoyage(), is(NONE));
123
-    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
124
-    assertThat(cargo.transportStatus(), is(IN_PORT));
125
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, NEWYORK, v200)));
126
-    assertFalse(cargo.isMisdirected());
127
-  }
128
-
129
-  private void loadInNewYork() throws CannotCreateHandlingEventException {
130
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-10"), v200, NEWYORK, LOAD);
131
-  }
132
-
133
-  private void checkDeliveryAfterLoadInNewYork() {
134
-    Cargo cargo = cargoRepository.find(trackingId);
135
-
136
-    assertThat(cargo.currentVoyage(), is(v200));
137
-    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
138
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
139
-    assertFalse(cargo.isMisdirected());
140
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, v200)));
141
-  }
142
-
143
-  @Test
144
-  public void cargoIsMisdirectedAndRerouted() throws Exception {
145
-    bookCargoFromHongkongToStockholm();
146
-    checkDeliveryAfterBooking();
147
-
148
-
149
-    // Initial route: Hongkong - Long Beach - New York - Stockholm
150
-    routeCargoFromHongkongToStockholm();
151
-    checkDeliveryAfterRouting();
152
-
153
-
154
-    receiveInHongkong();
155
-    checkDeliveryAfterReceiveInHongkong();
156
-
157
-    loadInHongkong();
158
-    checkDeliveryAfterLoadInHongKong();
159
-
160
-    unloadInTokyo();
161
-    checkDeliveryAfterUnloadInTokyo();
162
-
163
-
164
-    // Reroute: Tokyo - Hamburg - Stockholm
165
-    specifyNewRouteFromTokyoToStockholm();
166
-    checkDeliveryAfterNewRouteSpecified();
167
-
168
-    assignToNewRouteFromTokyoToStockholm();
169
-    checkDeliveryAfterAssignedToNewRoute();
170
-
171
-
172
-    loadInTokyo();
173
-    checkDeliveryAfterLoadInTokyo();
174
-
175
-    unloadInHamburg();
176
-    checkDeliveryAfterUnloadInHamburg();
177
-
178
-    loadInHamburg();
179
-    checkDeliveryAfterLoadInHamburg();
180
-
181
-    unloadInStockholmOffOf(v400);
182
-    checkDeliveryAfterUnloadInStockholm();
183
-
184
-    claimInStockholm();
185
-    checkDeliveryAfterClaimInStockholm();
186
-  }
187
-
188
-  private void bookCargoFromHongkongToStockholm() {
189
-    Date arrivalDeadline = toDate("2009-03-18");
190
-    final TrackingId trackingId1 = trackingIdFactory.nextTrackingId();
191
-    final RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, STOCKHOLM, arrivalDeadline);
192
-
193
-    Cargo cargo = new Cargo(trackingId1, routeSpecification);
194
-    cargoRepository.store(cargo);
195
-
196
-    trackingId = cargo.trackingId();
197
-  }
198
-
199
-  private void routeCargoFromHongkongToStockholm() {
200
-    Cargo cargo = cargoRepository.find(trackingId);
201
-    List<Itinerary> itineraries = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
202
-    Itinerary itinerary = itineraries.get(0);
203
-    cargo.assignToRoute(itinerary);
204
-    cargoRepository.store(cargo);
205
-  }
206
-
207
-  public void checkDeliveryAfterBooking() throws Exception {
208
-    Cargo cargo = cargoRepository.find(trackingId);
209
-
210
-    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
211
-    assertThat(cargo.routingStatus(), is(NOT_ROUTED));
212
-    assertFalse(cargo.isMisdirected());
213
-    assertNull(cargo.estimatedTimeOfArrival());
214
-    assertNull(cargo.nextExpectedActivity());
215
-  }
216
-
217
-  public void checkDeliveryAfterRouting() throws Exception {
218
-    Cargo cargo = cargoRepository.find(trackingId);
219
-
220
-    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
221
-    assertThat(cargo.routingStatus(), is(ROUTED));
222
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(RECEIVE, HONGKONG)));
223
-    assertNotNull(cargo.estimatedTimeOfArrival());
224
-  }
225
-
226
-  public void receiveInHongkong() throws CannotCreateHandlingEventException {
227
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-01"), null, HONGKONG, RECEIVE);
228
-  }
229
-
230
-  private void checkDeliveryAfterReceiveInHongkong() {
231
-    Cargo cargo = cargoRepository.find(trackingId);
232
-    assertThat(cargo.transportStatus(), is(IN_PORT));
233
-    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
234
-  }
235
-
236
-  public void loadInHongkong() throws CannotCreateHandlingEventException {
237
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-03"), v100, HONGKONG, LOAD);
238
-  }
239
-
240
-  private void checkDeliveryAfterLoadInHongKong() {
241
-    // Check current state - should be ok
242
-    Cargo cargo = cargoRepository.find(trackingId);
243
-
244
-    assertThat(cargo.currentVoyage(), is(v100));
245
-    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
246
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
247
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, LONGBEACH, v100)));
248
-    assertFalse(cargo.isMisdirected());
249
-  }
250
-
251
-  public void unloadInTokyo() throws CannotCreateHandlingEventException {
252
-    // Cargo is now (incorrectly) unloaded in Tokyo
253
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-05"), v100, TOKYO, UNLOAD);
254
-  }
255
-
256
-  private void checkDeliveryAfterUnloadInTokyo() {
257
-    Cargo cargo = cargoRepository.find(trackingId);
258
-    // Check current state - cargo is misdirected!
259
-    assertThat(cargo.currentVoyage(), is(NONE));
260
-    assertThat(cargo.lastKnownLocation(), is(TOKYO));
261
-    assertThat(cargo.transportStatus(), is(IN_PORT));
262
-    assertTrue(cargo.isMisdirected());
263
-    assertNull(cargo.nextExpectedActivity());
264
-  }
265
-
266
-  public void specifyNewRouteFromTokyoToStockholm() {
267
-    // TODO cleaner reroute from "earliest location from where the new route originates"
268
-    Cargo cargo = cargoRepository.find(trackingId);
269
-
270
-    // Specify a new route, this time from Tokyo (where it was incorrectly unloaded) to Stockholm
271
-    RouteSpecification fromTokyo = cargo.routeSpecification().withOrigin(TOKYO);
272
-    cargo.specifyNewRoute(fromTokyo);
273
-    cargoRepository.store(cargo);
274
-  }
275
-
276
-  public void checkDeliveryAfterNewRouteSpecified() {
277
-    Cargo cargo = cargoRepository.find(trackingId);
278
-
279
-    // The old itinerary does not satisfy the new specification
280
-    assertThat(cargo.routingStatus(), is(MISROUTED));
281
-    assertNull(cargo.nextExpectedActivity());
282
-  }
283
-
284
-  public void assignToNewRouteFromTokyoToStockholm() {
285
-    Cargo cargo = cargoRepository.find(trackingId);
286
-
287
-    // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
288
-    List<Itinerary> newItineraries = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
289
-    Itinerary newItinerary = newItineraries.get(0);
290
-
291
-    cargo.assignToRoute(newItinerary);
292
-    cargoRepository.store(cargo);
293
-  }
294
-
295
-  public void checkDeliveryAfterAssignedToNewRoute() {
296
-    Cargo cargo = cargoRepository.find(trackingId);
297
-
298
-    // New itinerary should satisfy new route
299
-    assertThat(cargo.routingStatus(), is(ROUTED));
300
-    // TODO is it really misdirected at this point?
301
-    assertTrue(cargo.isMisdirected());
302
-    //assertEquals(new HandlingActivity(LOAD, TOKYO, v300), cargo.nextExpectedActivity());
303
-    assertNull(cargo.nextExpectedActivity());
304
-  }
305
-
306
-  public void loadInTokyo() throws CannotCreateHandlingEventException {
307
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), v300, TOKYO, LOAD);
308
-  }
309
-
310
-  private void checkDeliveryAfterLoadInTokyo() {
311
-    Cargo cargo = cargoRepository.find(trackingId);
312
-    // Check current state - should be ok
313
-    assertThat(cargo.currentVoyage(), is(v300));
314
-    assertThat(cargo.lastKnownLocation(), is(TOKYO));
315
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
316
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, HAMBURG, v300)));
317
-    assertFalse(cargo.isMisdirected());
318
-  }
319
-
320
-  public void unloadInHamburg() throws CannotCreateHandlingEventException {
321
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-12"), v300, HAMBURG, UNLOAD);
322
-  }
323
-
324
-  private void checkDeliveryAfterUnloadInHamburg() {
325
-    Cargo cargo = cargoRepository.find(trackingId);
326
-    // Check current state - should be ok
327
-
328
-    assertThat(cargo.currentVoyage(), is(NONE));
329
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
330
-    assertThat(cargo.transportStatus(), is(IN_PORT));
331
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, HAMBURG, v400)));
332
-    assertFalse(cargo.isMisdirected());
333
-  }
334
-
335
-  public void loadInHamburg() throws CannotCreateHandlingEventException {
336
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-14"), v400, HAMBURG, LOAD);
337
-  }
338
-
339
-  private void checkDeliveryAfterLoadInHamburg() {
340
-    Cargo cargo = cargoRepository.find(trackingId);
341
-    // Check current state - should be ok
342
-
343
-    assertThat(cargo.currentVoyage(), is(v400));
344
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
345
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
346
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, v400)));
347
-    assertFalse(cargo.isMisdirected());
348
-  }
349
-
350
-  public void unloadInStockholmOffOf(Voyage voyage) throws CannotCreateHandlingEventException {
351
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-15"), voyage, STOCKHOLM, UNLOAD);
352
-  }
353
-
354
-  private void checkDeliveryAfterUnloadInStockholm() {
355
-    Cargo cargo = cargoRepository.find(trackingId);
356
-    // Check current state - should be ok
357
-    assertThat(cargo.currentVoyage(), is(NONE));
358
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
359
-    assertThat(cargo.transportStatus(), is(IN_PORT));
360
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(CLAIM, STOCKHOLM)));
361
-    assertFalse(cargo.isMisdirected());
362
-  }
363
-
364
-  private void claimInStockholm() throws CannotCreateHandlingEventException {
365
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-16"), null, STOCKHOLM, CLAIM);
366
-  }
367
-
368
-  private void checkDeliveryAfterClaimInStockholm() {
369
-    Cargo cargo = cargoRepository.find(trackingId);
370
-    // Check current state - should be ok
371
-    assertThat(cargo.currentVoyage(), is(NONE));
372
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
373
-    assertThat(cargo.transportStatus(), is(CLAIMED));
374
-    assertFalse(cargo.isMisdirected());
375
-    assertNull(cargo.nextExpectedActivity());
376
-  }
377
-
378
-  private void createHandlingEventAndUpdateAggregates(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
379
-    updateHandlingEventAggregate(completionTime, voyage, location, type);
380
-    updateCargoAggregate();
381
-  }
382
-
383
-  private void updateHandlingEventAggregate(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
384
-    VoyageNumber voyageNumber = voyage != null ? voyage.voyageNumber() : null;
385
-    HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(completionTime, trackingId, voyageNumber, location.unLocode(), type, new OperatorCode("ABCDE"));
386
-    handlingEventRepository.store(handlingEvent);
387
-  }
388
-
389
-  private void updateCargoAggregate() {
390
-    Cargo cargo = cargoRepository.find(trackingId);
391
-    HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(cargo);
392
-    cargo.handled(handlingEvent.activity(), new Date());
393
-    cargoRepository.store(cargo);
394
-  }
395
-
396
-  private static class ScenarioStubRoutingService implements RoutingService {
397
-
398
-    public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
399
-      if (routeSpecification.origin().equals(HONGKONG)) {
400
-        // Hongkong - NYC - Chicago - Stockholm, initial routing
401
-        return Arrays.asList(
402
-          new Itinerary(Arrays.asList(
403
-            new Leg(v100, HONGKONG, LONGBEACH, toDate("2009-03-03"), toDate("2009-03-09")),
404
-            new Leg(v250, LONGBEACH, NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")),
405
-            new Leg(v200, NEWYORK, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
406
-          ))
407
-        );
408
-      } else {
409
-        // Tokyo - Hamburg - Stockholm, rerouting misdirected cargo from Tokyo
410
-        return Arrays.asList(
411
-          new Itinerary(Arrays.asList(
412
-            new Leg(v300, TOKYO, HAMBURG, toDate("2009-03-08"), toDate("2009-03-12")),
413
-            new Leg(v400, HAMBURG, STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15"))
414
-          ))
415
-        );
416
-      }
417
-    }
418
-
419
-  }
420
-
421
-}

+ 0
- 102
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/scenario/VoyageRescheduledScenarioTest.java 查看文件

@@ -1,102 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.scenario;
2
-
3
-import static org.hamcrest.core.Is.is;
4
-import static org.junit.Assert.assertThat;
5
-import org.junit.Before;
6
-import org.junit.Test;
7
-import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
8
-import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
9
-import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.MISROUTED;
10
-import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.ROUTED;
11
-import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
12
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
13
-import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
14
-import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
15
-import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.TrackingIdFactoryInMem;
16
-
17
-import java.util.Date;
18
-
19
-public class VoyageRescheduledScenarioTest {
20
-
21
-  Cargo cargo;
22
-  Voyage voyage1;
23
-  Voyage voyage2;
24
-  Voyage voyage3;
25
-
26
-  @Before
27
-  public void setupCargo() {
28
-    TrackingIdFactoryInMem trackingIdFactory = new TrackingIdFactoryInMem();
29
-
30
-    // Creating new voyages to avoid rescheduling shared ones, breaking other tests
31
-    voyage1 = new Voyage(new VoyageNumber("V1"), HONGKONG_TO_NEW_YORK.schedule());
32
-    voyage2 = new Voyage(new VoyageNumber("V2"), NEW_YORK_TO_DALLAS.schedule());
33
-    voyage3 = new Voyage(new VoyageNumber("V3"), DALLAS_TO_HELSINKI.schedule());
34
-
35
-    TrackingId trackingId = trackingIdFactory.nextTrackingId();
36
-    RouteSpecification routeSpecification = new RouteSpecification(HANGZOU, STOCKHOLM, toDate("2008-12-23"));
37
-
38
-    cargo = new Cargo(trackingId, routeSpecification);
39
-    Itinerary itinerary = new Itinerary(
40
-      Leg.deriveLeg(voyage1, HANGZOU, NEWYORK),
41
-      Leg.deriveLeg(voyage2, NEWYORK, DALLAS),
42
-      Leg.deriveLeg(voyage3, DALLAS, STOCKHOLM)
43
-    );
44
-    cargo.assignToRoute(itinerary);
45
-  }
46
-
47
-  @Test
48
-  public void voyageIsRescheduledWithMaintainableRoute() {
49
-    assertThat(cargo.routingStatus(), is(ROUTED));
50
-
51
-    Date oldDepartureTime = toDate("2008-10-24", "07:00");
52
-
53
-    assertThat(voyage2.schedule().departureTimeAt(NEWYORK), is(oldDepartureTime));
54
-    assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(oldDepartureTime));
55
-
56
-    // Now voyage2 is rescheduled, the departure from NYC is delayed a few hours.
57
-    Date newDepartureTime = toDate("2008-10-24", "17:00");
58
-    voyage2.departureRescheduled(NEWYORK, newDepartureTime);
59
-
60
-    // The schedule of voyage2 is updated
61
-    assertThat(voyage2.schedule().departureTimeAt(NEWYORK), is(newDepartureTime));
62
-    // ...but the cargo itinerary still has the old departure time
63
-    assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(oldDepartureTime));
64
-
65
-    // Generate a new itinerary from the old one and assign the cargo to this route
66
-    Itinerary newItinerary = cargo.itinerary().withRescheduledVoyage(voyage2);
67
-    cargo.assignToRoute(newItinerary);
68
-
69
-    // Now the cargo aggregate is updated to reflect the scheduling change!
70
-    assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(newDepartureTime));
71
-    assertThat(cargo.routingStatus(), is(ROUTED));
72
-  }
73
-
74
-  @Test
75
-  public void voyageIsRescheduledWithUnmaintainableRoute() {
76
-    assertThat(cargo.routingStatus(), is(ROUTED));
77
-
78
-    // Voyage1 arrives in NYC at 2008-10-23 23:10
79
-    // Now rescheduling the departure of voyage2 to BEFORE
80
-    // voyage1 arrives in NYC. This makes it impossible to
81
-    // keep the latter part of the old itinerary, and the new itinerary
82
-    // is therefore truncated after unload in NYC.
83
-
84
-    // TODO delay the arrival instead of advancing the departure
85
-
86
-    Date newDepartureTime = toDate("2008-10-23", "18:30");
87
-    voyage2.departureRescheduled(NEWYORK, newDepartureTime);
88
-
89
-    // Only the part of the itinerary up to and including NYC is maintainable, the rest is truncated
90
-    Itinerary truncatedItinerary = cargo.itinerary().withRescheduledVoyage(voyage2);
91
-    assertThat(truncatedItinerary.lastLeg().unloadLocation(), is(NEWYORK));
92
-
93
-    //Or... The Itinerary is created with an 'Illegal Connection' based on a coomparison of
94
-    //each transfer with a Location.minimumAllowedConnectionTime(). Since Loation is an entity
95
-    //we don't allow Itinerary to dynamically use the property directly because it is not immutable.
96
-    
97
-    // The cargo enters MISROUTED state
98
-    cargo.assignToRoute(truncatedItinerary);
99
-    assertThat(cargo.routingStatus(), is(MISROUTED));
100
-  }
101
-
102
-}