|
|
@@ -1,191 +0,0 @@
|
|
1
|
|
-package se.citerus.dddsample;
|
|
2
|
|
-
|
|
3
|
|
-import junit.framework.TestCase;
|
|
4
|
|
-import se.citerus.dddsample.application.HandlingEventService;
|
|
5
|
|
-import se.citerus.dddsample.application.TrackingService;
|
|
6
|
|
-import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
|
|
7
|
|
-import se.citerus.dddsample.application.impl.TrackingServiceImpl;
|
|
8
|
|
-import se.citerus.dddsample.domain.model.cargo.*;
|
|
9
|
|
-import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.*;
|
|
10
|
|
-import se.citerus.dddsample.domain.model.carrier.Voyage;
|
|
11
|
|
-import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
|
|
12
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
13
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
|
|
14
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
|
|
15
|
|
-import se.citerus.dddsample.domain.model.location.Location;
|
|
16
|
|
-import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
17
|
|
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
18
|
|
-import se.citerus.dddsample.domain.service.DomainEventNotifier;
|
|
19
|
|
-import se.citerus.dddsample.domain.service.RoutingService;
|
|
20
|
|
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
|
|
21
|
|
-import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
|
|
22
|
|
-
|
|
23
|
|
-import java.util.*;
|
|
24
|
|
-
|
|
25
|
|
-/**
|
|
26
|
|
- * Cargo scenarios.
|
|
27
|
|
- */
|
|
28
|
|
-public class CargoHandlingScenarioTest extends TestCase {
|
|
29
|
|
-
|
|
30
|
|
- HandlingEventFactory handlingEventFactory;
|
|
31
|
|
-
|
|
32
|
|
- DomainEventNotifier domainEventNotifier;
|
|
33
|
|
-
|
|
34
|
|
- HandlingEventService handlingEventService;
|
|
35
|
|
- TrackingService trackingService;
|
|
36
|
|
- RoutingService routingService;
|
|
37
|
|
-
|
|
38
|
|
- HandlingEventRepository handlingEventRepository;
|
|
39
|
|
- CargoRepository cargoRepository;
|
|
40
|
|
- LocationRepository locationRepository;
|
|
41
|
|
- VoyageRepository voyageRepository;
|
|
42
|
|
-
|
|
43
|
|
- Cargo cargo;
|
|
44
|
|
-
|
|
45
|
|
-
|
|
46
|
|
- public void testCargoFromHongkongToStockholm() throws Exception {
|
|
47
|
|
-
|
|
48
|
|
- // Cargo from Hongkong to Stockholm (skipping the booking procedure here)
|
|
49
|
|
- TrackingId trackingId = generateTrackingId();
|
|
50
|
|
- Location origin = HONGKONG;
|
|
51
|
|
- Location destination = STOCKHOLM;
|
|
52
|
|
- cargo = new Cargo(trackingId, origin, destination);
|
|
53
|
|
-
|
|
54
|
|
-
|
|
55
|
|
- assertEquals(RoutingStatus.NOT_ROUTED, cargo.routingStatus());
|
|
56
|
|
-
|
|
57
|
|
- // Route cargo
|
|
58
|
|
- RouteSpecification routeSpecification = new RouteSpecification(cargo.origin(), cargo.destination(), inTwoWeeks());
|
|
59
|
|
- List<Itinerary> itineraries = routingService.fetchRoutesForSpecification(routeSpecification);
|
|
60
|
|
- Itinerary itinerary = selectPreferedItinerary(itineraries);
|
|
61
|
|
- cargo.assignToRoute(itinerary);
|
|
62
|
|
-
|
|
63
|
|
- // Handling begins: cargo is received in Hongkong
|
|
64
|
|
- HandlingEvent received = handlingEventFactory.createHandlingEvent(
|
|
65
|
|
- dateReceived(), trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.RECEIVE);
|
|
66
|
|
-
|
|
67
|
|
- handlingEventService.register(received);
|
|
68
|
|
-
|
|
69
|
|
-
|
|
70
|
|
- // Loaded onto carrier movement CM003 in Hongkong
|
|
71
|
|
- HandlingEvent loadedInHongkong = handlingEventFactory.createHandlingEvent(
|
|
72
|
|
- dateLoadingCompleted(), trackingId, CM003.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD);
|
|
73
|
|
-
|
|
74
|
|
- handlingEventService.register(loadedInHongkong);
|
|
75
|
|
-
|
|
76
|
|
- // Check current state - should be ok
|
|
77
|
|
- assertEquals(CM003, cargo.delivery().currentVoyage());
|
|
78
|
|
- assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
|
|
79
|
|
- assertEquals(TransportStatus.ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
80
|
|
- assertFalse(cargo.isMisdirected());
|
|
81
|
|
-
|
|
82
|
|
-
|
|
83
|
|
- // Cargo is now (incorrectly) unloaded in Tokyo
|
|
84
|
|
- HandlingEvent unloadedInTokyo = handlingEventFactory.createHandlingEvent(
|
|
85
|
|
- dateUnloadingCompleted(), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), HandlingEvent.Type.UNLOAD);
|
|
86
|
|
- handlingEventService.register(unloadedInTokyo);
|
|
87
|
|
-
|
|
88
|
|
- // Check current state - cargo is misdirected!
|
|
89
|
|
- assertEquals(Voyage.NONE, cargo.delivery().currentVoyage());
|
|
90
|
|
- assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
|
|
91
|
|
- assertEquals(TransportStatus.IN_PORT, cargo.delivery().transportStatus());
|
|
92
|
|
- assertTrue(cargo.isMisdirected());
|
|
93
|
|
-
|
|
94
|
|
- // Then: Reroute!
|
|
95
|
|
- }
|
|
96
|
|
-
|
|
97
|
|
-
|
|
98
|
|
-
|
|
99
|
|
- /*
|
|
100
|
|
- * Utility stubs below.
|
|
101
|
|
- */
|
|
102
|
|
-
|
|
103
|
|
- private Date dateReceived() {
|
|
104
|
|
- return new Date(100);
|
|
105
|
|
- }
|
|
106
|
|
-
|
|
107
|
|
- private Date dateLoadingCompleted() {
|
|
108
|
|
- return new Date(200);
|
|
109
|
|
- }
|
|
110
|
|
-
|
|
111
|
|
- private Date dateUnloadingCompleted() {
|
|
112
|
|
- return new Date(300);
|
|
113
|
|
- }
|
|
114
|
|
-
|
|
115
|
|
- private TrackingId generateTrackingId() {
|
|
116
|
|
- return new TrackingId("TI1");
|
|
117
|
|
- }
|
|
118
|
|
-
|
|
119
|
|
- private Date inTwoWeeks() {
|
|
120
|
|
- return new Date(new Date().getTime() + 1000*60*60*24*14);
|
|
121
|
|
- }
|
|
122
|
|
-
|
|
123
|
|
- private Itinerary selectPreferedItinerary(List<Itinerary> itineraries) {
|
|
124
|
|
- return itineraries.get(0);
|
|
125
|
|
- }
|
|
126
|
|
-
|
|
127
|
|
- protected void setUp() throws Exception {
|
|
128
|
|
-
|
|
129
|
|
- // Stub
|
|
130
|
|
- routingService = new RoutingService() {
|
|
131
|
|
- public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
|
|
132
|
|
- return Arrays.asList(
|
|
133
|
|
- new Itinerary(Arrays.asList(
|
|
134
|
|
- new Leg(CM003, HONGKONG, NEWYORK, new Date(), new Date()),
|
|
135
|
|
- new Leg(CM004, NEWYORK, CHICAGO, new Date(), new Date()),
|
|
136
|
|
- new Leg(CM005, CHICAGO, STOCKHOLM, new Date(), new Date())
|
|
137
|
|
- ))
|
|
138
|
|
- );
|
|
139
|
|
- }
|
|
140
|
|
- };
|
|
141
|
|
-
|
|
142
|
|
- // Synchronous stub
|
|
143
|
|
- domainEventNotifier = new DomainEventNotifier() {
|
|
144
|
|
- public void cargoWasHandled(HandlingEvent event) {
|
|
145
|
|
- trackingService.onCargoHandled(event.cargo().trackingId());
|
|
146
|
|
- }
|
|
147
|
|
- public void cargoWasMisdirected(Cargo cargo) {}
|
|
148
|
|
- public void cargoHasArrived(Cargo cargo) {}
|
|
149
|
|
- };
|
|
150
|
|
-
|
|
151
|
|
- // Stub
|
|
152
|
|
- cargoRepository = new CargoRepository() {
|
|
153
|
|
- public Cargo find(TrackingId trackingId) {
|
|
154
|
|
- return cargo;
|
|
155
|
|
- }
|
|
156
|
|
-
|
|
157
|
|
- public List<Cargo> findAll() {
|
|
158
|
|
- return null;
|
|
159
|
|
- }
|
|
160
|
|
-
|
|
161
|
|
- public void save(Cargo cargo) {
|
|
162
|
|
- }
|
|
163
|
|
-
|
|
164
|
|
- public TrackingId nextTrackingId() {
|
|
165
|
|
- return null;
|
|
166
|
|
- }
|
|
167
|
|
- };
|
|
168
|
|
-
|
|
169
|
|
- // Stub
|
|
170
|
|
- handlingEventRepository = new HandlingEventRepository() {
|
|
171
|
|
- public void save(HandlingEvent event) {
|
|
172
|
|
- Set<HandlingEvent> events = new HashSet<HandlingEvent>(cargo.delivery().history());
|
|
173
|
|
- events.add(event);
|
|
174
|
|
- CargoTestHelper.setDeliveryHistory(cargo, events);
|
|
175
|
|
- }
|
|
176
|
|
-
|
|
177
|
|
- public List<HandlingEvent> findEventsForCargo(TrackingId trackingId) {
|
|
178
|
|
- return null;
|
|
179
|
|
- }
|
|
180
|
|
- };
|
|
181
|
|
-
|
|
182
|
|
- // In-memory implementations
|
|
183
|
|
- locationRepository = new LocationRepositoryInMem();
|
|
184
|
|
- voyageRepository = new VoyageRepositoryInMem();
|
|
185
|
|
-
|
|
186
|
|
- // Domain services and factories that are implemented in the domain layer - not stubbed
|
|
187
|
|
- trackingService = new TrackingServiceImpl(domainEventNotifier, cargoRepository);
|
|
188
|
|
- handlingEventFactory = new HandlingEventFactory(cargoRepository, this.voyageRepository, this.locationRepository);
|
|
189
|
|
- handlingEventService = new HandlingEventServiceImpl(handlingEventRepository, domainEventNotifier);
|
|
190
|
|
- }
|
|
191
|
|
-}
|