Przeglądaj źródła

Use Leg static factory method that derives times from voyage

peter_backlund 17 lat temu
rodzic
commit
7267f6937f

+ 1
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/booking/facade/DTOAssembler.java Wyświetl plik

@@ -92,7 +92,7 @@ final class DTOAssembler {
92 92
       final Voyage voyage = voyageRepository.find(voyageNumber);
93 93
       final Location from = locationRepository.find(new UnLocode(legDTO.getFrom()));
94 94
       final Location to = locationRepository.find(new UnLocode(legDTO.getTo()));
95
-      legs.add(new Leg(voyage, from, to, legDTO.getLoadTime(), legDTO.getUnloadTime()));
95
+      legs.add(Leg.deriveLeg(voyage, from, to));
96 96
     }
97 97
     return new Itinerary(legs);
98 98
   }

+ 16
- 28
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/interfaces/booking/facade/DTOAssemblerTest.java Wyświetl plik

@@ -1,30 +1,24 @@
1 1
 package se.citerus.dddsample.tracking.core.interfaces.booking.facade;
2 2
 
3
+import static org.junit.Assert.*;
4
+import org.junit.Test;
5
+import se.citerus.dddsample.tracking.booking.api.CargoRoutingDTO;
6
+import se.citerus.dddsample.tracking.booking.api.LegDTO;
7
+import se.citerus.dddsample.tracking.booking.api.LocationDTO;
8
+import se.citerus.dddsample.tracking.booking.api.RouteCandidateDTO;
9
+import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
3 10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
4 11
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
5
-import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
6 12
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
7
-import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.STOCKHOLM;
8
-import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.MELBOURNE;
9
-import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
10 13
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM001;
11 14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
15
+import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.LocationRepositoryInMem;
12 16
 import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
13
-import se.citerus.dddsample.tracking.booking.api.LegDTO;
14
-import se.citerus.dddsample.tracking.booking.api.CargoRoutingDTO;
15
-import se.citerus.dddsample.tracking.booking.api.LocationDTO;
16
-import se.citerus.dddsample.tracking.booking.api.*;
17 17
 
18
-import java.util.Date;
18
+import java.util.ArrayList;
19 19
 import java.util.Arrays;
20
+import java.util.Date;
20 21
 import java.util.List;
21
-import java.util.ArrayList;
22
-
23
-import static org.junit.Assert.*;
24
-import org.junit.Test;
25
-import static org.easymock.EasyMock.createMock;
26
-import static org.easymock.EasyMock.expect;
27
-import static org.easymock.EasyMock.replay;
28 22
 
29 23
 public class DTOAssemblerTest {
30 24
 
@@ -96,20 +90,14 @@ public class DTOAssemblerTest {
96 90
   }
97 91
 
98 92
   @Test
99
-  public void formRouteCandidateDTO() throws Exception {
93
+  public void fromRouteCandidateDTO() throws Exception {
100 94
     final List<LegDTO> legs = new ArrayList<LegDTO>();
101
-    legs.add(new LegDTO("CM001", "AAAAA", "BBBBB", new Date(), new Date()));
102
-    legs.add(new LegDTO("CM001", "BBBBB", "CCCCC", new Date(), new Date()));
103
-
104
-    final LocationRepository locationRepository = createMock(LocationRepository.class);
105
-    expect(locationRepository.find(new UnLocode("AAAAA"))).andReturn(HONGKONG);
106
-    expect(locationRepository.find(new UnLocode("BBBBB"))).andReturn(TOKYO).times(2);
107
-    expect(locationRepository.find(new UnLocode("CCCCC"))).andReturn(CHICAGO);
95
+    legs.add(new LegDTO("CM003", "CNHKG", "USNYC", new Date(), new Date()));
96
+    legs.add(new LegDTO("CM004", "USNYC", "USCHI", new Date(), new Date()));
108 97
 
98
+    final LocationRepository locationRepository = new LocationRepositoryInMem();
109 99
     final VoyageRepository voyageRepository = new VoyageRepositoryInMem();
110 100
 
111
-    replay(locationRepository);
112
-
113 101
 
114 102
     // Tested call
115 103
     final Itinerary itinerary = DTOAssembler.fromDTO(new RouteCandidateDTO(legs), voyageRepository, locationRepository);
@@ -122,11 +110,11 @@ public class DTOAssemblerTest {
122 110
     final Leg leg1 = itinerary.legs().get(0);
123 111
     assertNotNull(leg1);
124 112
     assertEquals(HONGKONG, leg1.loadLocation());
125
-    assertEquals(TOKYO, leg1.unloadLocation());
113
+    assertEquals(NEWYORK, leg1.unloadLocation());
126 114
 
127 115
     final Leg leg2 = itinerary.legs().get(1);
128 116
     assertNotNull(leg2);
129
-    assertEquals(TOKYO, leg2.loadLocation());
117
+    assertEquals(NEWYORK, leg2.loadLocation());
130 118
     assertEquals(CHICAGO, leg2.unloadLocation());
131 119
   }
132 120