Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
d024d9c1cb

+ 15
- 15
dddsample/src/test/java/se/citerus/dddsample/CargoHandlingScenarioTest.java Dosyayı Görüntüle

1
 package se.citerus.dddsample;
1
 package se.citerus.dddsample;
2
 
2
 
3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
-import se.citerus.dddsample.application.persistence.CarrierMovementRepositoryInMem;
5
 import se.citerus.dddsample.application.persistence.LocationRepositoryInMem;
4
 import se.citerus.dddsample.application.persistence.LocationRepositoryInMem;
5
+import se.citerus.dddsample.application.persistence.VoyageRepositoryInMem;
6
 import se.citerus.dddsample.domain.model.cargo.*;
6
 import se.citerus.dddsample.domain.model.cargo.*;
7
 import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
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
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
11
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
11
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
12
 import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
12
 import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
38
   HandlingEventRepository handlingEventRepository;
38
   HandlingEventRepository handlingEventRepository;
39
   CargoRepository cargoRepository;
39
   CargoRepository cargoRepository;
40
   LocationRepository locationRepository;
40
   LocationRepository locationRepository;
41
-  CarrierMovementRepository carrierMovementRepository;
41
+  VoyageRepository voyageRepository;
42
 
42
 
43
   Cargo cargo;
43
   Cargo cargo;
44
 
44
 
66
 
66
 
67
     // Loaded onto carrier movement CM003 in Hongkong
67
     // Loaded onto carrier movement CM003 in Hongkong
68
     HandlingEvent loadedInHongkong = handlingEventFactory.createHandlingEvent(
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
     handlingEventService.register(loadedInHongkong);
71
     handlingEventService.register(loadedInHongkong);
72
 
72
 
73
     // Check current state - should be ok
73
     // Check current state - should be ok
74
-    assertEquals(CM003, cargo. deliveryHistory().currentCarrierMovement());
74
+    assertEquals(CM003, cargo. deliveryHistory().currentVoyage());
75
     assertEquals(HONGKONG, cargo.lastKnownLocation());
75
     assertEquals(HONGKONG, cargo.lastKnownLocation());
76
     assertEquals(StatusCode.ONBOARD_CARRIER, cargo.deliveryHistory().status());
76
     assertEquals(StatusCode.ONBOARD_CARRIER, cargo.deliveryHistory().status());
77
     assertFalse(cargo.isMisdirected());
77
     assertFalse(cargo.isMisdirected());
79
 
79
 
80
     // Cargo is now (incorrectly) unloaded in Tokyo
80
     // Cargo is now (incorrectly) unloaded in Tokyo
81
     HandlingEvent unloadedInTokyo = handlingEventFactory.createHandlingEvent(
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
     handlingEventService.register(unloadedInTokyo);
83
     handlingEventService.register(unloadedInTokyo);
84
 
84
 
85
     // Check current state - cargo is misdirected!
85
     // Check current state - cargo is misdirected!
86
-    assertEquals(CarrierMovement.NONE, cargo. deliveryHistory().currentCarrierMovement());
86
+    assertEquals(CarrierMovement.NONE, cargo. deliveryHistory().currentVoyage());
87
     assertEquals(TOKYO, cargo.lastKnownLocation());
87
     assertEquals(TOKYO, cargo.lastKnownLocation());
88
     assertEquals(StatusCode.IN_PORT, cargo.deliveryHistory().status());
88
     assertEquals(StatusCode.IN_PORT, cargo.deliveryHistory().status());
89
     assertTrue(cargo.isMisdirected());
89
     assertTrue(cargo.isMisdirected());
128
       public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
128
       public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
129
         return Arrays.asList(
129
         return Arrays.asList(
130
           new Itinerary(Arrays.asList(
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
     // Stub
164
     // Stub
165
     handlingEventRepository = new HandlingEventRepository() {
165
     handlingEventRepository = new HandlingEventRepository() {
166
       public void save(HandlingEvent event) {
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
         events.add(event);
168
         events.add(event);
169
         CargoTestHelper.setDeliveryHistory(cargo, events);
169
         CargoTestHelper.setDeliveryHistory(cargo, events);
170
       }
170
       }
176
 
176
 
177
     // In-memory implementations
177
     // In-memory implementations
178
     locationRepository = new LocationRepositoryInMem();
178
     locationRepository = new LocationRepositoryInMem();
179
-    carrierMovementRepository = new CarrierMovementRepositoryInMem();
179
+    voyageRepository = new VoyageRepositoryInMem();
180
 
180
 
181
     // Domain services and factories that are implemented in the domain layer - not stubbed
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
     handlingEventService = new HandlingEventServiceImpl(handlingEventRepository, domainEventNotifier);
184
     handlingEventService = new HandlingEventServiceImpl(handlingEventRepository, domainEventNotifier);
185
   }
185
   }
186
 }
186
 }

+ 9
- 9
dddsample/src/test/java/se/citerus/dddsample/ui/CargoTrackingViewAdapterTest.java Dosyayı Görüntüle

5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
6
 import se.citerus.dddsample.domain.model.cargo.CargoTestHelper;
6
 import se.citerus.dddsample.domain.model.cargo.CargoTestHelper;
7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
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
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
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
 import java.util.*;
14
 import java.util.*;
14
 
15
 
20
     List<HandlingEvent> events = new ArrayList<HandlingEvent>();
21
     List<HandlingEvent> events = new ArrayList<HandlingEvent>();
21
     events.add(new HandlingEvent(cargo, new Date(1), new Date(2), HandlingEvent.Type.RECEIVE, HANGZOU));
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
     CargoTestHelper.setDeliveryHistory(cargo, events);
27
     CargoTestHelper.setDeliveryHistory(cargo, events);
28
 
28
 
43
     assertEquals("RECEIVE", event.getType());
43
     assertEquals("RECEIVE", event.getType());
44
     assertEquals("CNHGH", event.getLocation());
44
     assertEquals("CNHGH", event.getLocation());
45
     assertEquals("1970-01-01 01:00", event.getTime());
45
     assertEquals("1970-01-01 01:00", event.getTime());
46
-    assertEquals("", event.getCarrierMovement());
46
+    assertEquals("", event.getVoyageNumber());
47
     assertTrue(event.isExpected());
47
     assertTrue(event.isExpected());
48
 
48
 
49
     event = it.next();
49
     event = it.next();
50
     assertEquals("LOAD", event.getType());
50
     assertEquals("LOAD", event.getType());
51
     assertEquals("CNHGH", event.getLocation());
51
     assertEquals("CNHGH", event.getLocation());
52
     assertEquals("1970-01-01 01:00", event.getTime());
52
     assertEquals("1970-01-01 01:00", event.getTime());
53
-    assertEquals("CM001", event.getCarrierMovement());
53
+    assertEquals("CM001", event.getVoyageNumber());
54
     assertTrue(event.isExpected());
54
     assertTrue(event.isExpected());
55
 
55
 
56
     event = it.next();
56
     event = it.next();
57
     assertEquals("UNLOAD", event.getType());
57
     assertEquals("UNLOAD", event.getType());
58
     assertEquals("FIHEL", event.getLocation());
58
     assertEquals("FIHEL", event.getLocation());
59
     assertEquals("1970-01-01 01:00", event.getTime());
59
     assertEquals("1970-01-01 01:00", event.getTime());
60
-    assertEquals("CM001", event.getCarrierMovement());
60
+    assertEquals("CM001", event.getVoyageNumber());
61
     assertTrue(event.isExpected());
61
     assertTrue(event.isExpected());
62
   }
62
   }
63
 
63