Преглед изворни кода

Added realistic voyages and replaced some of the older ones.

peter_backlund пре 17 година
родитељ
комит
c3e0ce62fa
11 измењених фајлова са 124 додато и 105 уклоњено
  1. 36
    23
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/SampleVoyages.java
  2. 2
    0
      dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/Voyage.java
  3. 4
    3
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/application/handling/HandlingEventServiceTest.java
  4. 5
    5
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventFactoryTest.java
  5. 7
    9
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventTest.java
  6. 9
    9
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycle.java
  7. 18
    18
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycleScenarioTest.java
  8. 2
    2
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  9. 17
    6
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java
  10. 1
    1
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/routing/ExternalRoutingServiceTest.java
  11. 23
    29
      dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/interfaces/booking/facade/DTOAssemblerTest.java

+ 36
- 23
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/SampleVoyages.java Прегледај датотеку

@@ -12,40 +12,54 @@ import java.util.*;
12 12
  */
13 13
 public class SampleVoyages {
14 14
 
15
-  public static final Voyage CM001 = createVoyage("CM001", STOCKHOLM, HAMBURG);
16
-  public static final Voyage CM002 = createVoyage("CM002", HAMBURG, HONGKONG);
17
-  public static final Voyage CM003 = createVoyage("CM003", HONGKONG, NEWYORK);
18
-  public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
19
-  public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
20
-  public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
21
-
22
-  private static Voyage createVoyage(String id, Location from, Location to) {
23
-    return new Voyage(new VoyageNumber(id), new Schedule(Arrays.asList(
24
-      new CarrierMovement(from, to, new Date(1), new Date(2))
25
-    )));
26
-  }
27
-
28
-  // TODO CM00[1-6] and createVoyage are deprecated. Remove and refactor tests.
29
-
30
-  public final static Voyage v100 = new Voyage.Builder(new VoyageNumber("V100"), HONGKONG).
15
+  public final static Voyage pacific1 = new Voyage.Builder(new VoyageNumber("PAC1"), HONGKONG).
31 16
     addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05")).
32 17
     addMovement(LONGBEACH, toDate("2009-03-06"), toDate("2009-03-09")).
18
+    addMovement(SEATTLE, toDate("2009-03-10"), toDate("2009-03-12")).
19
+    addMovement(HONGKONG, toDate("2009-03-15"), toDate("2009-03-19")).
20
+    build();
21
+
22
+  public final static Voyage pacific2 = new Voyage.Builder(new VoyageNumber("PAC2"), SHANGHAI).
23
+    addMovement(LONGBEACH, toDate("2009-03-06"), toDate("2009-03-08")).
24
+    addMovement(SEATTLE, toDate("2009-03-10"), toDate("2009-03-14")).
25
+    addMovement(HANGZOU, toDate("2009-03-14"), toDate("2009-03-16")).
26
+    addMovement(SHANGHAI, toDate("2009-03-17"), toDate("2009-03-19")).
33 27
     build();
34
-  public final static Voyage v200 = new Voyage.Builder(new VoyageNumber("V200"), SHANGHAI).
35
-    addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08")).
36
-    addMovement(ROTTERDAM, toDate("2009-03-10"), toDate("2009-03-14")).
37
-    addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16")).
28
+
29
+  public final static Voyage continental1 = new Voyage.Builder(new VoyageNumber("CNT1"), LONGBEACH).
30
+    addMovement(DALLAS, toDate("2009-03-06"), toDate("2009-03-08")).
31
+    addMovement(CHICAGO, toDate("2009-03-09"), toDate("2009-03-10")).
32
+    addMovement(NEWYORK, toDate("2009-03-11"), toDate("2009-03-14")).
38 33
     build();
39
-  public final static Voyage v250 = new Voyage.Builder(new VoyageNumber("V250"), LONGBEACH).
34
+
35
+  public final static Voyage continenal2 = new Voyage.Builder(new VoyageNumber("CNT2"), LONGBEACH).
40 36
     addMovement(DALLAS, toDate("2009-03-06"), toDate("2009-03-08")).
41 37
     addMovement(NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")).
42 38
     build();
39
+
40
+  public final static Voyage atlantic1 = new Voyage.Builder(new VoyageNumber("ATC1"), NEWYORK).
41
+      addMovement(ROTTERDAM, toDate("2009-03-15"), toDate("2009-03-18")).
42
+      addMovement(HAMBURG, toDate("2009-03-19"), toDate("2009-03-20")).
43
+      addMovement(HELSINKI, toDate("2009-03-21"), toDate("2009-03-22")).
44
+      addMovement(NEWYORK, toDate("2009-03-24"), toDate("2009-03-30")).
45
+      build();
46
+
47
+  public final static Voyage atlantic2 = new Voyage.Builder(new VoyageNumber("ATC2"), NEWYORK).
48
+      addMovement(ROTTERDAM, toDate("2009-03-17"), toDate("2009-03-20")).
49
+      addMovement(GOTHENBURG, toDate("2009-03-22"), toDate("2009-03-24")).
50
+      addMovement(STOCKHOLM, toDate("2009-03-25"), toDate("2009-03-26")).
51
+      addMovement(HELSINKI, toDate("2009-03-27"), toDate("2009-03-28")).
52
+      addMovement(NEWYORK, toDate("2009-03-31"), toDate("2009-04-04")).
53
+      build();
54
+
55
+
43 56
   public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
44 57
     addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
45 58
     addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
46 59
     addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
47 60
     addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
48 61
     build();
62
+
49 63
   public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
50 64
     addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
51 65
     addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
@@ -65,7 +79,6 @@ public class SampleVoyages {
65 79
       addMovement(NEWYORK, toDate("2008-10-14", "12:00"), toDate("2008-10-23", "23:10")).
66 80
       build();
67 81
 
68
-
69 82
   /**
70 83
    * Voyage number 0200T (by train)
71 84
    * <p/>
@@ -111,7 +124,7 @@ public class SampleVoyages {
111 124
       addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37")).
112 125
       build();
113 126
 
114
-  public static final Map<VoyageNumber, Voyage> ALL = new HashMap<VoyageNumber, Voyage>();
127
+  private static final Map<VoyageNumber, Voyage> ALL = new HashMap<VoyageNumber, Voyage>();
115 128
 
116 129
   static {
117 130
     for (Field field : SampleVoyages.class.getDeclaredFields()) {

+ 2
- 0
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/voyage/Voyage.java Прегледај датотеку

@@ -3,9 +3,11 @@ package se.citerus.dddsample.tracking.core.domain.model.voyage;
3 3
 import org.apache.commons.lang.Validate;
4 4
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
5 5
 import se.citerus.dddsample.tracking.core.domain.patterns.entity.EntitySupport;
6
+import sun.jvm.hotspot.runtime.PerfMemory;
6 7
 
7 8
 import java.util.ArrayList;
8 9
 import java.util.Date;
10
+import java.util.Iterator;
9 11
 import java.util.List;
10 12
 
11 13
 /**

+ 4
- 3
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/application/handling/HandlingEventServiceTest.java Прегледај датотеку

@@ -13,7 +13,8 @@ import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRep
13 13
 import se.citerus.dddsample.tracking.core.domain.model.handling.OperatorCode;
14 14
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
15 15
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
16
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM001;
16
+
17
+import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
17 18
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
18 19
 
19 20
 import java.util.Date;
@@ -45,14 +46,14 @@ public class HandlingEventServiceTest extends TestCase {
45 46
 
46 47
   public void testRegisterEvent() throws Exception {
47 48
     expect(cargoRepository.find(cargo.trackingId())).andReturn(cargo);
48
-    expect(voyageRepository.find(CM001.voyageNumber())).andReturn(CM001);
49
+    expect(voyageRepository.find(SampleVoyages.pacific1.voyageNumber())).andReturn(SampleVoyages.pacific1);
49 50
     expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
50 51
     handlingEventRepository.store(isA(HandlingEvent.class));
51 52
     systemEvents.notifyOfHandlingEvent(isA(HandlingEvent.class));
52 53
 
53 54
     replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
54 55
 
55
-    service.registerHandlingEvent(new Date(), cargo.trackingId(), CM001.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD, new OperatorCode("ABCDE"));
56
+    service.registerHandlingEvent(new Date(), cargo.trackingId(), SampleVoyages.pacific1.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD, new OperatorCode("ABCDE"));
56 57
   }
57 58
 
58 59
 }

+ 5
- 5
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventFactoryTest.java Прегледај датотеку

@@ -10,7 +10,7 @@ import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingE
10 10
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
11 11
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
12 12
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
13
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM001;
13
+import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
14 14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
15 15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
16 16
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
@@ -46,7 +46,7 @@ public class HandlingEventFactoryTest extends TestCase {
46 46
 
47 47
     replay(cargoRepository);
48 48
 
49
-    VoyageNumber voyageNumber = CM001.voyageNumber();
49
+    VoyageNumber voyageNumber = SampleVoyages.pacific1.voyageNumber();
50 50
     UnLocode unLocode = STOCKHOLM.unLocode();
51 51
     HandlingEvent handlingEvent = factory.createHandlingEvent(
52 52
       new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD, new OperatorCode("ABCDE")
@@ -54,7 +54,7 @@ public class HandlingEventFactoryTest extends TestCase {
54 54
 
55 55
     assertNotNull(handlingEvent);
56 56
     assertEquals(STOCKHOLM, handlingEvent.location());
57
-    assertEquals(CM001, handlingEvent.voyage());
57
+    assertEquals(SampleVoyages.pacific1, handlingEvent.voyage());
58 58
     assertEquals(cargo, handlingEvent.cargo());
59 59
     assertEquals(new Date(100), handlingEvent.completionTime());
60 60
     assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
@@ -86,7 +86,7 @@ public class HandlingEventFactoryTest extends TestCase {
86 86
     UnLocode invalid = new UnLocode("NOEXT");
87 87
     try {
88 88
       factory.createHandlingEvent(
89
-        new Date(100), trackingId, CM001.voyageNumber(), invalid, Type.LOAD, new OperatorCode("ABCDE")
89
+        new Date(100), trackingId, SampleVoyages.pacific1.voyageNumber(), invalid, Type.LOAD, new OperatorCode("ABCDE")
90 90
       );
91 91
       fail("Expected UnknownLocationException");
92 92
     } catch (UnknownLocationException expected) {
@@ -115,7 +115,7 @@ public class HandlingEventFactoryTest extends TestCase {
115 115
 
116 116
     try {
117 117
       factory.createHandlingEvent(
118
-        new Date(100), trackingId, CM001.voyageNumber(), STOCKHOLM.unLocode(), Type.LOAD, new OperatorCode("ABCDE")
118
+        new Date(100), trackingId, SampleVoyages.pacific1.voyageNumber(), STOCKHOLM.unLocode(), Type.LOAD, new OperatorCode("ABCDE")
119 119
       );
120 120
       fail("Expected UnknownCargoException");
121 121
     } catch (UnknownCargoException expected) {

+ 7
- 9
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventTest.java Прегледај датотеку

@@ -7,8 +7,6 @@ import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
7 7
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
8 8
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
9 9
 import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
10
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM003;
11
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM004;
12 10
 
13 11
 import static java.util.Arrays.asList;
14 12
 import java.util.Date;
@@ -24,16 +22,16 @@ public class HandlingEventTest extends TestCase {
24 22
 
25 23
   public void testNewWithCarrierMovement() throws Exception {
26 24
 
27
-    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, CM003, new OperatorCode("ABCDE"));
25
+    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, SampleVoyages.continental1, new OperatorCode("ABCDE"));
28 26
     assertEquals(HONGKONG, e1.location());
29 27
 
30
-    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, CM003, new OperatorCode("ABCDE"));
28
+    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, SampleVoyages.continental1, new OperatorCode("ABCDE"));
31 29
     assertEquals(NEWYORK, e2.location());
32 30
 
33 31
     // These event types prohibit a carrier movement association
34 32
     for (HandlingEvent.Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
35 33
       try {
36
-        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, CM003, new OperatorCode("ABCDE"));
34
+        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, SampleVoyages.continental1, new OperatorCode("ABCDE"));
37 35
         fail("Handling event type " + type + " prohibits carrier movement");
38 36
       } catch (IllegalArgumentException expected) {
39 37
       }
@@ -56,13 +54,13 @@ public class HandlingEventTest extends TestCase {
56 54
 
57 55
   public void testCurrentLocationLoadEvent() throws Exception {
58 56
 
59
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, CM004, new OperatorCode("ABCDE"));
57
+    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, SampleVoyages.continenal2, new OperatorCode("ABCDE"));
60 58
 
61 59
     assertEquals(CHICAGO, ev.location());
62 60
   }
63 61
 
64 62
   public void testCurrentLocationUnloadEvent() throws Exception {
65
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, CM004, new OperatorCode("ABCDE"));
63
+    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, SampleVoyages.continenal2, new OperatorCode("ABCDE"));
66 64
 
67 65
     assertEquals(HAMBURG, ev.location());
68 66
   }
@@ -99,8 +97,8 @@ public class HandlingEventTest extends TestCase {
99 97
     Date timeOccured = new Date();
100 98
     Date timeRegistered = new Date();
101 99
 
102
-    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005, new OperatorCode("ABCDE"));
103
-    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005, new OperatorCode("ABCDE"));
100
+    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.atlantic1, new OperatorCode("ABCDE"));
101
+    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.atlantic1, new OperatorCode("ABCDE"));
104 102
 
105 103
     assertTrue(ev1.equals(ev2));
106 104
     assertTrue(ev2.equals(ev1));

+ 9
- 9
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycle.java Прегледај датотеку

@@ -81,12 +81,12 @@ public class CargoLifecycle {
81 81
 
82 82
 
83 83
     // Loaded
84
-    cargo.handled(loadOnto(v100).in(HONGKONG));
84
+    cargo.handled(loadOnto(pacific1).in(HONGKONG));
85 85
 
86
-    assertThat(cargo.currentVoyage(), is(v100));
86
+    assertThat(cargo.currentVoyage(), is(pacific1));
87 87
     assertThat(cargo.lastKnownLocation(), is(HONGKONG));
88 88
     assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
89
-    assertThat(cargo.nextExpectedActivity(), is(unloadOff(v100).in(LONGBEACH)));
89
+    assertThat(cargo.nextExpectedActivity(), is(unloadOff(pacific1).in(LONGBEACH)));
90 90
     assertFalse(cargo.isMisdirected());
91 91
 
92 92
 
@@ -103,13 +103,13 @@ public class CargoLifecycle {
103 103
 
104 104
 
105 105
     // Unloaded
106
-    cargo.handled(unloadOff(v100).in(LONGBEACH));
106
+    cargo.handled(unloadOff(pacific1).in(LONGBEACH));
107 107
 
108 108
     assertThat(cargo.currentVoyage(), is(NONE));
109 109
     assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
110 110
     assertThat(cargo.transportStatus(), is(IN_PORT));
111 111
     assertFalse(cargo.isMisdirected());
112
-    assertThat(cargo.nextExpectedActivity(), is(loadOnto(v250).in(LONGBEACH)));
112
+    assertThat(cargo.nextExpectedActivity(), is(loadOnto(continental1).in(LONGBEACH)));
113 113
 
114 114
 
115 115
 
@@ -126,7 +126,7 @@ public class CargoLifecycle {
126 126
 
127 127
 
128 128
     // Unloaded in Rotterdam, wasn't supposed to happen
129
-    cargo.handled(unloadOff(v200).in(ROTTERDAM));
129
+    cargo.handled(unloadOff(pacific2).in(ROTTERDAM));
130 130
 
131 131
     // Misdirected
132 132
     assertTrue(cargo.isMisdirected());
@@ -211,9 +211,9 @@ public class CargoLifecycle {
211 211
   private static class ScenarioStubRoutingService implements RoutingService {
212 212
 
213 213
     private static final Itinerary itinerary1 = new Itinerary(asList(
214
-      new Leg(v100, HONGKONG, LONGBEACH, toDate("2009-03-03"), toDate("2009-03-09")),
215
-      new Leg(v250, LONGBEACH, NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")),
216
-      new Leg(v200, NEWYORK, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
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 217
     ));
218 218
 
219 219
     private static final Itinerary itinerary2 = new Itinerary(asList(

+ 18
- 18
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/scenario/CargoLifecycleScenarioTest.java Прегледај датотеку

@@ -77,7 +77,7 @@ public class CargoLifecycleScenarioTest {
77 77
     loadInNewYork();
78 78
     checkDeliveryAfterLoadInNewYork();
79 79
 
80
-    unloadInStockholmOffOf(v200);
80
+    unloadInStockholmOffOf(pacific2);
81 81
     checkDeliveryAfterUnloadInStockholm();
82 82
 
83 83
     customsInStockholm();
@@ -88,7 +88,7 @@ public class CargoLifecycleScenarioTest {
88 88
   }
89 89
 
90 90
   private void unloadInLongBeach() throws CannotCreateHandlingEventException {
91
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-06"), v100, LONGBEACH, UNLOAD);
91
+    createHandlingEventAndUpdateAggregates(toDate("2009-03-06"), pacific1, LONGBEACH, UNLOAD);
92 92
   }
93 93
 
94 94
   private void checkDeliveryAfterUnloadInLongBeach() {
@@ -98,25 +98,25 @@ public class CargoLifecycleScenarioTest {
98 98
     assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
99 99
     assertThat(cargo.transportStatus(), is(IN_PORT));
100 100
     assertFalse(cargo.isMisdirected());
101
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, LONGBEACH, v250)));
101
+    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, LONGBEACH, continental1)));
102 102
   }
103 103
 
104 104
   private void loadInLongBeach() throws CannotCreateHandlingEventException {
105
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-07"), v250, LONGBEACH, LOAD);
105
+    createHandlingEventAndUpdateAggregates(toDate("2009-03-07"), continental1, LONGBEACH, LOAD);
106 106
   }
107 107
 
108 108
   private void checkDeliveryAfterLoadInLongBeach() {
109 109
     Cargo cargo = cargoRepository.find(trackingId);
110 110
 
111
-    assertThat(cargo.currentVoyage(), is(v250));
111
+    assertThat(cargo.currentVoyage(), is(continental1));
112 112
     assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
113 113
     assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
114 114
     assertFalse(cargo.isMisdirected());
115
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, NEWYORK, v250)));
115
+    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, NEWYORK, continental1)));
116 116
   }
117 117
 
118 118
   private void unloadInNewYork() throws CannotCreateHandlingEventException {
119
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), v250, NEWYORK, UNLOAD);
119
+    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), continental1, NEWYORK, UNLOAD);
120 120
   }
121 121
 
122 122
   private void checkDeliveryAfterUnloadInNewYork() {
@@ -125,22 +125,22 @@ public class CargoLifecycleScenarioTest {
125 125
     assertThat(cargo.currentVoyage(), is(NONE));
126 126
     assertThat(cargo.lastKnownLocation(), is(NEWYORK));
127 127
     assertThat(cargo.transportStatus(), is(IN_PORT));
128
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, NEWYORK, v200)));
128
+    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, NEWYORK, pacific2)));
129 129
     assertFalse(cargo.isMisdirected());
130 130
   }
131 131
 
132 132
   private void loadInNewYork() throws CannotCreateHandlingEventException {
133
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-10"), v200, NEWYORK, LOAD);
133
+    createHandlingEventAndUpdateAggregates(toDate("2009-03-10"), pacific2, NEWYORK, LOAD);
134 134
   }
135 135
 
136 136
   private void checkDeliveryAfterLoadInNewYork() {
137 137
     Cargo cargo = cargoRepository.find(trackingId);
138 138
 
139
-    assertThat(cargo.currentVoyage(), is(v200));
139
+    assertThat(cargo.currentVoyage(), is(pacific2));
140 140
     assertThat(cargo.lastKnownLocation(), is(NEWYORK));
141 141
     assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
142 142
     assertFalse(cargo.isMisdirected());
143
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, v200)));
143
+    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, pacific2)));
144 144
   }
145 145
 
146 146
   @Test
@@ -239,23 +239,23 @@ public class CargoLifecycleScenarioTest {
239 239
   }
240 240
 
241 241
   public void loadInHongkong() throws CannotCreateHandlingEventException {
242
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-03"), v100, HONGKONG, LOAD);
242
+    createHandlingEventAndUpdateAggregates(toDate("2009-03-03"), pacific1, HONGKONG, LOAD);
243 243
   }
244 244
 
245 245
   private void checkDeliveryAfterLoadInHongKong() {
246 246
     // Check current state - should be ok
247 247
     Cargo cargo = cargoRepository.find(trackingId);
248 248
 
249
-    assertThat(cargo.currentVoyage(), is(v100));
249
+    assertThat(cargo.currentVoyage(), is(pacific1));
250 250
     assertThat(cargo.lastKnownLocation(), is(HONGKONG));
251 251
     assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
252
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, LONGBEACH, v100)));
252
+    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, LONGBEACH, pacific1)));
253 253
     assertFalse(cargo.isMisdirected());
254 254
   }
255 255
 
256 256
   public void unloadInTokyo() throws CannotCreateHandlingEventException {
257 257
     // Cargo is now (incorrectly) unloaded in Tokyo
258
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-05"), v100, TOKYO, UNLOAD);
258
+    createHandlingEventAndUpdateAggregates(toDate("2009-03-05"), pacific1, TOKYO, UNLOAD);
259 259
   }
260 260
 
261 261
   private void checkDeliveryAfterUnloadInTokyo() {
@@ -445,9 +445,9 @@ public class CargoLifecycleScenarioTest {
445 445
         // Hongkong - NYC - Chicago - Stockholm, initial routing
446 446
         return Arrays.asList(
447 447
           new Itinerary(Arrays.asList(
448
-            new Leg(v100, HONGKONG, LONGBEACH, toDate("2009-03-03"), toDate("2009-03-09")),
449
-            new Leg(v250, LONGBEACH, NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")),
450
-            new Leg(v200, NEWYORK, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
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 451
           ))
452 452
         );
453 453
       } else {

+ 2
- 2
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/CargoRepositoryTest.java Прегледај датотеку

@@ -9,7 +9,7 @@ import se.citerus.dddsample.tracking.core.domain.model.location.Location;
9 9
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
10 10
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
11 11
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
12
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM004;
12
+import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
13 13
 import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
14 14
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
15 15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
@@ -142,7 +142,7 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
142 142
 
143 143
     Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
144 144
     Location legTo = locationRepository.find(new UnLocode("DEHAM"));
145
-    Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(CM004, legFrom, legTo, new Date(), new Date())));
145
+    Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(SampleVoyages.continenal2, legFrom, legTo, new Date(), new Date())));
146 146
 
147 147
     cargo.assignToRoute(newItinerary);
148 148
 

+ 17
- 6
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java Прегледај датотеку

@@ -1,16 +1,21 @@
1 1
 package se.citerus.dddsample.tracking.core.infrastructure.persistence.hibernate;
2 2
 
3 3
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
4
+
4 5
 import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
5 6
 import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoRepository;
6 7
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
7 8
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
9
+import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
8 10
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
9 11
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
10 12
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
13
+
11 14
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.MELBOURNE;
15
+
12 16
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
13 17
 import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
18
+import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
14 19
 
15 20
 import java.util.Date;
16 21
 import java.util.List;
@@ -21,6 +26,8 @@ public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
21 26
   HandlingEventRepository handlingEventRepository;
22 27
   CargoRepository cargoRepository;
23 28
   LocationRepository locationRepository;
29
+  HandlingEventFactory handlingEventFactory;
30
+  VoyageRepository voyageRepository;
24 31
 
25 32
   public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
26 33
     this.handlingEventRepository = handlingEventRepository;
@@ -34,22 +41,26 @@ public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
34 41
     this.locationRepository = locationRepository;
35 42
   }
36 43
 
44
+  public void setVoyageRepository(VoyageRepository voyageRepository) {
45
+    this.voyageRepository = voyageRepository;
46
+  }
47
+
37 48
   public void testSave() {
38
-    Location location = locationRepository.find(new UnLocode("SESTO"));
49
+    handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
50
+    UnLocode unLocode = new UnLocode("SESTO");
51
+    Location location = locationRepository.find(unLocode);
39 52
 
40
-    Cargo cargo = cargoRepository.find(new TrackingId("XYZ"));
53
+    TrackingId trackingId = new TrackingId("XYZ");
41 54
     Date completionTime = new Date(10);
42
-    Date registrationTime = new Date(20);
43
-    HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, HandlingEvent.Type.CLAIM, location);
55
+    HandlingEvent event = handlingEventFactory.createHandlingEvent(completionTime, trackingId, null, unLocode, HandlingEvent.Type.CLAIM, null);
44 56
 
45 57
     handlingEventRepository.store(event);
46 58
 
47 59
     flush();
48 60
 
49
-    Map<String, Object> result = sjt.queryForMap("select * from HandlingEvent where id = ?", getLongId(event));
61
+    Map<String, Object> result = sjt.queryForMap("select * from HandlingEvent where sequenceNumber = ?", event.sequenceNumber());
50 62
     assertEquals(1L, result.get("CARGO_ID"));
51 63
     assertEquals(new Date(10), result.get("COMPLETIONTIME"));
52
-    assertEquals(new Date(20), result.get("REGISTRATIONTIME"));
53 64
     assertEquals("CLAIM", result.get("TYPE"));
54 65
     // TODO: the rest of the columns
55 66
   }

+ 1
- 1
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/infrastructure/routing/ExternalRoutingServiceTest.java Прегледај датотеку

@@ -55,7 +55,7 @@ public class ExternalRoutingServiceTest extends TestCase {
55 55
     RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, toDate("2009-04-01"));
56 56
     Cargo cargo = new Cargo(trackingId, routeSpecification);
57 57
 
58
-    expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
58
+    expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.pacific2);
59 59
 
60 60
     replay(voyageRepository);
61 61
 

+ 23
- 29
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/interfaces/booking/facade/DTOAssemblerTest.java Прегледај датотеку

@@ -10,7 +10,8 @@ import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
10 10
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
11 11
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
12 12
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
13
-import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM001;
13
+
14
+import se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages;
14 15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageRepository;
15 16
 import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.LocationRepositoryInMem;
16 17
 import se.citerus.dddsample.tracking.core.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
@@ -24,15 +25,13 @@ public class DTOAssemblerTest {
24 25
 
25 26
   @Test
26 27
   public void toCargoRoutingDTO() throws Exception {
27
-    final Location origin = STOCKHOLM;
28
-    final Location destination = MELBOURNE;
28
+    final Location origin = HONGKONG;
29
+    final Location destination = LONGBEACH;
29 30
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(origin, destination, new Date()));
30 31
 
31 32
     final Itinerary itinerary = new Itinerary(
32
-      Arrays.asList(
33
-        new Leg(CM001, origin, SHANGHAI, new Date(), new Date()),
34
-        new Leg(CM001, ROTTERDAM, destination, new Date(), new Date())
35
-      )
33
+      Leg.deriveLeg(SampleVoyages.pacific1, HONGKONG, TOKYO),
34
+      Leg.deriveLeg(SampleVoyages.pacific1, TOKYO, LONGBEACH)
36 35
     );
37 36
 
38 37
     cargo.assignToRoute(itinerary);
@@ -42,51 +41,46 @@ public class DTOAssemblerTest {
42 41
     assertEquals(2, dto.getLegs().size());
43 42
 
44 43
     LegDTO legDTO = dto.getLegs().get(0);
45
-    assertEquals("CM001", legDTO.getVoyageNumber());
46
-    assertEquals("SESTO", legDTO.getFrom());
47
-    assertEquals("CNSHA", legDTO.getTo());
44
+    assertEquals("PAC1", legDTO.getVoyageNumber());
45
+    assertEquals("CNHKG", legDTO.getFrom());
46
+    assertEquals("JNTKO", legDTO.getTo());
48 47
 
49 48
     legDTO = dto.getLegs().get(1);
50
-    assertEquals("CM001", legDTO.getVoyageNumber());
51
-    assertEquals("NLRTM", legDTO.getFrom());
52
-    assertEquals("AUMEL", legDTO.getTo());
49
+    assertEquals("PAC1", legDTO.getVoyageNumber());
50
+    assertEquals("JNTKO", legDTO.getFrom());
51
+    assertEquals("USLBG", legDTO.getTo());
53 52
   }
54 53
 
55 54
   @Test
56 55
   public void toCargoDTONoItinerary() throws Exception {
57
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
56
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HONGKONG, LONGBEACH, new Date()));
58 57
     final CargoRoutingDTO dto = DTOAssembler.toDTO(cargo);
59 58
 
60 59
     assertEquals("XYZ", dto.getTrackingId());
61
-    assertEquals("SESTO", dto.getOrigin());
62
-    assertEquals("AUMEL", dto.getFinalDestination());
60
+    assertEquals("CNHKG", dto.getOrigin());
61
+    assertEquals("USLBG", dto.getFinalDestination());
63 62
     assertTrue(dto.getLegs().isEmpty());
64 63
   }
65 64
 
66 65
   @Test
67 66
   public void toRouteCandidateDTO() throws Exception {
68
-    final Location origin = STOCKHOLM;
69
-    final Location destination = MELBOURNE;
70
-
71 67
     final Itinerary itinerary = new Itinerary(
72
-      Arrays.asList(
73
-        new Leg(CM001, origin, SHANGHAI, new Date(), new Date()),
74
-        new Leg(CM001, ROTTERDAM, destination, new Date(), new Date())
75
-      )
68
+      Leg.deriveLeg(SampleVoyages.pacific1, HONGKONG, TOKYO),
69
+      Leg.deriveLeg(SampleVoyages.pacific1, TOKYO, LONGBEACH)
76 70
     );
77 71
 
78 72
     final RouteCandidateDTO dto = DTOAssembler.toDTO(itinerary);
79 73
 
80 74
     assertEquals(2, dto.getLegs().size());
81 75
     LegDTO legDTO = dto.getLegs().get(0);
82
-    assertEquals("CM001", legDTO.getVoyageNumber());
83
-    assertEquals("SESTO", legDTO.getFrom());
84
-    assertEquals("CNSHA", legDTO.getTo());
76
+    assertEquals("PAC1", legDTO.getVoyageNumber());
77
+    assertEquals("CNHKG", legDTO.getFrom());
78
+    assertEquals("JNTKO", legDTO.getTo());
85 79
 
86 80
     legDTO = dto.getLegs().get(1);
87
-    assertEquals("CM001", legDTO.getVoyageNumber());
88
-    assertEquals("NLRTM", legDTO.getFrom());
89
-    assertEquals("AUMEL", legDTO.getTo());
81
+    assertEquals("PAC1", legDTO.getVoyageNumber());
82
+    assertEquals("JNTKO", legDTO.getFrom());
83
+    assertEquals("USLBG", legDTO.getTo());
90 84
   }
91 85
 
92 86
   @Test