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

Introduced Voyage, Schedule and VoyageNumber. CarrierMovement is now a value object, CarrierMovementId is dropped.

Leg now has load/unload location and time, and a reference to a Voyage.

HandlingEvent references a Voyage instead of a CarrierMovement.

DeliveryHistory is renamed to Delivery.

(Yes, it's very broken right now, but it compiles)
peter_backlund 18 лет назад
Родитель
Сommit
d024d9c1cb

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

@@ -1,12 +1,12 @@
1 1
 package se.citerus.dddsample;
2 2
 
3 3
 import junit.framework.TestCase;
4
-import se.citerus.dddsample.application.persistence.CarrierMovementRepositoryInMem;
5 4
 import se.citerus.dddsample.application.persistence.LocationRepositoryInMem;
5
+import se.citerus.dddsample.application.persistence.VoyageRepositoryInMem;
6 6
 import se.citerus.dddsample.domain.model.cargo.*;
7 7
 import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
8
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
9
-import static se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements.*;
8
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.*;
9
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
10 10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
11 11
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
12 12
 import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
@@ -38,7 +38,7 @@ public class CargoHandlingScenarioTest extends TestCase {
38 38
   HandlingEventRepository handlingEventRepository;
39 39
   CargoRepository cargoRepository;
40 40
   LocationRepository locationRepository;
41
-  CarrierMovementRepository carrierMovementRepository;
41
+  VoyageRepository voyageRepository;
42 42
 
43 43
   Cargo cargo;
44 44
 
@@ -66,12 +66,12 @@ public class CargoHandlingScenarioTest extends TestCase {
66 66
 
67 67
     // Loaded onto carrier movement CM003 in Hongkong
68 68
     HandlingEvent loadedInHongkong = handlingEventFactory.createHandlingEvent(
69
-      dateLoadingCompleted(), trackingId, CM003.carrierMovementId(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD);
69
+      dateLoadingCompleted(), trackingId, CM003.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD);
70 70
 
71 71
     handlingEventService.register(loadedInHongkong);
72 72
 
73 73
     // Check current state - should be ok
74
-    assertEquals(CM003, cargo. deliveryHistory().currentCarrierMovement());
74
+    assertEquals(CM003, cargo. deliveryHistory().currentVoyage());
75 75
     assertEquals(HONGKONG, cargo.lastKnownLocation());
76 76
     assertEquals(StatusCode.ONBOARD_CARRIER, cargo.deliveryHistory().status());
77 77
     assertFalse(cargo.isMisdirected());
@@ -79,11 +79,11 @@ public class CargoHandlingScenarioTest extends TestCase {
79 79
 
80 80
     // Cargo is now (incorrectly) unloaded in Tokyo
81 81
     HandlingEvent unloadedInTokyo = handlingEventFactory.createHandlingEvent(
82
-      dateUnloadingCompleted(), trackingId, CM003.carrierMovementId(), TOKYO.unLocode(), HandlingEvent.Type.UNLOAD);
82
+      dateUnloadingCompleted(), trackingId, CM003.voyageNumber(), TOKYO.unLocode(), HandlingEvent.Type.UNLOAD);
83 83
     handlingEventService.register(unloadedInTokyo);
84 84
 
85 85
     // Check current state - cargo is misdirected!
86
-    assertEquals(CarrierMovement.NONE, cargo. deliveryHistory().currentCarrierMovement());
86
+    assertEquals(CarrierMovement.NONE, cargo. deliveryHistory().currentVoyage());
87 87
     assertEquals(TOKYO, cargo.lastKnownLocation());
88 88
     assertEquals(StatusCode.IN_PORT, cargo.deliveryHistory().status());
89 89
     assertTrue(cargo.isMisdirected());
@@ -128,9 +128,9 @@ public class CargoHandlingScenarioTest extends TestCase {
128 128
       public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
129 129
         return Arrays.asList(
130 130
           new Itinerary(Arrays.asList(
131
-                new Leg(CM003, HONGKONG, NEWYORK),
132
-                new Leg(CM004, NEWYORK, CHICAGO),
133
-                new Leg(CM005, CHICAGO, STOCKHOLM)
131
+                new Leg(CM003, HONGKONG, NEWYORK, new Date(), new Date()),
132
+                new Leg(CM004, NEWYORK, CHICAGO, new Date(), new Date()),
133
+                new Leg(CM005, CHICAGO, STOCKHOLM, new Date(), new Date())
134 134
           ))
135 135
         );
136 136
       }
@@ -164,7 +164,7 @@ public class CargoHandlingScenarioTest extends TestCase {
164 164
     // Stub
165 165
     handlingEventRepository = new HandlingEventRepository() {
166 166
       public void save(HandlingEvent event) {
167
-        Set<HandlingEvent> events = new HashSet<HandlingEvent>(cargo.deliveryHistory().eventsOrderedByCompletionTime());
167
+        Set<HandlingEvent> events = new HashSet<HandlingEvent>(cargo.deliveryHistory().history());
168 168
         events.add(event);
169 169
         CargoTestHelper.setDeliveryHistory(cargo, events);
170 170
       }
@@ -176,11 +176,11 @@ public class CargoHandlingScenarioTest extends TestCase {
176 176
 
177 177
     // In-memory implementations
178 178
     locationRepository = new LocationRepositoryInMem();
179
-    carrierMovementRepository = new CarrierMovementRepositoryInMem();
179
+    voyageRepository = new VoyageRepositoryInMem();
180 180
 
181 181
     // Domain services and factories that are implemented in the domain layer - not stubbed
182
-    trackingService = new TrackingServiceImpl(cargoRepository);
183
-    handlingEventFactory = new HandlingEventFactory(cargoRepository, this.carrierMovementRepository, this.locationRepository);
182
+    trackingService = new TrackingServiceImpl(domainEventNotifier, cargoRepository);
183
+    handlingEventFactory = new HandlingEventFactory(cargoRepository, this.voyageRepository, this.locationRepository);
184 184
     handlingEventService = new HandlingEventServiceImpl(handlingEventRepository, domainEventNotifier);
185 185
   }
186 186
 }

+ 9
- 9
dddsample/src/test/java/se/citerus/dddsample/ui/CargoTrackingViewAdapterTest.java Просмотреть файл

@@ -5,10 +5,11 @@ import org.springframework.context.support.StaticApplicationContext;
5 5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
6 6
 import se.citerus.dddsample.domain.model.cargo.CargoTestHelper;
7 7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
9
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
8
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM001;
9
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM002;
10 10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
11
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
11
+import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
12
+import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
12 13
 
13 14
 import java.util.*;
14 15
 
@@ -20,9 +21,8 @@ public class CargoTrackingViewAdapterTest extends TestCase {
20 21
     List<HandlingEvent> events = new ArrayList<HandlingEvent>();
21 22
     events.add(new HandlingEvent(cargo, new Date(1), new Date(2), HandlingEvent.Type.RECEIVE, HANGZOU));
22 23
 
23
-    CarrierMovement cm001 = new CarrierMovement(new CarrierMovementId("CM001"), HANGZOU, GOTHENBURG, new Date(), new Date());
24
-    events.add(new HandlingEvent(cargo, new Date(3), new Date(4), HandlingEvent.Type.LOAD, HANGZOU, cm001));
25
-    events.add(new HandlingEvent(cargo, new Date(5), new Date(6), HandlingEvent.Type.UNLOAD, HELSINKI, cm001));
24
+    events.add(new HandlingEvent(cargo, new Date(3), new Date(4), HandlingEvent.Type.LOAD, HANGZOU, CM001));
25
+    events.add(new HandlingEvent(cargo, new Date(5), new Date(6), HandlingEvent.Type.UNLOAD, HELSINKI, CM002));
26 26
 
27 27
     CargoTestHelper.setDeliveryHistory(cargo, events);
28 28
 
@@ -43,21 +43,21 @@ public class CargoTrackingViewAdapterTest extends TestCase {
43 43
     assertEquals("RECEIVE", event.getType());
44 44
     assertEquals("CNHGH", event.getLocation());
45 45
     assertEquals("1970-01-01 01:00", event.getTime());
46
-    assertEquals("", event.getCarrierMovement());
46
+    assertEquals("", event.getVoyageNumber());
47 47
     assertTrue(event.isExpected());
48 48
 
49 49
     event = it.next();
50 50
     assertEquals("LOAD", event.getType());
51 51
     assertEquals("CNHGH", event.getLocation());
52 52
     assertEquals("1970-01-01 01:00", event.getTime());
53
-    assertEquals("CM001", event.getCarrierMovement());
53
+    assertEquals("CM001", event.getVoyageNumber());
54 54
     assertTrue(event.isExpected());
55 55
 
56 56
     event = it.next();
57 57
     assertEquals("UNLOAD", event.getType());
58 58
     assertEquals("FIHEL", event.getLocation());
59 59
     assertEquals("1970-01-01 01:00", event.getTime());
60
-    assertEquals("CM001", event.getCarrierMovement());
60
+    assertEquals("CM001", event.getVoyageNumber());
61 61
     assertTrue(event.isExpected());
62 62
   }
63 63