|
|
@@ -6,8 +6,9 @@ import se.citerus.dddsample.application.impl.BookingServiceImpl;
|
|
6
|
6
|
import se.citerus.dddsample.application.impl.CargoInspectionServiceImpl;
|
|
7
|
7
|
import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
|
|
8
|
8
|
import se.citerus.dddsample.domain.model.cargo.*;
|
|
|
9
|
+import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
|
|
9
|
10
|
import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.*;
|
|
10
|
|
-import se.citerus.dddsample.domain.model.carrier.Voyage;
|
|
|
11
|
+import static se.citerus.dddsample.domain.model.carrier.Voyage.NONE;
|
|
11
|
12
|
import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
|
|
12
|
13
|
import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
|
|
13
|
14
|
import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
|
|
|
@@ -83,7 +84,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
83
|
84
|
|
|
84
|
85
|
/* Use case 1: booking
|
|
85
|
86
|
|
|
86
|
|
- A new cargo is booked, and the unique tracking id is returned. */
|
|
|
87
|
+ A new cargo is booked, and the unique tracking id is assigned to the cargo. */
|
|
87
|
88
|
TrackingId trackingId = bookingService.bookNewCargo(
|
|
88
|
89
|
origin.unLocode(), destination.unLocode(), arrivalDeadline
|
|
89
|
90
|
);
|
|
|
@@ -98,7 +99,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
98
|
99
|
the cargo aggregate in a suitable way. */
|
|
99
|
100
|
Cargo cargo = cargoRepository.find(trackingId);
|
|
100
|
101
|
assertNotNull(cargo);
|
|
101
|
|
- assertEquals(TransportStatus.NOT_RECEIVED, cargo.delivery().transportStatus());
|
|
|
102
|
+ assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
|
|
102
|
103
|
assertEquals(RoutingStatus.NOT_ROUTED, cargo.routingStatus());
|
|
103
|
104
|
assertFalse(cargo.isMisdirected());
|
|
104
|
105
|
|
|
|
@@ -144,7 +145,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
144
|
145
|
// Check current state - should be ok
|
|
145
|
146
|
assertEquals(CM003, cargo.delivery().currentVoyage());
|
|
146
|
147
|
assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
|
|
147
|
|
- assertEquals(TransportStatus.ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
|
148
|
+ assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
148
|
149
|
assertFalse(cargo.isMisdirected());
|
|
149
|
150
|
|
|
150
|
151
|
/*
|
|
|
@@ -156,10 +157,10 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
156
|
157
|
*/
|
|
157
|
158
|
VoyageNumber noSuchVoyageNumber = new VoyageNumber("XX000");
|
|
158
|
159
|
UnLocode noSuchUnLocode = new UnLocode("ZZZZZ");
|
|
159
|
|
- HandlingEventRegistrationAttempt failedAttempt = new HandlingEventRegistrationAttempt(
|
|
|
160
|
+ HandlingEventRegistrationAttempt failingAttempt = new HandlingEventRegistrationAttempt(
|
|
160
|
161
|
new Date(), new Date(300), trackingId, noSuchVoyageNumber, LOAD, noSuchUnLocode
|
|
161
|
162
|
);
|
|
162
|
|
- handlingEventService.registerHandlingEvent(failedAttempt);
|
|
|
163
|
+ handlingEventService.registerHandlingEvent(failingAttempt);
|
|
163
|
164
|
|
|
164
|
165
|
|
|
165
|
166
|
// Cargo is now (incorrectly) unloaded in Tokyo
|
|
|
@@ -168,11 +169,15 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
168
|
169
|
));
|
|
169
|
170
|
|
|
170
|
171
|
// Check current state - cargo is misdirected!
|
|
171
|
|
- assertEquals(Voyage.NONE, cargo.delivery().currentVoyage());
|
|
|
172
|
+ assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
172
|
173
|
assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
|
|
173
|
|
- assertEquals(TransportStatus.IN_PORT, cargo.delivery().transportStatus());
|
|
|
174
|
+ assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
174
|
175
|
assertTrue(cargo.isMisdirected());
|
|
175
|
176
|
|
|
|
177
|
+
|
|
|
178
|
+ // -- Cargo needs to be rerouted --
|
|
|
179
|
+
|
|
|
180
|
+
|
|
176
|
181
|
// Specify a new route, this time from Tokyo (where it was incorrectly unloaded) to Stockholm
|
|
177
|
182
|
RouteSpecification fromTokyo = new RouteSpecification(TOKYO, STOCKHOLM, arrivalDeadline);
|
|
178
|
183
|
cargo.specifyNewRoute(fromTokyo);
|
|
|
@@ -188,8 +193,69 @@ public class CargoLifecycleScenarioTest extends TestCase {
|
|
188
|
193
|
// New itinerary should satisfy new route
|
|
189
|
194
|
assertEquals(RoutingStatus.ROUTED, cargo.routingStatus());
|
|
190
|
195
|
|
|
191
|
|
-
|
|
192
|
|
- // TODO handling from Tokyo to Stockholm
|
|
|
196
|
+
|
|
|
197
|
+ // -- Cargo has been rerouted, shipping continues --
|
|
|
198
|
+
|
|
|
199
|
+
|
|
|
200
|
+ // Load in Tokyo
|
|
|
201
|
+ HandlingEventRegistrationAttempt attempt2 = new HandlingEventRegistrationAttempt(
|
|
|
202
|
+ new Date(), new Date(500), trackingId, CM003.voyageNumber(), LOAD, TOKYO.unLocode()
|
|
|
203
|
+ );
|
|
|
204
|
+ handlingEventService.registerHandlingEvent(attempt2);
|
|
|
205
|
+
|
|
|
206
|
+ // Check current state - should be ok
|
|
|
207
|
+ assertEquals(CM003, cargo.delivery().currentVoyage());
|
|
|
208
|
+ assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
|
|
|
209
|
+ assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
|
210
|
+ assertFalse(cargo.isMisdirected());
|
|
|
211
|
+
|
|
|
212
|
+ // Unload in Hamburg
|
|
|
213
|
+ HandlingEventRegistrationAttempt attempt3 = new HandlingEventRegistrationAttempt(
|
|
|
214
|
+ new Date(), new Date(600), trackingId, CM003.voyageNumber(), UNLOAD, HAMBURG.unLocode()
|
|
|
215
|
+ );
|
|
|
216
|
+ handlingEventService.registerHandlingEvent(attempt3);
|
|
|
217
|
+
|
|
|
218
|
+ // Check current state - should be ok
|
|
|
219
|
+ assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
|
220
|
+ assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
|
|
|
221
|
+ assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
|
222
|
+ assertFalse(cargo.isMisdirected());
|
|
|
223
|
+
|
|
|
224
|
+ // Load in Hamburg
|
|
|
225
|
+ HandlingEventRegistrationAttempt attempt4 = new HandlingEventRegistrationAttempt(
|
|
|
226
|
+ new Date(), new Date(700), trackingId, CM005.voyageNumber(), LOAD, HAMBURG.unLocode()
|
|
|
227
|
+ );
|
|
|
228
|
+ handlingEventService.registerHandlingEvent(attempt4);
|
|
|
229
|
+
|
|
|
230
|
+ // Check current state - should be ok
|
|
|
231
|
+ assertEquals(CM005, cargo.delivery().currentVoyage());
|
|
|
232
|
+ assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
|
|
|
233
|
+ assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
|
|
|
234
|
+ assertFalse(cargo.isMisdirected());
|
|
|
235
|
+
|
|
|
236
|
+ // Unload in Stockholm
|
|
|
237
|
+ HandlingEventRegistrationAttempt attempt5 = new HandlingEventRegistrationAttempt(
|
|
|
238
|
+ new Date(), new Date(800), trackingId, CM005.voyageNumber(), UNLOAD, STOCKHOLM.unLocode()
|
|
|
239
|
+ );
|
|
|
240
|
+ handlingEventService.registerHandlingEvent(attempt5);
|
|
|
241
|
+
|
|
|
242
|
+ // Check current state - should be ok
|
|
|
243
|
+ assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
|
244
|
+ assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
|
|
|
245
|
+ assertEquals(IN_PORT, cargo.delivery().transportStatus());
|
|
|
246
|
+ assertFalse(cargo.isMisdirected());
|
|
|
247
|
+
|
|
|
248
|
+ // Finally, cargo is claimed in Stockholm. This ends the cargo lifecycle from our perspective.
|
|
|
249
|
+ HandlingEventRegistrationAttempt attempt6 = new HandlingEventRegistrationAttempt(
|
|
|
250
|
+ new Date(), new Date(900), trackingId, null, CLAIM, STOCKHOLM.unLocode()
|
|
|
251
|
+ );
|
|
|
252
|
+ handlingEventService.registerHandlingEvent(attempt6);
|
|
|
253
|
+
|
|
|
254
|
+ // Check current state - should be ok
|
|
|
255
|
+ assertEquals(NONE, cargo.delivery().currentVoyage());
|
|
|
256
|
+ assertEquals(STOCKHOLM, cargo.delivery().lastKnownLocation());
|
|
|
257
|
+ assertEquals(CLAIMED, cargo.delivery().transportStatus());
|
|
|
258
|
+ assertFalse(cargo.isMisdirected());
|
|
193
|
259
|
}
|
|
194
|
260
|
|
|
195
|
261
|
/*
|