|
|
@@ -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
|
+}
|