|
|
@@ -1,7 +1,9 @@
|
|
1
|
1
|
package se.citerus.dddsample.domain.model.cargo;
|
|
2
|
2
|
|
|
3
|
3
|
import junit.framework.TestCase;
|
|
|
4
|
+import se.citerus.dddsample.DateTestUtil;
|
|
4
|
5
|
import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
|
|
|
6
|
+import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
|
|
5
|
7
|
import se.citerus.dddsample.domain.model.carrier.Voyage;
|
|
6
|
8
|
import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
|
|
7
|
9
|
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
|
@@ -15,11 +17,11 @@ import java.util.*;
|
|
15
|
17
|
|
|
16
|
18
|
public class CargoTest extends TestCase {
|
|
17
|
19
|
|
|
18
|
|
- private Set<HandlingEvent> events;
|
|
|
20
|
+ private List<HandlingEvent> events;
|
|
19
|
21
|
private Voyage voyage;
|
|
20
|
22
|
|
|
21
|
23
|
protected void setUp() throws Exception {
|
|
22
|
|
- events = new HashSet<HandlingEvent>();
|
|
|
24
|
+ events = new ArrayList<HandlingEvent>();
|
|
23
|
25
|
|
|
24
|
26
|
voyage = new Voyage.Builder(new VoyageNumber("0123"), STOCKHOLM).
|
|
25
|
27
|
addMovement(HAMBURG, new Date(), new Date()).
|
|
|
@@ -28,6 +30,21 @@ public class CargoTest extends TestCase {
|
|
28
|
30
|
build();
|
|
29
|
31
|
}
|
|
30
|
32
|
|
|
|
33
|
+ public void testConstruction() throws Exception {
|
|
|
34
|
+ final TrackingId trackingId = new TrackingId("XYZ");
|
|
|
35
|
+ final Date arrivalDeadline = DateTestUtil.toDate("2009-03-13");
|
|
|
36
|
+ final RouteSpecification routeSpecification = new RouteSpecification(
|
|
|
37
|
+ STOCKHOLM, MELBOURNE, arrivalDeadline
|
|
|
38
|
+ );
|
|
|
39
|
+
|
|
|
40
|
+ final Cargo cargo = new Cargo(trackingId, STOCKHOLM, routeSpecification);
|
|
|
41
|
+
|
|
|
42
|
+ assertEquals(NOT_ROUTED, cargo.routingStatus());
|
|
|
43
|
+ assertEquals(NOT_RECEIVED, cargo.delivery().transportStatus());
|
|
|
44
|
+ assertEquals(Location.UNKNOWN, cargo.delivery().lastKnownLocation());
|
|
|
45
|
+ assertEquals(Voyage.NONE, cargo.delivery().currentVoyage());
|
|
|
46
|
+ }
|
|
|
47
|
+
|
|
31
|
48
|
public void testRoutingStatus() throws Exception {
|
|
32
|
49
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
33
|
50
|
final Itinerary good = new Itinerary();
|
|
|
@@ -39,7 +56,7 @@ public class CargoTest extends TestCase {
|
|
39
|
56
|
}
|
|
40
|
57
|
};
|
|
41
|
58
|
|
|
42
|
|
- cargo.specifyRoute(acceptOnlyGood);
|
|
|
59
|
+ cargo.specifyNewRoute(acceptOnlyGood);
|
|
43
|
60
|
|
|
44
|
61
|
assertEquals(NOT_ROUTED, cargo.routingStatus());
|
|
45
|
62
|
|
|
|
@@ -80,18 +97,6 @@ public class CargoTest extends TestCase {
|
|
80
|
97
|
assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
|
|
81
|
98
|
}
|
|
82
|
99
|
|
|
83
|
|
- public void testAtFinalLocation() throws Exception {
|
|
84
|
|
- Cargo cargo = populateCargoOffMelbourne();
|
|
85
|
|
-
|
|
86
|
|
- assertTrue(cargo.hasArrived());
|
|
87
|
|
- }
|
|
88
|
|
-
|
|
89
|
|
- public void testNotAtFinalLocationWhenNotUnloaded() throws Exception {
|
|
90
|
|
- Cargo cargo = populateCargoOnHongKong();
|
|
91
|
|
-
|
|
92
|
|
- assertFalse(cargo.hasArrived());
|
|
93
|
|
- }
|
|
94
|
|
-
|
|
95
|
100
|
public void testEquality() throws Exception {
|
|
96
|
101
|
RouteSpecification spec1 = new RouteSpecification(STOCKHOLM, HONGKONG, new Date());
|
|
97
|
102
|
RouteSpecification spec2 = new RouteSpecification(STOCKHOLM, MELBOURNE, new Date());
|
|
|
@@ -107,15 +112,13 @@ public class CargoTest extends TestCase {
|
|
107
|
112
|
}
|
|
108
|
113
|
|
|
109
|
114
|
public void testIsUnloadedAtFinalDestination() throws Exception {
|
|
110
|
|
- assertFalse(new Cargo().isUnloadedAtDestination());
|
|
111
|
|
-
|
|
112
|
115
|
Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
|
|
113
|
116
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
114
|
117
|
|
|
115
|
118
|
// Adding an event unrelated to unloading at final destination
|
|
116
|
119
|
events.add(
|
|
117
|
|
- new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
|
|
118
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
120
|
+ new HandlingEvent(cargo, new Date(10), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
|
|
|
121
|
+ cargo.updateStatus(events);
|
|
119
|
122
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
120
|
123
|
|
|
121
|
124
|
Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
|
|
|
@@ -124,52 +127,30 @@ public class CargoTest extends TestCase {
|
|
124
|
127
|
|
|
125
|
128
|
// Adding an unload event, but not at the final destination
|
|
126
|
129
|
events.add(
|
|
127
|
|
- new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, voyage));
|
|
128
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
130
|
+ new HandlingEvent(cargo, new Date(20), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, voyage));
|
|
|
131
|
+ cargo.updateStatus(events);
|
|
129
|
132
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
130
|
133
|
|
|
131
|
134
|
// Adding an event in the final destination, but not unload
|
|
132
|
135
|
events.add(
|
|
133
|
|
- new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK));
|
|
134
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
136
|
+ new HandlingEvent(cargo, new Date(30), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK));
|
|
|
137
|
+ cargo.updateStatus(events);
|
|
135
|
138
|
assertFalse(cargo.isUnloadedAtDestination());
|
|
136
|
139
|
|
|
137
|
140
|
// Finally, cargo is unloaded at final destination
|
|
138
|
141
|
events.add(
|
|
139
|
|
- new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, voyage));
|
|
140
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
142
|
+ new HandlingEvent(cargo, new Date(40), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, voyage));
|
|
|
143
|
+ cargo.updateStatus(events);
|
|
141
|
144
|
assertTrue(cargo.isUnloadedAtDestination());
|
|
142
|
145
|
}
|
|
143
|
146
|
|
|
144
|
|
- /* TODO implement nextExpectedEvent
|
|
145
|
|
- public void testNextExpectedEvent() {
|
|
146
|
|
- Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
|
|
147
|
|
- CarrierMovementId cmid = new CarrierMovementId("CM1");
|
|
148
|
|
- CarrierMovement cm1 = new CarrierMovement(cmid, HANGZOU, TOKYO);
|
|
149
|
|
- CarrierMovement cm2 = new CarrierMovement(cmid, TOKYO, NEWYORK);
|
|
150
|
|
-
|
|
151
|
|
- HandlingEvent event1 = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU, null);
|
|
152
|
|
-
|
|
153
|
|
- assertEquals(event1, cargo.nextExpectedEvent());
|
|
154
|
|
-
|
|
155
|
|
- cargo.deliveryHistory().addEvent(event1);
|
|
156
|
|
-
|
|
157
|
|
- HandlingEvent event2 = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, HANGZOU, cm1);
|
|
158
|
|
-
|
|
159
|
|
- assertEquals(event2, cargo.nextExpectedEvent());
|
|
160
|
|
-
|
|
161
|
|
- cargo.deliveryHistory().addEvent(event2);
|
|
162
|
|
- }
|
|
163
|
|
- */
|
|
164
|
|
-
|
|
165
|
|
-
|
|
166
|
147
|
// TODO: Generate test data some better way
|
|
167
|
148
|
private Cargo populateCargoReceivedStockholm() throws Exception {
|
|
168
|
149
|
final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
|
|
169
|
150
|
|
|
170
|
151
|
HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, STOCKHOLM);
|
|
171
|
152
|
events.add(he);
|
|
172
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
153
|
+ cargo.updateStatus(events);
|
|
173
|
154
|
|
|
174
|
155
|
return cargo;
|
|
175
|
156
|
}
|
|
|
@@ -178,7 +159,7 @@ public class CargoTest extends TestCase {
|
|
178
|
159
|
final Cargo cargo = populateCargoOffMelbourne();
|
|
179
|
160
|
|
|
180
|
161
|
events.add(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, MELBOURNE));
|
|
181
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
162
|
+ cargo.updateStatus(events);
|
|
182
|
163
|
|
|
183
|
164
|
return cargo;
|
|
184
|
165
|
}
|
|
|
@@ -193,7 +174,7 @@ public class CargoTest extends TestCase {
|
|
193
|
174
|
events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
194
|
175
|
events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
|
|
195
|
176
|
|
|
196
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
177
|
+ cargo.updateStatus(events);
|
|
197
|
178
|
return cargo;
|
|
198
|
179
|
}
|
|
199
|
180
|
|
|
|
@@ -204,7 +185,7 @@ public class CargoTest extends TestCase {
|
|
204
|
185
|
events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
|
|
205
|
186
|
events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
|
|
206
|
187
|
|
|
207
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
188
|
+ cargo.updateStatus(events);
|
|
208
|
189
|
return cargo;
|
|
209
|
190
|
}
|
|
210
|
191
|
|
|
|
@@ -220,7 +201,7 @@ public class CargoTest extends TestCase {
|
|
220
|
201
|
events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
|
|
221
|
202
|
events.add(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, voyage));
|
|
222
|
203
|
|
|
223
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
204
|
+ cargo.updateStatus(events);
|
|
224
|
205
|
return cargo;
|
|
225
|
206
|
}
|
|
226
|
207
|
|
|
|
@@ -235,7 +216,7 @@ public class CargoTest extends TestCase {
|
|
235
|
216
|
|
|
236
|
217
|
events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
|
|
237
|
218
|
|
|
238
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
219
|
+ cargo.updateStatus(events);
|
|
239
|
220
|
return cargo;
|
|
240
|
221
|
}
|
|
241
|
222
|
|
|
|
@@ -261,7 +242,7 @@ public class CargoTest extends TestCase {
|
|
261
|
242
|
handlingEvents.add(new HandlingEvent(cargo, new Date(130), new Date(140), HandlingEvent.Type.CUSTOMS, GOTHENBURG));
|
|
262
|
243
|
|
|
263
|
244
|
events.addAll(handlingEvents);
|
|
264
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
245
|
+ cargo.updateStatus(events);
|
|
265
|
246
|
assertFalse(cargo.isMisdirected());
|
|
266
|
247
|
|
|
267
|
248
|
//Try a couple of failing ones
|
|
|
@@ -271,7 +252,7 @@ public class CargoTest extends TestCase {
|
|
271
|
252
|
|
|
272
|
253
|
handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
|
|
273
|
254
|
events.addAll(handlingEvents);
|
|
274
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
255
|
+ cargo.updateStatus(events);
|
|
275
|
256
|
|
|
276
|
257
|
assertTrue(cargo.isMisdirected());
|
|
277
|
258
|
|
|
|
@@ -285,7 +266,7 @@ public class CargoTest extends TestCase {
|
|
285
|
266
|
handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, voyage));
|
|
286
|
267
|
|
|
287
|
268
|
events.addAll(handlingEvents);
|
|
288
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
269
|
+ cargo.updateStatus(events);
|
|
289
|
270
|
|
|
290
|
271
|
assertTrue(cargo.isMisdirected());
|
|
291
|
272
|
|
|
|
@@ -299,7 +280,7 @@ public class CargoTest extends TestCase {
|
|
299
|
280
|
handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM));
|
|
300
|
281
|
|
|
301
|
282
|
events.addAll(handlingEvents);
|
|
302
|
|
- cargo.setDeliveryHistory(new Delivery(events));
|
|
|
283
|
+ cargo.updateStatus(events);
|
|
303
|
284
|
|
|
304
|
285
|
assertTrue(cargo.isMisdirected());
|
|
305
|
286
|
}
|