|
|
@@ -8,14 +8,14 @@ import se.citerus.dddsample.application.HandlingEventService;
|
|
8
|
8
|
import se.citerus.dddsample.application.impl.BookingServiceImpl;
|
|
9
|
9
|
import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
|
|
10
|
10
|
import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
|
|
|
11
|
+import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
|
|
11
|
12
|
import se.citerus.dddsample.domain.model.cargo.*;
|
|
12
|
13
|
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
|
|
13
|
14
|
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
|
|
14
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
|
15
|
+import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
|
|
15
|
16
|
import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
|
|
16
|
17
|
import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
|
|
17
|
18
|
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
|
|
18
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingHistory;
|
|
19
|
19
|
import se.citerus.dddsample.domain.model.location.Location;
|
|
20
|
20
|
import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
21
|
21
|
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
|
@@ -27,10 +27,13 @@ import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
|
|
27
|
27
|
import se.citerus.dddsample.domain.service.RoutingService;
|
|
28
|
28
|
import se.citerus.dddsample.infrastructure.messaging.stub.SynchronousApplicationEventsStub;
|
|
29
|
29
|
import se.citerus.dddsample.infrastructure.persistence.inmemory.CargoRepositoryInMem;
|
|
|
30
|
+import se.citerus.dddsample.infrastructure.persistence.inmemory.HandlingEventRepositoryInMem;
|
|
30
|
31
|
import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
|
|
31
|
32
|
import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
|
|
32
|
33
|
|
|
33
|
|
-import java.util.*;
|
|
|
34
|
+import java.util.Arrays;
|
|
|
35
|
+import java.util.Date;
|
|
|
36
|
+import java.util.List;
|
|
34
|
37
|
|
|
35
|
38
|
public class CargoLifecycleScenarioTest extends TestCase {
|
|
36
|
39
|
|
|
|
@@ -85,7 +88,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
85
|
88
|
and it should arrive in no more than two weeks. */
|
|
86
|
89
|
Location origin = HONGKONG;
|
|
87
|
90
|
Location destination = STOCKHOLM;
|
|
88
|
|
- Date arrivalDeadline = inTwoWeeks();
|
|
|
91
|
+ Date arrivalDeadline = toDate("2009-03-18");
|
|
89
|
92
|
|
|
90
|
93
|
/* Use case 1: booking
|
|
91
|
94
|
|
|
|
@@ -105,10 +108,10 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
105
|
108
|
Cargo cargo = cargoRepository.find(trackingId);
|
|
106
|
109
|
assertNotNull(cargo);
|
|
107
|
110
|
assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
|
|
108
|
|
- assertEquals(NOT_ROUTED, cargo.routingStatus());
|
|
109
|
|
- assertFalse(cargo.isMisdirected());
|
|
110
|
|
- assertNull(cargo.estimatedTimeOfArrival());
|
|
111
|
|
- assertNull(cargo.nextExpectedActivity());
|
|
|
111
|
+ assertEquals(NOT_ROUTED, cargo.delivery().routingStatus());
|
|
|
112
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
113
|
+ assertNull(cargo.delivery().estimatedTimeOfArrival());
|
|
|
114
|
+ assertNull(cargo.delivery().nextExpectedActivity());
|
|
112
|
115
|
|
|
113
|
116
|
/* Use case 2: routing
|
|
114
|
117
|
|
|
|
@@ -123,9 +126,9 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
123
|
126
|
cargo.assignToRoute(itinerary);
|
|
124
|
127
|
|
|
125
|
128
|
assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
|
|
126
|
|
- assertEquals(ROUTED, cargo.routingStatus());
|
|
127
|
|
- assertNotNull(cargo.estimatedTimeOfArrival());
|
|
128
|
|
- assertEquals(new HandlingActivity(RECEIVE, HONGKONG), cargo.nextExpectedActivity());
|
|
|
129
|
+ assertEquals(ROUTED, cargo.delivery().routingStatus());
|
|
|
130
|
+ assertNotNull(cargo.delivery().estimatedTimeOfArrival());
|
|
|
131
|
+ assertEquals(new HandlingActivity(RECEIVE, HONGKONG), cargo.delivery().nextExpectedActivity());
|
|
129
|
132
|
|
|
130
|
133
|
/*
|
|
131
|
134
|
Use case 3: handling
|
|
|
@@ -142,7 +145,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
142
|
145
|
Handling begins: cargo is received in Hongkong.
|
|
143
|
146
|
*/
|
|
144
|
147
|
handlingEventService.registerHandlingEvent(
|
|
145
|
|
- new Date(100), trackingId, null, HONGKONG.unLocode(), RECEIVE
|
|
|
148
|
+ toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), RECEIVE
|
|
146
|
149
|
);
|
|
147
|
150
|
|
|
148
|
151
|
assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
|
@@ -150,15 +153,15 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
150
|
153
|
|
|
151
|
154
|
// Next event: Load onto voyage CM003 in Hongkong
|
|
152
|
155
|
handlingEventService.registerHandlingEvent(
|
|
153
|
|
- new Date(200), trackingId, CM003.voyageNumber(), HONGKONG.unLocode(), LOAD
|
|
|
156
|
+ toDate("2009-03-03"), trackingId, CM003.voyageNumber(), HONGKONG.unLocode(), LOAD
|
|
154
|
157
|
);
|
|
155
|
158
|
|
|
156
|
159
|
// Check current state - should be ok
|
|
157
|
160
|
assertEquals(CM003, cargo.delivery().currentVoyage());
|
|
158
|
161
|
assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
|
|
159
|
162
|
assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
160
|
|
- assertFalse(cargo.isMisdirected());
|
|
161
|
|
- assertEquals(new HandlingActivity(UNLOAD, NEWYORK, CM003), cargo.nextExpectedActivity());
|
|
|
163
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
164
|
+ assertEquals(new HandlingActivity(UNLOAD, NEWYORK, CM003), cargo.delivery().nextExpectedActivity());
|
|
162
|
165
|
|
|
163
|
166
|
|
|
164
|
167
|
/*
|
|
|
@@ -170,22 +173,26 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
170
|
173
|
*/
|
|
171
|
174
|
final VoyageNumber noSuchVoyageNumber = new VoyageNumber("XX000");
|
|
172
|
175
|
final UnLocode noSuchUnLocode = new UnLocode("ZZZZZ");
|
|
173
|
|
- handlingEventService.registerHandlingEvent(
|
|
174
|
|
- new Date(300), trackingId, noSuchVoyageNumber, noSuchUnLocode, LOAD
|
|
175
|
|
- );
|
|
|
176
|
+ try {
|
|
|
177
|
+ handlingEventService.registerHandlingEvent(
|
|
|
178
|
+ toDate("2009-03-05"), trackingId, noSuchVoyageNumber, noSuchUnLocode, LOAD
|
|
|
179
|
+ );
|
|
|
180
|
+ fail("Should not be able to register a handling event with invalid location and voyage");
|
|
|
181
|
+ } catch (CannotCreateHandlingEventException expected) {
|
|
|
182
|
+ }
|
|
176
|
183
|
|
|
177
|
184
|
|
|
178
|
185
|
// Cargo is now (incorrectly) unloaded in Tokyo
|
|
179
|
186
|
handlingEventService.registerHandlingEvent(
|
|
180
|
|
- new Date(400), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), UNLOAD
|
|
|
187
|
+ toDate("2009-03-05"), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), UNLOAD
|
|
181
|
188
|
);
|
|
182
|
189
|
|
|
183
|
190
|
// Check current state - cargo is misdirected!
|
|
184
|
191
|
assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
185
|
192
|
assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
|
|
186
|
193
|
assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
187
|
|
- assertTrue(cargo.isMisdirected());
|
|
188
|
|
- assertNull(cargo.nextExpectedActivity());
|
|
|
194
|
+ assertTrue(cargo.delivery().isMisdirected());
|
|
|
195
|
+ assertNull(cargo.delivery().nextExpectedActivity());
|
|
189
|
196
|
|
|
190
|
197
|
|
|
191
|
198
|
// -- Cargo needs to be rerouted --
|
|
|
@@ -196,8 +203,8 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
196
|
203
|
cargo.specifyNewRoute(fromTokyo);
|
|
197
|
204
|
|
|
198
|
205
|
// The old itinerary does not satisfy the new specification
|
|
199
|
|
- assertEquals(MISROUTED, cargo.routingStatus());
|
|
200
|
|
- assertNull(cargo.nextExpectedActivity());
|
|
|
206
|
+ assertEquals(MISROUTED, cargo.delivery().routingStatus());
|
|
|
207
|
+ assertNull(cargo.delivery().nextExpectedActivity());
|
|
201
|
208
|
|
|
202
|
209
|
// Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
|
|
203
|
210
|
List<Itinerary> newItineraries = bookingService.requestPossibleRoutesForCargo(cargo.trackingId());
|
|
|
@@ -205,7 +212,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
205
|
212
|
cargo.assignToRoute(newItinerary);
|
|
206
|
213
|
|
|
207
|
214
|
// New itinerary should satisfy new route
|
|
208
|
|
- assertEquals(ROUTED, cargo.routingStatus());
|
|
|
215
|
+ assertEquals(ROUTED, cargo.delivery().routingStatus());
|
|
209
|
216
|
|
|
210
|
217
|
// TODO we can't handle the face that after a reroute, the cargo isn't misdirected anymore
|
|
211
|
218
|
//assertFalse(cargo.isMisdirected());
|
|
|
@@ -217,65 +224,65 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
217
|
224
|
|
|
218
|
225
|
// Load in Tokyo
|
|
219
|
226
|
handlingEventService.registerHandlingEvent(
|
|
220
|
|
- new Date(500), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), LOAD
|
|
|
227
|
+ toDate("2009-03-08"), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), LOAD
|
|
221
|
228
|
);
|
|
222
|
229
|
|
|
223
|
230
|
// Check current state - should be ok
|
|
224
|
231
|
assertEquals(CM003, cargo.delivery().currentVoyage());
|
|
225
|
232
|
assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
|
|
226
|
233
|
assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
227
|
|
- assertFalse(cargo.isMisdirected());
|
|
228
|
|
- assertEquals(new HandlingActivity(UNLOAD, HAMBURG, CM003), cargo.nextExpectedActivity());
|
|
|
234
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
235
|
+ assertEquals(new HandlingActivity(UNLOAD, HAMBURG, CM003), cargo.delivery().nextExpectedActivity());
|
|
229
|
236
|
|
|
230
|
237
|
// Unload in Hamburg
|
|
231
|
238
|
handlingEventService.registerHandlingEvent(
|
|
232
|
|
- new Date(600), trackingId, CM003.voyageNumber(), HAMBURG.unLocode(), UNLOAD
|
|
|
239
|
+ toDate("2009-03-12"), trackingId, CM003.voyageNumber(), HAMBURG.unLocode(), UNLOAD
|
|
233
|
240
|
);
|
|
234
|
241
|
|
|
235
|
242
|
// Check current state - should be ok
|
|
236
|
243
|
assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
237
|
244
|
assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
|
|
238
|
245
|
assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
239
|
|
- assertFalse(cargo.isMisdirected());
|
|
240
|
|
- assertEquals(new HandlingActivity(LOAD, HAMBURG, CM005), cargo.nextExpectedActivity());
|
|
|
246
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
247
|
+ assertEquals(new HandlingActivity(LOAD, HAMBURG, CM005), cargo.delivery().nextExpectedActivity());
|
|
241
|
248
|
|
|
242
|
249
|
|
|
243
|
250
|
// Load in Hamburg
|
|
244
|
251
|
handlingEventService.registerHandlingEvent(
|
|
245
|
|
- new Date(700), trackingId, CM005.voyageNumber(), HAMBURG.unLocode(), LOAD
|
|
|
252
|
+ toDate("2009-03-14"), trackingId, CM005.voyageNumber(), HAMBURG.unLocode(), LOAD
|
|
246
|
253
|
);
|
|
247
|
254
|
|
|
248
|
255
|
// Check current state - should be ok
|
|
249
|
256
|
assertEquals(CM005, cargo.delivery().currentVoyage());
|
|
250
|
257
|
assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
|
|
251
|
258
|
assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
252
|
|
- assertFalse(cargo.isMisdirected());
|
|
253
|
|
- assertEquals(new HandlingActivity(UNLOAD, STOCKHOLM, CM005), cargo.nextExpectedActivity());
|
|
|
259
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
260
|
+ assertEquals(new HandlingActivity(UNLOAD, STOCKHOLM, CM005), cargo.delivery().nextExpectedActivity());
|
|
254
|
261
|
|
|
255
|
262
|
|
|
256
|
263
|
// Unload in Stockholm
|
|
257
|
264
|
handlingEventService.registerHandlingEvent(
|
|
258
|
|
- new Date(800), trackingId, CM005.voyageNumber(), STOCKHOLM.unLocode(), UNLOAD
|
|
|
265
|
+ toDate("2009-03-15"), trackingId, CM005.voyageNumber(), STOCKHOLM.unLocode(), UNLOAD
|
|
259
|
266
|
);
|
|
260
|
267
|
|
|
261
|
268
|
// Check current state - should be ok
|
|
262
|
269
|
assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
263
|
270
|
assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
|
|
264
|
271
|
assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
265
|
|
- assertFalse(cargo.isMisdirected());
|
|
266
|
|
- assertEquals(new HandlingActivity(CLAIM, STOCKHOLM), cargo.nextExpectedActivity());
|
|
|
272
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
273
|
+ assertEquals(new HandlingActivity(CLAIM, STOCKHOLM), cargo.delivery().nextExpectedActivity());
|
|
267
|
274
|
|
|
268
|
275
|
// Finally, cargo is claimed in Stockholm. This ends the cargo lifecycle from our perspective.
|
|
269
|
276
|
handlingEventService.registerHandlingEvent(
|
|
270
|
|
- new Date(900), trackingId, null, STOCKHOLM.unLocode(), CLAIM
|
|
|
277
|
+ toDate("2009-03-16"), trackingId, null, STOCKHOLM.unLocode(), CLAIM
|
|
271
|
278
|
);
|
|
272
|
279
|
|
|
273
|
280
|
// Check current state - should be ok
|
|
274
|
281
|
assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
275
|
282
|
assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
|
|
276
|
283
|
assertEquals(CLAIMED, cargo.delivery().transportStatus());
|
|
277
|
|
- assertFalse(cargo.isMisdirected());
|
|
278
|
|
- assertNull(cargo.nextExpectedActivity());
|
|
|
284
|
+ assertFalse(cargo.delivery().isMisdirected());
|
|
|
285
|
+ assertNull(cargo.delivery().nextExpectedActivity());
|
|
279
|
286
|
}
|
|
280
|
287
|
|
|
281
|
288
|
|
|
|
@@ -324,40 +331,20 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
324
|
331
|
|
|
325
|
332
|
applicationEvents = new SynchronousApplicationEventsStub();
|
|
326
|
333
|
|
|
327
|
|
- // Stub
|
|
328
|
|
- // TODO move functionality to in-mem impl
|
|
329
|
|
- handlingEventRepository = new HandlingEventRepository() {
|
|
330
|
|
- Map<TrackingId, List<HandlingEvent>> eventMap = new HashMap<TrackingId, List<HandlingEvent>>();
|
|
331
|
|
-
|
|
332
|
|
- @Override
|
|
333
|
|
- public void store(HandlingEvent event) {
|
|
334
|
|
- final TrackingId trackingId = event.cargo().trackingId();
|
|
335
|
|
- List<HandlingEvent> list = eventMap.get(trackingId);
|
|
336
|
|
- if (list == null) {
|
|
337
|
|
- list = new ArrayList<HandlingEvent>();
|
|
338
|
|
- eventMap.put(trackingId, list);
|
|
339
|
|
- }
|
|
340
|
|
- list.add(event);
|
|
341
|
|
- }
|
|
342
|
|
-
|
|
343
|
|
- @Override
|
|
344
|
|
- public HandlingHistory lookupHandlingHistoryOfCargo(TrackingId trackingId) {
|
|
345
|
|
- return new HandlingHistory(eventMap.get(trackingId));
|
|
346
|
|
- }
|
|
347
|
|
- };
|
|
348
|
|
-
|
|
349
|
|
- // In-memory implementations
|
|
|
334
|
+ // In-memory implementations of the repositories
|
|
|
335
|
+ handlingEventRepository = new HandlingEventRepositoryInMem();
|
|
350
|
336
|
cargoRepository = new CargoRepositoryInMem();
|
|
351
|
337
|
locationRepository = new LocationRepositoryInMem();
|
|
352
|
338
|
voyageRepository = new VoyageRepositoryInMem();
|
|
353
|
339
|
|
|
354
|
340
|
// Actual factories and application services, wired with stubbed or in-memory infrastructure
|
|
355
|
|
- cargoInspectionService = new CargoInspectionServiceImpl(applicationEvents, cargoRepository, handlingEventRepository);
|
|
356
|
341
|
handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
|
|
|
342
|
+
|
|
|
343
|
+ cargoInspectionService = new CargoInspectionServiceImpl(applicationEvents, cargoRepository, handlingEventRepository);
|
|
357
|
344
|
handlingEventService = new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
|
|
358
|
345
|
bookingService = new BookingServiceImpl(cargoRepository, locationRepository, routingService);
|
|
359
|
346
|
|
|
360
|
|
- // Stub
|
|
|
347
|
+ // Circular dependency when doing synchrounous calls
|
|
361
|
348
|
((SynchronousApplicationEventsStub) applicationEvents).setCargoInspectionService(cargoInspectionService);
|
|
362
|
349
|
}
|
|
363
|
350
|
|