|
|
@@ -15,6 +15,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
15
|
15
|
|
|
16
|
16
|
CargoRepository cargoRepository;
|
|
17
|
17
|
LocationRepository locationRepository;
|
|
|
18
|
+ CarrierMovementRepository carrierMovementRepository;
|
|
18
|
19
|
|
|
19
|
20
|
public void setCargoRepository(CargoRepository cargoRepository) {
|
|
20
|
21
|
this.cargoRepository = cargoRepository;
|
|
|
@@ -24,6 +25,10 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
24
|
25
|
this.locationRepository = locationRepository;
|
|
25
|
26
|
}
|
|
26
|
27
|
|
|
|
28
|
+ public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
|
|
|
29
|
+ this.carrierMovementRepository = carrierMovementRepository;
|
|
|
30
|
+ }
|
|
|
31
|
+
|
|
27
|
32
|
public void testFindByCargoId() {
|
|
28
|
33
|
Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
29
|
34
|
assertEquals(HONGKONG, cargo.origin());
|
|
|
@@ -103,13 +108,45 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
103
|
108
|
assertNull(map.get("ITINERARY_ID"));
|
|
104
|
109
|
}
|
|
105
|
110
|
|
|
106
|
|
- public void testSaveShouldNotCascadeToHandlingEvents() {
|
|
107
|
|
- /* TODO:
|
|
108
|
|
- this test indicates that the addEvent/addEvents methods on DeliveryHistory
|
|
109
|
|
- are somewhat unintuitive, since added events are not cascade-savded with the cargo.
|
|
110
|
|
- Also, it's not really needed except when loading a cargo, so perhaps something like
|
|
111
|
|
- Cargo.attachDeliveryHistory() would be better? */
|
|
|
111
|
+ public void testDeleteOrphanedItinerary() {
|
|
|
112
|
+ Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
|
113
|
+ Long itineraryId = getLongId(cargo.itinerary());
|
|
|
114
|
+
|
|
|
115
|
+ assertEquals(1, sjt.queryForInt("select count(*) from Itinerary where id = ?", itineraryId));
|
|
|
116
|
+
|
|
|
117
|
+ cargo.detachItinerary();
|
|
|
118
|
+ cargoRepository.save(cargo);
|
|
|
119
|
+ flush();
|
|
|
120
|
+
|
|
|
121
|
+ // Repository is responsible for deleting orphaned, detached itineraries
|
|
|
122
|
+ assertEquals(0, sjt.queryForInt("select count(*) from Itinerary where id = ?", itineraryId));
|
|
|
123
|
+ }
|
|
112
|
124
|
|
|
|
125
|
+ public void testReplaceItinerary() {
|
|
|
126
|
+ Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
|
127
|
+ Long oldItineraryId = getLongId(cargo.itinerary());
|
|
|
128
|
+ assertEquals(1, sjt.queryForInt("select count(*) from Itinerary where id = ?", oldItineraryId));
|
|
|
129
|
+
|
|
|
130
|
+ CarrierMovement cm = carrierMovementRepository.find(new CarrierMovementId("CAR_006"));
|
|
|
131
|
+ Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
|
|
|
132
|
+ Location legTo = locationRepository.find(new UnLocode("DEHAM"));
|
|
|
133
|
+ Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(cm, legFrom, legTo)));
|
|
|
134
|
+
|
|
|
135
|
+ cargo.attachItinerary(newItinerary);
|
|
|
136
|
+
|
|
|
137
|
+ cargoRepository.save(cargo);
|
|
|
138
|
+ flush();
|
|
|
139
|
+
|
|
|
140
|
+ // Old itinerary should be deleted
|
|
|
141
|
+ assertEquals(0, sjt.queryForInt("select count(*) from Itinerary where id = ?", oldItineraryId));
|
|
|
142
|
+
|
|
|
143
|
+ // New itinerary should be cascade-saved
|
|
|
144
|
+ Long newItineraryId = getLongId(cargo.itinerary());
|
|
|
145
|
+ assertEquals(1, sjt.queryForInt("select count(*) from Itinerary where id = ?", newItineraryId));
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+
|
|
|
149
|
+ public void testSaveShouldNotCascadeToHandlingEvents() {
|
|
113
|
150
|
Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
114
|
151
|
int eventCount = cargo.deliveryHistory().eventsOrderedByCompletionTime().size();
|
|
115
|
152
|
|