Pārlūkot izejas kodu

Introduced Voyage, Schedule and VoyageNumber. CarrierMovement is now a value object, CarrierMovementId is dropped.

Leg now has load/unload location and time, and a reference to a Voyage.

HandlingEvent references a Voyage instead of a CarrierMovement.

DeliveryHistory is renamed to Delivery.

(Yes, it's very broken right now, but it compiles)
peter_backlund 18 gadus atpakaļ
vecāks
revīzija
c4a0dfb1ee

+ 65
- 88
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java Parādīt failu

@@ -2,7 +2,9 @@ package se.citerus.dddsample.domain.model.cargo;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
5
+import se.citerus.dddsample.domain.model.carrier.Schedule;
6
+import se.citerus.dddsample.domain.model.carrier.Voyage;
7
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
6 8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7 9
 import se.citerus.dddsample.domain.model.location.Location;
8 10
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
@@ -13,7 +15,19 @@ import java.text.SimpleDateFormat;
13 15
 import java.util.*;
14 16
 
15 17
 public class CargoTest extends TestCase {
18
+
16 19
   private Set<HandlingEvent> events;
20
+  private Voyage voyage;
21
+
22
+  protected void setUp() throws Exception {
23
+    events = new HashSet<HandlingEvent>();
24
+
25
+    voyage = new Voyage(new VoyageNumber("0123"), new Schedule(Arrays.asList(
26
+      new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date()),
27
+      new CarrierMovement(HAMBURG, HONGKONG, new Date(), new Date()),
28
+      new CarrierMovement(HONGKONG, MELBOURNE, new Date(), new Date())
29
+    )));
30
+  }
17 31
 
18 32
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
19 33
     Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
@@ -69,10 +83,6 @@ public class CargoTest extends TestCase {
69 83
     assertFalse("Cargos are not equal when TrackingID differ", c1.equals(c2));
70 84
   }
71 85
 
72
-  protected void setUp() throws Exception {
73
-    events = new HashSet<HandlingEvent>();
74
-  }
75
-
76 86
   public void testIsUnloadedAtFinalDestination() throws Exception {
77 87
     assertFalse(new Cargo().isUnloadedAtDestination());
78 88
 
@@ -82,27 +92,28 @@ public class CargoTest extends TestCase {
82 92
     // Adding an event unrelated to unloading at final destination
83 93
     events.add(
84 94
       new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
85
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
95
+    cargo.setDeliveryHistory(new Delivery(events));
86 96
     assertFalse(cargo.isUnloadedAtDestination());
87 97
 
88
-    CarrierMovement cm1 = new CarrierMovement(new CarrierMovementId("CM1"), HANGZOU, NEWYORK, new Date(), new Date());
98
+    CarrierMovement cm1 = new CarrierMovement(HANGZOU, NEWYORK, new Date(), new Date());
99
+    Voyage voyage = new Voyage(new VoyageNumber("0123"), new Schedule(Arrays.asList(cm1)));
89 100
 
90 101
     // Adding an unload event, but not at the final destination
91 102
     events.add(
92
-      new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, cm1));
93
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
103
+      new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, TOKYO, voyage));
104
+    cargo.setDeliveryHistory(new Delivery(events));
94 105
     assertFalse(cargo.isUnloadedAtDestination());
95 106
 
96 107
     // Adding an event in the final destination, but not unload
97 108
     events.add(
98 109
       new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CUSTOMS, NEWYORK));
99
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
110
+    cargo.setDeliveryHistory(new Delivery(events));
100 111
     assertFalse(cargo.isUnloadedAtDestination());
101 112
 
102 113
     // Finally, cargo is unloaded at final destination
103 114
     events.add(
104
-      new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, cm1));
105
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
115
+      new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, NEWYORK, voyage));
116
+    cargo.setDeliveryHistory(new Delivery(events));
106 117
     assertTrue(cargo.isUnloadedAtDestination());
107 118
   }
108 119
 
@@ -134,7 +145,7 @@ public class CargoTest extends TestCase {
134 145
 
135 146
     HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, STOCKHOLM);
136 147
     events.add(he);
137
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
148
+    cargo.setDeliveryHistory(new Delivery(events));
138 149
 
139 150
     return cargo;
140 151
   }
@@ -143,7 +154,7 @@ public class CargoTest extends TestCase {
143 154
     final Cargo cargo = populateCargoOffMelbourne();
144 155
 
145 156
     events.add(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, MELBOURNE));
146
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
157
+    cargo.setDeliveryHistory(new Delivery(events));
147 158
 
148 159
     return cargo;
149 160
   }
@@ -151,86 +162,56 @@ public class CargoTest extends TestCase {
151 162
   private Cargo populateCargoOffHongKong() throws Exception {
152 163
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
153 164
 
154
-    final CarrierMovement stockholmToHamburg = new CarrierMovement(
155
-       new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG, new Date(), new Date());
156
-
157
-    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
158
-    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
159 165
 
160
-    final CarrierMovement hamburgToHongKong = new CarrierMovement(
161
-       new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG, new Date(), new Date());
166
+    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
167
+    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
162 168
 
163
-    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
164
-    events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
169
+    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
170
+    events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
165 171
 
166
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
172
+    cargo.setDeliveryHistory(new Delivery(events));
167 173
     return cargo;
168 174
   }
169 175
 
170 176
   private Cargo populateCargoOnHamburg() throws Exception {
171 177
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
172 178
 
173
-    final CarrierMovement stockholmToHamburg = new CarrierMovement(
174
-       new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG, new Date(), new Date());
175
-
176
-    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
177
-    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
179
+    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
180
+    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
181
+    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
178 182
 
179
-    final CarrierMovement hamburgToHongKong = new CarrierMovement(
180
-       new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG, new Date(), new Date());
181
-
182
-    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
183
-
184
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
183
+    cargo.setDeliveryHistory(new Delivery(events));
185 184
     return cargo;
186 185
   }
187 186
 
188 187
   private Cargo populateCargoOffMelbourne() throws Exception {
189 188
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
190 189
 
191
-    final CarrierMovement stockholmToHamburg = new CarrierMovement(
192
-       new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG, new Date(), new Date());
193
-
194
-    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
195
-    events.add(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, voyage));
191
+    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
196 192
 
197
-    final CarrierMovement hamburgToHongKong = new CarrierMovement(
198
-       new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG, new Date(), new Date());
193
+    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
194
+    events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
199 195
 
200
-    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
201
-    events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
196
+    events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
197
+    events.add(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, voyage));
202 198
 
203
-    final CarrierMovement hongKongToMelbourne = new CarrierMovement(
204
-       new CarrierMovementId("CAR_001"), HONGKONG, MELBOURNE, new Date(), new Date());
205
-
206
-    events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, hongKongToMelbourne));
207
-    events.add(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, MELBOURNE, hongKongToMelbourne));
208
-
209
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
199
+    cargo.setDeliveryHistory(new Delivery(events));
210 200
     return cargo;
211 201
   }
212 202
 
213 203
   private Cargo populateCargoOnHongKong() throws Exception {
214 204
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
215 205
 
216
-    final CarrierMovement stockholmToHamburg = new CarrierMovement(
217
-       new CarrierMovementId("CAR_001"), STOCKHOLM, HAMBURG, new Date(), new Date());
218
-
219
-    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, stockholmToHamburg));
220
-    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, stockholmToHamburg));
206
+    events.add(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, STOCKHOLM, voyage));
207
+    events.add(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, HAMBURG, voyage));
221 208
 
222
-    final CarrierMovement hamburgToHongKong = new CarrierMovement(
223
-       new CarrierMovementId("CAR_001"), HAMBURG, HONGKONG, new Date(), new Date());
209
+    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, voyage));
210
+    events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, voyage));
224 211
 
225
-    events.add(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, HAMBURG, hamburgToHongKong));
226
-    events.add(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, hamburgToHongKong));
212
+    events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, voyage));
227 213
 
228
-    final CarrierMovement hongKongToMelbourne = new CarrierMovement(
229
-       new CarrierMovementId("CAR_001"), HONGKONG, MELBOURNE, new Date(), new Date());
230
-
231
-    events.add(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, HONGKONG, hongKongToMelbourne));
232
-
233
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
214
+    cargo.setDeliveryHistory(new Delivery(events));
234 215
     return cargo;
235 216
   }
236 217
 
@@ -246,21 +227,23 @@ public class CargoTest extends TestCase {
246 227
 
247 228
     Collection<HandlingEvent> handlingEvents = new ArrayList<HandlingEvent>();
248 229
 
230
+    /*
249 231
     CarrierMovement abc = new CarrierMovement(new CarrierMovementId("ABC"), SHANGHAI, ROTTERDAM, new Date(), new Date());
250 232
     CarrierMovement def = new CarrierMovement(new CarrierMovementId("DEF"), ROTTERDAM, GOTHENBURG, new Date(), new Date());
251 233
     CarrierMovement ghi = new CarrierMovement(new CarrierMovementId("GHI"), ROTTERDAM, NEWYORK, new Date(), new Date());
252
-
234
+    */
235
+    
253 236
     //Happy path
254 237
     handlingEvents.add(new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.RECEIVE, SHANGHAI));
255
-    handlingEvents.add(new HandlingEvent(cargo, new Date(30), new Date(40), HandlingEvent.Type.LOAD, SHANGHAI, abc));
256
-    handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, abc));
257
-    handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, def));
258
-    handlingEvents.add(new HandlingEvent(cargo, new Date(90), new Date(100), HandlingEvent.Type.UNLOAD, GOTHENBURG, def));
238
+    handlingEvents.add(new HandlingEvent(cargo, new Date(30), new Date(40), HandlingEvent.Type.LOAD, SHANGHAI, voyage));
239
+    handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, voyage));
240
+    handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, voyage));
241
+    handlingEvents.add(new HandlingEvent(cargo, new Date(90), new Date(100), HandlingEvent.Type.UNLOAD, GOTHENBURG, voyage));
259 242
     handlingEvents.add(new HandlingEvent(cargo, new Date(110), new Date(120), HandlingEvent.Type.CLAIM, GOTHENBURG));
260 243
     handlingEvents.add(new HandlingEvent(cargo, new Date(130), new Date(140), HandlingEvent.Type.CUSTOMS, GOTHENBURG));
261 244
 
262 245
     events.addAll(handlingEvents);
263
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
246
+    cargo.setDeliveryHistory(new Delivery(events));
264 247
     assertFalse(cargo.isMisdirected());
265 248
 
266 249
     //Try a couple of failing ones
@@ -270,9 +253,8 @@ public class CargoTest extends TestCase {
270 253
 
271 254
     handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, HANGZOU));
272 255
     events.addAll(handlingEvents);
273
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
256
+    cargo.setDeliveryHistory(new Delivery(events));
274 257
 
275
-    cargo.updateState();
276 258
     assertTrue(cargo.isMisdirected());
277 259
 
278 260
 
@@ -280,14 +262,13 @@ public class CargoTest extends TestCase {
280 262
     handlingEvents = new ArrayList<HandlingEvent>();
281 263
 
282 264
     handlingEvents.add(new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.RECEIVE, SHANGHAI));
283
-    handlingEvents.add(new HandlingEvent(cargo, new Date(30), new Date(40), HandlingEvent.Type.LOAD, SHANGHAI, abc));
284
-    handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, abc));
285
-    handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, ghi));
265
+    handlingEvents.add(new HandlingEvent(cargo, new Date(30), new Date(40), HandlingEvent.Type.LOAD, SHANGHAI, voyage));
266
+    handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, voyage));
267
+    handlingEvents.add(new HandlingEvent(cargo, new Date(70), new Date(80), HandlingEvent.Type.LOAD, ROTTERDAM, voyage));
286 268
 
287 269
     events.addAll(handlingEvents);
288
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
270
+    cargo.setDeliveryHistory(new Delivery(events));
289 271
 
290
-    cargo.updateState();
291 272
     assertTrue(cargo.isMisdirected());
292 273
 
293 274
 
@@ -295,27 +276,23 @@ public class CargoTest extends TestCase {
295 276
     handlingEvents = new ArrayList<HandlingEvent>();
296 277
 
297 278
     handlingEvents.add(new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.RECEIVE, SHANGHAI));
298
-    handlingEvents.add(new HandlingEvent(cargo, new Date(30), new Date(40), HandlingEvent.Type.LOAD, SHANGHAI, abc));
299
-    handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, abc));
279
+    handlingEvents.add(new HandlingEvent(cargo, new Date(30), new Date(40), HandlingEvent.Type.LOAD, SHANGHAI, voyage));
280
+    handlingEvents.add(new HandlingEvent(cargo, new Date(50), new Date(60), HandlingEvent.Type.UNLOAD, ROTTERDAM, voyage));
300 281
     handlingEvents.add(new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM));
301 282
 
302 283
     events.addAll(handlingEvents);
303
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
284
+    cargo.setDeliveryHistory(new Delivery(events));
304 285
 
305
-    cargo.updateState();
306 286
     assertTrue(cargo.isMisdirected());
307 287
   }
308 288
 
309 289
   private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination) {
310 290
     Cargo cargo = new Cargo(new TrackingId("CARGO1"), origin, destination);
311 291
 
312
-    CarrierMovement cm = new CarrierMovement(
313
-      new CarrierMovementId("ABC"), origin, destination, new Date(), new Date());
314
-    
315 292
     Itinerary itinerary = new Itinerary(
316 293
       Arrays.asList(
317
-        new Leg(cm, origin, midpoint),
318
-        new Leg(cm, midpoint, destination)
294
+        new Leg(voyage, origin, midpoint, new Date(), new Date()),
295
+        new Leg(voyage, midpoint, destination, new Date(), new Date())
319 296
       )
320 297
     );
321 298
 

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTestHelper.java Parādīt failu

@@ -22,7 +22,7 @@ public class CargoTestHelper {
22 22
   }
23 23
 
24 24
   public static void setDeliveryHistory(Cargo cargo, Collection<HandlingEvent> events) {
25
-    cargo.setDeliveryHistory(new DeliveryHistory(events));
25
+    cargo.setDeliveryHistory(new Delivery(events));
26 26
   }
27 27
   
28 28
 }

+ 23
- 13
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java Parādīt failu

@@ -2,7 +2,9 @@ package se.citerus.dddsample.domain.model.cargo;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
5
+import se.citerus.dddsample.domain.model.carrier.Schedule;
6
+import se.citerus.dddsample.domain.model.carrier.Voyage;
7
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
6 8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7 9
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
8 10
 
@@ -12,10 +14,18 @@ import java.util.Date;
12 14
 import java.util.List;
13 15
 
14 16
 public class ItineraryTest extends TestCase {
15
-  private final CarrierMovement abc = new CarrierMovement(new CarrierMovementId("ABC"), SHANGHAI, ROTTERDAM, new Date(), new Date());
16
-  private final CarrierMovement def = new CarrierMovement(new CarrierMovementId("DEF"), ROTTERDAM, GOTHENBURG, new Date(), new Date());
17
-  private final CarrierMovement ghi = new CarrierMovement(new CarrierMovementId("GHI"), ROTTERDAM, NEWYORK, new Date(), new Date());
18
-  private final CarrierMovement jkl = new CarrierMovement(new CarrierMovementId("JKL"), SHANGHAI, HELSINKI, new Date(), new Date());
17
+  private final CarrierMovement abc = new CarrierMovement(SHANGHAI, ROTTERDAM, new Date(), new Date());
18
+  private final CarrierMovement def = new CarrierMovement(ROTTERDAM, GOTHENBURG, new Date(), new Date());
19
+  private final CarrierMovement ghi = new CarrierMovement(ROTTERDAM, NEWYORK, new Date(), new Date());
20
+  private final CarrierMovement jkl = new CarrierMovement(SHANGHAI, HELSINKI, new Date(), new Date());
21
+
22
+  Voyage voyage;
23
+
24
+  protected void setUp() throws Exception {
25
+    voyage = new Voyage(new VoyageNumber("0123"), new Schedule(Arrays.asList(
26
+      abc, def, ghi, jkl
27
+    )));
28
+  }
19 29
 
20 30
   public void testCargoOnTrack() throws Exception {
21 31
 
@@ -23,8 +33,8 @@ public class ItineraryTest extends TestCase {
23 33
 
24 34
     Itinerary itinerary = new Itinerary(
25 35
       Arrays.asList(
26
-        new Leg(new CarrierMovement(new CarrierMovementId("ABC"), SHANGHAI, ROTTERDAM, new Date(), new Date()), SHANGHAI, ROTTERDAM),
27
-        new Leg(new CarrierMovement(new CarrierMovementId("DEF"), ROTTERDAM, GOTHENBURG, new Date(), new Date()), ROTTERDAM, GOTHENBURG)
36
+        new Leg(voyage, SHANGHAI, ROTTERDAM, new Date(), new Date()),
37
+        new Leg(voyage, ROTTERDAM, GOTHENBURG, new Date(), new Date())
28 38
       )
29 39
     );
30 40
 
@@ -32,16 +42,16 @@ public class ItineraryTest extends TestCase {
32 42
     HandlingEvent event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, SHANGHAI);
33 43
     assertTrue(itinerary.isExpected(event));
34 44
 
35
-    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SHANGHAI, abc);
45
+    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
36 46
     assertTrue(itinerary.isExpected(event));
37 47
 
38
-    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, ROTTERDAM, abc);
48
+    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, ROTTERDAM, voyage);
39 49
     assertTrue(itinerary.isExpected(event));
40 50
 
41
-    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, def);
51
+    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, voyage);
42 52
     assertTrue(itinerary.isExpected(event));
43 53
 
44
-    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, GOTHENBURG, def);
54
+    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, GOTHENBURG, voyage);
45 55
     assertTrue(itinerary.isExpected(event));
46 56
 
47 57
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, GOTHENBURG);
@@ -56,11 +66,11 @@ public class ItineraryTest extends TestCase {
56 66
     assertFalse(itinerary.isExpected(event));
57 67
 
58 68
     //Loaded to onto the wrong ship, correct location
59
-    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, ghi);
69
+    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.LOAD, ROTTERDAM, voyage);
60 70
     assertFalse(itinerary.isExpected(event));
61 71
 
62 72
     //Unloaded from the wrong ship in the wrong location
63
-    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, HELSINKI, jkl);
73
+    event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.UNLOAD, HELSINKI, voyage);
64 74
     assertFalse(itinerary.isExpected(event));
65 75
 
66 76
     event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, ROTTERDAM);

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/LegTest.java Parādīt failu

@@ -6,7 +6,7 @@ public class LegTest extends TestCase {
6 6
 
7 7
   public void testConstructor() throws Exception {
8 8
     try {
9
-      new Leg(null,null,null);
9
+      new Leg(null,null,null,null,null);
10 10
       fail("Should not accept null constructor arguments");
11 11
     } catch (IllegalArgumentException expected) {}
12 12
   }

+ 0
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/RouteSpecificationTest.java Parādīt failu

@@ -15,7 +15,6 @@ public class RouteSpecificationTest extends TestCase {
15 15
   }
16 16
 
17 17
   public void testIsSatisfiedBySuccess() {
18
-    // TODO
19 18
     RouteSpecification spec = RouteSpecification.forCargo(cargo, new Date());
20 19
     Itinerary itinerary = new Itinerary();
21 20
     assertTrue(spec.isSatisfiedBy(itinerary));

+ 12
- 18
dddsample/src/test/java/se/citerus/dddsample/domain/model/carrier/CarrierMovementTest.java Parādīt failu

@@ -9,40 +9,34 @@ import java.util.Date;
9 9
 public class CarrierMovementTest extends TestCase {
10 10
 
11 11
   public void testConstructor() throws Exception {
12
-    CarrierMovementId id = new CarrierMovementId("CAR001");
13
-
14 12
     try {
15
-      new CarrierMovement(null, null, null, new Date(), new Date());
13
+      new CarrierMovement(null, null, new Date(), new Date());
16 14
       fail("Should not accept null constructor arguments");
17 15
     } catch (IllegalArgumentException expected) {}
18 16
 
19 17
     try {
20
-      new CarrierMovement(id, null, null, new Date(), new Date());
18
+      new CarrierMovement(null, null, new Date(), new Date());
21 19
       fail("Should not accept null constructor arguments");
22 20
     } catch (IllegalArgumentException expected) {}
23 21
 
24 22
     try {
25
-      new CarrierMovement(id, STOCKHOLM, null, new Date(), new Date());
23
+      new CarrierMovement(STOCKHOLM, null, new Date(), new Date());
26 24
       fail("Should not accept null constructor arguments");
27 25
     } catch (IllegalArgumentException expected) {}
28 26
 
29 27
     // Legal
30
-    new CarrierMovement(id, STOCKHOLM, HAMBURG, new Date(), new Date());
28
+    new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date());
31 29
   }
32 30
 
33 31
   public void testSameValueAsEqualsHashCode() throws Exception {
34
-    CarrierMovementId id1 = new CarrierMovementId("CAR1");
35
-    CarrierMovementId id2a = new CarrierMovementId("CAR2");
36
-    CarrierMovementId id2b = new CarrierMovementId("CAR2");
37
-
38
-    CarrierMovement cm1 = new CarrierMovement(id1, STOCKHOLM, HAMBURG, new Date(), new Date());
39
-    CarrierMovement cm2 = new CarrierMovement(id1, STOCKHOLM, HAMBURG, new Date(), new Date());
40
-    CarrierMovement cm3 = new CarrierMovement(id2a, HAMBURG, STOCKHOLM, new Date(), new Date());
41
-    CarrierMovement cm4 = new CarrierMovement(id2b, HAMBURG, STOCKHOLM, new Date(), new Date());
42
-
43
-    assertTrue(cm1.sameIdentityAs(cm2));
44
-    assertFalse(cm2.sameIdentityAs(cm3));
45
-    assertTrue(cm3.sameIdentityAs(cm4));
32
+    CarrierMovement cm1 = new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date());
33
+    CarrierMovement cm2 = new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date());
34
+    CarrierMovement cm3 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
35
+    CarrierMovement cm4 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
36
+
37
+    assertTrue(cm1.sameValueAs(cm2));
38
+    assertFalse(cm2.sameValueAs(cm3));
39
+    assertTrue(cm3.sameValueAs(cm4));
46 40
     
47 41
     assertTrue(cm1.equals(cm2));
48 42
     assertFalse(cm2.equals(cm3));

+ 0
- 50
dddsample/src/test/java/se/citerus/dddsample/domain/model/carrier/SampleCarrierMovements.java Parādīt failu

@@ -1,50 +0,0 @@
1
-package se.citerus.dddsample.domain.model.carrier;
2
-
3
-import se.citerus.dddsample.domain.model.location.Location;
4
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
5
-
6
-import java.lang.reflect.Field;
7
-import java.util.*;
8
-
9
-/**
10
- * Sample carrier movements, for test purposes.
11
- *
12
- */
13
-public class SampleCarrierMovements {
14
-
15
-  public static final CarrierMovement CM001 = createCarrierMovement("CM001", STOCKHOLM, HAMBURG);
16
-  public static final CarrierMovement CM002 = createCarrierMovement("CM002", HAMBURG, HONGKONG);
17
-  public static final CarrierMovement CM003 = createCarrierMovement("CM003", HONGKONG, NEWYORK);
18
-  public static final CarrierMovement CM004 = createCarrierMovement("CM004", NEWYORK, CHICAGO);
19
-  public static final CarrierMovement CM005 = createCarrierMovement("CM005", CHICAGO, HAMBURG);
20
-  public static final CarrierMovement CM006 = createCarrierMovement("CM006", HAMBURG, HANGZOU);
21
-
22
-  private static CarrierMovement createCarrierMovement(String id, Location from, Location to) {
23
-    return new CarrierMovement(
24
-      new CarrierMovementId(id), from, to,  new Date(), new Date());
25
-  }
26
-
27
-  public static final Map<CarrierMovementId, CarrierMovement> ALL = new HashMap();
28
-
29
-  static {
30
-    for (Field field : SampleCarrierMovements.class.getDeclaredFields()) {
31
-      if (field.getType().equals(CarrierMovement.class)) {
32
-        try {
33
-          CarrierMovement carrierMovement = (CarrierMovement) field.get(null);
34
-          ALL.put(carrierMovement.carrierMovementId(), carrierMovement);
35
-        } catch (IllegalAccessException e) {
36
-          throw new RuntimeException(e);
37
-        }
38
-      }
39
-    }
40
-  }
41
-
42
-  public static List<CarrierMovement> getAll() {
43
-    return new ArrayList(ALL.values());
44
-  }
45
-
46
-  public static CarrierMovement lookup(CarrierMovementId carrierMovementId) {
47
-    return ALL.get(carrierMovementId);
48
-  }
49
-  
50
-}

+ 51
- 0
dddsample/src/test/java/se/citerus/dddsample/domain/model/carrier/SampleVoyages.java Parādīt failu

@@ -0,0 +1,51 @@
1
+package se.citerus.dddsample.domain.model.carrier;
2
+
3
+import se.citerus.dddsample.domain.model.location.Location;
4
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
5
+
6
+import java.lang.reflect.Field;
7
+import java.util.*;
8
+
9
+/**
10
+ * Sample carrier movements, for test purposes.
11
+ *
12
+ */
13
+public class SampleVoyages {
14
+
15
+  public static final Voyage CM001 = createVoyage("CM001", STOCKHOLM, HAMBURG);
16
+  public static final Voyage CM002 = createVoyage("CM002", HAMBURG, HONGKONG);
17
+  public static final Voyage CM003 = createVoyage("CM003", HONGKONG, NEWYORK);
18
+  public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
19
+  public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
20
+  public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
21
+
22
+  private static Voyage createVoyage(String id, Location from, Location to) {
23
+    return new Voyage(new VoyageNumber(id), new Schedule(Arrays.asList(
24
+      new CarrierMovement(from, to, new Date(), new Date())
25
+    )));
26
+  }
27
+
28
+  public static final Map<VoyageNumber, Voyage> ALL = new HashMap();
29
+
30
+  static {
31
+    for (Field field : SampleVoyages.class.getDeclaredFields()) {
32
+      if (field.getType().equals(Voyage.class)) {
33
+        try {
34
+          Voyage voyage = (Voyage) field.get(null);
35
+          ALL.put(voyage.voyageNumber(), voyage);
36
+        } catch (IllegalAccessException e) {
37
+          throw new RuntimeException(e);
38
+        }
39
+      }
40
+    }
41
+  }
42
+
43
+  public static List<Voyage> getAll() {
44
+    return new ArrayList(ALL.values());
45
+  }
46
+
47
+  public static Voyage lookup(VoyageNumber voyageNumber) {
48
+    return ALL.get(voyageNumber);
49
+  }
50
+  
51
+}

+ 21
- 21
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java Parādīt failu

@@ -2,22 +2,22 @@ package se.citerus.dddsample.domain.model.handling;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import static org.easymock.EasyMock.*;
5
-import se.citerus.dddsample.application.persistence.CarrierMovementRepositoryInMem;
6 5
 import se.citerus.dddsample.application.persistence.LocationRepositoryInMem;
6
+import se.citerus.dddsample.application.persistence.VoyageRepositoryInMem;
7 7
 import se.citerus.dddsample.domain.model.cargo.Cargo;
8 8
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
9 9
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
10
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
11
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
12
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
13
-import static se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements.CM001;
10
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM001;
11
+import se.citerus.dddsample.domain.model.carrier.Voyage;
12
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
13
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
14 14
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type;
15 15
 import se.citerus.dddsample.domain.model.location.LocationRepository;
16 16
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
17 17
 import se.citerus.dddsample.domain.model.location.UnLocode;
18
-import se.citerus.dddsample.domain.service.UnknownCarrierMovementIdException;
18
+import se.citerus.dddsample.domain.service.UnknownCargoException;
19 19
 import se.citerus.dddsample.domain.service.UnknownLocationException;
20
-import se.citerus.dddsample.domain.service.UnknownTrackingIdException;
20
+import se.citerus.dddsample.domain.service.UnknownVoyageException;
21 21
 
22 22
 import java.util.Date;
23 23
 
@@ -25,7 +25,7 @@ public class HandlingEventFactoryTest extends TestCase {
25 25
 
26 26
   HandlingEventFactory factory;
27 27
   CargoRepository cargoRepository;
28
-  CarrierMovementRepository carrierMovementRepository;
28
+  VoyageRepository voyageRepository;
29 29
   LocationRepository locationRepository;
30 30
   TrackingId trackingId;
31 31
   Cargo cargo;
@@ -33,9 +33,9 @@ public class HandlingEventFactoryTest extends TestCase {
33 33
   protected void setUp() throws Exception {
34 34
 
35 35
     cargoRepository = createMock(CargoRepository.class);
36
-    carrierMovementRepository = new CarrierMovementRepositoryInMem();
36
+    voyageRepository = new VoyageRepositoryInMem();
37 37
     locationRepository = new LocationRepositoryInMem();
38
-    factory = new HandlingEventFactory(cargoRepository, carrierMovementRepository, locationRepository);
38
+    factory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
39 39
 
40 40
 
41 41
 
@@ -48,15 +48,15 @@ public class HandlingEventFactoryTest extends TestCase {
48 48
 
49 49
     replay(cargoRepository);
50 50
 
51
-    CarrierMovementId carrierMovementId = CM001.carrierMovementId();
51
+    VoyageNumber voyageNumber = CM001.voyageNumber();
52 52
     UnLocode unLocode = STOCKHOLM.unLocode();
53 53
     HandlingEvent handlingEvent = factory.createHandlingEvent(
54
-      new Date(100), trackingId, carrierMovementId, unLocode, Type.LOAD
54
+      new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD
55 55
     );
56 56
 
57 57
     assertNotNull(handlingEvent);
58 58
     assertEquals(STOCKHOLM, handlingEvent.location());
59
-    assertEquals(CM001, handlingEvent.carrierMovement());
59
+    assertEquals(CM001, handlingEvent.voyage());
60 60
     assertEquals(cargo, handlingEvent.cargo());
61 61
     assertEquals(new Date(100), handlingEvent.completionTime());
62 62
     assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
@@ -74,7 +74,7 @@ public class HandlingEventFactoryTest extends TestCase {
74 74
 
75 75
     assertNotNull(handlingEvent);
76 76
     assertEquals(STOCKHOLM, handlingEvent.location());
77
-    assertEquals(CarrierMovement.NONE, handlingEvent.carrierMovement());
77
+    assertEquals(Voyage.NONE, handlingEvent.voyage());
78 78
     assertEquals(cargo, handlingEvent.cargo());
79 79
     assertEquals(new Date(100), handlingEvent.completionTime());
80 80
     assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
@@ -88,7 +88,7 @@ public class HandlingEventFactoryTest extends TestCase {
88 88
     UnLocode invalid = new UnLocode("NOEXT");
89 89
     try {
90 90
       factory.createHandlingEvent(
91
-        new Date(100), trackingId, CM001.carrierMovementId(), invalid, Type.LOAD
91
+        new Date(100), trackingId, CM001.voyageNumber(), invalid, Type.LOAD
92 92
       );
93 93
       fail("Expected UnknownLocationException");
94 94
     } catch (UnknownLocationException expected) {}
@@ -100,12 +100,12 @@ public class HandlingEventFactoryTest extends TestCase {
100 100
     replay(cargoRepository);
101 101
 
102 102
     try {
103
-      CarrierMovementId invalid = new CarrierMovementId("XXX");
103
+      VoyageNumber invalid = new VoyageNumber("XXX");
104 104
       factory.createHandlingEvent(
105 105
         new Date(100), trackingId, invalid, STOCKHOLM.unLocode(), Type.LOAD
106 106
       );
107
-      fail("Expected UnknownCarrierMovementIdException");
108
-    } catch (UnknownCarrierMovementIdException expected) {}
107
+      fail("Expected UnknownVoyageException");
108
+    } catch (UnknownVoyageException expected) {}
109 109
   }
110 110
 
111 111
   public void testCreateHandlingEventUnknownTrackingId() throws Exception {
@@ -115,10 +115,10 @@ public class HandlingEventFactoryTest extends TestCase {
115 115
 
116 116
     try {
117 117
       factory.createHandlingEvent(
118
-        new Date(100), trackingId, CM001.carrierMovementId(), STOCKHOLM.unLocode(), Type.LOAD
118
+        new Date(100), trackingId, CM001.voyageNumber(), STOCKHOLM.unLocode(), Type.LOAD
119 119
       );
120
-      fail("Expected UnknownTrackingIdException");
121
-    } catch (UnknownTrackingIdException expected) {}
120
+      fail("Expected UnknownCargoException");
121
+    } catch (UnknownCargoException expected) {}
122 122
   }
123 123
 
124 124
   protected void tearDown() throws Exception {

+ 5
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java Parādīt failu

@@ -3,9 +3,9 @@ package se.citerus.dddsample.domain.model.handling;
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
5 5
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
6
-import se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements;
7
-import static se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements.CM003;
8
-import static se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements.CM004;
6
+import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
7
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM003;
8
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM004;
9 9
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
10 10
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
11 11
 
@@ -89,8 +89,8 @@ public class HandlingEventTest extends TestCase {
89 89
     Date timeOccured = new Date();
90 90
     Date timeRegistered = new Date();
91 91
 
92
-    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleCarrierMovements.CM005);
93
-    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleCarrierMovements.CM005);
92
+    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
93
+    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
94 94
 
95 95
     // Two handling events are not equal() even if all non-uuid fields are identical
96 96
     assertTrue(ev1.equals(ev2));

+ 20
- 20
dddsample/src/test/java/se/citerus/dddsample/domain/service/HandlingEventServiceTest.java Parādīt failu

@@ -5,9 +5,9 @@ import static org.easymock.EasyMock.*;
5 5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
6 6
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
7 7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
9
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
10
-import se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements;
8
+import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
9
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
10
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
11 11
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
12 12
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
13 13
 import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
@@ -22,7 +22,7 @@ public class HandlingEventServiceTest extends TestCase {
22 22
   private HandlingEventServiceImpl service;
23 23
   private DomainEventNotifier domainEventNotifier;
24 24
   private CargoRepository cargoRepository;
25
-  private CarrierMovementRepository carrierMovementRepository;
25
+  private VoyageRepository voyageRepository;
26 26
   private HandlingEventRepository handlingEventRepository;
27 27
   private LocationRepository locationRepository;
28 28
   private HandlingEventFactory handlingEventFactory;
@@ -33,16 +33,16 @@ public class HandlingEventServiceTest extends TestCase {
33 33
 
34 34
   protected void setUp() throws Exception{
35 35
     cargoRepository = createMock(CargoRepository.class);
36
-    carrierMovementRepository = createMock(CarrierMovementRepository.class);
36
+    voyageRepository = createMock(VoyageRepository.class);
37 37
     handlingEventRepository = createMock(HandlingEventRepository.class);
38 38
     locationRepository = createMock(LocationRepository.class);
39 39
     domainEventNotifier = createMock(DomainEventNotifier.class);
40 40
     service = new HandlingEventServiceImpl(handlingEventRepository, domainEventNotifier);
41
-    handlingEventFactory = new HandlingEventFactory(cargoRepository, carrierMovementRepository, locationRepository);
41
+    handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
42 42
   }
43 43
 
44 44
   protected void tearDown() throws Exception {
45
-    verify(cargoRepository, carrierMovementRepository, handlingEventRepository, domainEventNotifier);
45
+    verify(cargoRepository, voyageRepository, handlingEventRepository, domainEventNotifier);
46 46
   }
47 47
 
48 48
   public void testRegisterEvent() throws Exception {
@@ -51,8 +51,8 @@ public class HandlingEventServiceTest extends TestCase {
51 51
     final TrackingId trackingId = new TrackingId("ABC");
52 52
     expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
53 53
 
54
-    final CarrierMovementId carrierMovementId = new CarrierMovementId("AAA_BBB");
55
-    expect(carrierMovementRepository.find(carrierMovementId)).andReturn(SampleCarrierMovements.CM001);
54
+    final VoyageNumber voyageNumber = new VoyageNumber("AAA_BBB");
55
+    expect(voyageRepository.find(voyageNumber)).andReturn(SampleVoyages.CM001);
56 56
 
57 57
     final UnLocode unLocode = new UnLocode("SESTO");
58 58
     expect(locationRepository.find(unLocode)).andReturn(STOCKHOLM);
@@ -61,9 +61,9 @@ public class HandlingEventServiceTest extends TestCase {
61 61
     handlingEventRepository.save(isA(HandlingEvent.class));
62 62
     domainEventNotifier.cargoWasHandled(isA(HandlingEvent.class));
63 63
 
64
-    replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository, domainEventNotifier);
64
+    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
65 65
 
66
-    final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, carrierMovementId, unLocode, HandlingEvent.Type.LOAD);
66
+    final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, voyageNumber, unLocode, HandlingEvent.Type.LOAD);
67 67
     service.register(event);
68 68
   }
69 69
 
@@ -78,7 +78,7 @@ public class HandlingEventServiceTest extends TestCase {
78 78
 
79 79
     expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
80 80
 
81
-    replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository, domainEventNotifier);
81
+    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
82 82
 
83 83
     final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, null, STOCKHOLM.unLocode(), HandlingEvent.Type.CLAIM);
84 84
     service.register(event);
@@ -88,21 +88,21 @@ public class HandlingEventServiceTest extends TestCase {
88 88
   public void testRegisterEventInvalidCarrier() throws Exception {
89 89
     final Date date = new Date();
90 90
 
91
-    final CarrierMovementId carrierMovementId = new CarrierMovementId("AAA_BBB");
92
-    expect(carrierMovementRepository.find(carrierMovementId)).andReturn(null);
91
+    final VoyageNumber voyageNumber = new VoyageNumber("AAA_BBB");
92
+    expect(voyageRepository.find(voyageNumber)).andReturn(null);
93 93
 
94 94
     final TrackingId trackingId = new TrackingId("XYZ");
95 95
     expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, CHICAGO, STOCKHOLM));
96 96
 
97 97
     expect(locationRepository.find(MELBOURNE.unLocode())).andReturn(MELBOURNE);
98 98
     
99
-    replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository, domainEventNotifier);
99
+    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
100 100
     
101 101
     try {
102
-      final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, carrierMovementId, MELBOURNE.unLocode(), HandlingEvent.Type.UNLOAD);
102
+      final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, voyageNumber, MELBOURNE.unLocode(), HandlingEvent.Type.UNLOAD);
103 103
       service.register(event);
104 104
       fail("Should not be able to register an event with non-existing carrier movement");
105
-    } catch (UnknownCarrierMovementIdException expected) {}
105
+    } catch (UnknownVoyageException expected) {}
106 106
   }
107 107
   
108 108
   public void testRegisterEventInvalidCargo() throws Exception {
@@ -113,13 +113,13 @@ public class HandlingEventServiceTest extends TestCase {
113 113
 
114 114
     expect(locationRepository.find(HONGKONG.unLocode())).andReturn(HONGKONG);
115 115
     
116
-    replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository, domainEventNotifier);
116
+    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
117 117
     
118 118
     try {
119 119
       final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.CLAIM);
120 120
       service.register(event);
121 121
       fail("Should not be able to register an event with non-existing cargo");
122
-    } catch (UnknownTrackingIdException expected) {}
122
+    } catch (UnknownCargoException expected) {}
123 123
   }
124 124
   
125 125
   public void testRegisterEventInvalidLocation() throws Exception {
@@ -130,7 +130,7 @@ public class HandlingEventServiceTest extends TestCase {
130 130
     UnLocode wayOff = new UnLocode("XXYYY");
131 131
     expect(locationRepository.find(wayOff)).andReturn(null);
132 132
     
133
-    replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository, domainEventNotifier);
133
+    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
134 134
     
135 135
     try {
136 136
       final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, null, wayOff, HandlingEvent.Type.CLAIM);

+ 12
- 13
dddsample/src/test/java/se/citerus/dddsample/domain/service/RoutingServiceTest.java Parādīt failu

@@ -5,9 +5,9 @@ import static org.easymock.EasyMock.*;
5 5
 import se.citerus.dddsample.application.persistence.LocationRepositoryInMem;
6 6
 import se.citerus.dddsample.application.routing.ExternalRoutingService;
7 7
 import se.citerus.dddsample.domain.model.cargo.*;
8
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
9
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
10
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
8
+import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
9
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
10
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
11 11
 import se.citerus.dddsample.domain.model.location.Location;
12 12
 import se.citerus.dddsample.domain.model.location.LocationRepository;
13 13
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
@@ -23,15 +23,15 @@ import java.util.List;
23 23
 public class RoutingServiceTest extends TestCase {
24 24
 
25 25
   private ExternalRoutingService routingService;
26
-  private CarrierMovementRepository carrierMovementRepository;
26
+  private VoyageRepository voyageRepository;
27 27
 
28 28
   protected void setUp() throws Exception {
29 29
     routingService = new ExternalRoutingService();
30 30
     LocationRepository locationRepository = new LocationRepositoryInMem();
31 31
     routingService.setLocationRepository(locationRepository);
32 32
 
33
-    carrierMovementRepository = createMock(CarrierMovementRepository.class);
34
-    routingService.setCarrierMovementRepository(carrierMovementRepository);
33
+    voyageRepository = createMock(VoyageRepository.class);
34
+    routingService.setCarrierMovementRepository(voyageRepository);
35 35
 
36 36
     GraphTraversalService graphTraversalService = new GraphTraversalServiceImpl(new GraphDAO(createMock(DataSource.class)) {
37 37
       public List<String> listLocations() {
@@ -49,10 +49,9 @@ public class RoutingServiceTest extends TestCase {
49 49
     Cargo cargo = new Cargo(trackingId, HONGKONG, HELSINKI);
50 50
     RouteSpecification routeSpecification = RouteSpecification.forCargo(cargo, new Date());
51 51
 
52
-    expect(carrierMovementRepository.find(isA(CarrierMovementId.class))).
53
-      andStubReturn(new CarrierMovement(new CarrierMovementId("CM"), CHICAGO, HAMBURG, new Date(), new Date()));
52
+    expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
54 53
     
55
-    replay(carrierMovementRepository);
54
+    replay(voyageRepository);
56 55
 
57 56
     List<Itinerary> candidates = routingService.fetchRoutesForSpecification(routeSpecification);
58 57
     assertNotNull(candidates);
@@ -63,19 +62,19 @@ public class RoutingServiceTest extends TestCase {
63 62
       assertFalse(legs.isEmpty());
64 63
 
65 64
       // Cargo origin and start of first leg should match
66
-      assertEquals(cargo.origin(), legs.get(0).from());
65
+      assertEquals(cargo.origin(), legs.get(0).loadLocation());
67 66
 
68 67
       // Cargo final destination and last leg stop should match
69
-      Location lastLegStop = legs.get(legs.size() - 1).to();
68
+      Location lastLegStop = legs.get(legs.size() - 1).unloadLocation();
70 69
       assertEquals(cargo.destination(), lastLegStop);
71 70
 
72 71
       for (int i = 0; i < legs.size() - 1; i++) {
73 72
         // Assert that all legs are conencted
74
-        assertEquals(legs.get(i).to(), legs.get(i + 1).from());
73
+        assertEquals(legs.get(i).unloadLocation(), legs.get(i + 1).loadLocation());
75 74
       }
76 75
     }
77 76
 
78
-    verify(carrierMovementRepository);
77
+    verify(voyageRepository);
79 78
   }
80 79
 
81 80
 }

+ 6
- 6
dddsample/src/test/java/se/citerus/dddsample/domain/service/TrackingScenarioTest.java Parādīt failu

@@ -3,10 +3,10 @@ package se.citerus.dddsample.domain.service;
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
5 5
 import se.citerus.dddsample.domain.model.cargo.CargoTestHelper;
6
-import se.citerus.dddsample.domain.model.cargo.DeliveryHistory;
6
+import se.citerus.dddsample.domain.model.cargo.Delivery;
7 7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import static se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements.CM001;
9
-import static se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements.CM002;
8
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM001;
9
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM002;
10 10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
11 11
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
12 12
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.UNLOAD;
@@ -25,12 +25,12 @@ public class TrackingScenarioTest extends TestCase {
25 25
 
26 26
     Cargo cargo = populateCargo();
27 27
 
28
-    DeliveryHistory deliveryHistory = cargo.deliveryHistory();
28
+    Delivery delivery = cargo.deliveryHistory();
29 29
 
30
-    List<HandlingEvent> handlingEvents = deliveryHistory.eventsOrderedByCompletionTime();
30
+    List<HandlingEvent> handlingEvents = delivery.history();
31 31
 
32 32
     assertEquals(4, handlingEvents.size());
33
-    final HandlingEvent event = deliveryHistory.lastEvent();
33
+    final HandlingEvent event = delivery.lastEvent();
34 34
 
35 35
     assertEquals(UNLOAD, event.type());
36 36
 

+ 9
- 7
dddsample/src/test/java/se/citerus/dddsample/domain/service/TrackingServiceTest.java Parādīt failu

@@ -6,8 +6,7 @@ import se.citerus.dddsample.domain.model.cargo.Cargo;
6 6
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
7 7
 import se.citerus.dddsample.domain.model.cargo.CargoTestHelper;
8 8
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
9
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
10
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
9
+import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
11 10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
12 11
 import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
13 12
 import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
@@ -22,19 +21,22 @@ public class TrackingServiceTest extends TestCase {
22 21
 
23 22
   TrackingServiceImpl cargoService;
24 23
   CargoRepository cargoRepository;
24
+  DomainEventNotifier domainEventNotifier;
25 25
 
26 26
   protected void setUp() throws Exception {
27 27
     cargoRepository = createMock(CargoRepository.class);
28
-    cargoService = new TrackingServiceImpl(cargoRepository);
28
+    domainEventNotifier = createMock(DomainEventNotifier.class);
29
+    cargoService = new TrackingServiceImpl(domainEventNotifier, cargoRepository);
29 30
   }
30 31
 
31 32
   public void testTrackingScenario() {
32 33
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, CHICAGO);
33 34
 
34 35
     HandlingEvent claimed = new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.CLAIM, STOCKHOLM);
35
-    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), STOCKHOLM, CHICAGO, new Date(), new Date());
36
-    HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, STOCKHOLM, carrierMovement);
37
-    HandlingEvent unloaded = new HandlingEvent(cargo, new Date(100), new Date(110), HandlingEvent.Type.UNLOAD, CHICAGO, carrierMovement);
36
+
37
+    HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, STOCKHOLM, SampleVoyages.CM001);
38
+    HandlingEvent unloaded = new HandlingEvent(cargo, new Date(100), new Date(110), HandlingEvent.Type.UNLOAD, CHICAGO, SampleVoyages.CM002);
39
+
38 40
     // Add out of order to verify ordering in DTO
39 41
     List<HandlingEvent> eventList = Arrays.asList(loaded, unloaded, claimed);
40 42
 
@@ -50,7 +52,7 @@ public class TrackingServiceTest extends TestCase {
50 52
 
51 53
     assertEquals(cargo, trackedCargo);
52 54
 
53
-    List<HandlingEvent> events = trackedCargo.deliveryHistory().eventsOrderedByCompletionTime();
55
+    List<HandlingEvent> events = trackedCargo.deliveryHistory().history();
54 56
     assertEquals(3, events.size());
55 57
 
56 58
     // Claim happened first