|
|
@@ -6,18 +6,10 @@ import static se.citerus.dddsample.domain.SampleLocations.*;
|
|
6
|
6
|
import java.text.DateFormat;
|
|
7
|
7
|
import java.text.ParseException;
|
|
8
|
8
|
import java.text.SimpleDateFormat;
|
|
9
|
|
-import java.util.ArrayList;
|
|
10
|
|
-import java.util.Collection;
|
|
11
|
|
-import java.util.Date;
|
|
|
9
|
+import java.util.*;
|
|
12
|
10
|
|
|
13
|
11
|
public class CargoTest extends TestCase {
|
|
14
|
|
-
|
|
15
|
|
- // TODO:
|
|
16
|
|
- // it seems that events are not added to the system by cargo.deliveryHistory().addEvent(),
|
|
17
|
|
- // but rather new HandlingEvents are stored and associated with its cargo. This test should
|
|
18
|
|
- // work against the repositories or the service layer. The delivery history of a cargo should be
|
|
19
|
|
- // read-only from the cargo end. // PeBa
|
|
20
|
|
-
|
|
|
12
|
+ private Set<HandlingEvent> events;
|
|
21
|
13
|
|
|
22
|
14
|
public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
|
|
23
|
15
|
Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
|
|
|
@@ -73,6 +65,10 @@ public class CargoTest extends TestCase {
|
|
73
|
65
|
assertFalse("Cargos are not equal when TrackingID differ", c1.equals(c2));
|
|
74
|
66
|
}
|
|
75
|
67
|
|
|
|
68
|
+ protected void setUp() throws Exception {
|
|
|
69
|
+ events = new HashSet<HandlingEvent>();
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
76
|
72
|
public void testIsUnloadedAtFinalDestination() throws Exception {
|
|
77
|
73
|
assertFalse(new Cargo().isUnloadedAtDestination());
|
|
78
|
74
|
|
|
|
@@ -80,25 +76,29 @@ public class CargoTest extends TestCase {
|
|
80
|
76
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
81
|
77
|
|
|
82
|
78
|
// Adding an event unrelated to unloading at final destination
|
|
83
|
|
- cargo.deliveryHistory().addEvent(
|
|
|
79
|
+ events.add(
|
|
84
|
80
|
new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU, null));
|
|
|
81
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
85
|
82
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
86
|
83
|
|
|
87
|
84
|
CarrierMovement cm1 = new CarrierMovement(new CarrierMovementId("CM1"), HANGZOU, NEWYORK);
|
|
88
|
85
|
|
|
89
|
86
|
// Adding an unload event, but not at the final destination
|
|
90
|
|
- cargo.deliveryHistory().addEvent(
|
|
|
87
|
+ events.add(
|
|
91
|
88
|
new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, cm1));
|
|
|
89
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
92
|
90
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
93
|
91
|
|
|
94
|
92
|
// Adding an event in the final destination, but not unload
|
|
95
|
|
- cargo.deliveryHistory().addEvent(
|
|
|
93
|
+ events.add(
|
|
96
|
94
|
new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK, null));
|
|
|
95
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
97
|
96
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
98
|
97
|
|
|
99
|
98
|
// Finally, cargo is unloaded at final destination
|
|
100
|
|
- cargo.deliveryHistory().addEvent(
|
|
|
99
|
+ events.add(
|
|
101
|
100
|
new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, cm1));
|
|
|
101
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
102
|
102
|
assertTrue(cargo.isUnloadedAtDestination());
|
|
103
|
103
|
}
|
|
104
|
104
|
|
|
|
@@ -129,7 +129,8 @@ public class CargoTest extends TestCase {
|
|
129
|
129
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
|
|
130
|
130
|
|
|
131
|
131
|
HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, STOCKHOLM, null);
|
|
132
|
|
- cargo.deliveryHistory().addEvent(he);
|
|
|
132
|
+ events.add(he);
|
|
|
133
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
133
|
134
|
|
|
134
|
135
|
return cargo;
|
|
135
|
136
|
}
|
|
|
@@ -137,7 +138,8 @@ public class CargoTest extends TestCase {
|
|
137
|
138
|
private Cargo populateCargoClaimedMelbourne() throws Exception {
|
|
138
|
139
|
final Cargo cargo = populateCargoOffMelbourne();
|
|
139
|
140
|
|
|
140
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, MELBOURNE, null));
|
|
|
141
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, MELBOURNE, null));
|
|
|
142
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
141
|
143
|
|
|
142
|
144
|
return cargo;
|
|
143
|
145
|
}
|
|
|
@@ -148,15 +150,16 @@ public class CargoTest extends TestCase {
|
|
148
|
150
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
149
|
151
|
new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG);
|
|
150
|
152
|
|
|
151
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
152
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
|
153
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
|
154
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
153
|
155
|
|
|
154
|
156
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
155
|
157
|
new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG);
|
|
156
|
158
|
|
|
157
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
158
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
|
|
|
159
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
|
160
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
|
|
159
|
161
|
|
|
|
162
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
160
|
163
|
return cargo;
|
|
161
|
164
|
}
|
|
162
|
165
|
|
|
|
@@ -166,14 +169,15 @@ public class CargoTest extends TestCase {
|
|
166
|
169
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
167
|
170
|
new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG);
|
|
168
|
171
|
|
|
169
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
170
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
|
172
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
|
173
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
171
|
174
|
|
|
172
|
175
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
173
|
176
|
new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG);
|
|
174
|
177
|
|
|
175
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
|
178
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
176
|
179
|
|
|
|
180
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
177
|
181
|
return cargo;
|
|
178
|
182
|
}
|
|
179
|
183
|
|
|
|
@@ -183,21 +187,22 @@ public class CargoTest extends TestCase {
|
|
183
|
187
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
184
|
188
|
new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG);
|
|
185
|
189
|
|
|
186
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
187
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
|
190
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
|
191
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
188
|
192
|
|
|
189
|
193
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
190
|
194
|
new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG);
|
|
191
|
195
|
|
|
192
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
193
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
|
|
|
196
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
|
197
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
|
|
194
|
198
|
|
|
195
|
199
|
final CarrierMovement hongKongToMelbourne = new CarrierMovement(
|
|
196
|
200
|
new CarrierMovementId("CAR_001"), HONGKONG, MELBOURNE);
|
|
197
|
201
|
|
|
198
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, hongKongToMelbourne));
|
|
199
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, hongKongToMelbourne));
|
|
|
202
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, hongKongToMelbourne));
|
|
|
203
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, hongKongToMelbourne));
|
|
200
|
204
|
|
|
|
205
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
201
|
206
|
return cargo;
|
|
202
|
207
|
}
|
|
203
|
208
|
|
|
|
@@ -207,20 +212,21 @@ public class CargoTest extends TestCase {
|
|
207
|
212
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
208
|
213
|
new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG);
|
|
209
|
214
|
|
|
210
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
211
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
|
215
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
|
|
|
216
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
|
|
212
|
217
|
|
|
213
|
218
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
214
|
219
|
new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG);
|
|
215
|
220
|
|
|
216
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
217
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
|
|
|
221
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
|
|
|
222
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
|
|
218
|
223
|
|
|
219
|
224
|
final CarrierMovement hongKongToMelbourne = new CarrierMovement(
|
|
220
|
225
|
new CarrierMovementId("CAR_001"), HONGKONG, MELBOURNE);
|
|
221
|
226
|
|
|
222
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, hongKongToMelbourne));
|
|
|
227
|
+ events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, hongKongToMelbourne));
|
|
223
|
228
|
|
|
|
229
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
224
|
230
|
return cargo;
|
|
225
|
231
|
}
|
|
226
|
232
|
|
|
|
@@ -249,7 +255,8 @@ public class CargoTest extends TestCase {
|
|
249
|
255
|
handlingEvents.add(new HandlingEvent(cargo, new Date(110), new Date(120), HandlingEvent.Type.CLAIM, GOTHENBURG, null));
|
|
250
|
256
|
handlingEvents.add(new HandlingEvent(cargo, new Date(130), new Date(140), HandlingEvent.Type.CUSTOMS, GOTHENBURG, null));
|
|
251
|
257
|
|
|
252
|
|
- cargo.deliveryHistory().addAllEvents(handlingEvents);
|
|
|
258
|
+ events.addAll(handlingEvents);
|
|
|
259
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
253
|
260
|
assertFalse(cargo.isMisdirected());
|
|
254
|
261
|
|
|
255
|
262
|
//Try a couple of failing ones
|
|
|
@@ -258,7 +265,8 @@ public class CargoTest extends TestCase {
|
|
258
|
265
|
handlingEvents = new ArrayList<HandlingEvent>();
|
|
259
|
266
|
|
|
260
|
267
|
handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU, null));
|
|
261
|
|
- cargo.deliveryHistory().addAllEvents(handlingEvents);
|
|
|
268
|
+ events.addAll(handlingEvents);
|
|
|
269
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
262
|
270
|
assertTrue(cargo.isMisdirected());
|
|
263
|
271
|
|
|
264
|
272
|
|
|
|
@@ -270,7 +278,8 @@ public class CargoTest extends TestCase {
|
|
270
|
278
|
handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, abc));
|
|
271
|
279
|
handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, ghi));
|
|
272
|
280
|
|
|
273
|
|
- cargo.deliveryHistory().addAllEvents(handlingEvents);
|
|
|
281
|
+ events.addAll(handlingEvents);
|
|
|
282
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
274
|
283
|
assertTrue(cargo.isMisdirected());
|
|
275
|
284
|
|
|
276
|
285
|
|
|
|
@@ -282,7 +291,8 @@ public class CargoTest extends TestCase {
|
|
282
|
291
|
handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, abc));
|
|
283
|
292
|
handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM, null));
|
|
284
|
293
|
|
|
285
|
|
- cargo.deliveryHistory().addAllEvents(handlingEvents);
|
|
|
294
|
+ events.addAll(handlingEvents);
|
|
|
295
|
+ cargo.setDeliveryHistory(new DeliveryHistory(events));
|
|
286
|
296
|
assertTrue(cargo.isMisdirected());
|
|
287
|
297
|
}
|
|
288
|
298
|
|