Parcourir la source

Made CargoLifecycleScenarioTest use explicit dates.

Improved voyages in scenario test.

Improved toString of HandlingEvent.
peter_backlund il y a 17 ans
Parent
révision
f128558146

+ 12
- 3
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEvent.java Voir le fichier

@@ -3,8 +3,6 @@ package se.citerus.dddsample.domain.model.handling;
3 3
 import org.apache.commons.lang.Validate;
4 4
 import org.apache.commons.lang.builder.EqualsBuilder;
5 5
 import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import org.apache.commons.lang.builder.ToStringBuilder;
7
-import org.apache.commons.lang.builder.ToStringStyle;
8 6
 import se.citerus.dddsample.domain.model.cargo.Cargo;
9 7
 import se.citerus.dddsample.domain.model.location.Location;
10 8
 import se.citerus.dddsample.domain.model.voyage.Voyage;
@@ -203,7 +201,18 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
203 201
 
204 202
   @Override
205 203
   public String toString() {
206
-    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
204
+    final StringBuilder builder = new StringBuilder("\n--- Handling event ---\n").
205
+      append("Cargo: ").append(cargo.trackingId()).append("\n").
206
+      append("Type: ").append(type).append("\n").
207
+      append("Location: ").append(location.name()).append("\n").
208
+      append("Completed on: ").append(completionTime).append("\n").
209
+      append("Registered on: ").append(registrationTime).append("\n");
210
+    
211
+    if (voyage != null) {
212
+      builder.append("Voyage: ").append(voyage.voyageNumber()).append("\n");
213
+    }
214
+
215
+    return builder.toString();
207 216
   }
208 217
 
209 218
   HandlingEvent() {

+ 21
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/SampleVoyages.java Voir le fichier

@@ -19,7 +19,6 @@ public class SampleVoyages {
19 19
   public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
20 20
   public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
21 21
   public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
22
-
23 22
   private static Voyage createVoyage(String id, Location from, Location to) {
24 23
     return new Voyage(new VoyageNumber(id), new Schedule(Arrays.asList(
25 24
       new CarrierMovement(from, to, new Date(), new Date())
@@ -28,6 +27,27 @@ public class SampleVoyages {
28 27
 
29 28
   // TODO CM00[1-6] and createVoyage are deprecated. Remove and refactor tests.
30 29
 
30
+  public final static Voyage v100 = new Voyage.Builder(new VoyageNumber("V100"), HONGKONG).
31
+    addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05")).
32
+    addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-09")).
33
+    build();
34
+  public final static Voyage v200 = new Voyage.Builder(new VoyageNumber("V200"), TOKYO).
35
+      addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08")).
36
+      addMovement(CHICAGO, toDate("2009-03-10"), toDate("2009-03-14")).
37
+      addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16")).
38
+      build();
39
+  public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
40
+        addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
41
+        addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
42
+        addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
43
+        addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
44
+        build();
45
+  public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
46
+          addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
47
+          addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
48
+          addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22")).
49
+          build();
50
+
31 51
   /**
32 52
    * Voyage number 0100S (by ship)
33 53
    *

+ 19
- 30
dddsample/src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java Voir le fichier

@@ -82,7 +82,6 @@ public class CargoLifecycleScenarioTest extends TestCase {
82 82
    */
83 83
   RoutingService routingService;
84 84
 
85
-
86 85
   public void testCargoFromHongkongToStockholm() throws Exception {
87 86
     /* Test setup: A cargo should be shipped from Hongkong to Stockholm,
88 87
        and it should arrive in no more than two weeks. */
@@ -153,15 +152,15 @@ public class CargoLifecycleScenarioTest extends TestCase {
153 152
     
154 153
     // Next event: Load onto voyage CM003 in Hongkong
155 154
     handlingEventService.registerHandlingEvent(
156
-      toDate("2009-03-03"), trackingId, CM003.voyageNumber(), HONGKONG.unLocode(), LOAD
155
+      toDate("2009-03-03"), trackingId, v100.voyageNumber(), HONGKONG.unLocode(), LOAD
157 156
     );
158 157
 
159 158
     // Check current state - should be ok
160
-    assertEquals(CM003, cargo.delivery().currentVoyage());
159
+    assertEquals(v100, cargo.delivery().currentVoyage());
161 160
     assertEquals(HONGKONG, cargo.delivery().lastKnownLocation());
162 161
     assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
163 162
     assertFalse(cargo.delivery().isMisdirected());
164
-    assertEquals(new HandlingActivity(UNLOAD, NEWYORK, CM003), cargo.delivery().nextExpectedActivity());
163
+    assertEquals(new HandlingActivity(UNLOAD, NEWYORK, v100), cargo.delivery().nextExpectedActivity());
165 164
 
166 165
 
167 166
     /*
@@ -184,7 +183,7 @@ public class CargoLifecycleScenarioTest extends TestCase {
184 183
 
185 184
     // Cargo is now (incorrectly) unloaded in Tokyo
186 185
     handlingEventService.registerHandlingEvent(
187
-      toDate("2009-03-05"), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), UNLOAD
186
+      toDate("2009-03-05"), trackingId, v100.voyageNumber(), TOKYO.unLocode(), UNLOAD
188 187
     );
189 188
 
190 189
     // Check current state - cargo is misdirected!
@@ -225,19 +224,19 @@ public class CargoLifecycleScenarioTest extends TestCase {
225 224
 
226 225
     // Load in Tokyo
227 226
     handlingEventService.registerHandlingEvent(
228
-      toDate("2009-03-08"), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), LOAD
227
+      toDate("2009-03-08"), trackingId, v300.voyageNumber(), TOKYO.unLocode(), LOAD
229 228
     );
230 229
 
231 230
     // Check current state - should be ok
232
-    assertEquals(CM003, cargo.delivery().currentVoyage());
231
+    assertEquals(v300, cargo.delivery().currentVoyage());
233 232
     assertEquals(TOKYO, cargo.delivery().lastKnownLocation());
234 233
     assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
235 234
     assertFalse(cargo.delivery().isMisdirected());
236
-    assertEquals(new HandlingActivity(UNLOAD, HAMBURG, CM003), cargo.delivery().nextExpectedActivity());
235
+    assertEquals(new HandlingActivity(UNLOAD, HAMBURG, v300), cargo.delivery().nextExpectedActivity());
237 236
 
238 237
     // Unload in Hamburg
239 238
     handlingEventService.registerHandlingEvent(
240
-      toDate("2009-03-12"), trackingId, CM003.voyageNumber(), HAMBURG.unLocode(), UNLOAD
239
+      toDate("2009-03-12"), trackingId, v300.voyageNumber(), HAMBURG.unLocode(), UNLOAD
241 240
     );
242 241
 
243 242
     // Check current state - should be ok
@@ -245,25 +244,25 @@ public class CargoLifecycleScenarioTest extends TestCase {
245 244
     assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
246 245
     assertEquals(IN_PORT, cargo.delivery().transportStatus());
247 246
     assertFalse(cargo.delivery().isMisdirected());
248
-    assertEquals(new HandlingActivity(LOAD, HAMBURG, CM005), cargo.delivery().nextExpectedActivity());
247
+    assertEquals(new HandlingActivity(LOAD, HAMBURG, v400), cargo.delivery().nextExpectedActivity());
249 248
 
250 249
 
251 250
     // Load in Hamburg
252 251
     handlingEventService.registerHandlingEvent(
253
-      toDate("2009-03-14"), trackingId, CM005.voyageNumber(), HAMBURG.unLocode(), LOAD
252
+      toDate("2009-03-14"), trackingId, v400.voyageNumber(), HAMBURG.unLocode(), LOAD
254 253
     );
255 254
 
256 255
     // Check current state - should be ok
257
-    assertEquals(CM005, cargo.delivery().currentVoyage());
256
+    assertEquals(v400, cargo.delivery().currentVoyage());
258 257
     assertEquals(HAMBURG, cargo.delivery().lastKnownLocation());
259 258
     assertEquals(ONBOARD_CARRIER, cargo.delivery().transportStatus());
260 259
     assertFalse(cargo.delivery().isMisdirected());
261
-    assertEquals(new HandlingActivity(UNLOAD, STOCKHOLM, CM005), cargo.delivery().nextExpectedActivity());
260
+    assertEquals(new HandlingActivity(UNLOAD, STOCKHOLM, v400), cargo.delivery().nextExpectedActivity());
262 261
 
263 262
 
264 263
     // Unload in Stockholm
265 264
     handlingEventService.registerHandlingEvent(
266
-      toDate("2009-03-15"), trackingId, CM005.voyageNumber(), STOCKHOLM.unLocode(), UNLOAD
265
+      toDate("2009-03-15"), trackingId, v400.voyageNumber(), STOCKHOLM.unLocode(), UNLOAD
267 266
     );
268 267
 
269 268
     // Check current state - should be ok
@@ -287,42 +286,32 @@ public class CargoLifecycleScenarioTest extends TestCase {
287 286
   }
288 287
 
289 288
 
290
-
291
-
292
-
293
-
294 289
   /*
295 290
   * Utility stubs below.
296 291
   */
297 292
 
298
-  private Date inTwoWeeks() {
299
-    return new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 14);
300
-  }
301
-
302 293
   private Itinerary selectPreferedItinerary(List<Itinerary> itineraries) {
303 294
     return itineraries.get(0);
304 295
   }
305 296
 
306 297
   protected void setUp() throws Exception {
307
-    // Stub
308
-    // TODO new voyages
309 298
     routingService = new RoutingService() {
310 299
       public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
311 300
         if (routeSpecification.origin().equals(HONGKONG)) {
312 301
           // Hongkong - NYC - Chicago - Stockholm, initial routing
313 302
           return Arrays.asList(
314 303
             new Itinerary(Arrays.asList(
315
-              new Leg(CM003, HONGKONG, NEWYORK, new Date(), new Date()),
316
-              new Leg(CM004, NEWYORK, CHICAGO, new Date(), new Date()),
317
-              new Leg(CM005, CHICAGO, STOCKHOLM, new Date(), new Date())
304
+              new Leg(v100, HONGKONG, NEWYORK, toDate("2009-03-03"), toDate("2009-03-09")),
305
+              new Leg(v200, NEWYORK, CHICAGO, toDate("2009-03-10"), toDate("2009-03-14")),
306
+              new Leg(v200, CHICAGO, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
318 307
             ))
319 308
           );
320 309
         } else {
321
-          // Tokyo - Hamburg - Stockholm, rerouting
310
+          // Tokyo - Hamburg - Stockholm, rerouting misdirected cargo from Tokyo 
322 311
           return Arrays.asList(
323 312
             new Itinerary(Arrays.asList(
324
-              new Leg(CM003, TOKYO, HAMBURG, new Date(), new Date()),
325
-              new Leg(CM005, HAMBURG, STOCKHOLM, new Date(), new Date())
313
+              new Leg(v300, TOKYO, HAMBURG, toDate("2009-03-08"), toDate("2009-03-12")),
314
+              new Leg(v400, HAMBURG, STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15"))
326 315
             ))
327 316
           );
328 317
         }