|
|
@@ -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
|
|
-}
|