|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+package se.citerus.dddsample.service;
|
|
|
2
|
+
|
|
|
3
|
+import junit.framework.TestCase;
|
|
|
4
|
+import se.citerus.dddsample.domain.*;
|
|
|
5
|
+import se.citerus.dddsample.repository.CargoRepository;
|
|
|
6
|
+
|
|
|
7
|
+import java.util.Date;
|
|
|
8
|
+import java.util.Set;
|
|
|
9
|
+
|
|
|
10
|
+public class RoutingServiceTest extends TestCase {
|
|
|
11
|
+
|
|
|
12
|
+ RoutingService routingService;
|
|
|
13
|
+ CargoRepository cargoRepository;
|
|
|
14
|
+ HandlingEventService handlingEventService;
|
|
|
15
|
+
|
|
|
16
|
+ public void testCalculateRoute() throws Exception {
|
|
|
17
|
+ TrackingId trackingId = new TrackingId("XYZ123");
|
|
|
18
|
+ Cargo cargo = cargoRepository.find(trackingId);
|
|
|
19
|
+
|
|
|
20
|
+ Specification specification = null;
|
|
|
21
|
+
|
|
|
22
|
+ /*
|
|
|
23
|
+ The routing service calculates a number of possible routes that
|
|
|
24
|
+ satisfy the given specification (must arrive in three days, must not
|
|
|
25
|
+ cost more than $10,000 etc).
|
|
|
26
|
+ */
|
|
|
27
|
+ Set<Itinerary> itineraryCandidates = routingService.calculatePossibleRoutes(cargo, specification);
|
|
|
28
|
+
|
|
|
29
|
+ /*
|
|
|
30
|
+ Someone, or something, selects the most appropriate itinerary and
|
|
|
31
|
+ assigns that itinerary to the cargo.
|
|
|
32
|
+ */
|
|
|
33
|
+ Itinerary itinerary = selectItinerary(itineraryCandidates);
|
|
|
34
|
+ cargo.assignItinerary(itinerary);
|
|
|
35
|
+
|
|
|
36
|
+ /*
|
|
|
37
|
+ A number of events occur, all of which are according to plan
|
|
|
38
|
+ */
|
|
|
39
|
+ handlingEventService.register(new Date(), trackingId, new CarrierMovementId("A001"), new UnLocode("SE","STO"), null);
|
|
|
40
|
+ handlingEventService.register(new Date(), trackingId, new CarrierMovementId("B002"), null, null);
|
|
|
41
|
+ handlingEventService.register(new Date(), trackingId, new CarrierMovementId("C003"), null, null);
|
|
|
42
|
+
|
|
|
43
|
+ /*
|
|
|
44
|
+ Cargo should not be misdirected at this point.
|
|
|
45
|
+ */
|
|
|
46
|
+ assertFalse(cargo.isMisdirected());
|
|
|
47
|
+
|
|
|
48
|
+ /*
|
|
|
49
|
+ An unexpected event occur.
|
|
|
50
|
+ */
|
|
|
51
|
+ handlingEventService.register(null, null, null, null, null);
|
|
|
52
|
+
|
|
|
53
|
+ /*
|
|
|
54
|
+ Now the cargo is misdirected.
|
|
|
55
|
+ */
|
|
|
56
|
+ assertTrue(cargo.isMisdirected());
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+
|
|
|
60
|
+ // Stub for the itinerary selection process
|
|
|
61
|
+ private Itinerary selectItinerary(Set<Itinerary> itineraryCandidates) {
|
|
|
62
|
+ return itineraryCandidates.iterator().next();
|
|
|
63
|
+ }
|
|
|
64
|
+
|
|
|
65
|
+}
|