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

Further improvments of sample voyages and test environment.

peter_backlund 16 лет назад
Родитель
Сommit
7686cd5503
18 измененных файлов: 491 добавлений и 656 удалений
  1. 72
    29
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/application/util/SampleDataGenerator.java
  2. 11
    7
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Cargo.java
  3. 1
    1
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java
  4. 8
    7
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Itinerary.java
  5. 6
    2
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Leg.java
  6. 1
    1
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/RouteSpecification.java
  7. 4
    3
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/location/CustomsZone.java
  8. 13
    19
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/SampleVoyages.java
  9. 130
    61
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/CargoTest.java
  10. 2
    5
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/ItineraryTest.java
  11. 1
    1
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/LegTest.java
  12. 3
    10
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/RouteSpecificationTest.java
  13. 2
    2
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventTest.java
  14. 217
    19
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycle.java
  15. 0
    466
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycleScenarioTest.java
  16. 10
    10
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  17. 5
    7
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java
  18. 5
    6
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/interfaces/booking/facade/DTOAssemblerTest.java

+ 72
- 29
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/application/util/SampleDataGenerator.java Просмотреть файл

45
   }
45
   }
46
 
46
 
47
   private static void loadHandlingEventData(JdbcTemplate jdbcTemplate) {
47
   private static void loadHandlingEventData(JdbcTemplate jdbcTemplate) {
48
+    String activitySql = "insert into HandlingActivity (id, handling_event_type, location_id, voyage_id) values (?, ?, ?, ?)";
49
+      Object[][] actvityArgs = {
50
+        {1, "RECEIVE", 1, null},
51
+        {2, "LOAD",    1, 1},
52
+        {3, "UNLOAD",  5, 1},
53
+        {4, "LOAD",    5, 1},
54
+        {5, "UNLOAD",  6, 1},
55
+        {6, "LOAD",    6, 1},
56
+        {7, "UNLOAD",  3, 1},
57
+        {8, "LOAD",    3, 1},
58
+        {9, "UNLOAD",  4, 1},
59
+        {10, "LOAD",    4, 1},
60
+        {11, "UNLOAD",  2, 1},
61
+        {12, "CLAIM",   2, null},
62
+
63
+        //ZYX (AUMEL - USCHI - DEHAM -)
64
+        {13, "RECEIVE", 2, null},
65
+        {14, "LOAD",    2, 2},
66
+        {15, "UNLOAD",  7, 2},
67
+        {16, "LOAD",    7, 2},
68
+        {17, "UNLOAD",  6, 2},
69
+        {18, "LOAD",    6, 2},
70
+
71
+        //ABC
72
+        {19, "CLAIM", 2, null},
73
+
74
+        //CBA
75
+        {20, "RECEIVE", 2, null},
76
+        {21, "LOAD",    2, 2},
77
+        {22, "UNLOAD",  7, 2},
78
+
79
+        //FGH
80
+        {23, "RECEIVE", 3, null},
81
+        {24, "LOAD",    3, 3},
82
+
83
+        // JKL
84
+        {25, "RECEIVE", 6, null},
85
+        {26, "LOAD",    6, 3},
86
+        {27, "UNLOAD",  5, 3}  // Unexpected event
87
+      };
88
+    executeUpdate(jdbcTemplate, activitySql, actvityArgs);
89
+
90
+
48
     String handlingEventSql =
91
     String handlingEventSql =
49
-      "insert into HandlingEvent (sequence_number, completionTime, registrationTime, type, location_id, voyage_id, cargo_id, operator_code) " +
50
-        "values (?, ?, ?, ?, ?, ?, ?,?)";
92
+      "insert into HandlingEvent (sequence_number, completionTime, registrationTime, cargo_id, operator_code, activity_id) " +
93
+        "values (?, ?, ?, ?, ?, ?)";
51
 
94
 
52
     Object[][] handlingEventArgs = {
95
     Object[][] handlingEventArgs = {
53
       //XYZ (SESTO-FIHEL-DEHAM-CNHKG-JPTOK-AUMEL)
96
       //XYZ (SESTO-FIHEL-DEHAM-CNHKG-JPTOK-AUMEL)
54
-      {1, ts(0), ts((0)), "RECEIVE", 1, null, 1, null},
55
-      {2, ts((4)), ts((5)), "LOAD", 1, 1, 1, "AS34F"},
56
-      {3, ts((14)), ts((14)), "UNLOAD", 5, 1, 1, "AS34F"},
57
-      {4, ts((15)), ts((15)), "LOAD", 5, 1, 1, "AS34F"},
58
-      {5, ts((30)), ts((30)), "UNLOAD", 6, 1, 1, "AS34F"},
59
-      {6, ts((33)), ts((33)), "LOAD", 6, 1, 1, "AS34F"},
60
-      {7, ts((34)), ts((34)), "UNLOAD", 3, 1, 1, "AS34F"},
61
-      {8, ts((60)), ts((60)), "LOAD", 3, 1, 1, "AS34F"},
62
-      {9, ts((70)), ts((71)), "UNLOAD", 4, 1, 1, "AS34F"},
63
-      {10, ts((75)), ts((75)), "LOAD", 4, 1, 1, "AS34F"},
64
-      {11, ts((88)), ts((88)), "UNLOAD", 2, 1, 1, "AS34F"},
65
-      {12, ts((100)), ts((102)), "CLAIM", 2, null, 1, null},
97
+      {1, ts(0), ts((0)), 1, null, 1},
98
+      {2, ts((4)), ts((5)), 1, "AS34F", 2},
99
+      {3, ts((14)), ts((14)), 1, "AS34F", 3},
100
+      {4, ts((15)), ts((15)), 1, "AS34F", 4},
101
+      {5, ts((30)), ts((30)), 1, "AS34F", 5},
102
+      {6, ts((33)), ts((33)), 1, "AS34F", 6},
103
+      {7, ts((34)), ts((34)), 1, "AS34F", 7},
104
+      {8, ts((60)), ts((60)), 1, "AS34F", 8},
105
+      {9, ts((70)), ts((71)), 1, "AS34F", 9},
106
+      {10, ts((75)), ts((75)), 1, "AS34F", 10},
107
+      {11, ts((88)), ts((88)), 1, "AS34F", 11},
108
+      {12, ts((100)), ts((102)), 1, null, 12},
66
 
109
 
67
       //ZYX (AUMEL - USCHI - DEHAM -)
110
       //ZYX (AUMEL - USCHI - DEHAM -)
68
-      {13, ts((200)), ts((201)), "RECEIVE", 2, null, 3, null},
69
-      {14, ts((202)), ts((202)), "LOAD", 2, 2, 3, "AS34F"},
70
-      {15, ts((208)), ts((208)), "UNLOAD", 7, 2, 3, "AS34F"},
71
-      {16, ts((212)), ts((212)), "LOAD", 7, 2, 3, "AS34F"},
72
-      {17, ts((230)), ts((230)), "UNLOAD", 6, 2, 3, "AS34F"},
73
-      {18, ts((235)), ts((235)), "LOAD", 6, 2, 3, "AS34F"},
111
+      {13, ts((200)), ts((201)), 3, null, 13},
112
+      {14, ts((202)), ts((202)), 3, "AS34F", 14},
113
+      {15, ts((208)), ts((208)), 3, "AS34F", 15},
114
+      {16, ts((212)), ts((212)), 3, "AS34F", 16},
115
+      {17, ts((230)), ts((230)), 3, "AS34F", 17},
116
+      {18, ts((235)), ts((235)), 3, "AS34F", 18},
74
 
117
 
75
       //ABC
118
       //ABC
76
-      {19, ts((20)), ts((21)), "CLAIM", 2, null, 2, null},
119
+      {19, ts((20)), ts((21)), 2, null, 19},
77
 
120
 
78
       //CBA
121
       //CBA
79
-      {20, ts((0)), ts((1)), "RECEIVE", 2, null, 4, null},
80
-      {21, ts((10)), ts((11)), "LOAD", 2, 2, 4, "AS34F"},
81
-      {22, ts((20)), ts((21)), "UNLOAD", 7, 2, 4, "AS34F"},
122
+      {20, ts((0)), ts((1)), 4, null, 20},
123
+      {21, ts((10)), ts((11)), 4, "AS34F", 21},
124
+      {22, ts((20)), ts((21)), 4, "AS34F", 22},
82
 
125
 
83
       //FGH
126
       //FGH
84
-      {23, ts(100), ts(160), "RECEIVE", 3, null, 5, null},
85
-      {24, ts(150), ts(110), "LOAD", 3, 3, 5, "AS34F"},
127
+      {23, ts(100), ts(160), 5, null, 23},
128
+      {24, ts(150), ts(110), 5, "AS34F", 24},
86
 
129
 
87
       // JKL
130
       // JKL
88
-      {25, ts(200), ts(220), "RECEIVE", 6, null, 6, null},
89
-      {26, ts(300), ts(330), "LOAD", 6, 3, 6, "AS34F"},
90
-      {27, ts(400), ts(440), "UNLOAD", 5, 3, 6}  // Unexpected event
131
+      {25, ts(200), ts(220), 6, null, 25},
132
+      {26, ts(300), ts(330), 6, "AS34F", 26},
133
+      {27, ts(400), ts(440), 6, null, 27}  // Unexpected event
91
     };
134
     };
92
     executeUpdate(jdbcTemplate, handlingEventSql, handlingEventArgs);
135
     executeUpdate(jdbcTemplate, handlingEventSql, handlingEventArgs);
93
   }
136
   }

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

113
 
113
 
114
     if (delivery.isRoutedAfterHandling()) {
114
     if (delivery.isRoutedAfterHandling()) {
115
       return itinerary.firstLeg().deriveLoadActivity();
115
       return itinerary.firstLeg().deriveLoadActivity();
116
-    } else {
117
-      if (unloadedInCustomsClearancePoint()) {
118
-        return customsIn(customsClearancePoint());
119
-      } else {
120
-        return itinerary.activitySucceding(delivery.mostRecentPhysicalHandlingActivity());
121
-      }
122
     }
116
     }
117
+
118
+    if (unloadedInCustomsClearancePoint()) {
119
+      return customsIn(customsClearancePoint());
120
+    }
121
+
122
+    return itinerary.activitySucceding(delivery.mostRecentPhysicalHandlingActivity());
123
   }
123
   }
124
 
124
 
125
   private boolean unloadedInCustomsClearancePoint() {
125
   private boolean unloadedInCustomsClearancePoint() {
210
    * @return True if the cargo is ready to be claimed.
210
    * @return True if the cargo is ready to be claimed.
211
    */
211
    */
212
   public boolean isReadyToClaim() {
212
   public boolean isReadyToClaim() {
213
-    return delivery.onTheGroundAtDestination(routeSpecification);
213
+    if (customsClearancePoint().sameAs(routeSpecification.destination())) {
214
+      return customsIn(customsClearancePoint()).sameValueAs(mostRecentHandlingActivity());
215
+    } else {
216
+      return delivery.onTheGroundAtDestination(routeSpecification);
217
+    }
214
   }
218
   }
215
 
219
 
216
   /**
220
   /**

+ 1
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Delivery.java Просмотреть файл

134
    */
134
    */
135
   boolean onTheGroundAtDestination(final RouteSpecification routeSpecification) {
135
   boolean onTheGroundAtDestination(final RouteSpecification routeSpecification) {
136
     return hasBeenHandledAfterRouting() &&
136
     return hasBeenHandledAfterRouting() &&
137
-           mostRecentHandlingActivity.type() == UNLOAD && 
137
+           mostRecentHandlingActivity.type() == UNLOAD &&
138
            routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
138
            routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
139
   }
139
   }
140
 
140
 

+ 8
- 7
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Itinerary.java Просмотреть файл

5
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
5
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
6
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
6
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
7
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
7
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
8
-import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.*;
8
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.claimIn;
9
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.receiveIn;
9
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
10
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
10
 import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObjectSupport;
11
 import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObjectSupport;
11
 
12
 
17
 public class Itinerary extends ValueObjectSupport<Itinerary> {
18
 public class Itinerary extends ValueObjectSupport<Itinerary> {
18
 
19
 
19
   private final List<Leg> legs;
20
   private final List<Leg> legs;
21
+  // Null object
22
+  static final Itinerary NONE = new Itinerary();
20
 
23
 
21
   /**
24
   /**
22
    * Constructor.
25
    * Constructor.
27
     Validate.notEmpty(legs);
30
     Validate.notEmpty(legs);
28
     Validate.noNullElements(legs);
31
     Validate.noNullElements(legs);
29
 
32
 
33
+    // TODO
34
+    // Validate that legs are in proper order, connected
30
     /*final Iterator<Leg> it = legs.iterator();
35
     /*final Iterator<Leg> it = legs.iterator();
31
     Leg leg = it.next();
36
     Leg leg = it.next();
32
     while (it.hasNext()) {
37
     while (it.hasNext()) {
41
       Validate.isTrue(lit.previous().unloadTime().before(lit.next().loadTime()));
46
       Validate.isTrue(lit.previous().unloadTime().before(lit.next().loadTime()));
42
     }*/
47
     }*/
43
 
48
 
44
-    // TODO
45
-    // Validate that legs are in proper order, connected
46
-    // and that load/unload times are doable?
47
-
48
     this.legs = legs;
49
     this.legs = legs;
49
   }
50
   }
50
 
51
 
253
       return null;
254
       return null;
254
     } else {
255
     } else {
255
       if (handlingActivity.type() == LOAD) {
256
       if (handlingActivity.type() == LOAD) {
256
-        return unloadOff(handlingActivity.voyage()).in(matchingLeg.unloadLocation());
257
+        return matchingLeg.deriveUnloadActivity();
257
       } else if (handlingActivity.type() == UNLOAD) {
258
       } else if (handlingActivity.type() == UNLOAD) {
258
         return deriveFromNextLeg(nextLeg(matchingLeg));
259
         return deriveFromNextLeg(nextLeg(matchingLeg));
259
       } else {
260
       } else {
278
 
279
 
279
   Itinerary() {
280
   Itinerary() {
280
     // Needed by Hibernate
281
     // Needed by Hibernate
281
-    legs = null;
282
+    legs = Collections.emptyList();
282
   }
283
   }
283
 
284
 
284
 }
285
 }

+ 6
- 2
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/Leg.java Просмотреть файл

24
   private final Date unloadTime;
24
   private final Date unloadTime;
25
 
25
 
26
   // TODO hide this, use factory only
26
   // TODO hide this, use factory only
27
-  public Leg(Voyage voyage, Location loadLocation, Location unloadLocation, Date loadTime, Date unloadTime) {
27
+  public Leg(final Voyage voyage, final Location loadLocation, final Location unloadLocation, final Date loadTime, final Date unloadTime) {
28
     Validate.notNull(voyage, "Voyage is required");
28
     Validate.notNull(voyage, "Voyage is required");
29
     Validate.notNull(loadLocation, "Load location is required");
29
     Validate.notNull(loadLocation, "Load location is required");
30
     Validate.notNull(unloadLocation, "Unload location is required");
30
     Validate.notNull(unloadLocation, "Unload location is required");
56
    * @param unloadLocation unload location
56
    * @param unloadLocation unload location
57
    * @return A leg on this voyage between the given locations.
57
    * @return A leg on this voyage between the given locations.
58
    */
58
    */
59
-  public static Leg deriveLeg(Voyage voyage, Location loadLocation, Location unloadLocation) {
59
+  public static Leg deriveLeg(final Voyage voyage, final Location loadLocation, final Location unloadLocation) {
60
+    // TODO enable this (or perhaps the requirement for load/unlaod time covers this?)
61
+    //voyage.locations().contains(loadLocation);
62
+    //voyage.locations().contains(unloadLocation);
63
+    Validate.notNull(voyage, "Voyage is required");
60
     return new Leg(voyage, loadLocation, unloadLocation, voyage.schedule().departureTimeAt(loadLocation), voyage.schedule().arrivalTimeAt(unloadLocation));
64
     return new Leg(voyage, loadLocation, unloadLocation, voyage.schedule().departureTimeAt(loadLocation), voyage.schedule().arrivalTimeAt(unloadLocation));
61
   }
65
   }
62
 
66
 

+ 1
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/cargo/RouteSpecification.java Просмотреть файл

96
 
96
 
97
   @Override
97
   @Override
98
   public String toString() {
98
   public String toString() {
99
-    return origin + " to " + destination + " by " + arrivalDeadline;
99
+    return origin + " - " + destination + " by " + arrivalDeadline;
100
   }
100
   }
101
 
101
 
102
   RouteSpecification() {
102
   RouteSpecification() {

+ 4
- 3
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/location/CustomsZone.java Просмотреть файл

31
     Validate.notNull(code, "Code is required");
31
     Validate.notNull(code, "Code is required");
32
     Validate.isTrue(VALID_PATTERN.matcher(code).matches(), code + " is not a valid customs zone code (does not match pattern)");
32
     Validate.isTrue(VALID_PATTERN.matcher(code).matches(), code + " is not a valid customs zone code (does not match pattern)");
33
     Validate.notNull(name, "Name is required");
33
     Validate.notNull(name, "Name is required");
34
+
34
     this.code = code.toUpperCase();
35
     this.code = code.toUpperCase();
35
     this.name = name;
36
     this.name = name;
36
   }
37
   }
45
    * following this route. Note that specific voyages, etc do not
46
    * following this route. Note that specific voyages, etc do not
46
    * matter, only the sequence of Locations.
47
    * matter, only the sequence of Locations.
47
    *
48
    *
48
-   * @param route
49
-   * @return
49
+   * @param route a list of locations
50
+   * @return The first location on the route that is in this customs zone.
50
    */
51
    */
51
   public Location entryPoint(final List<Location> route) {
52
   public Location entryPoint(final List<Location> route) {
52
     for (Location location : route) {
53
     for (Location location : route) {
108
     return name;
109
     return name;
109
   }
110
   }
110
 
111
 
111
-  public boolean includes(final Location location) {
112
+  boolean includes(final Location location) {
112
     return this.sameAs(location.customsZone());
113
     return this.sameAs(location.customsZone());
113
   }
114
   }
114
 
115
 

+ 13
- 19
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/SampleVoyages.java Просмотреть файл

1
 package se.citerus.dddsample.tracking.core.domain.model.voyage;
1
 package se.citerus.dddsample.tracking.core.domain.model.voyage;
2
 
2
 
3
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
3
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
4
-import se.citerus.dddsample.tracking.core.domain.model.location.Location;
5
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
4
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
6
 
5
 
7
 import java.lang.reflect.Field;
6
 import java.lang.reflect.Field;
8
-import java.util.*;
7
+import java.util.ArrayList;
8
+import java.util.HashMap;
9
+import java.util.List;
10
+import java.util.Map;
9
 
11
 
10
 /**
12
 /**
11
  * Sample carrier movements, for test purposes.
13
  * Sample carrier movements, for test purposes.
20
     build();
22
     build();
21
 
23
 
22
   public final static Voyage pacific2 = new Voyage.Builder(new VoyageNumber("PAC2"), SHANGHAI).
24
   public final static Voyage pacific2 = new Voyage.Builder(new VoyageNumber("PAC2"), SHANGHAI).
25
+    addMovement(TOKYO, toDate("2009-03-04"), toDate("2009-03-05")).
23
     addMovement(LONGBEACH, toDate("2009-03-06"), toDate("2009-03-08")).
26
     addMovement(LONGBEACH, toDate("2009-03-06"), toDate("2009-03-08")).
24
     addMovement(SEATTLE, toDate("2009-03-10"), toDate("2009-03-14")).
27
     addMovement(SEATTLE, toDate("2009-03-10"), toDate("2009-03-14")).
25
     addMovement(HANGZOU, toDate("2009-03-14"), toDate("2009-03-16")).
28
     addMovement(HANGZOU, toDate("2009-03-14"), toDate("2009-03-16")).
32
     addMovement(NEWYORK, toDate("2009-03-11"), toDate("2009-03-14")).
35
     addMovement(NEWYORK, toDate("2009-03-11"), toDate("2009-03-14")).
33
     build();
36
     build();
34
 
37
 
35
-  public final static Voyage continenal2 = new Voyage.Builder(new VoyageNumber("CNT2"), LONGBEACH).
38
+  public final static Voyage continental2 = new Voyage.Builder(new VoyageNumber("CNT2"), LONGBEACH).
36
     addMovement(DALLAS, toDate("2009-03-06"), toDate("2009-03-08")).
39
     addMovement(DALLAS, toDate("2009-03-06"), toDate("2009-03-08")).
37
     addMovement(NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")).
40
     addMovement(NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")).
38
     build();
41
     build();
39
 
42
 
43
+  public final static Voyage continental3 = new Voyage.Builder(new VoyageNumber("CNT3"), SEATTLE).
44
+    addMovement(CHICAGO, toDate("2009-03-06"), toDate("2009-03-08")).
45
+    addMovement(NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")).
46
+    build();
47
+
40
   public final static Voyage atlantic1 = new Voyage.Builder(new VoyageNumber("ATC1"), NEWYORK).
48
   public final static Voyage atlantic1 = new Voyage.Builder(new VoyageNumber("ATC1"), NEWYORK).
41
       addMovement(ROTTERDAM, toDate("2009-03-15"), toDate("2009-03-18")).
49
       addMovement(ROTTERDAM, toDate("2009-03-15"), toDate("2009-03-18")).
42
       addMovement(HAMBURG, toDate("2009-03-19"), toDate("2009-03-20")).
50
       addMovement(HAMBURG, toDate("2009-03-19"), toDate("2009-03-20")).
45
       build();
53
       build();
46
 
54
 
47
   public final static Voyage atlantic2 = new Voyage.Builder(new VoyageNumber("ATC2"), NEWYORK).
55
   public final static Voyage atlantic2 = new Voyage.Builder(new VoyageNumber("ATC2"), NEWYORK).
48
-      addMovement(ROTTERDAM, toDate("2009-03-17"), toDate("2009-03-20")).
56
+      addMovement(HAMBURG, toDate("2009-03-17"), toDate("2009-03-20")).
49
       addMovement(GOTHENBURG, toDate("2009-03-22"), toDate("2009-03-24")).
57
       addMovement(GOTHENBURG, toDate("2009-03-22"), toDate("2009-03-24")).
50
       addMovement(STOCKHOLM, toDate("2009-03-25"), toDate("2009-03-26")).
58
       addMovement(STOCKHOLM, toDate("2009-03-25"), toDate("2009-03-26")).
51
       addMovement(HELSINKI, toDate("2009-03-27"), toDate("2009-03-28")).
59
       addMovement(HELSINKI, toDate("2009-03-27"), toDate("2009-03-28")).
52
       addMovement(NEWYORK, toDate("2009-03-31"), toDate("2009-04-04")).
60
       addMovement(NEWYORK, toDate("2009-03-31"), toDate("2009-04-04")).
53
       build();
61
       build();
54
 
62
 
55
-
56
-  public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
57
-    addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
58
-    addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
59
-    addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
60
-    addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
61
-    build();
62
-
63
-  public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
64
-    addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
65
-    addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
66
-    addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22")).
67
-    build();
68
-
69
   /**
63
   /**
70
    * Voyage number 0100S (by ship)
64
    * Voyage number 0100S (by ship)
71
    * <p/>
65
    * <p/>
126
 
120
 
127
   private static final Map<VoyageNumber, Voyage> ALL = new HashMap<VoyageNumber, Voyage>();
121
   private static final Map<VoyageNumber, Voyage> ALL = new HashMap<VoyageNumber, Voyage>();
128
 
122
 
129
-  static {
123
+    static {
130
     for (Field field : SampleVoyages.class.getDeclaredFields()) {
124
     for (Field field : SampleVoyages.class.getDeclaredFields()) {
131
       if (field.getType().equals(Voyage.class)) {
125
       if (field.getType().equals(Voyage.class)) {
132
         try {
126
         try {

+ 130
- 61
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/CargoTest.java Просмотреть файл

10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
11
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
11
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
12
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
12
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
13
-import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.loadOnto;
14
-import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.unloadOff;
13
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.*;
14
+import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
16
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
16
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
17
 
17
 
18
-import java.util.Arrays;
19
 import java.util.Date;
18
 import java.util.Date;
20
 
19
 
21
 public class CargoTest extends TestCase {
20
 public class CargoTest extends TestCase {
151
     assertFalse("Cargos are not equal when TrackingID differ", c1.equals(c2));
150
     assertFalse("Cargos are not equal when TrackingID differ", c1.equals(c2));
152
   }
151
   }
153
 
152
 
154
-  public void testIsReadyToClaim() throws Exception {
155
-    Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
153
+  public void testIsReadyToClaimWithDestinationDifferentFromCustomsClearancePoint() {
154
+    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(HONGKONG, NEWYORK, toDate("2009-12-24")));
155
+    Itinerary itinerary = new Itinerary(
156
+      Leg.deriveLeg(pacific1, HONGKONG, LONGBEACH),
157
+      Leg.deriveLeg(continental2, LONGBEACH, NEWYORK)
158
+    );
159
+    cargo.assignToRoute(itinerary);
160
+    assertFalse(cargo.routeSpecification().destination().sameAs(cargo.customsClearancePoint()));
156
     assertFalse(cargo.isReadyToClaim());
161
     assertFalse(cargo.isReadyToClaim());
157
 
162
 
158
-    // Adding an event unrelated to unloading at final destination
159
-    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU));
163
+    cargo.handled(unloadOff(pacific1).in(LONGBEACH));
160
     assertFalse(cargo.isReadyToClaim());
164
     assertFalse(cargo.isReadyToClaim());
161
 
165
 
162
-    Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
163
-        addMovement(NEWYORK, new Date(1), new Date(2)).
164
-        build();
165
-
166
-    // Adding an unload event, but not at the final destination
167
-    cargo.handled(new HandlingActivity(UNLOAD, TOKYO, voyage));
166
+    cargo.handled(loadOnto(continental2).in(LONGBEACH));
168
     assertFalse(cargo.isReadyToClaim());
167
     assertFalse(cargo.isReadyToClaim());
169
-
170
-    // Adding an event in the final destination, but not unload
171
-    /*cargo.handled(new HandlingActivity(CUSTOMS, NEWYORK));
172
-    assertFalse(cargo.isReadyToClaim());
173
-    assertFalse(cargo.isMisdirected());*/
174
-
175
-    // Finally, cargo is unloaded at final destination
176
-    cargo.handled(new HandlingActivity(UNLOAD, NEWYORK, voyage));
168
+    
169
+    cargo.handled(unloadOff(continental2).in(NEWYORK));
177
     assertTrue(cargo.isReadyToClaim());
170
     assertTrue(cargo.isReadyToClaim());
178
   }
171
   }
179
 
172
 
180
-  public void testCustomsInMelbourne() throws Exception {
181
-    Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
182
-    
183
-    /*cargo.handled(unloadOff(crazyVoyage).in(HAMBURG));
184
-    assertThat(cargo.nextExpectedActivity(), is(loadOnto(crazyVoyage).in(HAMBURG)));
185
-    assertFalse(cargo.isMisdirected());
173
+  public void testIsReadyToClaimWithDestinationSameAsCustomsClearancePoint() {
174
+    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(SHANGHAI, SEATTLE, toDate("2009-12-24")));
175
+    Itinerary itinerary = new Itinerary(
176
+      Leg.deriveLeg(pacific2, SHANGHAI, SEATTLE)
177
+    );
178
+    cargo.assignToRoute(itinerary);
179
+    assertTrue(cargo.routeSpecification().destination().sameAs(cargo.customsClearancePoint()));
180
+    assertFalse(cargo.isReadyToClaim());
186
 
181
 
187
-    cargo.handled(loadOnto(crazyVoyage).in(HAMBURG));
188
-    assertThat(cargo.nextExpectedActivity(), is(unloadOff(crazyVoyage).in(MELBOURNE)));
189
-    assertFalse(cargo.isMisdirected());
182
+    cargo.handled(unloadOff(pacific2).in(SEATTLE));
183
+    assertFalse(cargo.isReadyToClaim());
190
 
184
 
191
-    cargo.handled(unloadOff(crazyVoyage).in(MELBOURNE));
192
-    assertThat(cargo.nextExpectedActivity(), is(customsIn(MELBOURNE)));
193
-    assertFalse(cargo.isMisdirected());
185
+    cargo.handled(customsIn(SEATTLE));
186
+    assertTrue(cargo.isReadyToClaim());
194
 
187
 
195
-    cargo.handled(customsIn(MELBOURNE));
196
-    assertThat(cargo.nextExpectedActivity(), is(claimIn(MELBOURNE)));
197
-    assertFalse(cargo.isMisdirected());*/
188
+    cargo.handled(claimIn(SEATTLE));
189
+    assertFalse(cargo.isReadyToClaim());
198
   }
190
   }
199
 
191
 
200
   private Cargo populateCargoReceivedStockholm() throws Exception {
192
   private Cargo populateCargoReceivedStockholm() throws Exception {
240
     return cargo;
232
     return cargo;
241
   }
233
   }
242
 
234
 
243
-  public void testIsMisdirected() throws Exception {
244
-    //A cargo with no itinerary is not misdirected
245
-    Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
235
+  public void testIsMisdirectedHappyPath() throws Exception {
236
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
237
+
238
+    //A cargo with no handling events is not misdirected
246
     assertFalse(cargo.isMisdirected());
239
     assertFalse(cargo.isMisdirected());
247
 
240
 
248
-    cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
241
+    cargo.handled(receiveIn(SHANGHAI));
242
+    assertFalse(cargo.isMisdirected());
249
 
243
 
250
-    //A cargo with no handling events is not misdirected
244
+    cargo.handled(loadOnto(pacific2).in(SHANGHAI));
251
     assertFalse(cargo.isMisdirected());
245
     assertFalse(cargo.isMisdirected());
252
 
246
 
253
-    //Happy path
254
-    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI));
255
-    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage));
256
-    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage));
257
-    cargo.handled(new HandlingActivity(LOAD, ROTTERDAM, crazyVoyage));
258
-    cargo.handled(new HandlingActivity(UNLOAD, GOTHENBURG, crazyVoyage));
259
-    cargo.handled(new HandlingActivity(CLAIM, GOTHENBURG));
260
-    cargo.handled(new HandlingActivity(CUSTOMS, GOTHENBURG));
247
+    cargo.handled(unloadOff(pacific2).in(SEATTLE));
261
     assertFalse(cargo.isMisdirected());
248
     assertFalse(cargo.isMisdirected());
262
 
249
 
263
-    //Try a couple of failing ones
250
+    cargo.handled(customsIn(SEATTLE));
251
+    assertFalse(cargo.isMisdirected());
264
 
252
 
265
-    cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
253
+    cargo.handled(loadOnto(continental3).in(SEATTLE));
254
+    assertFalse(cargo.isMisdirected());
255
+
256
+    cargo.handled(unloadOff(continental3).in(CHICAGO));
257
+    assertFalse(cargo.isMisdirected());
258
+
259
+    cargo.handled(claimIn(CHICAGO));
260
+    assertFalse(cargo.isMisdirected());
261
+  }
266
 
262
 
267
-    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU));
263
+  public void testIsMisdirectedIncorrectReceive() throws Exception {
264
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
265
+
266
+    cargo.handled(receiveIn(TOKYO));
268
     assertTrue(cargo.isMisdirected());
267
     assertTrue(cargo.isMisdirected());
268
+  }
269
 
269
 
270
+  public void testIsMisdirectedLoadOntoWrongVoyage() throws Exception {
271
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
270
 
272
 
271
-    cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
273
+    cargo.handled(loadOnto(pacific1).in(HONGKONG));
274
+    assertTrue(cargo.isMisdirected());
275
+  }
272
 
276
 
273
-    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI));
274
-    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage));
275
-    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage));
276
-    cargo.handled(new HandlingActivity(CLAIM, ROTTERDAM));
277
+  public void testIsMisdirectedUnloadInWrongLocation() throws Exception {
278
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
277
 
279
 
280
+    cargo.handled(unloadOff(pacific2).in(TOKYO));
278
     assertTrue(cargo.isMisdirected());
281
     assertTrue(cargo.isMisdirected());
279
   }
282
   }
280
 
283
 
284
+  public void testIsMisdirectedCustomsInWrongLocation() throws Exception {
285
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
286
+
287
+    cargo.handled(customsIn(CHICAGO));
288
+    assertTrue(cargo.isMisdirected());
289
+  }
290
+
291
+  public void testIsMisdirectedClaimedInWrongLocation() throws Exception {
292
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
293
+
294
+    cargo.handled(claimIn(SEATTLE));
295
+    assertTrue(cargo.isMisdirected());
296
+  }
297
+
298
+  public void testIsMisdirectedAfterRerouting() throws Exception {
299
+    Cargo cargo = shanghaiSeattleChicagoOnPacific2AndContinental3();
300
+
301
+    cargo.handled(loadOnto(pacific2).in(SHANGHAI));
302
+    assertFalse(cargo.isMisdirected());
303
+
304
+    // Cargo destination is changed by customer mid-route
305
+    RouteSpecification newRouteSpec = cargo.routeSpecification().
306
+      withOrigin(cargo.lastKnownLocation()).
307
+      withDestination(NEWYORK);
308
+
309
+    cargo.specifyNewRoute(newRouteSpec);
310
+    // Misrouted, but not misdirected. Delivery is still accoring to plan (itinerary),
311
+    // but not according to desire (route specification).
312
+    assertFalse(cargo.isMisdirected());
313
+    assertTrue(cargo.routingStatus() == MISROUTED);
314
+
315
+    /**
316
+     * This is a perfect example of how LegMatch is a modelling breakthrough.
317
+     * It allows us to easily construct an itinerary that completes the remainder of the
318
+     * old itinerary and appends the new and different path.
319
+     */
320
+    Leg currentLeg = cargo.itinerary().legMatchOf(cargo.mostRecentHandlingActivity()).leg();
321
+    Itinerary newItinerary = new Itinerary(
322
+      currentLeg,
323
+      Leg.deriveLeg(continental3, SEATTLE, NEWYORK)
324
+    );
325
+    cargo.assignToRoute(newItinerary);
326
+    assertFalse(cargo.isMisdirected());
327
+
328
+    cargo.handled(unloadOff(pacific2).in(SEATTLE));
329
+    assertFalse(cargo.isMisdirected());
330
+
331
+    cargo.handled(loadOnto(continental3).in(SEATTLE));
332
+    assertFalse(cargo.isMisdirected());
333
+
334
+    cargo.handled(unloadOff(continental3).in(NEWYORK));
335
+    assertFalse(cargo.isMisdirected());
336
+  }
337
+
338
+  private Cargo shanghaiSeattleChicagoOnPacific2AndContinental3() {
339
+    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(SHANGHAI, CHICAGO, toDate("2009-12-24")));
340
+
341
+    // A cargo with no itinerary is not misdirected
342
+    assertFalse(cargo.isMisdirected());
343
+
344
+    Itinerary itinerary = new Itinerary(
345
+        Leg.deriveLeg(pacific2, SHANGHAI, SEATTLE),
346
+        Leg.deriveLeg(continental3, SEATTLE, CHICAGO)
347
+    );
348
+    cargo.assignToRoute(itinerary);
349
+    return cargo;
350
+  }
351
+
281
   public void testCustomsClearancePoint() {
352
   public void testCustomsClearancePoint() {
282
     //cargo destination NYC
353
     //cargo destination NYC
283
     final Cargo cargo = new Cargo(new TrackingId("XYZ"),
354
     final Cargo cargo = new Cargo(new TrackingId("XYZ"),
328
     Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, new Date()));
399
     Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, new Date()));
329
 
400
 
330
     Itinerary itinerary = new Itinerary(
401
     Itinerary itinerary = new Itinerary(
331
-        Arrays.asList(
332
-            new Leg(crazyVoyage, origin, midpoint, new Date(1), new Date(2)),
333
-            new Leg(crazyVoyage, midpoint, destination, new Date(3), new Date(4))
334
-        )
402
+        Leg.deriveLeg(crazyVoyage, origin, midpoint),
403
+        Leg.deriveLeg(crazyVoyage, midpoint, destination)
335
     );
404
     );
336
 
405
 
337
     cargo.assignToRoute(itinerary);
406
     cargo.assignToRoute(itinerary);

+ 2
- 5
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/ItineraryTest.java Просмотреть файл

12
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
12
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
13
 
13
 
14
 import java.util.ArrayList;
14
 import java.util.ArrayList;
15
-import java.util.Arrays;
16
 import java.util.Date;
15
 import java.util.Date;
17
 import java.util.List;
16
 import java.util.List;
18
 
17
 
50
   public void testIfCargoIsOnTrack() {
49
   public void testIfCargoIsOnTrack() {
51
 
50
 
52
     Itinerary itinerary = new Itinerary(
51
     Itinerary itinerary = new Itinerary(
53
-      Arrays.asList(
54
-        new Leg(voyage, SHANGHAI, ROTTERDAM, new Date(1), new Date(2)),
55
-        new Leg(voyage, ROTTERDAM, GOTHENBURG, new Date(3), new Date(4))
56
-      )
52
+        Leg.deriveLeg(voyage, SHANGHAI, ROTTERDAM),
53
+        Leg.deriveLeg(voyage, ROTTERDAM, GOTHENBURG)
57
     );
54
     );
58
 
55
 
59
     // HandlingActivity.Load(cargo, RECEIVE, SHANGHAI, toDate("2009-05-03"))
56
     // HandlingActivity.Load(cargo, RECEIVE, SHANGHAI, toDate("2009-05-03"))

+ 1
- 1
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/LegTest.java Просмотреть файл

15
 
15
 
16
   final Voyage voyage = NEW_YORK_TO_DALLAS;
16
   final Voyage voyage = NEW_YORK_TO_DALLAS;
17
 
17
 
18
-  @Test(expected = NullPointerException.class)
18
+  @Test(expected = IllegalArgumentException.class)
19
   public void testConstructor() throws Exception {
19
   public void testConstructor() throws Exception {
20
     Leg.deriveLeg(null, null, null);
20
     Leg.deriveLeg(null, null, null);
21
   }
21
   }

+ 3
- 10
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/cargo/RouteSpecificationTest.java Просмотреть файл

6
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
6
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
7
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
7
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
8
 
8
 
9
-import java.util.Arrays;
10
-
11
 public class RouteSpecificationTest extends TestCase {
9
 public class RouteSpecificationTest extends TestCase {
12
 
10
 
13
   final Voyage hongKongTokyoNewYork = new Voyage.Builder(
11
   final Voyage hongKongTokyoNewYork = new Voyage.Builder(
23
     addMovement(CHICAGO, toDate("2009-02-12"), toDate("2009-02-20")).
21
     addMovement(CHICAGO, toDate("2009-02-12"), toDate("2009-02-20")).
24
     build();
22
     build();
25
 
23
 
26
-  // TODO:
27
-  // it shouldn't be possible to create Legs that have load/unload locations
28
-  // and/or dates that don't match the voyage's carrier movements.
29
-  final Itinerary itinerary = new Itinerary(Arrays.asList(
30
-    new Leg(hongKongTokyoNewYork, HONGKONG, NEWYORK,
31
-      toDate("2009-02-01"), toDate("2009-02-10")),
32
-    new Leg(dallasNewYorkChicago, NEWYORK, CHICAGO,
33
-      toDate("2009-02-12"), toDate("2009-02-20")))
24
+  final Itinerary itinerary = new Itinerary(
25
+    Leg.deriveLeg(hongKongTokyoNewYork, HONGKONG, NEWYORK),
26
+    Leg.deriveLeg(dallasNewYorkChicago, NEWYORK, CHICAGO)
34
   );
27
   );
35
 
28
 
36
   public void testIsSatisfiedBy_Success() {
29
   public void testIsSatisfiedBy_Success() {

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

54
 
54
 
55
   public void testCurrentLocationLoadEvent() throws Exception {
55
   public void testCurrentLocationLoadEvent() throws Exception {
56
 
56
 
57
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, SampleVoyages.continenal2, new OperatorCode("ABCDE"));
57
+    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, SampleVoyages.continental2, new OperatorCode("ABCDE"));
58
 
58
 
59
     assertEquals(CHICAGO, ev.location());
59
     assertEquals(CHICAGO, ev.location());
60
   }
60
   }
61
 
61
 
62
   public void testCurrentLocationUnloadEvent() throws Exception {
62
   public void testCurrentLocationUnloadEvent() throws Exception {
63
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, SampleVoyages.continenal2, new OperatorCode("ABCDE"));
63
+    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, SampleVoyages.continental2, new OperatorCode("ABCDE"));
64
 
64
 
65
     assertEquals(HAMBURG, ev.location());
65
     assertEquals(HAMBURG, ev.location());
66
   }
66
   }

+ 217
- 19
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycle.java Просмотреть файл

12
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
12
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
13
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage.NONE;
13
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage.NONE;
14
 import se.citerus.dddsample.tracking.core.domain.service.RoutingService;
14
 import se.citerus.dddsample.tracking.core.domain.service.RoutingService;
15
+import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.TrackingIdFactoryInMem;
15
 
16
 
16
 import static java.util.Arrays.asList;
17
 import static java.util.Arrays.asList;
17
-import static java.util.Collections.emptyList;
18
+import java.util.Date;
18
 import java.util.List;
19
 import java.util.List;
19
 
20
 
20
 public class CargoLifecycle {
21
 public class CargoLifecycle {
21
 
22
 
22
   @Test
23
   @Test
23
-  public void cargoIsMisdirectedAndRerouted() throws Exception {
24
+  public void cargoIsProperlyDelivered() throws Exception {
25
+    Cargo cargo = setupCargoFromHongkongToStockholm();
26
+
27
+    // Initial state, before routing
28
+    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
29
+    assertThat(cargo.routingStatus(), is(NOT_ROUTED));
30
+    assertFalse(cargo.isMisdirected());
31
+    assertNull(cargo.estimatedTimeOfArrival());
32
+    assertNull(cargo.nextExpectedActivity());
33
+
34
+
35
+
36
+    // Route: Hongkong - Long Beach - New York - Stockholm
37
+    List<Itinerary> itineraries =
38
+      routingService.fetchRoutesForSpecification(cargo.routeSpecification());
39
+    Itinerary itinerary = selectAppropriateRoute(itineraries);
40
+    cargo.assignToRoute(itinerary);
41
+
42
+    // Routed
43
+    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
44
+    assertThat(cargo.routingStatus(), is(ROUTED));
45
+    assertThat(cargo.nextExpectedActivity(), is(receiveIn(HONGKONG)));
46
+    assertNotNull(cargo.estimatedTimeOfArrival());
47
+    assertThat(cargo.customsClearancePoint(), is(STOCKHOLM));
48
+
49
+    // Received
50
+    cargo.handled(receiveIn(HONGKONG));
51
+
52
+    assertThat(cargo.transportStatus(), is(IN_PORT));
53
+    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
54
+
55
+    // Loaded
56
+    cargo.handled(loadOnto(pacific1).in(HONGKONG));
57
+
58
+    assertThat(cargo.currentVoyage(), is(pacific1));
59
+    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
60
+    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
61
+    assertThat(cargo.nextExpectedActivity(), is(unloadOff(pacific1).in(LONGBEACH)));
62
+    assertFalse(cargo.isMisdirected());
63
+
64
+    // Unloaded
65
+    cargo.handled(unloadOff(pacific1).in(LONGBEACH));
66
+
67
+    assertFalse(cargo.isMisdirected());
68
+    assertThat(cargo.currentVoyage(), is(NONE));
69
+    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
70
+    assertThat(cargo.transportStatus(), is(IN_PORT));
71
+    assertThat(cargo.nextExpectedActivity(), is(loadOnto(continental1).in(LONGBEACH)));
72
+
73
+    cargo.handled(loadOnto(continental1).in(LONGBEACH));
74
+
75
+    assertFalse(cargo.isMisdirected());
76
+    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
77
+    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
78
+    assertThat(cargo.currentVoyage(), is(continental1));
79
+    assertThat(cargo.nextExpectedActivity(), is(unloadOff(continental1).in(NEWYORK)));
80
+
81
+    cargo.handled(unloadOff(continental1).in(NEWYORK));
82
+
83
+    assertFalse(cargo.isMisdirected());
84
+    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
85
+    assertThat(cargo.transportStatus(), is(IN_PORT));
86
+    assertThat(cargo.currentVoyage(), is(NONE));
87
+    assertThat(cargo.nextExpectedActivity(), is(loadOnto(atlantic2).in(NEWYORK)));
88
+
89
+    cargo.handled(loadOnto(atlantic2).in(NEWYORK));
90
+
91
+    assertFalse(cargo.isMisdirected());
92
+    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
93
+    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
94
+    assertThat(cargo.currentVoyage(), is(atlantic2));
95
+    assertThat(cargo.nextExpectedActivity(), is(unloadOff(atlantic2).in(STOCKHOLM)));
96
+
97
+    cargo.handled(unloadOff(atlantic2).in(STOCKHOLM));
98
+
99
+    assertFalse(cargo.isReadyToClaim());
100
+    assertFalse(cargo.isMisdirected());
101
+    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
102
+    assertThat(cargo.transportStatus(), is(IN_PORT));
103
+    assertThat(cargo.currentVoyage(), is(NONE));
104
+    assertThat(cargo.nextExpectedActivity(), is(customsIn(STOCKHOLM)));
105
+
106
+    cargo.handled(customsIn(STOCKHOLM));
107
+
108
+    assertTrue(cargo.isReadyToClaim());
109
+    assertThat(cargo.nextExpectedActivity(), is(claimIn(STOCKHOLM)));
110
+
111
+    cargo.handled(claimIn(STOCKHOLM));
24
     
112
     
25
-    TrackingId trackingId = new TrackingId("ABC");
26
-    RouteSpecification routeSpecification =
27
-      new RouteSpecification(HONGKONG, STOCKHOLM, toDate("2009-03-18"));
28
-    Cargo cargo = new Cargo(trackingId, routeSpecification);
113
+    assertNull(cargo.nextExpectedActivity());
114
+  }
115
+
116
+  @Test
117
+  public void cargoIsMisdirectedAndRerouted() throws Exception {
118
+
119
+    Cargo cargo = setupCargoFromHongkongToStockholm();
29
 
120
 
30
     // Initial state, before routing
121
     // Initial state, before routing
31
     assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
122
     assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
168
     cargo.assignToRoute(newItinerary);
259
     cargo.assignToRoute(newItinerary);
169
 
260
 
170
     assertThat(cargo.routingStatus(), is(ROUTED));
261
     assertThat(cargo.routingStatus(), is(ROUTED));
171
-    assertThat(cargo.nextExpectedActivity(), is(loadOnto(v300).in(ROTTERDAM)));
262
+    assertThat(cargo.nextExpectedActivity(), is(loadOnto(atlantic1).in(ROTTERDAM)));
172
 
263
 
173
 
264
 
174
 
265
 
182
 
273
 
183
 
274
 
184
     // Loaded, back on track
275
     // Loaded, back on track
185
-    cargo.handled(loadOnto(v300).in(ROTTERDAM));
276
+    cargo.handled(loadOnto(atlantic1).in(ROTTERDAM));
186
     assertFalse(cargo.isMisdirected());
277
     assertFalse(cargo.isMisdirected());
187
     assertThat(cargo.lastKnownLocation(), is(ROTTERDAM));
278
     assertThat(cargo.lastKnownLocation(), is(ROTTERDAM));
188
     assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
279
     assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
202
 
293
 
203
   }
294
   }
204
 
295
 
296
+  @Test
297
+  public void customerRequestsChangeOfDestination() throws Exception {
298
+    Cargo cargo = setupCargoFromHongkongToStockholm();
299
+
300
+    // Initial state, before routing
301
+    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
302
+    assertThat(cargo.routingStatus(), is(NOT_ROUTED));
303
+    assertFalse(cargo.isMisdirected());
304
+    assertNull(cargo.estimatedTimeOfArrival());
305
+    assertNull(cargo.nextExpectedActivity());
306
+
307
+
308
+
309
+    // Route: Hongkong - Long Beach - New York - Stockholm
310
+    List<Itinerary> itineraries =
311
+      routingService.fetchRoutesForSpecification(cargo.routeSpecification());
312
+    Itinerary itinerary = selectAppropriateRoute(itineraries);
313
+    cargo.assignToRoute(itinerary);
314
+
315
+    // Routed
316
+    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
317
+    assertThat(cargo.routingStatus(), is(ROUTED));
318
+    assertThat(cargo.nextExpectedActivity(), is(receiveIn(HONGKONG)));
319
+    assertNotNull(cargo.estimatedTimeOfArrival());
320
+
321
+    // Received
322
+    cargo.handled(receiveIn(HONGKONG));
323
+
324
+    assertThat(cargo.transportStatus(), is(IN_PORT));
325
+    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
326
+
327
+    // Loaded
328
+    cargo.handled(loadOnto(pacific1).in(HONGKONG));
329
+
330
+    assertThat(cargo.currentVoyage(), is(pacific1));
331
+    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
332
+    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
333
+    assertThat(cargo.nextExpectedActivity(), is(unloadOff(pacific1).in(LONGBEACH)));
334
+    assertFalse(cargo.isMisdirected());
335
+
336
+    // Unloaded
337
+    cargo.handled(unloadOff(pacific1).in(LONGBEACH));
338
+
339
+    assertThat(cargo.currentVoyage(), is(NONE));
340
+    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
341
+    assertThat(cargo.transportStatus(), is(IN_PORT));
342
+    assertFalse(cargo.isMisdirected());
343
+    assertThat(cargo.nextExpectedActivity(), is(loadOnto(continental1).in(LONGBEACH)));
344
+
345
+    // Customer wants cargo to go to Rotterdam instead of Stockholm
346
+    RouteSpecification toRotterdam = cargo.routeSpecification().
347
+      withOrigin(cargo.lastKnownLocation()).
348
+      withDestination(ROTTERDAM);
349
+
350
+    cargo.specifyNewRoute(toRotterdam);
351
+
352
+    // Misrouted
353
+    assertThat(cargo.routingStatus(), is(MISROUTED));
354
+    assertFalse(cargo.isMisdirected());
355
+    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
356
+    assertThat(cargo.transportStatus(), is(IN_PORT));
357
+
358
+    // Assign to new route
359
+    List<Itinerary> available = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
360
+    Itinerary newItinerary = selectAppropriateRoute(available);
361
+    cargo.assignToRoute(newItinerary);
362
+
363
+    assertThat(cargo.routingStatus(), is(ROUTED));
364
+    assertThat(cargo.nextExpectedActivity(), is(loadOnto(continental2).in(LONGBEACH)));
365
+
366
+    // Loaded, back on track
367
+    cargo.handled(loadOnto(continental2).in(LONGBEACH));
368
+    assertFalse(cargo.isMisdirected());
369
+    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
370
+    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
371
+    assertThat(cargo.nextExpectedActivity(), is(unloadOff(continental2).in(NEWYORK)));
372
+
373
+    // Fast forward a bit
374
+    cargo.handled(unloadOff(continental2).in(NEWYORK));
375
+    cargo.handled(loadOnto(atlantic1).in(NEWYORK));
376
+
377
+    // Cargo enters its destination customs zone
378
+    cargo.handled(unloadOff(atlantic1).in(ROTTERDAM));
379
+    assertThat(cargo.nextExpectedActivity(), is(customsIn(ROTTERDAM)));
380
+    cargo.handled(customsIn(ROTTERDAM));
381
+    assertThat(cargo.nextExpectedActivity(), is(claimIn(ROTTERDAM)));
382
+  }
383
+
384
+  private Cargo setupCargoFromHongkongToStockholm() {
385
+    TrackingId trackingId = trackingIdFactory.nextTrackingId();
386
+    Date arrivalDeadline = toDate("2009-04-10");
387
+    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, STOCKHOLM, arrivalDeadline);
388
+
389
+    return new Cargo(trackingId, routeSpecification);
390
+  }
391
+
392
+  // Stubbed out customer selection process
205
   private Itinerary selectAppropriateRoute(List<Itinerary> itineraries) {
393
   private Itinerary selectAppropriateRoute(List<Itinerary> itineraries) {
206
     return itineraries.get(0);
394
     return itineraries.get(0);
207
   }
395
   }
208
 
396
 
209
-  RoutingService routingService = new ScenarioStubRoutingService();
397
+  private final RoutingService routingService = new ScenarioStubRoutingService();
398
+
399
+  private final TrackingIdFactory trackingIdFactory = new TrackingIdFactoryInMem();
210
 
400
 
211
   private static class ScenarioStubRoutingService implements RoutingService {
401
   private static class ScenarioStubRoutingService implements RoutingService {
212
 
402
 
213
-    private static final Itinerary itinerary1 = new Itinerary(asList(
214
-      new Leg(pacific1, HONGKONG, LONGBEACH, toDate("2009-03-03"), toDate("2009-03-09")),
215
-      new Leg(continental1, LONGBEACH, NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")),
216
-      new Leg(pacific2, NEWYORK, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
217
-    ));
403
+    private static final Itinerary itinerary1 = new Itinerary(
404
+      Leg.deriveLeg(pacific1, HONGKONG, LONGBEACH),
405
+      Leg.deriveLeg(continental1, LONGBEACH, NEWYORK),
406
+      Leg.deriveLeg(atlantic2, NEWYORK, STOCKHOLM)
407
+    );
408
+
409
+    private static final Itinerary itinerary2 = new Itinerary(
410
+      Leg.deriveLeg(atlantic1, ROTTERDAM, HAMBURG),
411
+      Leg.deriveLeg(atlantic2, HAMBURG, STOCKHOLM)
412
+    );
218
 
413
 
219
-    private static final Itinerary itinerary2 = new Itinerary(asList(
220
-      new Leg(v300, ROTTERDAM, HAMBURG, toDate("2009-03-10"), toDate("2009-03-12")),
221
-      new Leg(v400, HAMBURG, STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15"))
222
-    ));
414
+    private static final Itinerary itinerary3 = new Itinerary(
415
+      Leg.deriveLeg(continental2, LONGBEACH, NEWYORK),
416
+      Leg.deriveLeg(atlantic1, NEWYORK, ROTTERDAM)
417
+    );
223
 
418
 
224
     public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
419
     public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
225
       if (routeSpecification.origin().sameAs(HONGKONG)) {
420
       if (routeSpecification.origin().sameAs(HONGKONG)) {
228
       } else if (routeSpecification.origin().sameAs(ROTTERDAM)) {
423
       } else if (routeSpecification.origin().sameAs(ROTTERDAM)) {
229
         // Rotterdam - Hamburg - Stockholm, rerouting misdirected cargo from Rotterdam
424
         // Rotterdam - Hamburg - Stockholm, rerouting misdirected cargo from Rotterdam
230
         return asList(itinerary2);
425
         return asList(itinerary2);
426
+      } else if (routeSpecification.origin().sameAs(LONGBEACH)) {
427
+        // Customer requested change of destination
428
+        return asList(itinerary3);
231
       } else {
429
       } else {
232
-        return emptyList();
430
+        throw new IllegalStateException("No stubbed data for " + routeSpecification);
233
       }
431
       }
234
     }
432
     }
235
 
433
 

+ 0
- 466
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycleScenarioTest.java Просмотреть файл

1
-package se.citerus.dddsample.tracking.core.domain.scenario;
2
-
3
-import static org.hamcrest.core.Is.is;
4
-import static org.junit.Assert.*;
5
-import org.junit.Test;
6
-import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
7
-import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
8
-import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.*;
9
-import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.*;
10
-import se.citerus.dddsample.tracking.core.domain.model.handling.*;
11
-import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
12
-import se.citerus.dddsample.tracking.core.domain.model.location.Location;
13
-import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
14
-import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
15
-import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
16
-import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.*;
17
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.*;
18
-import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
19
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage.NONE;
20
-import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
21
-import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
22
-import se.citerus.dddsample.tracking.core.domain.service.RoutingService;
23
-import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.*;
24
-
25
-import java.util.Arrays;
26
-import java.util.Date;
27
-import java.util.List;
28
-
29
-public class CargoLifecycleScenarioTest {
30
-
31
-  /**
32
-   * Repository implementations are part of the infrastructure layer,
33
-   * which in this test is stubbed out by in-memory replacements.
34
-   */
35
-  HandlingEventRepository handlingEventRepository = new HandlingEventRepositoryInMem();
36
-  CargoRepository cargoRepository = new CargoRepositoryInMem();
37
-  LocationRepository locationRepository = new LocationRepositoryInMem();
38
-  VoyageRepository voyageRepository = new VoyageRepositoryInMem();
39
-
40
-  HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
41
-  TrackingIdFactory trackingIdFactory = new TrackingIdFactoryInMem();
42
-
43
-  /**
44
-   * This is a domain service interface, whose implementation
45
-   * is part of the infrastructure layer (re mote call to external system).
46
-   * <p/>
47
-   * It is stubbed in this test.
48
-   */
49
-  RoutingService routingService = new ScenarioStubRoutingService();
50
-
51
-  TrackingId trackingId;
52
-
53
-  @Test
54
-  public void cargoIsCorrectlyDelivered() throws Exception {
55
-    bookCargoFromHongkongToStockholm();
56
-    checkDeliveryAfterBooking();
57
-
58
-    // Route: Hongkong - Long Beach - New York - Stockholm
59
-    routeCargoFromHongkongToStockholm();
60
-    checkDeliveryAfterRouting();
61
-
62
-    receiveInHongkong();
63
-    checkDeliveryAfterReceiveInHongkong();
64
-
65
-    loadInHongkong();
66
-    checkDeliveryAfterLoadInHongKong();
67
-
68
-    unloadInLongBeach();
69
-    checkDeliveryAfterUnloadInLongBeach();
70
-
71
-    loadInLongBeach();
72
-    checkDeliveryAfterLoadInLongBeach();
73
-
74
-    unloadInNewYork();
75
-    checkDeliveryAfterUnloadInNewYork();
76
-
77
-    loadInNewYork();
78
-    checkDeliveryAfterLoadInNewYork();
79
-
80
-    unloadInStockholmOffOf(pacific2);
81
-    checkDeliveryAfterUnloadInStockholm();
82
-
83
-    customsInStockholm();
84
-    checkDeliveryAfterCustomsInStockholm();
85
-    
86
-    claimInStockholm();
87
-    checkDeliveryAfterClaimInStockholm();
88
-  }
89
-
90
-  private void unloadInLongBeach() throws CannotCreateHandlingEventException {
91
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-06"), pacific1, LONGBEACH, UNLOAD);
92
-  }
93
-
94
-  private void checkDeliveryAfterUnloadInLongBeach() {
95
-    Cargo cargo = cargoRepository.find(trackingId);
96
-
97
-    assertThat(cargo.currentVoyage(), is(NONE));
98
-    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
99
-    assertThat(cargo.transportStatus(), is(IN_PORT));
100
-    assertFalse(cargo.isMisdirected());
101
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, LONGBEACH, continental1)));
102
-  }
103
-
104
-  private void loadInLongBeach() throws CannotCreateHandlingEventException {
105
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-07"), continental1, LONGBEACH, LOAD);
106
-  }
107
-
108
-  private void checkDeliveryAfterLoadInLongBeach() {
109
-    Cargo cargo = cargoRepository.find(trackingId);
110
-
111
-    assertThat(cargo.currentVoyage(), is(continental1));
112
-    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
113
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
114
-    assertFalse(cargo.isMisdirected());
115
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, NEWYORK, continental1)));
116
-  }
117
-
118
-  private void unloadInNewYork() throws CannotCreateHandlingEventException {
119
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), continental1, NEWYORK, UNLOAD);
120
-  }
121
-
122
-  private void checkDeliveryAfterUnloadInNewYork() {
123
-    Cargo cargo = cargoRepository.find(trackingId);
124
-
125
-    assertThat(cargo.currentVoyage(), is(NONE));
126
-    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
127
-    assertThat(cargo.transportStatus(), is(IN_PORT));
128
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, NEWYORK, pacific2)));
129
-    assertFalse(cargo.isMisdirected());
130
-  }
131
-
132
-  private void loadInNewYork() throws CannotCreateHandlingEventException {
133
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-10"), pacific2, NEWYORK, LOAD);
134
-  }
135
-
136
-  private void checkDeliveryAfterLoadInNewYork() {
137
-    Cargo cargo = cargoRepository.find(trackingId);
138
-
139
-    assertThat(cargo.currentVoyage(), is(pacific2));
140
-    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
141
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
142
-    assertFalse(cargo.isMisdirected());
143
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, pacific2)));
144
-  }
145
-
146
-  @Test
147
-  public void cargoIsMisdirectedAndRerouted() throws Exception {
148
-    bookCargoFromHongkongToStockholm();
149
-    checkDeliveryAfterBooking();
150
-
151
-
152
-    // Initial route: Hongkong - Long Beach - New York - Stockholm
153
-    routeCargoFromHongkongToStockholm();
154
-    checkDeliveryAfterRouting();
155
-
156
-    receiveInHongkong();
157
-    checkDeliveryAfterReceiveInHongkong();
158
-
159
-    loadInHongkong();
160
-    checkDeliveryAfterLoadInHongKong();
161
-
162
-    unloadInTokyo();
163
-    checkDeliveryAfterUnloadInTokyo();
164
-
165
-
166
-    // Reroute: Tokyo - Hamburg - Stockholm
167
-    specifyNewRouteFromTokyoToStockholm();
168
-    checkDeliveryAfterNewRouteSpecified();
169
-
170
-    assignToNewRouteFromTokyoToStockholm();
171
-    checkDeliveryAfterAssignedToNewRoute();
172
-
173
-
174
-    loadInTokyo();
175
-    checkDeliveryAfterLoadInTokyo();
176
-
177
-    unloadInHamburg();
178
-    checkDeliveryAfterUnloadInHamburg();
179
-
180
-    customsInHamburg();
181
-    checkDeliveryAfterCustomsInHamburg();
182
-
183
-    loadInHamburg();
184
-    checkDeliveryAfterLoadInHamburg();
185
-
186
-    unloadInStockholmOffOf(v400);
187
-    checkDeliveryAfterUnloadInStockholm2();
188
-
189
-    claimInStockholm();
190
-    checkDeliveryAfterClaimInStockholm();
191
-  }
192
-
193
-  private void bookCargoFromHongkongToStockholm() {
194
-    Date arrivalDeadline = toDate("2009-03-18");
195
-    final TrackingId trackingId1 = trackingIdFactory.nextTrackingId();
196
-    final RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, STOCKHOLM, arrivalDeadline);
197
-
198
-    Cargo cargo = new Cargo(trackingId1, routeSpecification);
199
-    cargoRepository.store(cargo);
200
-
201
-    trackingId = cargo.trackingId();
202
-  }
203
-
204
-  private void routeCargoFromHongkongToStockholm() {
205
-    Cargo cargo = cargoRepository.find(trackingId);
206
-    List<Itinerary> itineraries = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
207
-    Itinerary itinerary = itineraries.get(0);
208
-    cargo.assignToRoute(itinerary);
209
-    cargoRepository.store(cargo);
210
-  }
211
-
212
-  public void checkDeliveryAfterBooking() throws Exception {
213
-    Cargo cargo = cargoRepository.find(trackingId);
214
-
215
-    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
216
-    assertThat(cargo.routingStatus(), is(NOT_ROUTED));
217
-    assertFalse(cargo.isMisdirected());
218
-    assertNull(cargo.estimatedTimeOfArrival());
219
-    assertNull(cargo.nextExpectedActivity());
220
-  }
221
-
222
-  public void checkDeliveryAfterRouting() throws Exception {
223
-    Cargo cargo = cargoRepository.find(trackingId);
224
-
225
-    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
226
-    assertThat(cargo.routingStatus(), is(ROUTED));
227
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(RECEIVE, HONGKONG)));
228
-    assertNotNull(cargo.estimatedTimeOfArrival());
229
-  }
230
-
231
-  public void receiveInHongkong() throws CannotCreateHandlingEventException {
232
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-01"), null, HONGKONG, RECEIVE);
233
-  }
234
-
235
-  private void checkDeliveryAfterReceiveInHongkong() {
236
-    Cargo cargo = cargoRepository.find(trackingId);
237
-    assertThat(cargo.transportStatus(), is(IN_PORT));
238
-    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
239
-  }
240
-
241
-  public void loadInHongkong() throws CannotCreateHandlingEventException {
242
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-03"), pacific1, HONGKONG, LOAD);
243
-  }
244
-
245
-  private void checkDeliveryAfterLoadInHongKong() {
246
-    // Check current state - should be ok
247
-    Cargo cargo = cargoRepository.find(trackingId);
248
-
249
-    assertThat(cargo.currentVoyage(), is(pacific1));
250
-    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
251
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
252
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, LONGBEACH, pacific1)));
253
-    assertFalse(cargo.isMisdirected());
254
-  }
255
-
256
-  public void unloadInTokyo() throws CannotCreateHandlingEventException {
257
-    // Cargo is now (incorrectly) unloaded in Tokyo
258
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-05"), pacific1, TOKYO, UNLOAD);
259
-  }
260
-
261
-  private void checkDeliveryAfterUnloadInTokyo() {
262
-    Cargo cargo = cargoRepository.find(trackingId);
263
-    // Check current state - cargo is misdirected!
264
-    assertThat(cargo.currentVoyage(), is(NONE));
265
-    assertThat(cargo.lastKnownLocation(), is(TOKYO));
266
-    assertThat(cargo.transportStatus(), is(IN_PORT));
267
-    assertTrue(cargo.isMisdirected());
268
-    assertNull(cargo.nextExpectedActivity());
269
-  }
270
-
271
-  public void specifyNewRouteFromTokyoToStockholm() {
272
-    // TODO cleaner reroute from "earliest location from where the new route originates"
273
-    Cargo cargo = cargoRepository.find(trackingId);
274
-
275
-    // Specify a new route, this time from Tokyo (where it was incorrectly unloaded) to Stockholm
276
-    RouteSpecification fromTokyo = cargo.routeSpecification().withOrigin(TOKYO);
277
-    cargo.specifyNewRoute(fromTokyo);
278
-    cargoRepository.store(cargo);
279
-  }
280
-
281
-  public void checkDeliveryAfterNewRouteSpecified() {
282
-    Cargo cargo = cargoRepository.find(trackingId);
283
-
284
-    // The old itinerary does not satisfy the new specification
285
-    assertThat(cargo.routingStatus(), is(MISROUTED));
286
-    assertNull(cargo.nextExpectedActivity());
287
-  }
288
-
289
-  public void assignToNewRouteFromTokyoToStockholm() {
290
-    Cargo cargo = cargoRepository.find(trackingId);
291
-
292
-    // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
293
-    List<Itinerary> newItineraries = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
294
-    Itinerary newItinerary = newItineraries.get(0);
295
-
296
-    cargo.assignToRoute(newItinerary);
297
-    cargoRepository.store(cargo);
298
-  }
299
-
300
-  public void checkDeliveryAfterAssignedToNewRoute() {
301
-    Cargo cargo = cargoRepository.find(trackingId);
302
-
303
-    // New itinerary should satisfy new route
304
-    assertThat(cargo.routingStatus(), is(ROUTED));
305
-    assertFalse(cargo.isMisdirected());
306
-    assertThat(cargo.nextExpectedActivity(), is(loadOnto(v300).in(TOKYO)));
307
-  }
308
-
309
-  public void loadInTokyo() throws CannotCreateHandlingEventException {
310
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), v300, TOKYO, LOAD);
311
-  }
312
-
313
-  private void checkDeliveryAfterLoadInTokyo() {
314
-    Cargo cargo = cargoRepository.find(trackingId);
315
-    // Check current state - should be ok
316
-    assertThat(cargo.currentVoyage(), is(v300));
317
-    assertThat(cargo.lastKnownLocation(), is(TOKYO));
318
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
319
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, HAMBURG, v300)));
320
-    assertFalse(cargo.isMisdirected());
321
-  }
322
-
323
-  public void unloadInHamburg() throws CannotCreateHandlingEventException {
324
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-12"), v300, HAMBURG, UNLOAD);
325
-  }
326
-
327
-  private void checkDeliveryAfterUnloadInHamburg() {
328
-    Cargo cargo = cargoRepository.find(trackingId);
329
-    // Check current state - should be ok
330
-
331
-    assertThat(cargo.currentVoyage(), is(NONE));
332
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
333
-    assertThat(cargo.transportStatus(), is(IN_PORT));
334
-    assertThat(cargo.nextExpectedActivity(), is(customsIn(HAMBURG)));
335
-    assertFalse(cargo.isMisdirected());
336
-  }
337
-
338
-  public void customsInHamburg() throws CannotCreateHandlingEventException {
339
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-12"), null, HAMBURG, CUSTOMS);
340
-  }
341
-
342
-  private void checkDeliveryAfterCustomsInHamburg() {
343
-    Cargo cargo = cargoRepository.find(trackingId);
344
-    // Check current state - should be ok
345
-
346
-    assertThat(cargo.currentVoyage(), is(NONE));
347
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
348
-    assertThat(cargo.transportStatus(), is(IN_PORT));
349
-    assertThat(cargo.mostRecentHandlingActivity(), is(customsIn(HAMBURG)));
350
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, HAMBURG, v400)));
351
-    assertFalse(cargo.isMisdirected());
352
-  }
353
-
354
-
355
-  public void loadInHamburg() throws CannotCreateHandlingEventException {
356
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-14"), v400, HAMBURG, LOAD);
357
-  }
358
-
359
-  private void checkDeliveryAfterLoadInHamburg() {
360
-    Cargo cargo = cargoRepository.find(trackingId);
361
-    // Check current state - should be ok
362
-
363
-    assertThat(cargo.currentVoyage(), is(v400));
364
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
365
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
366
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, v400)));
367
-    assertFalse(cargo.isMisdirected());
368
-  }
369
-
370
-  public void unloadInStockholmOffOf(Voyage voyage) throws CannotCreateHandlingEventException {
371
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-15"), voyage, STOCKHOLM, UNLOAD);
372
-  }
373
-
374
-  private void checkDeliveryAfterUnloadInStockholm() {
375
-    Cargo cargo = cargoRepository.find(trackingId);
376
-    // Check current state - should be ok
377
-    assertThat(cargo.currentVoyage(), is(NONE));
378
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
379
-    assertThat(cargo.transportStatus(), is(IN_PORT));
380
-    assertThat(cargo.nextExpectedActivity(), is(customsIn(STOCKHOLM)));
381
-    assertFalse(cargo.isMisdirected());
382
-  }
383
-
384
-  private void checkDeliveryAfterUnloadInStockholm2() {
385
-    Cargo cargo = cargoRepository.find(trackingId);
386
-    // Check current state - should be ok
387
-    assertThat(cargo.currentVoyage(), is(NONE));
388
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
389
-    assertThat(cargo.transportStatus(), is(IN_PORT));
390
-    assertThat(cargo.nextExpectedActivity(), is(claimIn(STOCKHOLM)));
391
-    assertFalse(cargo.isMisdirected());
392
-  }
393
-  
394
-  private void customsInStockholm() {
395
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-16"), null, STOCKHOLM, CUSTOMS);
396
-  }
397
-  
398
-  private void checkDeliveryAfterCustomsInStockholm() {
399
-    Cargo cargo = cargoRepository.find(trackingId);
400
-    // Check current state - should be ok
401
-    assertThat(cargo.currentVoyage(), is(NONE));
402
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
403
-    assertThat(cargo.transportStatus(), is(IN_PORT));
404
-    assertThat(cargo.nextExpectedActivity(), is(claimIn(STOCKHOLM)));
405
-    assertFalse(cargo.isMisdirected());
406
-  }
407
-
408
-  private void claimInStockholm() throws CannotCreateHandlingEventException {
409
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-16"), null, STOCKHOLM, CLAIM);
410
-  }
411
-
412
-  private void checkDeliveryAfterClaimInStockholm() {
413
-    Cargo cargo = cargoRepository.find(trackingId);
414
-    // Check current state - should be ok
415
-    assertThat(cargo.currentVoyage(), is(NONE));
416
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
417
-    assertThat(cargo.transportStatus(), is(CLAIMED));
418
-    assertFalse(cargo.isMisdirected());
419
-    assertNull(cargo.nextExpectedActivity());
420
-  }
421
-
422
-  private void createHandlingEventAndUpdateAggregates(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
423
-    EventSequenceNumber eventSequenceNumber = updateHandlingEventAggregate(completionTime, voyage, location, type);
424
-    updateCargoAggregate(eventSequenceNumber);
425
-  }
426
-
427
-  private EventSequenceNumber updateHandlingEventAggregate(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
428
-    VoyageNumber voyageNumber = voyage != null ? voyage.voyageNumber() : null;
429
-    HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(completionTime, trackingId, voyageNumber, location.unLocode(), type, new OperatorCode("ABCDE"));
430
-    handlingEventRepository.store(handlingEvent);
431
-    return handlingEvent.sequenceNumber();
432
-  }
433
-
434
-  private void updateCargoAggregate(EventSequenceNumber eventSequenceNumber) {
435
-    Cargo cargo = cargoRepository.find(trackingId);
436
-    HandlingEvent handlingEvent = handlingEventRepository.find(eventSequenceNumber);
437
-    cargo.handled(handlingEvent.activity());
438
-    cargoRepository.store(cargo);
439
-  }
440
-
441
-  private static class ScenarioStubRoutingService implements RoutingService {
442
-
443
-    public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
444
-      if (routeSpecification.origin().equals(HONGKONG)) {
445
-        // Hongkong - NYC - Chicago - Stockholm, initial routing
446
-        return Arrays.asList(
447
-          new Itinerary(Arrays.asList(
448
-            new Leg(pacific1, HONGKONG, LONGBEACH, toDate("2009-03-03"), toDate("2009-03-09")),
449
-            new Leg(continental1, LONGBEACH, NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")),
450
-            new Leg(pacific2, NEWYORK, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
451
-          ))
452
-        );
453
-      } else {
454
-        // Tokyo - Hamburg - Stockholm, rerouting misdirected cargo from Tokyo
455
-        return Arrays.asList(
456
-          new Itinerary(Arrays.asList(
457
-            new Leg(v300, TOKYO, HAMBURG, toDate("2009-03-08"), toDate("2009-03-12")),
458
-            new Leg(v400, HAMBURG, STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15"))
459
-          ))
460
-        );
461
-      }
462
-    }
463
-
464
-  }
465
-
466
-}

+ 10
- 10
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/CargoRepositoryTest.java Просмотреть файл

9
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
9
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
10
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
10
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
12
-import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
12
+import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.atlantic2;
13
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
13
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
16
 
16
 
17
-import java.util.Arrays;
18
 import java.util.Date;
17
 import java.util.Date;
19
 import java.util.List;
18
 import java.util.List;
20
 import java.util.Map;
19
 import java.util.Map;
108
     Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, new Date()));
107
     Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, new Date()));
109
     cargoRepository.store(cargo);
108
     cargoRepository.store(cargo);
110
 
109
 
111
-    cargo.assignToRoute(new Itinerary(Arrays.asList(
112
-      new Leg(
110
+    cargo.assignToRoute(new Itinerary(
111
+      Leg.deriveLeg(
113
         voyageRepository.find(new VoyageNumber("0101")),
112
         voyageRepository.find(new VoyageNumber("0101")),
114
         locationRepository.find(STOCKHOLM.unLocode()),
113
         locationRepository.find(STOCKHOLM.unLocode()),
115
-        locationRepository.find(MELBOURNE.unLocode()),
116
-        new Date(), new Date())
117
-    )));
114
+        locationRepository.find(MELBOURNE.unLocode()))
115
+    ));
118
 
116
 
119
     flush();
117
     flush();
120
 
118
 
140
     Long cargoId = getLongId(cargo);
138
     Long cargoId = getLongId(cargo);
141
     assertEquals(3, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));
139
     assertEquals(3, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));
142
 
140
 
143
-    Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
144
-    Location legTo = locationRepository.find(new UnLocode("DEHAM"));
145
-    Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(SampleVoyages.continenal2, legFrom, legTo, new Date(), new Date())));
141
+    Location legFrom = locationRepository.find(new UnLocode("DEHAM"));
142
+    Location legTo = locationRepository.find(new UnLocode("FIHEL"));
143
+    Itinerary newItinerary = new Itinerary(
144
+        Leg.deriveLeg(atlantic2, legFrom, legTo)
145
+    );
146
 
146
 
147
     cargo.assignToRoute(newItinerary);
147
     cargo.assignToRoute(newItinerary);
148
 
148
 

+ 5
- 7
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java Просмотреть файл

1
 package se.citerus.dddsample.tracking.core.infrastructure.persistence.hibernate;
1
 package se.citerus.dddsample.tracking.core.infrastructure.persistence.hibernate;
2
 
2
 
3
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
3
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
4
-
5
 import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
4
 import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
6
 import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoRepository;
5
 import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoRepository;
7
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
6
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
10
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
9
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
12
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
13
-
14
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.MELBOURNE;
12
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.MELBOURNE;
15
-
16
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
13
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
17
-import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
14
+import static se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity.claimIn;
18
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
19
 
16
 
20
 import java.util.Date;
17
 import java.util.Date;
58
 
55
 
59
     flush();
56
     flush();
60
 
57
 
61
-    Map<String, Object> result = sjt.queryForMap("select * from HandlingEvent where sequenceNumber = ?", event.sequenceNumber());
58
+    Map<String, Object> result = sjt.queryForMap("select * from HandlingEvent where sequence_number = ?", event.sequenceNumber());
62
     assertEquals(1L, result.get("CARGO_ID"));
59
     assertEquals(1L, result.get("CARGO_ID"));
63
     assertEquals(new Date(10), result.get("COMPLETIONTIME"));
60
     assertEquals(new Date(10), result.get("COMPLETIONTIME"));
64
-    assertEquals("CLAIM", result.get("TYPE"));
65
     // TODO: the rest of the columns
61
     // TODO: the rest of the columns
66
   }
62
   }
67
 
63
 
76
     HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(cargo);
72
     HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(cargo);
77
     assertEquals(cargo, handlingEvent.cargo());
73
     assertEquals(cargo, handlingEvent.cargo());
78
     assertEquals(toDate("2007-09-27", "05:00"), handlingEvent.completionTime());
74
     assertEquals(toDate("2007-09-27", "05:00"), handlingEvent.completionTime());
79
-    assertEquals(new HandlingActivity(HandlingEvent.Type.CLAIM, MELBOURNE), handlingEvent.activity());
75
+
76
+    assertEquals(claimIn(MELBOURNE), handlingEvent.activity());
77
+    assertEquals(handlingEvent.activity(), claimIn(MELBOURNE));
80
   }
78
   }
81
 
79
 
82
 }
80
 }

+ 5
- 6
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/interfaces/booking/facade/DTOAssemblerTest.java Просмотреть файл

10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
12
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
12
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
13
-
14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
13
 import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
16
 import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.LocationRepositoryInMem;
15
 import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.LocationRepositoryInMem;
86
   @Test
85
   @Test
87
   public void fromRouteCandidateDTO() throws Exception {
86
   public void fromRouteCandidateDTO() throws Exception {
88
     final List<LegDTO> legs = new ArrayList<LegDTO>();
87
     final List<LegDTO> legs = new ArrayList<LegDTO>();
89
-    legs.add(new LegDTO("CM003", "CNHKG", "USNYC", new Date(), new Date()));
90
-    legs.add(new LegDTO("CM004", "USNYC", "USCHI", new Date(), new Date()));
88
+    legs.add(new LegDTO("PAC1", "CNHKG", "USLBG", new Date(), new Date()));
89
+    legs.add(new LegDTO("CNT1", "USLBG", "USNYC", new Date(), new Date()));
91
 
90
 
92
     final LocationRepository locationRepository = new LocationRepositoryInMem();
91
     final LocationRepository locationRepository = new LocationRepositoryInMem();
93
     final VoyageRepository voyageRepository = new VoyageRepositoryInMem();
92
     final VoyageRepository voyageRepository = new VoyageRepositoryInMem();
104
     final Leg leg1 = itinerary.legs().get(0);
103
     final Leg leg1 = itinerary.legs().get(0);
105
     assertNotNull(leg1);
104
     assertNotNull(leg1);
106
     assertEquals(HONGKONG, leg1.loadLocation());
105
     assertEquals(HONGKONG, leg1.loadLocation());
107
-    assertEquals(NEWYORK, leg1.unloadLocation());
106
+    assertEquals(LONGBEACH, leg1.unloadLocation());
108
 
107
 
109
     final Leg leg2 = itinerary.legs().get(1);
108
     final Leg leg2 = itinerary.legs().get(1);
110
     assertNotNull(leg2);
109
     assertNotNull(leg2);
111
-    assertEquals(NEWYORK, leg2.loadLocation());
112
-    assertEquals(CHICAGO, leg2.unloadLocation());
110
+    assertEquals(LONGBEACH, leg2.loadLocation());
111
+    assertEquals(NEWYORK, leg2.unloadLocation());
113
   }
112
   }
114
 
113
 
115
   @Test
114
   @Test