|
|
@@ -13,11 +13,16 @@ import java.util.Map;
|
|
13
|
13
|
public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
14
|
14
|
|
|
15
|
15
|
CargoRepository cargoRepository;
|
|
|
16
|
+ LocationRepository locationRepository;
|
|
16
|
17
|
|
|
17
|
18
|
public void setCargoRepository(CargoRepository cargoRepository) {
|
|
18
|
19
|
this.cargoRepository = cargoRepository;
|
|
19
|
20
|
}
|
|
20
|
21
|
|
|
|
22
|
+ public void setLocationRepository(LocationRepository locationRepository) {
|
|
|
23
|
+ this.locationRepository = locationRepository;
|
|
|
24
|
+ }
|
|
|
25
|
+
|
|
21
|
26
|
public void testFindByCargoId() {
|
|
22
|
27
|
Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
23
|
28
|
assertEquals(HONGKONG, cargo.origin());
|
|
|
@@ -74,19 +79,55 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
74
|
79
|
}
|
|
75
|
80
|
|
|
76
|
81
|
public void testSave() {
|
|
77
|
|
- sessionFactory.getCurrentSession().saveOrUpdate(STOCKHOLM);
|
|
78
|
|
- sessionFactory.getCurrentSession().saveOrUpdate(MELBOURNE);
|
|
79
|
|
-
|
|
|
82
|
+ TrackingId trackingId = new TrackingId("AAA");
|
|
|
83
|
+ Location origin = locationRepository.find(STOCKHOLM.unLocode());
|
|
|
84
|
+ Location destination = locationRepository.find(MELBOURNE.unLocode());
|
|
80
|
85
|
|
|
81
|
|
- Cargo cargo = new Cargo(new TrackingId("AAA"), STOCKHOLM, MELBOURNE);
|
|
|
86
|
+ Cargo cargo = new Cargo(trackingId, origin, destination);
|
|
82
|
87
|
cargoRepository.save(cargo);
|
|
83
|
88
|
|
|
84
|
89
|
flush();
|
|
85
|
90
|
|
|
86
|
|
- Map<String, Object> map = sjt.queryForMap("select * from Cargo where tracking_id = 'AAA'");
|
|
|
91
|
+ Map<String, Object> map = sjt.queryForMap(
|
|
|
92
|
+ "select * from Cargo where tracking_id = ?", trackingId.idString());
|
|
87
|
93
|
|
|
88
|
94
|
assertEquals("AAA", map.get("TRACKING_ID"));
|
|
89
|
|
- // TODO: check origin/finalDestination ids
|
|
|
95
|
+
|
|
|
96
|
+ Long originId = (Long) sessionFactory.getCurrentSession().getIdentifier(origin);
|
|
|
97
|
+ assertEquals(originId, map.get("ORIGIN_ID"));
|
|
|
98
|
+
|
|
|
99
|
+ Long destinationId = (Long) sessionFactory.getCurrentSession().getIdentifier(destination);
|
|
|
100
|
+ assertEquals(destinationId, map.get("DESTINATION_ID"));
|
|
|
101
|
+
|
|
|
102
|
+ assertNull(map.get("ITINERARY_ID"));
|
|
|
103
|
+ }
|
|
|
104
|
+
|
|
|
105
|
+ public void testSaveShouldNotCascadeToHandlingEvents() {
|
|
|
106
|
+ /* TODO:
|
|
|
107
|
+ this test indicates that the addEvent/addEvents methods on DeliveryHistory
|
|
|
108
|
+ are somewhat unintuitive, since added events are not cascade-savded with the cargo.
|
|
|
109
|
+ Also, it's not really needed except when loading a cargo, so perhaps something like
|
|
|
110
|
+ Cargo.attachDeliveryHistory() would be better? */
|
|
|
111
|
+
|
|
|
112
|
+ Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
|
113
|
+ int eventCount = cargo.deliveryHistory().eventsOrderedByCompletionTime().size();
|
|
|
114
|
+
|
|
|
115
|
+ Location origin = locationRepository.find(STOCKHOLM.unLocode());
|
|
|
116
|
+
|
|
|
117
|
+ HandlingEvent event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, origin, null);
|
|
|
118
|
+ assertFalse(cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event));
|
|
|
119
|
+
|
|
|
120
|
+ cargo.deliveryHistory().addEvent(event);
|
|
|
121
|
+ assertTrue(cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event));
|
|
|
122
|
+
|
|
|
123
|
+ // Save cargo, evict from session and then re-load it - should not pick up the added event,
|
|
|
124
|
+ // as it was never cascade-saved
|
|
|
125
|
+ cargoRepository.save(cargo);
|
|
|
126
|
+ sessionFactory.getCurrentSession().evict(cargo);
|
|
|
127
|
+
|
|
|
128
|
+ cargo = cargoRepository.find(cargo.trackingId());
|
|
|
129
|
+ assertFalse(cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event));
|
|
|
130
|
+ assertEquals(eventCount, cargo.deliveryHistory().eventsOrderedByCompletionTime().size());
|
|
90
|
131
|
}
|
|
91
|
132
|
|
|
92
|
133
|
public void testFindAll() {
|
|
|
@@ -95,4 +136,13 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
95
|
136
|
assertEquals(6, all.size());
|
|
96
|
137
|
}
|
|
97
|
138
|
|
|
|
139
|
+ public void testNextTrackingId() {
|
|
|
140
|
+ TrackingId trackingId = cargoRepository.nextTrackingId();
|
|
|
141
|
+ assertNotNull(trackingId);
|
|
|
142
|
+
|
|
|
143
|
+ TrackingId trackingId2 = cargoRepository.nextTrackingId();
|
|
|
144
|
+ assertNotNull(trackingId2);
|
|
|
145
|
+ assertFalse(trackingId.equals(trackingId2));
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
98
|
148
|
}
|