Quellcode durchsuchen

Brought tests up to speed with code changes.

peter_backlund vor 18 Jahren
Ursprung
Commit
fbcada7479

+ 1
- 1
dddsample/pom.xml Datei anzeigen

@@ -128,7 +128,7 @@
128 128
           </execution>
129 129
         </executions>
130 130
         <configuration>
131
-          <sei>se.citerus.dddsample.interfaces.handling.HandlingEventServiceEndpointImpl</sei>
131
+          <sei>se.citerus.dddsample.interfaces.handling.ws.HandlingReportServiceImpl</sei>
132 132
           <genWsdl>true</genWsdl>
133 133
         </configuration>
134 134
       </plugin>

+ 3
- 2
dddsample/src/test/java/se/citerus/dddsample/application/HandlingEventServiceTest.java Datei anzeigen

@@ -5,6 +5,7 @@ import static org.easymock.EasyMock.*;
5 5
 import se.citerus.dddsample.application.impl.HandlingEventServiceImpl;
6 6
 import se.citerus.dddsample.domain.model.cargo.Cargo;
7 7
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
8
+import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
8 9
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
9 10
 import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
10 11
 import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
@@ -28,9 +29,9 @@ public class HandlingEventServiceTest extends TestCase {
28 29
   private LocationRepository locationRepository;
29 30
   private HandlingEventFactory handlingEventFactory;
30 31
 
31
-  private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), HAMBURG, TOKYO);
32
+  private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), new RouteSpecification(HAMBURG, TOKYO, new Date()));
32 33
 
33
-  private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), HONGKONG, HELSINKI);
34
+  private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, HELSINKI, new Date()));
34 35
 
35 36
   protected void setUp() throws Exception{
36 37
     cargoRepository = createMock(CargoRepository.class);

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/application/RoutingServiceTest.java Datei anzeigen

@@ -46,8 +46,8 @@ public class RoutingServiceTest extends TestCase {
46 46
 
47 47
   public void testCalculatePossibleRoutes() {
48 48
     TrackingId trackingId = new TrackingId("ABC");
49
-    Cargo cargo = new Cargo(trackingId, HONGKONG, HELSINKI);
50
-    RouteSpecification routeSpecification = new RouteSpecification(cargo.origin(), cargo.destination(), new Date());
49
+    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, new Date());
50
+    Cargo cargo = new Cargo(trackingId, routeSpecification);
51 51
 
52 52
     expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
53 53
     

+ 8
- 9
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java Datei anzeigen

@@ -2,8 +2,6 @@ package se.citerus.dddsample.domain.model.cargo;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
6
-import se.citerus.dddsample.domain.model.carrier.Schedule;
7 5
 import se.citerus.dddsample.domain.model.carrier.Voyage;
8 6
 import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
9 7
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
@@ -23,11 +21,11 @@ public class CargoTest extends TestCase {
23 21
   protected void setUp() throws Exception {
24 22
     events = new HashSet<HandlingEvent>();
25 23
 
26
-    voyage = new Voyage(new VoyageNumber("0123"), new Schedule(Arrays.asList(
27
-      new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date()),
28
-      new CarrierMovement(HAMBURG, HONGKONG, new Date(), new Date()),
29
-      new CarrierMovement(HONGKONG, MELBOURNE, new Date(), new Date())
30
-    )));
24
+    voyage = new Voyage.Builder(new VoyageNumber("0123"), STOCKHOLM).
25
+      addMovement(HAMBURG, new Date(), new Date()).
26
+      addMovement(HONGKONG, new Date(), new Date()).
27
+      addMovement(MELBOURNE, new Date(), new Date()).
28
+      build();
31 29
   }
32 30
 
33 31
   public void testRoutingStatus() throws Exception {
@@ -118,8 +116,9 @@ public class CargoTest extends TestCase {
118 116
     cargo.setDeliveryHistory(new Delivery(events));
119 117
     assertFalse(cargo.isUnloadedAtDestination());
120 118
 
121
-    CarrierMovement cm1 = new CarrierMovement(HANGZOU, NEWYORK, new Date(), new Date());
122
-    Voyage voyage = new Voyage(new VoyageNumber("0123"), new Schedule(Arrays.asList(cm1)));
119
+    Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
120
+      addMovement(NEWYORK, new Date(), new Date()).
121
+      build();
123 122
 
124 123
     // Adding an unload event, but not at the final destination
125 124
     events.add(

+ 12
- 9
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java Datei anzeigen

@@ -2,7 +2,6 @@ package se.citerus.dddsample.domain.model.cargo;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
5
-import se.citerus.dddsample.domain.model.carrier.Schedule;
6 5
 import se.citerus.dddsample.domain.model.carrier.Voyage;
7 6
 import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
8 7
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
@@ -22,18 +21,22 @@ public class ItineraryTest extends TestCase {
22 21
   Voyage voyage, wrongVoyage;
23 22
 
24 23
   protected void setUp() throws Exception {
25
-    voyage = new Voyage(new VoyageNumber("0123"), new Schedule(Arrays.asList(
26
-      abc, def, ghi, jkl
27
-    )));
28
-    wrongVoyage = new Voyage(new VoyageNumber("666"), new Schedule(Arrays.asList(
29
-      new CarrierMovement(NEWYORK, STOCKHOLM, new Date(), new Date()),
30
-      new CarrierMovement(STOCKHOLM, HELSINKI, new Date(), new Date())
31
-    )));
24
+    voyage = new Voyage.Builder(new VoyageNumber("0123"), SHANGHAI).
25
+      addMovement(ROTTERDAM, new Date(), new Date()).
26
+      addMovement(GOTHENBURG, new Date(), new Date()).
27
+      build();
28
+
29
+    wrongVoyage = new Voyage.Builder(new VoyageNumber("666"), NEWYORK).
30
+      addMovement(STOCKHOLM, new Date(), new Date()).
31
+      addMovement(HELSINKI, new Date(), new Date()).
32
+      build();
32 33
   }
33 34
 
34 35
   public void testCargoOnTrack() throws Exception {
35 36
 
36
-    Cargo cargo = new Cargo(new TrackingId("CARGO1"), SHANGHAI, GOTHENBURG);
37
+    TrackingId trackingId = new TrackingId("CARGO1");
38
+    RouteSpecification routeSpecification = new RouteSpecification(SHANGHAI, GOTHENBURG, new Date());
39
+    Cargo cargo = new Cargo(trackingId, routeSpecification);
37 40
 
38 41
     Itinerary itinerary = new Itinerary(
39 42
       Arrays.asList(

+ 2
- 8
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/RouteSpecificationTest.java Datei anzeigen

@@ -8,16 +8,10 @@ import java.util.Date;
8 8
 
9 9
 public class RouteSpecificationTest extends TestCase {
10 10
 
11
-  private Cargo cargo;
12
-
13
-  public void setUp() {
14
-    cargo = new Cargo(new TrackingId("AAA"), HONGKONG, CHICAGO);
15
-  }
16
-
17 11
   public void testIsSatisfiedBySuccess() {
18
-    RouteSpecification spec = new RouteSpecification(cargo.origin(), cargo.destination(), new Date());
12
+    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, CHICAGO, new Date());
19 13
     Itinerary itinerary = new Itinerary();
20
-    assertTrue(spec.isSatisfiedBy(itinerary));
14
+    assertTrue(routeSpecification.isSatisfiedBy(itinerary));
21 15
   }
22 16
 
23 17
   public void testIsSatisfiedByInvalidDate() {

+ 3
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java Datei anzeigen

@@ -4,6 +4,7 @@ import junit.framework.TestCase;
4 4
 import static org.easymock.EasyMock.*;
5 5
 import se.citerus.dddsample.domain.model.cargo.Cargo;
6 6
 import se.citerus.dddsample.domain.model.cargo.CargoRepository;
7
+import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
7 8
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8 9
 import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM001;
9 10
 import se.citerus.dddsample.domain.model.carrier.Voyage;
@@ -37,7 +38,8 @@ public class HandlingEventFactoryTest extends TestCase {
37 38
 
38 39
 
39 40
     trackingId = new TrackingId("ABC");
40
-    cargo = new Cargo(trackingId, TOKYO, HELSINKI);
41
+    RouteSpecification routeSpecification = new RouteSpecification(TOKYO, HELSINKI, new Date());
42
+    cargo = new Cargo(trackingId, routeSpecification);
41 43
   }
42 44
 
43 45
   public void testCreateHandlingEventWithCarrierMovement() throws Exception {

+ 8
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java Datei anzeigen

@@ -2,6 +2,7 @@ package se.citerus.dddsample.domain.model.handling;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.model.cargo.Cargo;
5
+import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
5 6
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
6 7
 import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
7 8
 import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM003;
@@ -13,7 +14,13 @@ import static java.util.Arrays.asList;
13 14
 import java.util.Date;
14 15
 
15 16
 public class HandlingEventTest extends TestCase {
16
-  private final Cargo cargo = new Cargo(new TrackingId("XYZ"), HONGKONG, NEWYORK);
17
+  private Cargo cargo;
18
+
19
+  protected void setUp() throws Exception {
20
+    TrackingId trackingId = new TrackingId("XYZ");
21
+    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, NEWYORK, new Date());
22
+    cargo = new Cargo(trackingId, routeSpecification);
23
+  }
17 24
 
18 25
   public void testNewWithCarrierMovement() throws Exception {
19 26
 

+ 11
- 6
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java Datei anzeigen

@@ -2,7 +2,11 @@ package se.citerus.dddsample.infrastructure.persistence.hibernate;
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.*;
5
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM004;
6
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.HELSINKI_TO_HONGKONG;
7
+import se.citerus.dddsample.domain.model.carrier.Voyage;
8
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
9
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
6 10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7 11
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
8 12
 import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.RECEIVE;
@@ -11,7 +15,10 @@ import se.citerus.dddsample.domain.model.location.LocationRepository;
11 15
 import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
12 16
 import se.citerus.dddsample.domain.model.location.UnLocode;
13 17
 
14
-import java.util.*;
18
+import java.util.Arrays;
19
+import java.util.Date;
20
+import java.util.List;
21
+import java.util.Map;
15 22
 
16 23
 public class CargoRepositoryTest extends AbstractRepositoryTest {
17 24
 
@@ -46,9 +53,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
46 53
 
47 54
     HandlingEvent secondEvent = events.get(1);
48 55
 
49
-    Voyage voyage = new Voyage(new VoyageNumber("0303"), new Schedule(new ArrayList<CarrierMovement>()));
50
-
51
-    assertHandlingEvent(cargo,  secondEvent, LOAD, HONGKONG, 150, 110, voyage);
56
+    assertHandlingEvent(cargo, secondEvent, LOAD, HONGKONG, 150, 110, HELSINKI_TO_HONGKONG);
52 57
 
53 58
     List<Leg> legs = cargo.itinerary().legs();
54 59
     assertEquals(3, legs.size());
@@ -116,7 +121,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
116 121
 
117 122
     Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
118 123
     Location legTo = locationRepository.find(new UnLocode("DEHAM"));
119
-    Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(SampleVoyages.CM004, legFrom, legTo, new Date(), new Date())));
124
+    Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(CM004, legFrom, legTo, new Date(), new Date())));
120 125
 
121 126
     cargo.assignToRoute(newItinerary);
122 127
 

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java Datei anzeigen

@@ -45,8 +45,8 @@ public class ExternalRoutingServiceTest extends TestCase {
45 45
 
46 46
   public void testCalculatePossibleRoutes() {
47 47
     TrackingId trackingId = new TrackingId("ABC");
48
-    Cargo cargo = new Cargo(trackingId, HONGKONG, HELSINKI);
49
-    RouteSpecification routeSpecification = new RouteSpecification(cargo.origin(), cargo.destination(), new Date());
48
+    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, new Date());
49
+    Cargo cargo = new Cargo(trackingId, routeSpecification);
50 50
 
51 51
     expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
52 52
     

+ 0
- 48
dddsample/src/test/java/se/citerus/dddsample/interfaces/handling/HandlinEventServiceEndpointTest.java Datei anzeigen

@@ -1,48 +0,0 @@
1
-package se.citerus.dddsample.interfaces.handling;
2
-
3
-import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
-import se.citerus.dddsample.application.HandlingEventRegistrationAttempt;
6
-import se.citerus.dddsample.application.SystemEvents;
7
-
8
-import java.text.SimpleDateFormat;
9
-import java.util.Date;
10
-
11
-public class HandlinEventServiceEndpointTest extends TestCase {
12
-
13
-  private HandlingEventServiceEndpointImpl endpoint;
14
-  private SimpleDateFormat sdf = new SimpleDateFormat(HandlingEventServiceEndpointImpl.ISO_8601_FORMAT);
15
-  private Date date = new Date(100);
16
-  private SystemEvents systemEvents;
17
-
18
-  protected void setUp() throws Exception {
19
-    endpoint = new HandlingEventServiceEndpointImpl();
20
-
21
-    systemEvents = createMock(SystemEvents.class);
22
-    endpoint.setSystemEvents(systemEvents);
23
-  }
24
-
25
-  public void testRegisterValidEvent() throws Exception {
26
-    systemEvents.receivedHandlingEventRegistrationAttempt(isA(HandlingEventRegistrationAttempt.class));
27
-    replay(systemEvents);
28
-
29
-    // Tested call
30
-    endpoint.register(sdf.format(date), "FOO", "CAR_456", "CNHKG", "LOAD");
31
-  }
32
-
33
-  public void testRegisterInalidEvent() throws Exception {
34
-    replay(systemEvents);
35
-
36
-    // Tested call
37
-    try {
38
-      endpoint.register("NOT_A_DATE", "", "", "NOT_A_UN_LOCODE", "NOT_A_TYPE");
39
-      fail("Should not accept invalid ");
40
-    } catch (Exception expected) {
41
-      System.err.println(expected);
42
-    }
43
-  }
44
-
45
-  protected void tearDown() throws Exception {
46
-    verify(systemEvents);
47
-  }
48
-}

+ 4
- 2
dddsample/src/test/java/se/citerus/dddsample/scenario/CargoHandlingScenarioTest.java Datei anzeigen

@@ -49,15 +49,17 @@ public class CargoHandlingScenarioTest extends TestCase {
49 49
 
50 50
     // Cargo from Hongkong to Stockholm (skipping the booking procedure here)
51 51
     TrackingId trackingId = generateTrackingId();
52
+
52 53
     Location origin = HONGKONG;
53 54
     Location destination = STOCKHOLM;
54
-    cargo = new Cargo(trackingId, origin, destination);
55
+    Date arrivalDeadline = inTwoWeeks();
56
+    RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
55 57
 
58
+    cargo = new Cargo(trackingId, routeSpecification);
56 59
 
57 60
     assertEquals(RoutingStatus.NOT_ROUTED, cargo.routingStatus());
58 61
 
59 62
     // Route cargo
60
-    RouteSpecification routeSpecification = new RouteSpecification(cargo.origin(), cargo.destination(), inTwoWeeks());
61 63
     List<Itinerary> itineraries = routingService.fetchRoutesForSpecification(routeSpecification);
62 64
     Itinerary itinerary = selectPreferedItinerary(itineraries);
63 65
     cargo.assignToRoute(itinerary);

+ 4
- 5
dddsample/src/test/java/se/citerus/dddsample/scenario/TrackingScenarioTest.java Datei anzeigen

@@ -1,10 +1,7 @@
1 1
 package se.citerus.dddsample.scenario;
2 2
 
3 3
 import junit.framework.TestCase;
4
-import se.citerus.dddsample.domain.model.cargo.Cargo;
5
-import se.citerus.dddsample.domain.model.cargo.CargoTestHelper;
6
-import se.citerus.dddsample.domain.model.cargo.Delivery;
7
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
4
+import se.citerus.dddsample.domain.model.cargo.*;
8 5
 import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM001;
9 6
 import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.CM002;
10 7
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
@@ -40,7 +37,9 @@ public class TrackingScenarioTest extends TestCase {
40 37
   }
41 38
 
42 39
   private Cargo populateCargo() throws Exception {
43
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
40
+    final TrackingId trackingId = new TrackingId("XYZ");
41
+    final RouteSpecification routeSpecification = new RouteSpecification(STOCKHOLM, MELBOURNE, new Date());
42
+    final Cargo cargo = new Cargo(trackingId, routeSpecification);
44 43
 
45 44
     final List<HandlingEvent> handlingEventList = Arrays.asList(
46 45
       new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), LOAD, STOCKHOLM, CM001),

+ 3
- 0
dddsample/src/test/resources/handling_events.csv Datei anzeigen

@@ -0,0 +1,3 @@
1
+2008-10-29 12:30:00.000	ZYX	V100	SESTO	LOAD
2
+2008-10-31 04:00:00.000	ZYX	V100	HELSINKI	UNLOAD
3
+2008-10-31 08:12:00.000	ZYX	HELSINKI	UNLOAD