|
|
@@ -12,9 +12,7 @@ import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
|
|
12
|
12
|
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
|
|
13
|
13
|
import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
14
|
14
|
import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
15
|
|
-import se.citerus.dddsample.domain.model.location.UnLocode;
|
|
16
|
|
-import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
|
|
17
|
|
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
|
|
|
15
|
+import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
|
|
18
|
16
|
import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
|
|
19
|
17
|
|
|
20
|
18
|
import java.util.Date;
|
|
|
@@ -26,10 +24,8 @@ public class HandlingEventServiceTest extends TestCase {
|
|
26
|
24
|
private VoyageRepository voyageRepository;
|
|
27
|
25
|
private HandlingEventRepository handlingEventRepository;
|
|
28
|
26
|
private LocationRepository locationRepository;
|
|
29
|
|
- private HandlingEventFactory handlingEventFactory;
|
|
30
|
27
|
|
|
31
|
|
- private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), new RouteSpecification(HAMBURG, TOKYO, new Date()));
|
|
32
|
|
- private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, HELSINKI, new Date()));
|
|
|
28
|
+ private final Cargo cargo = new Cargo(new TrackingId("ABC"), new RouteSpecification(HAMBURG, TOKYO, new Date()));
|
|
33
|
29
|
|
|
34
|
30
|
protected void setUp() throws Exception{
|
|
35
|
31
|
cargoRepository = createMock(CargoRepository.class);
|
|
|
@@ -37,7 +33,8 @@ public class HandlingEventServiceTest extends TestCase {
|
|
37
|
33
|
handlingEventRepository = createMock(HandlingEventRepository.class);
|
|
38
|
34
|
locationRepository = createMock(LocationRepository.class);
|
|
39
|
35
|
applicationEvents = createMock(ApplicationEvents.class);
|
|
40
|
|
- handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
|
|
|
36
|
+
|
|
|
37
|
+ HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
|
|
41
|
38
|
service = new HandlingEventServiceImpl(handlingEventRepository, applicationEvents, handlingEventFactory);
|
|
42
|
39
|
}
|
|
43
|
40
|
|
|
|
@@ -46,87 +43,15 @@ public class HandlingEventServiceTest extends TestCase {
|
|
46
|
43
|
}
|
|
47
|
44
|
|
|
48
|
45
|
public void testRegisterEvent() throws Exception {
|
|
49
|
|
- final TrackingId trackingId = new TrackingId("ABC");
|
|
50
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
|
|
51
|
|
-
|
|
52
|
|
- final VoyageNumber voyageNumber = new VoyageNumber("AAA_BBB");
|
|
53
|
|
- expect(voyageRepository.find(voyageNumber)).andReturn(SampleVoyages.CM001);
|
|
54
|
|
-
|
|
55
|
|
- final UnLocode unLocode = new UnLocode("SESTO");
|
|
56
|
|
- expect(locationRepository.find(unLocode)).andReturn(STOCKHOLM);
|
|
57
|
|
-
|
|
58
|
|
- // TODO: does not inspect the handling event instance in a sufficient way
|
|
59
|
|
- handlingEventRepository.store(isA(HandlingEvent.class));
|
|
60
|
|
- applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
|
|
61
|
|
-
|
|
62
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
|
|
63
|
|
-
|
|
64
|
|
- final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(
|
|
65
|
|
- new Date(), new Date(), trackingId, voyageNumber, HandlingEvent.Type.LOAD, unLocode
|
|
66
|
|
- );
|
|
67
|
|
- service.registerHandlingEvent(attempt.getCompletionTime(), attempt.getTrackingId(), attempt.getVoyageNumber(), attempt.getUnLocode(), attempt.getType());
|
|
68
|
|
- }
|
|
69
|
|
-
|
|
70
|
|
- public void testRegisterEventWithoutCarrierMovement() throws Exception {
|
|
71
|
|
- final TrackingId trackingId = new TrackingId("ABC");
|
|
72
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
|
|
73
|
|
-
|
|
|
46
|
+ expect(cargoRepository.find(cargo.trackingId())).andReturn(cargo);
|
|
|
47
|
+ expect(voyageRepository.find(CM001.voyageNumber())).andReturn(CM001);
|
|
|
48
|
+ expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
|
|
74
|
49
|
handlingEventRepository.store(isA(HandlingEvent.class));
|
|
75
|
50
|
applicationEvents.cargoWasHandled(isA(HandlingEvent.class));
|
|
76
|
51
|
|
|
77
|
|
- expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
|
|
78
|
|
-
|
|
79
|
52
|
replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
|
|
80
|
53
|
|
|
81
|
|
- final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(
|
|
82
|
|
- new Date(), new Date(), trackingId, null, HandlingEvent.Type.RECEIVE, STOCKHOLM.unLocode()
|
|
83
|
|
- );
|
|
84
|
|
- service.registerHandlingEvent(attempt.getCompletionTime(), attempt.getTrackingId(), attempt.getVoyageNumber(), attempt.getUnLocode(), attempt.getType());
|
|
|
54
|
+ service.registerHandlingEvent(new Date(), cargo.trackingId(), CM001.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD);
|
|
85
|
55
|
}
|
|
86
|
|
-
|
|
87
|
56
|
|
|
88
|
|
- public void testRegisterEventInvalidCarrier() throws Exception {
|
|
89
|
|
- final VoyageNumber voyageNumber = new VoyageNumber("AAA_BBB");
|
|
90
|
|
- expect(voyageRepository.find(voyageNumber)).andReturn(null);
|
|
91
|
|
-
|
|
92
|
|
- final TrackingId trackingId = new TrackingId("XYZ");
|
|
93
|
|
- expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, new RouteSpecification(CHICAGO, STOCKHOLM, new Date())));
|
|
94
|
|
-
|
|
95
|
|
- expect(locationRepository.find(MELBOURNE.unLocode())).andReturn(MELBOURNE);
|
|
96
|
|
-
|
|
97
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
|
|
98
|
|
-
|
|
99
|
|
- final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(
|
|
100
|
|
- new Date(), new Date(), trackingId, voyageNumber, HandlingEvent.Type.UNLOAD, MELBOURNE.unLocode()
|
|
101
|
|
- );
|
|
102
|
|
- service.registerHandlingEvent(attempt.getCompletionTime(), attempt.getTrackingId(), attempt.getVoyageNumber(), attempt.getUnLocode(), attempt.getType());
|
|
103
|
|
- }
|
|
104
|
|
-
|
|
105
|
|
- public void testRegisterEventInvalidCargo() throws Exception {
|
|
106
|
|
- final TrackingId trackingId = new TrackingId("XYZ");
|
|
107
|
|
- expect(cargoRepository.find(trackingId)).andReturn(null);
|
|
108
|
|
-
|
|
109
|
|
- expect(locationRepository.find(HONGKONG.unLocode())).andReturn(HONGKONG);
|
|
110
|
|
-
|
|
111
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
|
|
112
|
|
-
|
|
113
|
|
- final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(
|
|
114
|
|
- new Date(), new Date(), trackingId, new VoyageNumber("V001"), HandlingEvent.Type.CLAIM, HONGKONG.unLocode()
|
|
115
|
|
- );
|
|
116
|
|
- service.registerHandlingEvent(attempt.getCompletionTime(), attempt.getTrackingId(), attempt.getVoyageNumber(), attempt.getUnLocode(), attempt.getType());
|
|
117
|
|
- }
|
|
118
|
|
-
|
|
119
|
|
- public void testRegisterEventInvalidLocation() throws Exception {
|
|
120
|
|
- final TrackingId trackingId = new TrackingId("XYZ");
|
|
121
|
|
- expect(cargoRepository.find(trackingId)).andReturn(cargoXYZ);
|
|
122
|
|
- UnLocode wayOff = new UnLocode("XXYYY");
|
|
123
|
|
- expect(locationRepository.find(wayOff)).andReturn(null);
|
|
124
|
|
-
|
|
125
|
|
- replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, applicationEvents);
|
|
126
|
|
-
|
|
127
|
|
- final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(
|
|
128
|
|
- new Date(), new Date(), trackingId, null, HandlingEvent.Type.CLAIM, wayOff
|
|
129
|
|
- );
|
|
130
|
|
- service.registerHandlingEvent(attempt.getCompletionTime(), attempt.getTrackingId(), attempt.getVoyageNumber(), attempt.getUnLocode(), attempt.getType());
|
|
131
|
|
- }
|
|
132
|
57
|
}
|