Просмотр исходного кода

Added Location to HandlingEvent c-tor

jorgen_falk 18 лет назад
Родитель
Сommit
e9b47376b6

+ 7
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java Просмотреть файл

@@ -69,6 +69,13 @@ public class Cargo {
69 69
    */
70 70
   public Location lastKnownLocation() {
71 71
     HandlingEvent lastEvent = deliveryHistory.lastEvent();
72
+    
73
+    if (lastEvent == null) {
74
+      return Location.UNKNOWN;
75
+    }
76
+    
77
+    
78
+    
72 79
     if (lastEvent != null) {
73 80
       return lastEvent.location();
74 81
     } else {

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java Просмотреть файл

@@ -73,7 +73,7 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository{
73 73
 
74 74
   
75 75
   private void registerEvent(Cargo cargo, String date, Type type, CarrierMovement carrierMovement) throws ParseException{
76
-    HandlingEvent event = new HandlingEvent(cargo, getDate(date), new Date(), type, carrierMovement);
76
+    HandlingEvent event = new HandlingEvent(cargo, getDate(date), new Date(), type, null, carrierMovement);
77 77
     //cargo.handle(event);
78 78
     String id = cargo.trackingId() + "_" + type + "_" + date;
79 79
     

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java Просмотреть файл

@@ -22,7 +22,7 @@ public class HandlingEventServiceImpl implements HandlingEventService {
22 22
     Date registrationTime = new Date();
23 23
     HandlingEvent event;
24 24
     if (carrierMovement != null) {
25
-      event = new HandlingEvent(cargo, completionTime, registrationTime, type, carrierMovement);
25
+      event = new HandlingEvent(cargo, completionTime, registrationTime, type, location, carrierMovement);
26 26
     } else {
27 27
       event = new HandlingEvent(cargo, completionTime, registrationTime, type, location);
28 28
     }

+ 18
- 18
dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java Просмотреть файл

@@ -94,14 +94,14 @@ public class CargoTest extends TestCase {
94 94
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
95 95
             new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
96 96
 
97
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
98
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
97
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
98
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
99 99
 
100 100
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
101 101
             new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
102 102
 
103
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
104
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
103
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
104
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
105 105
 
106 106
     return cargo;
107 107
   }
@@ -112,13 +112,13 @@ public class CargoTest extends TestCase {
112 112
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
113 113
             new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
114 114
 
115
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
116
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
115
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
116
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
117 117
 
118 118
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
119 119
             new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
120 120
 
121
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
121
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
122 122
 
123 123
     return cargo;
124 124
   }
@@ -129,20 +129,20 @@ public class CargoTest extends TestCase {
129 129
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
130 130
             new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
131 131
 
132
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
133
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
132
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
133
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
134 134
 
135 135
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
136 136
             new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
137 137
 
138
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
139
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
138
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
139
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
140 140
 
141 141
     final CarrierMovement hongKongToMelbourne = new CarrierMovement(
142 142
             new CarrierMovementId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
143 143
 
144
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongKongToMelbourne));
145
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, hongKongToMelbourne));
144
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, new Location("CNHGK"), hongKongToMelbourne));
145
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, new Location("AUMEL"), hongKongToMelbourne));
146 146
 
147 147
     return cargo;
148 148
   }
@@ -153,19 +153,19 @@ public class CargoTest extends TestCase {
153 153
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
154 154
             new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
155 155
 
156
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
157
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
156
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
157
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
158 158
 
159 159
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
160 160
             new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
161 161
 
162
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
163
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
162
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
163
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
164 164
 
165 165
     final CarrierMovement hongKongToMelbourne = new CarrierMovement(
166 166
             new CarrierMovementId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
167 167
 
168
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongKongToMelbourne));
168
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, new Location("CNHGK"), hongKongToMelbourne));
169 169
 
170 170
     return cargo;
171 171
   }

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/domain/DeliveryHistoryTest.java Просмотреть файл

@@ -16,9 +16,9 @@ public class DeliveryHistoryTest extends TestCase {
16 16
     DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
17 17
     CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), new Location("FROM"), new Location("TO"));
18 18
     HandlingEvent he1 = new HandlingEvent(null, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, new Location("TO"));
19
-    HandlingEvent he2 = new HandlingEvent(null, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, carrierMovement);
19
+    HandlingEvent he2 = new HandlingEvent(null, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, new Location("TO"), carrierMovement);
20 20
     HandlingEvent he3 = new HandlingEvent(null, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, new Location("FROM"));
21
-    HandlingEvent he4 = new HandlingEvent(null, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, carrierMovement);
21
+    HandlingEvent he4 = new HandlingEvent(null, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("FROM"), carrierMovement);
22 22
     dh.addEvent(he1, he2, he3, he4);
23 23
 
24 24
     List<HandlingEvent> orderEvents = dh.eventsOrderedByCompletionTime();

+ 7
- 7
dddsample/src/test/java/se/citerus/dddsample/domain/HandlingEventTest.java Просмотреть файл

@@ -15,15 +15,15 @@ public class HandlingEventTest extends TestCase {
15 15
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, finalDestination);
16 16
     CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("C01"), origin, finalDestination);
17 17
 
18
-    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, carrierMovement);
18
+    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, origin, carrierMovement);
19 19
     assertEquals(origin, e1.location());
20 20
 
21
-    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, carrierMovement);
21
+    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, finalDestination, carrierMovement);
22 22
     assertEquals(finalDestination, e2.location());
23 23
     
24 24
     for (Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
25 25
       try {
26
-        new HandlingEvent(cargo, new Date(), new Date(), type, carrierMovement);
26
+        new HandlingEvent(cargo, new Date(), new Date(), type, origin, carrierMovement);
27 27
         fail("Handling event with carrier movement and type " + type + " is not legal");
28 28
       } catch (IllegalArgumentException expected) {}
29 29
     }
@@ -47,7 +47,7 @@ public class HandlingEventTest extends TestCase {
47 47
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
48 48
     CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
49 49
     
50
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), LOAD, cm);
50
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), LOAD, locationAAA, cm);
51 51
     
52 52
     assertEquals(locationAAA, ev.location());
53 53
   }
@@ -58,7 +58,7 @@ public class HandlingEventTest extends TestCase {
58 58
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
59 59
     CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
60 60
     
61
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), UNLOAD, cm);
61
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), UNLOAD, locationBBB, cm);
62 62
     
63 63
     assertEquals(locationBBB, ev.location());
64 64
   }
@@ -98,8 +98,8 @@ public class HandlingEventTest extends TestCase {
98 98
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
99 99
     CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
100 100
 
101
-    HandlingEvent ev1 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, cm);
102
-    HandlingEvent ev2 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, cm);
101
+    HandlingEvent ev1 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, locationAAA, cm);
102
+    HandlingEvent ev2 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, locationAAA, cm);
103 103
 
104 104
     // Two handling events are not equal() even if all non-uuid fields are identical
105 105
     assertTrue(ev1.equals(ev2));

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java Просмотреть файл

@@ -35,10 +35,10 @@ public class TrackingScenarioTest extends TestCase {
35 35
             new CarrierMovementId("CAR_002"), new Location("DEHAM"), new Location("CNHKG"));
36 36
     DeliveryHistory dh = new DeliveryHistory();
37 37
     dh.addEvent(
38
-            new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg),
39
-            new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg),
40
-            new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong),
41
-            new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong)
38
+            new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg),
39
+            new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg),
40
+            new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong),
41
+            new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHKG"), hamburgToHongKong)
42 42
     );
43 43
     return dh;
44 44
   }

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java Просмотреть файл

@@ -78,8 +78,8 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
78 78
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("ORIG"), new Location("DEST"));
79 79
     HandlingEvent claimed = new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.CLAIM, new Location("SESTO"));
80 80
     CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("MUGER"));
81
-    HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, carrierMovement);
82
-    HandlingEvent unloaded = new HandlingEvent(cargo, new Date(100), new Date(110), HandlingEvent.Type.UNLOAD, carrierMovement);
81
+    HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, new Location("SESTO"), carrierMovement);
82
+    HandlingEvent unloaded = new HandlingEvent(cargo, new Date(100), new Date(110), HandlingEvent.Type.UNLOAD, new Location("MUGER"), carrierMovement);
83 83
     // Add out of order to verify ordering in DTO
84 84
     cargo.deliveryHistory().addEvent(loaded, unloaded, claimed);
85 85