瀏覽代碼

Added completion time parameter to cargo.handled() to enable Cargo to determine whether or not the specified activity should refresh the delivery or not.

peter_backlund 17 年之前
父節點
當前提交
8fd74c913a

+ 8
- 4
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/application/event/CargoUpdater.java 查看文件

@@ -2,16 +2,18 @@ package se.citerus.dddsample.tracking.core.application.event;
2 2
 
3 3
 import org.apache.commons.logging.Log;
4 4
 import org.apache.commons.logging.LogFactory;
5
-import org.springframework.transaction.annotation.Transactional;
6
-import org.springframework.stereotype.Service;
7 5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Service;
7
+import org.springframework.transaction.annotation.Transactional;
8 8
 import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
9 9
 import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoRepository;
10
+import se.citerus.dddsample.tracking.core.domain.model.handling.EventSequenceNumber;
10 11
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
11 12
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
12
-import se.citerus.dddsample.tracking.core.domain.model.handling.EventSequenceNumber;
13 13
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
14 14
 
15
+import java.util.Date;
16
+
15 17
 @Service
16 18
 public class CargoUpdater {
17 19
 
@@ -39,8 +41,9 @@ public class CargoUpdater {
39 41
 
40 42
     final HandlingActivity activity = handlingEvent.activity();
41 43
     final Cargo cargo = handlingEvent.cargo();
44
+    final Date completionTime = handlingEvent.completionTime();
42 45
 
43
-    cargo.handled(activity);
46
+    cargo.handled(activity, completionTime);
44 47
     cargoRepository.store(cargo);
45 48
 
46 49
     systemEvents.notifyOfCargoUpdate(cargo);
@@ -48,6 +51,7 @@ public class CargoUpdater {
48 51
   }
49 52
 
50 53
   CargoUpdater() {
54
+    // Needed by CGLIB
51 55
   }
52 56
 
53 57
 }

+ 2
- 2
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/application/util/SampleDataGenerator.java 查看文件

@@ -253,7 +253,7 @@ public class SampleDataGenerator implements ServletContextListener {
253 253
         }
254 254
 
255 255
         final HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(abc123);
256
-        abc123.handled(handlingEvent.activity());
256
+        abc123.handled(handlingEvent.activity(), new Date());
257 257
         session.update(abc123);
258 258
 
259 259
         // Cargo JKL567
@@ -297,7 +297,7 @@ public class SampleDataGenerator implements ServletContextListener {
297 297
         }
298 298
 
299 299
         HandlingEvent handlingEvent1 = handlingEventRepository.mostRecentHandling(jkl567);
300
-        jkl567.handled(handlingEvent1.activity());
300
+        jkl567.handled(handlingEvent1.activity(), new Date());
301 301
         session.update(jkl567);
302 302
       }
303 303
     });

+ 65
- 3
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Cargo.java 查看文件

@@ -121,7 +121,59 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
121 121
       return null;
122 122
     }
123 123
 
124
-    final Location lastKnownLocation = delivery.lastKnownLocation();
124
+
125
+    
126
+    /*
127
+    if (delivery.transportStatus() == NOT_RECEIVED) {
128
+      return itinerary.firstLeg().receive();
129
+    }
130
+
131
+    Leg leg = itinerary.legMatching(delivery.mostRecentHandlingActivity());
132
+
133
+    if (leg == null) return null;
134
+
135
+    if (onboardCarrier()) return leg.unload();
136
+    else if (inPort())
137
+      if (leg.sameValueAs(itinerary.lastLeg())) return leg.claim();
138
+      else return leg.load();
139
+    else return null;
140
+
141
+  private boolean inPort() {
142
+    return delivery.transportStatus() == IN_PORT;
143
+  }
144
+
145
+  private boolean onboardCarrier() {
146
+    return delivery.transportStatus() == ONBOARD_CARRIER;
147
+  }
148
+
149
+
150
+    */
151
+
152
+  /*
153
+    public Date timeOfNextHandling() {
154
+      if (notReceived()) {
155
+        return null;
156
+      }
157
+
158
+      final Leg leg = itinerary.legMatching(delivery.mostRecentHandlingActivity());
159
+
160
+      if (leg == null) return null;
161
+
162
+      if (onboardCarrier()) return leg.unloadTime();
163
+      else if (inPort())
164
+        if (leg.sameValueAs(itinerary.lastLeg())) return null;
165
+        else return leg.loadTime();
166
+      else return null;
167
+    }
168
+
169
+  private boolean notReceived() {
170
+    return delivery.transportStatus() == NOT_RECEIVED;
171
+  }
172
+  */
173
+
174
+
175
+
176
+  final Location lastKnownLocation = delivery.lastKnownLocation();
125 177
 
126 178
     switch (delivery.transportStatus()) {
127 179
       case IN_PORT:
@@ -270,12 +322,22 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
270 322
    * since {@link HandlingEvent} is in a different aggregate.
271 323
    *
272 324
    * @param handlingActivity handling activity
325
+   * @param completionTime when the activity was completed
273 326
    */
274
-  public void handled(final HandlingActivity handlingActivity) {
327
+  public void handled(final HandlingActivity handlingActivity, final Date completionTime) {
275 328
     Validate.notNull(handlingActivity, "Handling activity is required");
276 329
 
330
+    if (delivery.lastTimestamp().after(completionTime)) {
331
+      return;
332
+    }
333
+
334
+    // TODO
335
+    // What if an activity that should logically happen later is entered with
336
+    // a completion time that's before some other activity?
337
+    // Who should win - logic or completion time?
338
+
277 339
     // Delivery is a value object, so it's replaced with a new one
278
-    this.delivery = Delivery.whenHandled(handlingActivity);
340
+    this.delivery = Delivery.cargoWasHandled(handlingActivity, completionTime);
279 341
   }
280 342
 
281 343
   @Override

+ 10
- 12
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java 查看文件

@@ -24,24 +24,25 @@ class Delivery extends ValueObjectSupport<Delivery> {
24 24
    * Derives a new delivery when a cargo has been handled.
25 25
    *
26 26
    * @param handlingActivity  handling activity
27
+   * @param completionTime
27 28
    * @return An up to date delivery
28 29
    */
29
-  static Delivery whenHandled(final HandlingActivity handlingActivity) {
30
+  static Delivery cargoWasHandled(final HandlingActivity handlingActivity, Date completionTime) {
30 31
     Validate.notNull(handlingActivity, "Handling activity is required");
31 32
 
32
-    return new Delivery(handlingActivity);
33
+    return new Delivery(handlingActivity, completionTime);
33 34
   }
34 35
 
35 36
   /**
36 37
    * @return Initial delivery, before any handling has taken place
37 38
    */
38 39
   static Delivery initial() {
39
-    return new Delivery(null);
40
+    return new Delivery(null, new Date(0L));
40 41
   }
41 42
 
42
-  Delivery(final HandlingActivity mostRecentHandlingActivity) {
43
+  Delivery(final HandlingActivity mostRecentHandlingActivity, final Date completionTime) {
43 44
     this.mostRecentHandlingActivity = mostRecentHandlingActivity;
44
-    this.calculatedAt = new Date();
45
+    this.calculatedAt = completionTime;
45 46
   }
46 47
 
47 48
   HandlingActivity mostRecentHandlingActivity() {
@@ -100,16 +101,13 @@ class Delivery extends ValueObjectSupport<Delivery> {
100 101
     }
101 102
 
102 103
     if (mostRecentHandlingActivity.type() == CUSTOMS) {
103
-      return !handledAtDestination(routeSpecification);
104
+      boolean handledAtDestination = routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
105
+      return !handledAtDestination;
104 106
     } else {
105 107
       return !itinerary.wasExpecting(mostRecentHandlingActivity);
106 108
     }
107 109
   }
108 110
 
109
-  private boolean handledAtDestination(final RouteSpecification routeSpecification) {
110
-    return routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
111
-  }
112
-
113 111
   /**
114 112
    * @return True if the cargo has been unloaded at the final destination.
115 113
    * @param routeSpecification route specification
@@ -117,7 +115,7 @@ class Delivery extends ValueObjectSupport<Delivery> {
117 115
   boolean isUnloadedAtDestination(final RouteSpecification routeSpecification) {
118 116
     if (hasBeenHandled()) {
119 117
       return (mostRecentHandlingActivity.type() == CLAIM ||
120
-              mostRecentHandlingActivity.type() == UNLOAD && handledAtDestination(routeSpecification));
118
+              mostRecentHandlingActivity.type() == UNLOAD && routeSpecification.destination().sameAs(mostRecentHandlingActivity.location()));
121 119
     } else {
122 120
       return false;
123 121
     }
@@ -143,7 +141,7 @@ class Delivery extends ValueObjectSupport<Delivery> {
143 141
   /**
144 142
    * @return When this delivery was calculated.
145 143
    */
146
-  Date calculatedAt() {
144
+  Date lastTimestamp() {
147 145
     return new Date(calculatedAt.getTime());
148 146
   }
149 147
 

+ 48
- 31
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/CargoTest.java 查看文件

@@ -3,6 +3,7 @@ package se.citerus.dddsample.tracking.core.domain.model.cargo;
3 3
 import junit.framework.TestCase;
4 4
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
5 5
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.*;
6
+import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.IN_PORT;
6 7
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.NOT_RECEIVED;
7 8
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
8 9
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
@@ -78,6 +79,22 @@ public class CargoTest extends TestCase {
78 79
     assertEquals(ROUTED, cargo.routingStatus());
79 80
   }
80 81
 
82
+  public void testOutOrderHandling() throws Exception {
83
+    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
84
+
85
+    cargo.handled(HandlingActivity.loadedOnto(crazyVoyage).in(STOCKHOLM), toDate("2009-10-01"));
86
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage), toDate("2009-10-01"));
87
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage), toDate("2009-10-02"));
88
+    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage), toDate("2009-10-04"));
89
+    assertEquals(cargo.transportStatus(), IN_PORT);
90
+    assertEquals(cargo.lastKnownLocation(), HONGKONG);
91
+
92
+    // Out of order handling, does not affect state of cargo
93
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage), toDate("2009-10-03"));
94
+    assertEquals(IN_PORT, cargo.transportStatus());
95
+    assertEquals(HONGKONG, cargo.lastKnownLocation());
96
+  }
97
+
81 98
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
82 99
     Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
83 100
 
@@ -127,7 +144,7 @@ public class CargoTest extends TestCase {
127 144
     assertFalse(cargo.isReadyToClaim());
128 145
 
129 146
     // Adding an event unrelated to unloading at final destination
130
-    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU));
147
+    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU), new Date());
131 148
     assertFalse(cargo.isReadyToClaim());
132 149
 
133 150
     Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
@@ -135,59 +152,59 @@ public class CargoTest extends TestCase {
135 152
       build();
136 153
 
137 154
     // Adding an unload event, but not at the final destination
138
-    cargo.handled(new HandlingActivity(UNLOAD, TOKYO, voyage));
155
+    cargo.handled(new HandlingActivity(UNLOAD, TOKYO, voyage), new Date());
139 156
     assertFalse(cargo.isReadyToClaim());
140 157
 
141 158
     // Adding an event in the final destination, but not unload
142
-    cargo.handled(new HandlingActivity(CUSTOMS, NEWYORK));
159
+    cargo.handled(new HandlingActivity(CUSTOMS, NEWYORK), new Date());
143 160
     assertFalse(cargo.isReadyToClaim());
144 161
 
145 162
     // Finally, cargo is unloaded at final destination
146
-    cargo.handled(new HandlingActivity(UNLOAD, NEWYORK, voyage));
163
+    cargo.handled(new HandlingActivity(UNLOAD, NEWYORK, voyage), new Date());
147 164
     assertTrue(cargo.isReadyToClaim());
148 165
   }
149 166
 
150 167
   private Cargo populateCargoReceivedStockholm() throws Exception {
151 168
     final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
152
-    cargo.handled(new HandlingActivity(RECEIVE, STOCKHOLM));
169
+    cargo.handled(new HandlingActivity(RECEIVE, STOCKHOLM), new Date());
153 170
     return cargo;
154 171
   }
155 172
 
156 173
   private Cargo populateCargoClaimedMelbourne() throws Exception {
157 174
     final Cargo cargo = populateCargoOffMelbourne();
158 175
 
159
-    cargo.handled(new HandlingActivity(CLAIM, MELBOURNE));
176
+    cargo.handled(new HandlingActivity(CLAIM, MELBOURNE), new Date());
160 177
     return cargo;
161 178
   }
162 179
 
163 180
   private Cargo populateCargoOffHongKong() throws Exception {
164 181
     final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
165 182
     
166
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
167
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
168
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
169
-    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage));
183
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage), new Date());
184
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage), new Date());
185
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage), new Date());
186
+    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage), new Date());
170 187
     return cargo;
171 188
   }
172 189
 
173 190
   private Cargo populateCargoOnHamburg() throws Exception {
174 191
     final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
175 192
     
176
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
177
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
178
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
193
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage), new Date());
194
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage), new Date());
195
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage), new Date());
179 196
     return cargo;
180 197
   }
181 198
 
182 199
   private Cargo populateCargoOffMelbourne() throws Exception {
183 200
     final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
184 201
 
185
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
186
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
187
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
188
-    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage));
189
-    cargo.handled(new HandlingActivity(LOAD, HONGKONG, crazyVoyage));
190
-    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage));
202
+    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage), new Date());
203
+    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage), new Date());
204
+    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage), new Date());
205
+    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage), new Date());
206
+    cargo.handled(new HandlingActivity(LOAD, HONGKONG, crazyVoyage), new Date());
207
+    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage), new Date());
191 208
 
192 209
     return cargo;
193 210
   }
@@ -203,30 +220,30 @@ public class CargoTest extends TestCase {
203 220
     assertFalse(cargo.isMisdirected());
204 221
 
205 222
     //Happy path
206
-    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI));
207
-    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage));
208
-    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage));
209
-    cargo.handled(new HandlingActivity(LOAD, ROTTERDAM, crazyVoyage));
210
-    cargo.handled(new HandlingActivity(UNLOAD, GOTHENBURG, crazyVoyage));
211
-    cargo.handled(new HandlingActivity(CLAIM, GOTHENBURG));
212
-    cargo.handled(new HandlingActivity(CUSTOMS, GOTHENBURG));
223
+    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI), new Date());
224
+    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage), new Date());
225
+    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage), new Date());
226
+    cargo.handled(new HandlingActivity(LOAD, ROTTERDAM, crazyVoyage), new Date());
227
+    cargo.handled(new HandlingActivity(UNLOAD, GOTHENBURG, crazyVoyage), new Date());
228
+    cargo.handled(new HandlingActivity(CLAIM, GOTHENBURG), new Date());
229
+    cargo.handled(new HandlingActivity(CUSTOMS, GOTHENBURG), new Date());
213 230
     assertFalse(cargo.isMisdirected());
214 231
 
215 232
     //Try a couple of failing ones
216 233
 
217 234
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
218 235
 
219
-    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU));
236
+    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU), new Date());
220 237
     assertTrue(cargo.isMisdirected());
221 238
 
222 239
 
223 240
 
224 241
     cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
225 242
 
226
-    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI));
227
-    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage));
228
-    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage));
229
-    cargo.handled(new HandlingActivity(CLAIM, ROTTERDAM));
243
+    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI), new Date());
244
+    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage), new Date());
245
+    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage), new Date());
246
+    cargo.handled(new HandlingActivity(CLAIM, ROTTERDAM), new Date());
230 247
 
231 248
     assertTrue(cargo.isMisdirected());
232 249
   }

+ 11
- 11
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/DeliveryTest.java 查看文件

@@ -39,14 +39,14 @@ public class DeliveryTest extends TestCase {
39 39
     assertFalse(delivery.isUnloadedAtDestination(routeSpecification));
40 40
     assertEquals(Location.UNKNOWN, delivery.lastKnownLocation());
41 41
     assertEquals(NOT_RECEIVED, delivery.transportStatus());
42
-    assertTrue(delivery.calculatedAt().before(new Date()));
42
+    assertTrue(delivery.lastTimestamp().before(new Date()));
43 43
   }
44 44
 
45 45
   public void testUpdateOnHandlingHappyPath() {
46 46
     // 1. Receive
47 47
 
48 48
     HandlingActivity handlingActivity = new HandlingActivity(RECEIVE, HANGZOU);
49
-    Delivery newDelivery = Delivery.whenHandled(handlingActivity);
49
+    Delivery newDelivery = Delivery.cargoWasHandled(handlingActivity, new Date());
50 50
 
51 51
     // Changed on handling
52 52
     assertEquals(Voyage.NONE, newDelivery.currentVoyage());
@@ -61,12 +61,12 @@ public class DeliveryTest extends TestCase {
61 61
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
62 62
 
63 63
     // Updated on every calculation
64
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
64
+    assertTrue(delivery.lastTimestamp().before(newDelivery.lastTimestamp()));
65 65
 
66 66
     // 2. Load
67 67
 
68 68
     handlingActivity = new HandlingActivity(LOAD, HANGZOU, HONGKONG_TO_NEW_YORK);
69
-    newDelivery = Delivery.whenHandled(handlingActivity);
69
+    newDelivery = Delivery.cargoWasHandled(handlingActivity, new Date());
70 70
 
71 71
     assertEquals(HONGKONG_TO_NEW_YORK, newDelivery.currentVoyage());
72 72
     assertEquals(HANGZOU, newDelivery.lastKnownLocation());
@@ -77,14 +77,14 @@ public class DeliveryTest extends TestCase {
77 77
 
78 78
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
79 79
 
80
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
80
+    assertTrue(delivery.lastTimestamp().before(newDelivery.lastTimestamp()));
81 81
 
82 82
     // Skipping intermediate load/unloads
83 83
 
84 84
     // 3. Unload
85 85
 
86 86
     handlingActivity = new HandlingActivity(UNLOAD, STOCKHOLM, DALLAS_TO_HELSINKI);
87
-    newDelivery = Delivery.whenHandled(handlingActivity);
87
+    newDelivery = Delivery.cargoWasHandled(handlingActivity, new Date());
88 88
 
89 89
     assertEquals(Voyage.NONE, newDelivery.currentVoyage());
90 90
     assertEquals(STOCKHOLM, newDelivery.lastKnownLocation());
@@ -95,12 +95,12 @@ public class DeliveryTest extends TestCase {
95 95
 
96 96
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
97 97
 
98
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
98
+    assertTrue(delivery.lastTimestamp().before(newDelivery.lastTimestamp()));
99 99
 
100 100
     // 4. Claim
101 101
 
102 102
     handlingActivity = new HandlingActivity(CLAIM, STOCKHOLM);
103
-    newDelivery = Delivery.whenHandled(handlingActivity);
103
+    newDelivery = Delivery.cargoWasHandled(handlingActivity, new Date());
104 104
 
105 105
     assertEquals(Voyage.NONE, newDelivery.currentVoyage());
106 106
     assertEquals(STOCKHOLM, newDelivery.lastKnownLocation());
@@ -111,13 +111,13 @@ public class DeliveryTest extends TestCase {
111 111
 
112 112
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
113 113
 
114
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
114
+    assertTrue(delivery.lastTimestamp().before(newDelivery.lastTimestamp()));
115 115
   }
116 116
 
117 117
   public void testUpdateOnHandlingWhenMisdirected() {
118 118
     // Unload in Hamburg, which is the wrong location
119 119
     HandlingActivity handlingActivity = new HandlingActivity(UNLOAD, HAMBURG, DALLAS_TO_HELSINKI);
120
-    Delivery newDelivery = Delivery.whenHandled(handlingActivity);
120
+    Delivery newDelivery = Delivery.cargoWasHandled(handlingActivity, new Date());
121 121
 
122 122
     assertEquals(Voyage.NONE, newDelivery.currentVoyage());
123 123
     assertEquals(HAMBURG, newDelivery.lastKnownLocation());
@@ -130,7 +130,7 @@ public class DeliveryTest extends TestCase {
130 130
 
131 131
     assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
132 132
 
133
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
133
+    assertTrue(delivery.lastTimestamp().before(newDelivery.lastTimestamp()));
134 134
 
135 135
     // New route specification, old itinerary
136 136
     RouteSpecification newRouteSpecification = routeSpecification.withOrigin(HAMBURG);

+ 1
- 1
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/scenario/CargoLifecycleScenarioTest.java 查看文件

@@ -390,7 +390,7 @@ public class CargoLifecycleScenarioTest {
390 390
   private void updateCargoAggregate() {
391 391
     Cargo cargo = cargoRepository.find(trackingId);
392 392
     HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(cargo);
393
-    cargo.handled(handlingEvent.activity());
393
+    cargo.handled(handlingEvent.activity(), new Date());
394 394
     cargoRepository.store(cargo);
395 395
   }
396 396