|
|
@@ -1,7 +1,7 @@
|
|
1
|
1
|
package se.citerus.dddsample.domain.model.cargo;
|
|
2
|
2
|
|
|
3
|
3
|
import junit.framework.TestCase;
|
|
4
|
|
-import se.citerus.dddsample.application.util.DateTestUtil;
|
|
|
4
|
+import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
|
|
5
|
5
|
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
|
|
6
|
6
|
import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
|
|
7
|
7
|
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
|
@@ -11,9 +11,6 @@ import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
11
|
11
|
import se.citerus.dddsample.domain.model.voyage.Voyage;
|
|
12
|
12
|
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
|
|
13
|
13
|
|
|
14
|
|
-import java.text.DateFormat;
|
|
15
|
|
-import java.text.ParseException;
|
|
16
|
|
-import java.text.SimpleDateFormat;
|
|
17
|
14
|
import java.util.*;
|
|
18
|
15
|
|
|
19
|
16
|
public class CargoTest extends TestCase {
|
|
|
@@ -33,7 +30,7 @@ public class CargoTest extends TestCase {
|
|
33
|
30
|
|
|
34
|
31
|
public void testConstruction() throws Exception {
|
|
35
|
32
|
final TrackingId trackingId = new TrackingId("XYZ");
|
|
36
|
|
- final Date arrivalDeadline = DateTestUtil.toDate("2009-03-13");
|
|
|
33
|
+ final Date arrivalDeadline = toDate("2009-03-13");
|
|
37
|
34
|
final RouteSpecification routeSpecification = new RouteSpecification(
|
|
38
|
35
|
STOCKHOLM, MELBOURNE, arrivalDeadline
|
|
39
|
36
|
);
|
|
|
@@ -119,7 +116,7 @@ public class CargoTest extends TestCase {
|
|
119
|
116
|
// Adding an event unrelated to unloading at final destination
|
|
120
|
117
|
events.add(
|
|
121
|
118
|
new HandlingEvent(cargo, new Date(10), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
|
|
122
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
119
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
123
|
120
|
assertFalse(cargo.delivery().isUnloadedAtDestination());
|
|
124
|
121
|
|
|
125
|
122
|
Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
|
|
|
@@ -129,29 +126,49 @@ public class CargoTest extends TestCase {
|
|
129
|
126
|
// Adding an unload event, but not at the final destination
|
|
130
|
127
|
events.add(
|
|
131
|
128
|
new HandlingEvent(cargo, new Date(20), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, voyage));
|
|
132
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
129
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
133
|
130
|
assertFalse(cargo.delivery().isUnloadedAtDestination());
|
|
134
|
131
|
|
|
135
|
132
|
// Adding an event in the final destination, but not unload
|
|
136
|
133
|
events.add(
|
|
137
|
134
|
new HandlingEvent(cargo, new Date(30), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK));
|
|
138
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
135
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
139
|
136
|
assertFalse(cargo.delivery().isUnloadedAtDestination());
|
|
140
|
137
|
|
|
141
|
138
|
// Finally, cargo is unloaded at final destination
|
|
142
|
139
|
events.add(
|
|
143
|
140
|
new HandlingEvent(cargo, new Date(40), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, voyage));
|
|
144
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
141
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
145
|
142
|
assertTrue(cargo.delivery().isUnloadedAtDestination());
|
|
146
|
143
|
}
|
|
147
|
144
|
|
|
|
145
|
+ public void testDeriveDeliveryFromHandlingHistory() throws Exception {
|
|
|
146
|
+ RouteSpecification sharedRouteSpec = new RouteSpecification(SHANGHAI, GOTHENBURG, toDate("2009-04-01"));
|
|
|
147
|
+ Cargo cargo1 = new Cargo(new TrackingId("ABC"), sharedRouteSpec);
|
|
|
148
|
+ Cargo cargo2 = new Cargo(new TrackingId("DEF"), sharedRouteSpec);
|
|
|
149
|
+ assertFalse(cargo1.sameIdentityAs(cargo2));
|
|
|
150
|
+
|
|
|
151
|
+ HandlingHistory handlingHistoryOfCargo1 = HandlingHistory.fromEvents(Arrays.asList(
|
|
|
152
|
+ new HandlingEvent(cargo1, toDate("2009-03-10"), toDate("2009-03-12"), HandlingEvent.Type.RECEIVE, HANGZOU)
|
|
|
153
|
+ ));
|
|
|
154
|
+
|
|
|
155
|
+ // This is ok
|
|
|
156
|
+ cargo1.deriveDeliveryProgress(handlingHistoryOfCargo1);
|
|
|
157
|
+
|
|
|
158
|
+ try {
|
|
|
159
|
+ cargo2.deriveDeliveryProgress(handlingHistoryOfCargo1);
|
|
|
160
|
+ fail("A cargo should not be able to derive its delivery progress from a handling history of a different cargo");
|
|
|
161
|
+ } catch (IllegalArgumentException expected) {
|
|
|
162
|
+ }
|
|
|
163
|
+ }
|
|
|
164
|
+
|
|
148
|
165
|
// TODO: Generate test data some better way
|
|
149
|
166
|
private Cargo populateCargoReceivedStockholm() throws Exception {
|
|
150
|
167
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
151
|
168
|
|
|
152
|
|
- HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, STOCKHOLM);
|
|
|
169
|
+ HandlingEvent he = new HandlingEvent(cargo, toDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, STOCKHOLM);
|
|
153
|
170
|
events.add(he);
|
|
154
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
171
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
155
|
172
|
|
|
156
|
173
|
return cargo;
|
|
157
|
174
|
}
|
|
|
@@ -159,8 +176,8 @@ public class CargoTest extends TestCase {
|
|
159
|
176
|
private Cargo populateCargoClaimedMelbourne() throws Exception {
|
|
160
|
177
|
final Cargo cargo = populateCargoOffMelbourne();
|
|
161
|
178
|
|
|
162
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, MELBOURNE));
|
|
163
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
179
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, MELBOURNE));
|
|
|
180
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
164
|
181
|
|
|
165
|
182
|
return cargo;
|
|
166
|
183
|
}
|
|
|
@@ -169,55 +186,55 @@ public class CargoTest extends TestCase {
|
|
169
|
186
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
170
|
187
|
|
|
171
|
188
|
|
|
172
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
173
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
|
189
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
|
190
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
174
|
191
|
|
|
175
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
176
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
|
192
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
|
193
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
177
|
194
|
|
|
178
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
195
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
179
|
196
|
return cargo;
|
|
180
|
197
|
}
|
|
181
|
198
|
|
|
182
|
199
|
private Cargo populateCargoOnHamburg() throws Exception {
|
|
183
|
200
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
184
|
201
|
|
|
185
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
186
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
187
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
|
202
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
|
203
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
|
204
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
188
|
205
|
|
|
189
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
206
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
190
|
207
|
return cargo;
|
|
191
|
208
|
}
|
|
192
|
209
|
|
|
193
|
210
|
private Cargo populateCargoOffMelbourne() throws Exception {
|
|
194
|
211
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
195
|
212
|
|
|
196
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
197
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
|
213
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
|
214
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
198
|
215
|
|
|
199
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
200
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
|
216
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
|
217
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
201
|
218
|
|
|
202
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
|
|
203
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, voyage));
|
|
|
219
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
|
|
|
220
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, voyage));
|
|
204
|
221
|
|
|
205
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
222
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
206
|
223
|
return cargo;
|
|
207
|
224
|
}
|
|
208
|
225
|
|
|
209
|
226
|
private Cargo populateCargoOnHongKong() throws Exception {
|
|
210
|
227
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
211
|
228
|
|
|
212
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
213
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
|
229
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
|
|
|
230
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
214
|
231
|
|
|
215
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
216
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
|
232
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
|
233
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
217
|
234
|
|
|
218
|
|
- events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
|
|
|
235
|
+ events.add(new HandlingEvent(cargo, toDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
|
|
219
|
236
|
|
|
220
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
237
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
221
|
238
|
return cargo;
|
|
222
|
239
|
}
|
|
223
|
240
|
|
|
|
@@ -243,7 +260,7 @@ public class CargoTest extends TestCase {
|
|
243
|
260
|
handlingEvents.add(new HandlingEvent(cargo, new Date(130), new Date(140), HandlingEvent.Type.CUSTOMS, GOTHENBURG));
|
|
244
|
261
|
|
|
245
|
262
|
events.addAll(handlingEvents);
|
|
246
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
263
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
247
|
264
|
assertFalse(cargo.delivery().isMisdirected());
|
|
248
|
265
|
|
|
249
|
266
|
//Try a couple of failing ones
|
|
|
@@ -253,7 +270,7 @@ public class CargoTest extends TestCase {
|
|
253
|
270
|
|
|
254
|
271
|
handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
|
|
255
|
272
|
events.addAll(handlingEvents);
|
|
256
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
273
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
257
|
274
|
|
|
258
|
275
|
assertTrue(cargo.delivery().isMisdirected());
|
|
259
|
276
|
|
|
|
@@ -267,7 +284,7 @@ public class CargoTest extends TestCase {
|
|
267
|
284
|
handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, voyage));
|
|
268
|
285
|
|
|
269
|
286
|
events.addAll(handlingEvents);
|
|
270
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
287
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
271
|
288
|
|
|
272
|
289
|
assertTrue(cargo.delivery().isMisdirected());
|
|
273
|
290
|
|
|
|
@@ -281,7 +298,7 @@ public class CargoTest extends TestCase {
|
|
281
|
298
|
handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM));
|
|
282
|
299
|
|
|
283
|
300
|
events.addAll(handlingEvents);
|
|
284
|
|
- cargo.deriveDeliveryProgress(new HandlingHistory(events));
|
|
|
301
|
+ cargo.deriveDeliveryProgress(HandlingHistory.fromEvents(events));
|
|
285
|
302
|
|
|
286
|
303
|
assertTrue(cargo.delivery().isMisdirected());
|
|
287
|
304
|
}
|
|
|
@@ -300,15 +317,4 @@ public class CargoTest extends TestCase {
|
|
300
|
317
|
return cargo;
|
|
301
|
318
|
}
|
|
302
|
319
|
|
|
303
|
|
- /**
|
|
304
|
|
- * Parse an ISO 8601 (YYYY-MM-DD) String to Date
|
|
305
|
|
- *
|
|
306
|
|
- * @param isoFormat String to parse.
|
|
307
|
|
- * @return Created date instance.
|
|
308
|
|
- * @throws ParseException Thrown if parsing fails.
|
|
309
|
|
- */
|
|
310
|
|
- private Date getDate(String isoFormat) throws ParseException {
|
|
311
|
|
- final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
312
|
|
- return dateFormat.parse(isoFormat);
|
|
313
|
|
- }
|
|
314
|
320
|
}
|