|
|
@@ -10,17 +10,19 @@ import se.citerus.dddsample.domain.model.cargo.TrackingId;
|
|
10
|
10
|
import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
|
|
11
|
11
|
import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
|
|
12
|
12
|
import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
|
|
13
|
|
-import se.citerus.dddsample.domain.model.handling.*;
|
|
|
13
|
+import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
|
|
|
14
|
+import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
|
15
|
+import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
|
|
|
16
|
+import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
|
|
14
|
17
|
import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
15
|
18
|
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
16
|
19
|
import se.citerus.dddsample.domain.model.location.UnLocode;
|
|
17
|
|
-import se.citerus.dddsample.domain.service.DomainEventNotifier;
|
|
18
|
20
|
|
|
19
|
21
|
import java.util.Date;
|
|
20
|
22
|
|
|
21
|
23
|
public class HandlingEventServiceTest extends TestCase {
|
|
22
|
24
|
private HandlingEventServiceImpl service;
|
|
23
|
|
- private DomainEventNotifier domainEventNotifier;
|
|
|
25
|
+ private SystemEvents systemEvents;
|
|
24
|
26
|
private CargoRepository cargoRepository;
|
|
25
|
27
|
private VoyageRepository voyageRepository;
|
|
26
|
28
|
private HandlingEventRepository handlingEventRepository;
|
|
|
@@ -36,13 +38,13 @@ public class HandlingEventServiceTest extends TestCase {
|
|
36
|
38
|
voyageRepository = createMock(VoyageRepository.class);
|
|
37
|
39
|
handlingEventRepository = createMock(HandlingEventRepository.class);
|
|
38
|
40
|
locationRepository = createMock(LocationRepository.class);
|
|
39
|
|
- domainEventNotifier = createMock(DomainEventNotifier.class);
|
|
|
41
|
+ systemEvents = createMock(SystemEvents.class);
|
|
40
|
42
|
handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
|
|
41
|
|
- service = new HandlingEventServiceImpl(handlingEventRepository, domainEventNotifier, handlingEventFactory);
|
|
|
43
|
+ service = new HandlingEventServiceImpl(handlingEventRepository, systemEvents, handlingEventFactory);
|
|
42
|
44
|
}
|
|
43
|
45
|
|
|
44
|
46
|
protected void tearDown() throws Exception {
|
|
45
|
|
- verify(cargoRepository, voyageRepository, handlingEventRepository, domainEventNotifier);
|
|
|
47
|
+ verify(cargoRepository, voyageRepository, handlingEventRepository, systemEvents);
|
|
46
|
48
|
}
|
|
47
|
49
|
|
|
48
|
50
|
public void testRegisterEvent() throws Exception {
|
|
|
@@ -57,9 +59,9 @@ public class HandlingEventServiceTest extends TestCase {
|
|
57
|
59
|
|
|
58
|
60
|
// TODO: does not inspect the handling event instance in a sufficient way
|
|
59
|
61
|
handlingEventRepository.save(isA(HandlingEvent.class));
|
|
60
|
|
- domainEventNotifier.cargoWasHandled(isA(HandlingEvent.class));
|
|
|
62
|
+ systemEvents.cargoWasHandled(isA(HandlingEvent.class));
|
|
61
|
63
|
|
|
62
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
|
|
|
64
|
+ replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
|
|
63
|
65
|
|
|
64
|
66
|
service.register(new HandlingEventRegistrationAttempt(
|
|
65
|
67
|
new Date(), new Date(), trackingId, voyageNumber, HandlingEvent.Type.LOAD, unLocode
|
|
|
@@ -71,11 +73,11 @@ public class HandlingEventServiceTest extends TestCase {
|
|
71
|
73
|
expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
|
|
72
|
74
|
|
|
73
|
75
|
handlingEventRepository.save(isA(HandlingEvent.class));
|
|
74
|
|
- domainEventNotifier.cargoWasHandled(isA(HandlingEvent.class));
|
|
|
76
|
+ systemEvents.cargoWasHandled(isA(HandlingEvent.class));
|
|
75
|
77
|
|
|
76
|
78
|
expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
|
|
77
|
79
|
|
|
78
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
|
|
|
80
|
+ replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
|
|
79
|
81
|
|
|
80
|
82
|
service.register(new HandlingEventRegistrationAttempt(
|
|
81
|
83
|
new Date(), new Date(), trackingId, null, HandlingEvent.Type.RECEIVE, STOCKHOLM.unLocode()
|
|
|
@@ -91,15 +93,14 @@ public class HandlingEventServiceTest extends TestCase {
|
|
91
|
93
|
expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, CHICAGO, STOCKHOLM));
|
|
92
|
94
|
|
|
93
|
95
|
expect(locationRepository.find(MELBOURNE.unLocode())).andReturn(MELBOURNE);
|
|
|
96
|
+
|
|
|
97
|
+ systemEvents.rejectHandlingEventRegistrationAttempt(isA(HandlingEventRegistrationAttempt.class), isA(CannotCreateHandlingEventException.class));
|
|
|
98
|
+
|
|
|
99
|
+ replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
|
|
94
|
100
|
|
|
95
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
|
|
96
|
|
-
|
|
97
|
|
- try {
|
|
98
|
|
- service.register(new HandlingEventRegistrationAttempt(
|
|
99
|
|
- new Date(), new Date(), trackingId, voyageNumber, HandlingEvent.Type.UNLOAD, MELBOURNE.unLocode()
|
|
100
|
|
- ));
|
|
101
|
|
- fail("Should not be able to register an event with non-existing carrier movement");
|
|
102
|
|
- } catch (UnknownVoyageException expected) {}
|
|
|
101
|
+ service.register(new HandlingEventRegistrationAttempt(
|
|
|
102
|
+ new Date(), new Date(), trackingId, voyageNumber, HandlingEvent.Type.UNLOAD, MELBOURNE.unLocode()
|
|
|
103
|
+ ));
|
|
103
|
104
|
}
|
|
104
|
105
|
|
|
105
|
106
|
public void testRegisterEventInvalidCargo() throws Exception {
|
|
|
@@ -107,15 +108,14 @@ public class HandlingEventServiceTest extends TestCase {
|
|
107
|
108
|
expect(cargoRepository.find(trackingId)).andReturn(null);
|
|
108
|
109
|
|
|
109
|
110
|
expect(locationRepository.find(HONGKONG.unLocode())).andReturn(HONGKONG);
|
|
|
111
|
+
|
|
|
112
|
+ systemEvents.rejectHandlingEventRegistrationAttempt(isA(HandlingEventRegistrationAttempt.class), isA(CannotCreateHandlingEventException.class));
|
|
|
113
|
+
|
|
|
114
|
+ replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
|
|
110
|
115
|
|
|
111
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
|
|
112
|
|
-
|
|
113
|
|
- try {
|
|
114
|
116
|
service.register(new HandlingEventRegistrationAttempt(
|
|
115
|
117
|
new Date(), new Date(), trackingId, new VoyageNumber("V001"), HandlingEvent.Type.CLAIM, HONGKONG.unLocode()
|
|
116
|
118
|
));
|
|
117
|
|
- fail("Should not be able to register an event with non-existing cargo");
|
|
118
|
|
- } catch (UnknownCargoException expected) {}
|
|
119
|
119
|
}
|
|
120
|
120
|
|
|
121
|
121
|
public void testRegisterEventInvalidLocation() throws Exception {
|
|
|
@@ -123,14 +123,13 @@ public class HandlingEventServiceTest extends TestCase {
|
|
123
|
123
|
expect(cargoRepository.find(trackingId)).andReturn(cargoXYZ);
|
|
124
|
124
|
UnLocode wayOff = new UnLocode("XXYYY");
|
|
125
|
125
|
expect(locationRepository.find(wayOff)).andReturn(null);
|
|
|
126
|
+
|
|
|
127
|
+ systemEvents.rejectHandlingEventRegistrationAttempt(isA(HandlingEventRegistrationAttempt.class), isA(CannotCreateHandlingEventException.class));
|
|
|
128
|
+
|
|
|
129
|
+ replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
|
|
126
|
130
|
|
|
127
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, domainEventNotifier);
|
|
128
|
|
-
|
|
129
|
|
- try {
|
|
130
|
|
- service.register(new HandlingEventRegistrationAttempt(
|
|
131
|
|
- new Date(), new Date(), trackingId, null, HandlingEvent.Type.CLAIM, wayOff
|
|
132
|
|
- ));
|
|
133
|
|
- fail("Should not be able to register an event with non-existing Location");
|
|
134
|
|
- } catch (UnknownLocationException expected) {}
|
|
|
131
|
+ service.register(new HandlingEventRegistrationAttempt(
|
|
|
132
|
+ new Date(), new Date(), trackingId, null, HandlingEvent.Type.CLAIM, wayOff
|
|
|
133
|
+ ));
|
|
135
|
134
|
}
|
|
136
|
135
|
}
|