peter_backlund 17 лет назад
Родитель
Сommit
effe40ef27

+ 7
- 0
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Cargo.java Просмотреть файл

@@ -250,6 +250,13 @@ public class Cargo extends EntitySupport<Cargo,TrackingId> {
250 250
   }
251 251
 
252 252
   /**
253
+   * @return
254
+   */
255
+  public HandlingActivity mostRecentHandlingActivity() {
256
+    return delivery.mostRecentHandlingActivity();
257
+  }
258
+
259
+  /**
253 260
    * Updates all aspects of the cargo aggregate status
254 261
    * based on the current route specification, itinerary and handling of the cargo.
255 262
    * <p/>

+ 4
- 0
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java Просмотреть файл

@@ -44,6 +44,10 @@ class Delivery extends ValueObjectSupport<Delivery> {
44 44
     this.calculatedAt = new Date();
45 45
   }
46 46
 
47
+  HandlingActivity mostRecentHandlingActivity() {
48
+    return mostRecentHandlingActivity;
49
+  }
50
+  
47 51
   /**
48 52
    * @return Transport status
49 53
    */

+ 79
- 0
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/application/event/CargoUpdaterTest.java Просмотреть файл

@@ -0,0 +1,79 @@
1
+package se.citerus.dddsample.tracking.core.application.event;
2
+
3
+import static org.easymock.EasyMock.*;
4
+import static org.hamcrest.MatcherAssert.assertThat;
5
+import static org.hamcrest.Matchers.equalTo;
6
+import static org.hamcrest.Matchers.not;
7
+import org.junit.Before;
8
+import org.junit.Test;
9
+import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
10
+import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
11
+import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoFactory;
12
+import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoRepository;
13
+import se.citerus.dddsample.tracking.core.domain.model.handling.*;
14
+import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.LOAD;
15
+import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
16
+import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.GOTHENBURG;
17
+import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.HONGKONG;
18
+import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.HONGKONG_TO_NEW_YORK;
19
+import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
20
+import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.*;
21
+
22
+public class CargoUpdaterTest {
23
+
24
+  SystemEvents systemEvents;
25
+  CargoUpdater cargoUpdater;
26
+  CargoFactory cargoFactory;
27
+  HandlingEventFactory handlingEventFactory;
28
+  CargoRepository cargoRepository;
29
+  HandlingEventRepository handlingEventRepository;
30
+  LocationRepository locationRepository;
31
+  VoyageRepository voyageRepository;
32
+
33
+  @Before
34
+  public void setUp() throws CannotCreateHandlingEventException {
35
+    systemEvents = createMock(SystemEvents.class);
36
+    cargoRepository = new CargoRepositoryInMem();
37
+    handlingEventRepository = new HandlingEventRepositoryInMem();
38
+    locationRepository = new LocationRepositoryInMem();
39
+    voyageRepository = new VoyageRepositoryInMem();
40
+    cargoFactory = new CargoFactory(locationRepository, new TrackingIdGeneratorInMem());
41
+    handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
42
+    cargoUpdater = new CargoUpdater(systemEvents, cargoRepository, handlingEventRepository);
43
+  }
44
+
45
+  @Test
46
+  public void updateCargo() throws CannotCreateHandlingEventException {
47
+    Cargo cargo = cargoFactory.newCargo(HONGKONG.unLocode(), GOTHENBURG.unLocode(), toDate("2009-10-15"));
48
+    cargoRepository.store(cargo);
49
+
50
+    HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(
51
+      toDate("2009-10-01", "14:30"),
52
+      cargo.trackingId(),
53
+      HONGKONG_TO_NEW_YORK.voyageNumber(),
54
+      HONGKONG.unLocode(),
55
+      LOAD
56
+    );
57
+    handlingEventRepository.store(handlingEvent);
58
+
59
+    systemEvents.notifyOfCargoUpdate(cargo);
60
+    replay(systemEvents);
61
+
62
+    assertThat(handlingEvent.activity(), not(equalTo(cargo.mostRecentHandlingActivity())));
63
+
64
+    cargoUpdater.updateCargo(handlingEvent.sequenceNumber());
65
+    
66
+    assertThat(handlingEvent.activity(), equalTo(cargo.mostRecentHandlingActivity()));
67
+
68
+    verify(systemEvents);
69
+  }
70
+
71
+  @Test
72
+  public void handlingEventNotFound() {
73
+    replay(systemEvents);
74
+
75
+    cargoUpdater.updateCargo(EventSequenceNumber.valueOf(999L));
76
+    
77
+    verify(systemEvents);
78
+  }
79
+}