|
|
@@ -6,6 +6,7 @@ import se.citerus.dddsample.domain.*;
|
|
6
|
6
|
import se.citerus.dddsample.repository.CargoRepository;
|
|
7
|
7
|
import se.citerus.dddsample.repository.CarrierMovementRepository;
|
|
8
|
8
|
import se.citerus.dddsample.repository.HandlingEventRepository;
|
|
|
9
|
+import se.citerus.dddsample.repository.LocationRepository;
|
|
9
|
10
|
|
|
10
|
11
|
import java.util.Date;
|
|
11
|
12
|
|
|
|
@@ -14,21 +15,28 @@ public class HandlingEventServiceTest extends TestCase {
|
|
14
|
15
|
private CargoRepository cargoRepository;
|
|
15
|
16
|
private CarrierMovementRepository carrierMovementRepository;
|
|
16
|
17
|
private HandlingEventRepository handlingEventRepository;
|
|
|
18
|
+ private LocationRepository locationRepository;
|
|
17
|
19
|
|
|
18
|
20
|
private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), new Location("AFROM"), new Location("ABCTO"));
|
|
19
|
21
|
private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new Location("XFROM"), new Location("XYZTO"));
|
|
20
|
22
|
private final CarrierMovement cmAAA_BBB = new CarrierMovement(
|
|
21
|
23
|
new CarrierMovementId("CAR_001"), new Location("AAAAA"), new Location("BBBBB"));
|
|
|
24
|
+
|
|
|
25
|
+ private final Location locationSESTO = new Location("SESTO");
|
|
|
26
|
+ private final Location locationAUMEL = new Location("AUMEL");
|
|
|
27
|
+ private final Location locationCNHKG = new Location("CNHKG");
|
|
22
|
28
|
|
|
23
|
29
|
protected void setUp() throws Exception{
|
|
24
|
30
|
service = new HandlingEventServiceImpl();
|
|
25
|
31
|
cargoRepository = createMock(CargoRepository.class);
|
|
26
|
32
|
carrierMovementRepository = createMock(CarrierMovementRepository.class);
|
|
27
|
33
|
handlingEventRepository = createMock(HandlingEventRepository.class);
|
|
|
34
|
+ locationRepository = createMock(LocationRepository.class);
|
|
28
|
35
|
|
|
29
|
36
|
service.setCargoRepository(cargoRepository);
|
|
30
|
37
|
service.setCarrierRepository(carrierMovementRepository);
|
|
31
|
38
|
service.setHandlingEventRepository(handlingEventRepository);
|
|
|
39
|
+ service.setLocationRepository(locationRepository);
|
|
32
|
40
|
}
|
|
33
|
41
|
|
|
34
|
42
|
protected void tearDown() throws Exception {
|
|
|
@@ -43,11 +51,13 @@ public class HandlingEventServiceTest extends TestCase {
|
|
43
|
51
|
|
|
44
|
52
|
final CarrierMovementId carrierMovementId = new CarrierMovementId("AAA_BBB");
|
|
45
|
53
|
expect(carrierMovementRepository.find(carrierMovementId)).andReturn(cmAAA_BBB);
|
|
|
54
|
+
|
|
|
55
|
+ expect(locationRepository.find("SESTO")).andReturn(locationSESTO);
|
|
46
|
56
|
|
|
47
|
57
|
// TODO: does not inspect the handling event instance in a sufficient way
|
|
48
|
58
|
handlingEventRepository.save(isA(HandlingEvent.class));
|
|
49
|
59
|
|
|
50
|
|
- replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
|
|
|
60
|
+ replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
|
|
51
|
61
|
|
|
52
|
62
|
service.register(date, trackingId, carrierMovementId, "SESTO", HandlingEvent.Type.LOAD);
|
|
53
|
63
|
}
|
|
|
@@ -59,8 +69,10 @@ public class HandlingEventServiceTest extends TestCase {
|
|
59
|
69
|
expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
|
|
60
|
70
|
|
|
61
|
71
|
handlingEventRepository.save(isA(HandlingEvent.class));
|
|
|
72
|
+
|
|
|
73
|
+ expect(locationRepository.find("SESTO")).andReturn(locationSESTO);
|
|
62
|
74
|
|
|
63
|
|
- replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
|
|
|
75
|
+ replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
|
|
64
|
76
|
|
|
65
|
77
|
service.register(date, trackingId, null, "SESTO", HandlingEvent.Type.CLAIM);
|
|
66
|
78
|
}
|
|
|
@@ -75,7 +87,9 @@ public class HandlingEventServiceTest extends TestCase {
|
|
75
|
87
|
final TrackingId trackingId = new TrackingId("XYZ");
|
|
76
|
88
|
expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, new Location("FROMX"), new Location("TOYYY")));
|
|
77
|
89
|
|
|
78
|
|
- replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
|
|
|
90
|
+ expect(locationRepository.find("AUMEL")).andReturn(locationAUMEL);
|
|
|
91
|
+
|
|
|
92
|
+ replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
|
|
79
|
93
|
|
|
80
|
94
|
try {
|
|
81
|
95
|
service.register(date, trackingId, carrierMovementId, "AUMEL", HandlingEvent.Type.UNLOAD);
|
|
|
@@ -89,11 +103,28 @@ public class HandlingEventServiceTest extends TestCase {
|
|
89
|
103
|
final TrackingId trackingId = new TrackingId("XYZ");
|
|
90
|
104
|
expect(cargoRepository.find(trackingId)).andReturn(null);
|
|
91
|
105
|
|
|
92
|
|
- replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
|
|
|
106
|
+ expect(locationRepository.find("CNHKG")).andReturn(locationCNHKG);
|
|
|
107
|
+
|
|
|
108
|
+ replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
|
|
93
|
109
|
|
|
94
|
110
|
try {
|
|
95
|
111
|
service.register(date, trackingId, null, "CNHKG", HandlingEvent.Type.CLAIM);
|
|
96
|
112
|
fail("Should not be able to register an event with non-existing cargo");
|
|
97
|
113
|
} catch (UnknownTrackingIdException expected) {}
|
|
98
|
114
|
}
|
|
|
115
|
+
|
|
|
116
|
+ public void testRegisterEventInvalidLocation() throws Exception {
|
|
|
117
|
+ final Date date = new Date();
|
|
|
118
|
+
|
|
|
119
|
+ final TrackingId trackingId = new TrackingId("XYZ");
|
|
|
120
|
+ expect(cargoRepository.find(trackingId)).andReturn(cargoXYZ);
|
|
|
121
|
+ expect(locationRepository.find("WAY_OFF")).andReturn(null);
|
|
|
122
|
+
|
|
|
123
|
+ replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
|
|
|
124
|
+
|
|
|
125
|
+ try {
|
|
|
126
|
+ service.register(date, trackingId, null, "WAY_OFF", HandlingEvent.Type.CLAIM);
|
|
|
127
|
+ fail("Should not be able to register an event with non-existing Location");
|
|
|
128
|
+ } catch (UnknownLocationException expected) {}
|
|
|
129
|
+ }
|
|
99
|
130
|
}
|