|
|
@@ -2,9 +2,10 @@ package se.citerus.dddsample.application.persistence;
|
|
2
|
2
|
|
|
3
|
3
|
import se.citerus.dddsample.application.util.SampleDataGenerator;
|
|
4
|
4
|
import se.citerus.dddsample.domain.model.cargo.*;
|
|
5
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
|
|
6
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
|
|
7
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
|
|
|
5
|
+import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
|
|
|
6
|
+import se.citerus.dddsample.domain.model.carrier.Voyage;
|
|
|
7
|
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
|
|
|
8
|
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
|
|
8
|
9
|
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
9
|
10
|
import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
|
|
10
|
11
|
import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.RECEIVE;
|
|
|
@@ -22,7 +23,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
22
|
23
|
|
|
23
|
24
|
CargoRepository cargoRepository;
|
|
24
|
25
|
LocationRepository locationRepository;
|
|
25
|
|
- CarrierMovementRepository carrierMovementRepository;
|
|
|
26
|
+ VoyageRepository voyageRepository;
|
|
26
|
27
|
|
|
27
|
28
|
public void setCargoRepository(CargoRepository cargoRepository) {
|
|
28
|
29
|
this.cargoRepository = cargoRepository;
|
|
|
@@ -32,8 +33,8 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
32
|
33
|
this.locationRepository = locationRepository;
|
|
33
|
34
|
}
|
|
34
|
35
|
|
|
35
|
|
- public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
|
|
36
|
|
- this.carrierMovementRepository = carrierMovementRepository;
|
|
|
36
|
+ public void setCarrierMovementRepository(VoyageRepository voyageRepository) {
|
|
|
37
|
+ this.voyageRepository = voyageRepository;
|
|
37
|
38
|
}
|
|
38
|
39
|
|
|
39
|
40
|
public void testFindByCargoId() {
|
|
|
@@ -41,18 +42,17 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
41
|
42
|
assertEquals(HONGKONG, cargo.origin());
|
|
42
|
43
|
assertEquals(HELSINKI, cargo.destination());
|
|
43
|
44
|
|
|
44
|
|
- DeliveryHistory dh = cargo.deliveryHistory();
|
|
|
45
|
+ Delivery dh = cargo.deliveryHistory();
|
|
45
|
46
|
assertNotNull(dh);
|
|
46
|
47
|
|
|
47
|
|
- List<HandlingEvent> events = dh.eventsOrderedByCompletionTime();
|
|
|
48
|
+ List<HandlingEvent> events = dh.history();
|
|
48
|
49
|
assertEquals(2, events.size());
|
|
49
|
50
|
|
|
50
|
51
|
HandlingEvent firstEvent = events.get(0);
|
|
51
|
|
- assertHandlingEvent(cargo, firstEvent, RECEIVE, HONGKONG, 100, 160, CarrierMovement.NONE);
|
|
|
52
|
+ assertHandlingEvent(cargo, firstEvent, RECEIVE, HONGKONG, 100, 160, Voyage.NONE);
|
|
52
|
53
|
|
|
53
|
54
|
HandlingEvent secondEvent = events.get(1);
|
|
54
|
|
- CarrierMovement expectedCm = new CarrierMovement(new CarrierMovementId("CAR_010"), HONGKONG, MELBOURNE, new Date(), new Date());
|
|
55
|
|
- assertHandlingEvent(cargo, secondEvent, LOAD, HONGKONG, 150, 110, expectedCm);
|
|
|
55
|
+ assertHandlingEvent(cargo, secondEvent, LOAD, HONGKONG, 150, 110, SampleVoyages.CM001);
|
|
56
|
56
|
|
|
57
|
57
|
List<Leg> legs = cargo.itinerary().legs();
|
|
58
|
58
|
assertEquals(3, legs.size());
|
|
|
@@ -67,7 +67,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
67
|
67
|
assertLeg(thirdLeg, "CAR_011", STOCKHOLM, HELSINKI);
|
|
68
|
68
|
}
|
|
69
|
69
|
|
|
70
|
|
- private void assertHandlingEvent(Cargo cargo, HandlingEvent event, HandlingEvent.Type expectedEventType, Location expectedLocation, int completionTimeMs, int registrationTimeMs, CarrierMovement expectedCarrierMovement) {
|
|
|
70
|
+ private void assertHandlingEvent(Cargo cargo, HandlingEvent event, HandlingEvent.Type expectedEventType, Location expectedLocation, int completionTimeMs, int registrationTimeMs, Voyage voyage) {
|
|
71
|
71
|
assertEquals(expectedEventType, event.type());
|
|
72
|
72
|
assertEquals(expectedLocation, event.location());
|
|
73
|
73
|
|
|
|
@@ -77,7 +77,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
77
|
77
|
Date expectedRegistrationTime = SampleDataGenerator.offset(registrationTimeMs);
|
|
78
|
78
|
assertEquals(expectedRegistrationTime, event.registrationTime());
|
|
79
|
79
|
|
|
80
|
|
- assertEquals(expectedCarrierMovement, event.carrierMovement());
|
|
|
80
|
+ assertEquals(voyage, event.voyage());
|
|
81
|
81
|
assertEquals(cargo, event.cargo());
|
|
82
|
82
|
}
|
|
83
|
83
|
|
|
|
@@ -85,10 +85,10 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
85
|
85
|
assertNull(cargoRepository.find(new TrackingId("UNKNOWN")));
|
|
86
|
86
|
}
|
|
87
|
87
|
|
|
88
|
|
- private void assertLeg(Leg firstLeg, String cmId, Location expectedFrom, Location expectedTo) {
|
|
89
|
|
- assertEquals(new CarrierMovementId(cmId), firstLeg.carrierMovement().carrierMovementId());
|
|
90
|
|
- assertEquals(expectedFrom, firstLeg.from());
|
|
91
|
|
- assertEquals(expectedTo, firstLeg.to());
|
|
|
88
|
+ private void assertLeg(Leg firstLeg, String vn, Location expectedFrom, Location expectedTo) {
|
|
|
89
|
+ assertEquals(new VoyageNumber(vn), firstLeg.voyage().voyageNumber());
|
|
|
90
|
+ assertEquals(expectedFrom, firstLeg.loadLocation());
|
|
|
91
|
+ assertEquals(expectedTo, firstLeg.unloadLocation());
|
|
92
|
92
|
}
|
|
93
|
93
|
|
|
94
|
94
|
public void testSave() {
|
|
|
@@ -120,10 +120,9 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
120
|
120
|
Long oldItineraryId = getLongId(cargo.itinerary());
|
|
121
|
121
|
assertEquals(1, sjt.queryForInt("select count(*) from Itinerary where id = ?", oldItineraryId));
|
|
122
|
122
|
|
|
123
|
|
- CarrierMovement cm = carrierMovementRepository.find(new CarrierMovementId("CAR_006"));
|
|
124
|
123
|
Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
|
|
125
|
124
|
Location legTo = locationRepository.find(new UnLocode("DEHAM"));
|
|
126
|
|
- Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(cm, legFrom, legTo)));
|
|
|
125
|
+ Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(SampleVoyages.CM004, legFrom, legTo, new Date(), new Date())));
|
|
127
|
126
|
|
|
128
|
127
|
cargo.assignToRoute(newItinerary);
|
|
129
|
128
|
|
|
|
@@ -141,15 +140,15 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
141
|
140
|
|
|
142
|
141
|
public void testSaveShouldNotCascadeToHandlingEvents() {
|
|
143
|
142
|
Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
|
|
144
|
|
- int eventCount = cargo.deliveryHistory().eventsOrderedByCompletionTime().size();
|
|
|
143
|
+ int eventCount = cargo.deliveryHistory().history().size();
|
|
145
|
144
|
|
|
146
|
145
|
Location origin = locationRepository.find(STOCKHOLM.unLocode());
|
|
147
|
146
|
|
|
148
|
147
|
HandlingEvent event = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.RECEIVE, origin);
|
|
149
|
|
- assertFalse(cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event));
|
|
|
148
|
+ assertFalse(cargo.deliveryHistory().history().contains(event));
|
|
150
|
149
|
|
|
151
|
150
|
CargoTestHelper.setDeliveryHistory(cargo, Arrays.asList(event));
|
|
152
|
|
- assertTrue(cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event));
|
|
|
151
|
+ assertTrue(cargo.deliveryHistory().history().contains(event));
|
|
153
|
152
|
|
|
154
|
153
|
// Save cargo, evict from session and then re-load it - should not pick up the added event,
|
|
155
|
154
|
// as it was never cascade-saved
|
|
|
@@ -157,8 +156,8 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
|
|
157
|
156
|
getSession().evict(cargo);
|
|
158
|
157
|
|
|
159
|
158
|
cargo = cargoRepository.find(cargo.trackingId());
|
|
160
|
|
- assertFalse(cargo.deliveryHistory().eventsOrderedByCompletionTime().contains(event));
|
|
161
|
|
- assertEquals(eventCount, cargo.deliveryHistory().eventsOrderedByCompletionTime().size());
|
|
|
159
|
+ assertFalse(cargo.deliveryHistory().history().contains(event));
|
|
|
160
|
+ assertEquals(eventCount, cargo.deliveryHistory().history().size());
|
|
162
|
161
|
}
|
|
163
|
162
|
|
|
164
|
163
|
public void testFindAll() {
|