Procházet zdrojové kódy

Introduced a UnLocode class, consistent with CarrierMovementId and TrackingId for CarrierMovement and Cargo, respectively.

Brought Spring version back up to 2.5.1
peter_backlund před 18 roky
rodič
revize
9dfbdf5ce6
31 změnil soubory, kde provedl 399 přidání a 243 odebrání
  1. 14
    16
      dddsample/pom.xml
  2. 34
    25
      dddsample/src/main/java/se/citerus/dddsample/domain/Location.java
  3. 2
    0
      dddsample/src/main/java/se/citerus/dddsample/domain/TrackingId.java
  4. 63
    0
      dddsample/src/main/java/se/citerus/dddsample/domain/UnLocode.java
  5. 2
    1
      dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepositoryInMem.java
  6. 2
    1
      dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryInMem.java
  7. 3
    1
      dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java
  8. 2
    1
      dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepository.java
  9. 4
    3
      dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepositoryHibernate.java
  10. 4
    4
      dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java
  11. 4
    1
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventService.java
  12. 4
    4
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java
  13. 5
    4
      dddsample/src/main/java/se/citerus/dddsample/service/UnknownLocationException.java
  14. 8
    8
      dddsample/src/main/java/se/citerus/dddsample/util/SampleDataGenerator.java
  15. 4
    1
      dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpointImpl.java
  16. 0
    1
      dddsample/src/main/resources/context-persistence.xml
  17. 51
    46
      dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java
  18. 7
    5
      dddsample/src/test/java/se/citerus/dddsample/domain/DeliveryHistoryTest.java
  19. 20
    24
      dddsample/src/test/java/se/citerus/dddsample/domain/HandlingEventTest.java
  20. 11
    19
      dddsample/src/test/java/se/citerus/dddsample/domain/LocationTest.java
  21. 11
    7
      dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java
  22. 57
    0
      dddsample/src/test/java/se/citerus/dddsample/domain/UnLocodeTest.java
  23. 4
    0
      dddsample/src/test/java/se/citerus/dddsample/repository/AbstractRepositoryTest.java
  24. 8
    10
      dddsample/src/test/java/se/citerus/dddsample/repository/CargoRepositoryTest.java
  25. 6
    10
      dddsample/src/test/java/se/citerus/dddsample/repository/CarrierMovementRepositoryTest.java
  26. 7
    7
      dddsample/src/test/java/se/citerus/dddsample/repository/HandlingEventRepositoryTest.java
  27. 4
    2
      dddsample/src/test/java/se/citerus/dddsample/repository/LocationRepositoryTest.java
  28. 15
    11
      dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java
  29. 29
    19
      dddsample/src/test/java/se/citerus/dddsample/service/HandlingEventServiceTest.java
  30. 9
    9
      dddsample/src/test/java/se/citerus/dddsample/web/CargoTrackingControllerTest.java
  31. 5
    3
      dddsample/src/test/java/se/citerus/dddsample/ws/HandlinEventServiceEndpointTest.java

+ 14
- 16
dddsample/pom.xml Zobrazit soubor

@@ -85,6 +85,9 @@
85 85
     <developerConnection>scm:svn:https://dddsample.svn.sourceforge.net/svnroot/dddsample</developerConnection>
86 86
     <url>http://ddd.sventon.org</url>
87 87
   </scm>
88
+  <properties>
89
+    <spring.version>2.5.1</spring.version>
90
+  </properties>
88 91
   <build>
89 92
     <plugins>
90 93
       <!-- Compiler -->
@@ -101,6 +104,7 @@
101 104
       <plugin>
102 105
         <groupId>org.mortbay.jetty</groupId>
103 106
         <artifactId>maven-jetty-plugin</artifactId>
107
+        <version>6.1.4</version>
104 108
         <configuration>
105 109
           <!--scanIntervalSeconds>10</scanIntervalSeconds-->
106 110
         </configuration>
@@ -110,6 +114,7 @@
110 114
       <plugin>
111 115
         <groupId>org.codehaus.mojo</groupId>
112 116
         <artifactId>jaxws-maven-plugin</artifactId>
117
+        <version>1.9</version>
113 118
         <executions>
114 119
           <execution>
115 120
             <goals>
@@ -120,13 +125,11 @@
120 125
         <configuration>
121 126
           <sei>se.citerus.dddsample.ws.HandlingEventServiceEndpointImpl</sei>
122 127
           <genWsdl>true</genWsdl>
123
-          <verbose>true</verbose>
124 128
         </configuration>
125 129
       </plugin>
126
-      
130
+
127 131
       <!-- Jar plugin for generation of WS Client classes -->
128 132
       <plugin>
129
-        <groupId>org.apache.maven.plugins</groupId>
130 133
         <artifactId>maven-jar-plugin</artifactId>
131 134
         <executions>
132 135
           <execution>
@@ -143,7 +146,7 @@
143 146
           </execution>
144 147
         </executions>
145 148
       </plugin>
146
-      
149
+
147 150
     </plugins>
148 151
   </build>
149 152
   <dependencies>
@@ -156,29 +159,27 @@
156 159
     <dependency>
157 160
       <groupId>org.springframework</groupId>
158 161
       <artifactId>spring-webmvc</artifactId>
159
-      <version>2.0.8</version>
162
+      <version>${spring.version}</version>
160 163
     </dependency>
161 164
     <dependency>
162 165
       <groupId>org.springframework</groupId>
163
-      <artifactId>spring-hibernate3</artifactId>
164
-      <!-- -orm in 2.5.x -->
165
-      <version>2.0.8</version>
166
+      <artifactId>spring-orm</artifactId>
167
+      <version>${spring.version}</version>
166 168
     </dependency>
167 169
     <dependency>
168 170
       <groupId>org.springframework</groupId>
169 171
       <artifactId>spring-jdbc</artifactId>
170
-      <version>2.0.8</version>
172
+      <version>${spring.version}</version>
171 173
     </dependency>
172 174
     <dependency>
173 175
       <groupId>org.springframework</groupId>
174 176
       <artifactId>spring-aop</artifactId>
175
-      <version>2.0.8</version>
177
+      <version>${spring.version}</version>
176 178
     </dependency>
177 179
     <dependency>
178 180
       <groupId>org.springframework</groupId>
179
-      <artifactId>spring-mock</artifactId>
180
-      <!-- -test in 2.5.x -->
181
-      <version>2.0.8</version>
181
+      <artifactId>spring-test</artifactId>
182
+      <version>${spring.version}</version>
182 183
       <scope>test</scope>
183 184
     </dependency>
184 185
     <dependency>
@@ -272,17 +273,14 @@
272 273
     <plugins>
273 274
       <!-- Javadoc -->
274 275
       <plugin>
275
-        <groupId>org.apache.maven.plugins</groupId>
276 276
         <artifactId>maven-javadoc-plugin</artifactId>
277 277
       </plugin>
278 278
       <!-- Source code cross reference -->
279 279
       <plugin>
280
-        <groupId>org.apache.maven.plugins</groupId>
281 280
         <artifactId>maven-jxr-plugin</artifactId>
282 281
       </plugin>
283 282
       <!-- Test report -->
284 283
       <plugin>
285
-        <groupId>org.apache.maven.plugins</groupId>
286 284
         <artifactId>maven-surefire-report-plugin</artifactId>
287 285
       </plugin>
288 286
     </plugins>

+ 34
- 25
dddsample/src/main/java/se/citerus/dddsample/domain/Location.java Zobrazit soubor

@@ -2,10 +2,10 @@ package se.citerus.dddsample.domain;
2 2
 
3 3
 import org.apache.commons.lang.Validate;
4 4
 
5
+import javax.persistence.Embedded;
5 6
 import javax.persistence.Entity;
6 7
 import javax.persistence.GeneratedValue;
7 8
 import javax.persistence.Id;
8
-import java.util.regex.Pattern;
9 9
 
10 10
 @Entity
11 11
 public class Location {
@@ -14,44 +14,50 @@ public class Location {
14 14
   @GeneratedValue
15 15
   private Long id;
16 16
 
17
-  private String unlocode;
17
+  @Embedded
18
+  private UnLocode unLocode;
18 19
 
19
-  /**
20
-   * Regular expression of a UN Locode (exactly five letters of the english alphabet)
21
-   */
22
-  private static final Pattern unlocodePattern = Pattern.compile("[a-zA-Z]{5}");
20
+  private String name;
23 21
 
24 22
   /**
25 23
    * Special Location object that marks an unknown location.
26 24
    */
27
-  public static final Location UNKNOWN = new Location();
25
+  public static final Location UNKNOWN = new Location(
26
+    new UnLocode("XX","XXX"), "Unknown location"
27
+  );
28 28
 
29
-  // Internal constructor
30
-  private Location() {
31
-    this.unlocode = "Unknown";
29
+  /**
30
+   * @param unLocode UN Locode
31
+   * @param name location name
32
+   * @throws IllegalArgumentException if the UN Locode or name is null
33
+   */
34
+  public Location(UnLocode unLocode, String name) {
35
+    // TODO:
36
+    // It shouldn't really be possible to create a new location -
37
+    // it should only be looked up in the location repository.
38
+    Validate.notNull(unLocode);
39
+    Validate.notNull(name);
40
+    this.unLocode = unLocode;
41
+    this.name = name;
32 42
   }
33 43
 
34 44
   /**
35
-   * @param unlocode UN locode
36
-   * @throws IllegalArgumentException if the UN locode is anything other than five letters of the US alphabet
45
+   * @return UN Locode for this location.
37 46
    */
38
-  public Location(String unlocode) {
39
-    Validate.notNull(unlocode);
40
-    Validate.isTrue(unlocodePattern.matcher(unlocode).matches(),
41
-            "\"" + unlocode + "\" is not a valid UN Locode");
42
-    this.unlocode = unlocode;
47
+  public UnLocode unLocode() {
48
+    return unLocode;
43 49
   }
44 50
 
45 51
   /**
46
-   * @return United Nations Location Code for this location.
52
+   * @return Actual name of this location, e.g. "Stockholm".
47 53
    */
48
-  public String unlocode() {
49
-    return unlocode;
54
+  public String name() {
55
+    return name;
50 56
   }
51 57
 
52 58
   /**
53 59
    * @param object to compare
54
-   * @return True if unlocodes are equal.
60
+   * @return True iff UN locodes are equal.
55 61
    */
56 62
   @Override
57 63
   public boolean equals(Object object) {
@@ -65,20 +71,23 @@ public class Location {
65 71
       return false;
66 72
     }
67 73
     Location other = (Location) object;
68
-    return this.unlocode.equals(other.unlocode);
74
+    return this.unLocode.equals(other.unLocode);
69 75
   }
70 76
 
71 77
   /**
72
-   * @return Hash code of unlocode.
78
+   * @return Hash code of UN locode.
73 79
    */
74 80
   @Override
75 81
   public int hashCode() {
76
-    return unlocode.hashCode();
82
+    return unLocode.hashCode();
77 83
   }
78 84
 
79 85
   @Override
80 86
   public String toString() {
81
-    return unlocode;
87
+    return unLocode.idString() + " (" + name + ")";
82 88
   }
83 89
 
90
+  // Needed by Hibernate
91
+  Location() {}
92
+
84 93
 }

+ 2
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/TrackingId.java Zobrazit soubor

@@ -1,5 +1,6 @@
1 1
 package se.citerus.dddsample.domain;
2 2
 
3
+import org.apache.commons.lang.Validate;
3 4
 import org.apache.commons.lang.builder.EqualsBuilder;
4 5
 import org.apache.commons.lang.builder.HashCodeBuilder;
5 6
 
@@ -17,6 +18,7 @@ public class TrackingId {
17 18
   private String id;
18 19
 
19 20
   public TrackingId(String id) {
21
+    Validate.notNull(id);
20 22
     this.id = id;
21 23
   }
22 24
 

+ 63
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/UnLocode.java Zobrazit soubor

@@ -0,0 +1,63 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+import org.apache.commons.lang.Validate;
4
+import org.apache.commons.lang.builder.EqualsBuilder;
5
+import org.apache.commons.lang.builder.HashCodeBuilder;
6
+
7
+import javax.persistence.Embeddable;
8
+import java.util.Arrays;
9
+import java.util.regex.Pattern;
10
+
11
+/**
12
+ * United nations location code.
13
+ *
14
+ * http://www.unece.org/cefact/locode/
15
+ * http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE
16
+ */
17
+@Embeddable
18
+public class UnLocode {
19
+
20
+  private String unlocode;
21
+
22
+  // Country code is exactly two letters
23
+  private static final Pattern countryCodePattern = Pattern.compile("[a-zA-Z]{2}");
24
+
25
+  // Location code is usually three letters, but may contain the numbers 2-9 as well
26
+  private static final Pattern locationCodePattern = Pattern.compile("[a-zA-Z2-9]{3}");
27
+
28
+  public UnLocode(String countryCode, String locationCode) {
29
+    validateArgs(countryCode, locationCode);
30
+
31
+    this.unlocode = (countryCode + locationCode).toUpperCase();
32
+  }
33
+
34
+  private void validateArgs(String countryCode, String locationCode) {
35
+    Validate.noNullElements(Arrays.asList(countryCode, locationCode),
36
+            "Neither country code nor location code may be null");
37
+    Validate.isTrue(countryCodePattern.matcher(countryCode).matches(),
38
+      "\"" + countryCode + "\" is not a valid country code");
39
+    Validate.isTrue(locationCodePattern.matcher(locationCode).matches(),
40
+      "\"" + locationCode + "\" is not a valid location code");
41
+  }
42
+
43
+  /**
44
+   * @return country code and location code concatenated
45
+   */
46
+  public String idString() {
47
+    return unlocode;
48
+  }
49
+
50
+  @Override
51
+  public boolean equals(Object obj) {
52
+    return EqualsBuilder.reflectionEquals(this, obj);
53
+  }
54
+
55
+  @Override
56
+  public int hashCode() {
57
+    return HashCodeBuilder.reflectionHashCode(this);
58
+  }
59
+
60
+  // Needed by Hibernate
61
+  UnLocode() {
62
+  }
63
+}

+ 2
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepositoryInMem.java Zobrazit soubor

@@ -2,7 +2,6 @@ package se.citerus.dddsample.repository;
2 2
 
3 3
 import org.springframework.dao.DataRetrievalFailureException;
4 4
 import se.citerus.dddsample.domain.Cargo;
5
-import se.citerus.dddsample.domain.Location;
6 5
 import se.citerus.dddsample.domain.TrackingId;
7 6
 
8 7
 import java.util.HashMap;
@@ -43,6 +42,7 @@ public class CargoRepositoryInMem implements CargoRepository {
43 42
    * @throws Exception
44 43
    */
45 44
   public void init() throws Exception {
45
+/*
46 46
     String trackIdXYZ = "XYZ";
47 47
     final Cargo cargoXYZ = new Cargo(new TrackingId(trackIdXYZ), new Location("SESTO"), new Location("AUMEL"));
48 48
     cargoDb.put(trackIdXYZ, cargoXYZ);
@@ -58,6 +58,7 @@ public class CargoRepositoryInMem implements CargoRepository {
58 58
     String trackIdCBA = "CBA";
59 59
     final Cargo cargoCBA = new Cargo(new TrackingId(trackIdCBA), new Location("FIHEL"), new Location("SESTO"));
60 60
     cargoDb.put(trackIdCBA, cargoCBA);
61
+*/
61 62
 
62 63
     /*
63 64
     for (Cargo cargo : cargoDb.values()) {

+ 2
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryInMem.java Zobrazit soubor

@@ -2,7 +2,6 @@ package se.citerus.dddsample.repository;
2 2
 
3 3
 import se.citerus.dddsample.domain.CarrierMovement;
4 4
 import se.citerus.dddsample.domain.CarrierMovementId;
5
-import se.citerus.dddsample.domain.Location;
6 5
 
7 6
 import java.util.HashMap;
8 7
 import java.util.Map;
@@ -16,6 +15,7 @@ public class CarrierMovementRepositoryInMem implements CarrierMovementRepository
16 15
   }
17 16
 
18 17
   private void setup() {
18
+/*
19 19
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
20 20
             new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
21 21
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
@@ -32,6 +32,7 @@ public class CarrierMovementRepositoryInMem implements CarrierMovementRepository
32 32
     carriers.put(new CarrierMovementId("AUMEL_JPTOK"), melbourneToTokyo);
33 33
     carriers.put(new CarrierMovementId("JPTOK_USLA"), tokyoToLosAngeles);
34 34
     carriers.put(new CarrierMovementId("SESTO_FIHEL"), stockholmToHelsinki);
35
+*/
35 36
   }
36 37
 
37 38
   public CarrierMovement find(CarrierMovementId carrierMovementId) {

+ 3
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java Zobrazit soubor

@@ -31,7 +31,8 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository{
31 31
    * @throws ParseException
32 32
    */
33 33
   public void init() throws ParseException {
34
-    
34
+/*
35
+
35 36
     // CargoXYZ
36 37
     final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
37 38
     registerEvent(cargoXYZ, "2007-11-30", HandlingEvent.Type.RECEIVE, null);
@@ -69,6 +70,7 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository{
69 70
     //CargoCBA
70 71
     final Cargo cargoCBA = new Cargo(new TrackingId("CBA"), new Location("FIHEL"), new Location("SESTO"));
71 72
     registerEvent(cargoCBA, "2008-01-10", HandlingEvent.Type.RECEIVE, null);
73
+*/
72 74
   }
73 75
 
74 76
   

+ 2
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepository.java Zobrazit soubor

@@ -1,9 +1,10 @@
1 1
 package se.citerus.dddsample.repository;
2 2
 
3 3
 import se.citerus.dddsample.domain.Location;
4
+import se.citerus.dddsample.domain.UnLocode;
4 5
 
5 6
 public interface LocationRepository {
6 7
 
7
-  Location find(String string);
8
+  Location find(UnLocode unLocode);
8 9
 
9 10
 }

+ 4
- 3
dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepositoryHibernate.java Zobrazit soubor

@@ -1,13 +1,14 @@
1 1
 package se.citerus.dddsample.repository;
2 2
 
3 3
 import se.citerus.dddsample.domain.Location;
4
+import se.citerus.dddsample.domain.UnLocode;
4 5
 
5 6
 public class LocationRepositoryHibernate extends HibernateRepository implements LocationRepository {
6 7
 
7
-  public Location find(String unlcode) {
8
+  public Location find(UnLocode unLocode) {
8 9
     return (Location) getSession().
9
-          createQuery("from Location where unlocode = ?").
10
-          setParameter(0, unlcode).
10
+          createQuery("from Location where unLocode = ?").
11
+          setParameter(0, unLocode).
11 12
           uniqueResult();
12 13
   }
13 14
 }

+ 4
- 4
dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java Zobrazit soubor

@@ -24,14 +24,14 @@ public class CargoServiceImpl implements CargoService {
24 24
     HandlingEvent lastEvent = cargo.deliveryHistory().lastEvent();
25 25
     String currentLocation;
26 26
     if (lastEvent != null) {
27
-      currentLocation = lastEvent.location().unlocode();
27
+      currentLocation = lastEvent.location().toString();
28 28
     } else {
29 29
       currentLocation = "";
30 30
     }
31 31
     final CargoWithHistoryDTO dto = new CargoWithHistoryDTO(
32 32
             cargo.trackingId().idString(),
33
-            cargo.origin().unlocode(),
34
-            cargo.finalDestination().unlocode(),
33
+            cargo.origin().toString(),
34
+            cargo.finalDestination().toString(),
35 35
             currentLocation
36 36
     );
37 37
     final List<HandlingEvent> events = cargo.deliveryHistory().eventsOrderedByCompletionTime();
@@ -39,7 +39,7 @@ public class CargoServiceImpl implements CargoService {
39 39
       CarrierMovement cm = event.carrierMovement();
40 40
       String carrierIdString = (cm == null) ? "" : cm.carrierId().idString();
41 41
       dto.addEvent(new HandlingEventDTO(
42
-              event.location().unlocode(),
42
+              event.location().toString(),
43 43
               event.type().toString(),
44 44
               carrierIdString,
45 45
               event.completionTime()

+ 4
- 1
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventService.java Zobrazit soubor

@@ -3,6 +3,7 @@ package se.citerus.dddsample.service;
3 3
 import se.citerus.dddsample.domain.CarrierMovementId;
4 4
 import se.citerus.dddsample.domain.HandlingEvent;
5 5
 import se.citerus.dddsample.domain.TrackingId;
6
+import se.citerus.dddsample.domain.UnLocode;
6 7
 
7 8
 import java.util.Date;
8 9
 
@@ -19,10 +20,12 @@ public interface HandlingEventService {
19 20
    * @param carrierMovementId carrier movement id, if applicable (may be null)
20 21
    * @param unlocode United Nations Location Code for the location of the event
21 22
    * @param type type of event
23
+   *
22 24
    * @throws UnknownCarrierMovementIdException if there's not carrier movement with this id
23 25
    * @throws UnknownTrackingIdException if there's no cargo with this tracking id
26
+   * @throws UnknownLocationException if there's no location with this UN Locode 
24 27
    */
25
-  void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, String unlocode, HandlingEvent.Type type)
28
+  void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type)
26 29
   throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException;
27 30
 
28 31
 }

+ 4
- 4
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java Zobrazit soubor

@@ -17,7 +17,7 @@ public class HandlingEventServiceImpl implements HandlingEventService {
17 17
   private LocationRepository locationRepository;
18 18
 
19 19
   @Transactional(readOnly = false)
20
-  public void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, String unlocode, HandlingEvent.Type type) throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException {
20
+  public void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type) throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException {
21 21
     Cargo cargo = findCargo(trackingId);
22 22
     CarrierMovement carrierMovement = findCarrierMovement(carrierMovementId);
23 23
     Location location = findLocation(unlocode);
@@ -53,13 +53,13 @@ public class HandlingEventServiceImpl implements HandlingEventService {
53 53
     return carrierMovement;
54 54
   }
55 55
 
56
-  private Location findLocation(String unlocode) throws UnknownLocationException {
57
-    if (unlocode == null){
56
+  private Location findLocation(UnLocode unlocode) throws UnknownLocationException {
57
+    if (unlocode == null) {
58 58
       return Location.UNKNOWN;
59 59
     }
60 60
     
61 61
     Location location = locationRepository.find(unlocode);
62
-    if (location == null){
62
+    if (location == null) {
63 63
       throw new UnknownLocationException(unlocode);
64 64
     }
65 65
     

+ 5
- 4
dddsample/src/main/java/se/citerus/dddsample/service/UnknownLocationException.java Zobrazit soubor

@@ -1,16 +1,17 @@
1 1
 package se.citerus.dddsample.service;
2 2
 
3
+import se.citerus.dddsample.domain.UnLocode;
4
+
3 5
 public class UnknownLocationException extends Exception {
4 6
 
5
-  private String unlocode;
7
+  private UnLocode unlocode;
6 8
 
7
-  public UnknownLocationException(String unlocode) {
9
+  public UnknownLocationException(UnLocode unlocode) {
8 10
     this.unlocode = unlocode;
9 11
   }
10 12
 
11
-
12 13
   @Override
13 14
   public String getMessage() {
14
-    return "No location with UN location code " + unlocode + " exists in the system";
15
+    return "No location with UN locode " + unlocode.idString() + " exists in the system";
15 16
   }
16 17
 }

+ 8
- 8
dddsample/src/main/java/se/citerus/dddsample/util/SampleDataGenerator.java Zobrazit soubor

@@ -87,15 +87,15 @@ public class SampleDataGenerator implements ServletContextListener {
87 87
   }
88 88
 
89 89
   private static void loadLocationData(JdbcTemplate jdbcTemplate) {
90
-    String locationSql = "insert into Location (id, unlocode) values (?, ?)";
90
+    String locationSql = "insert into Location (id, unlocode, name) values (?, ?, ?)";
91 91
     Object[][] locationArgs = {
92
-      {1, "SESTO"},
93
-      {2, "AUMEL"},
94
-      {3, "CNHKG"},
95
-      {4, "JPTOK"},
96
-      {5, "FIHEL"},
97
-      {6, "DEHAM"},
98
-      {7, "USCHI"}
92
+      {1, "SESTO", "Stockholm"},
93
+      {2, "AUMEL", "Melbourne"},
94
+      {3, "CNHKG", "Hongkong"},
95
+      {4, "JPTOK", "Tokyo"},
96
+      {5, "FIHEL", "Helsinki"},
97
+      {6, "DEHAM", "Hamburg"},
98
+      {7, "USCHI", "Chicago"}
99 99
     };
100 100
     executeUpdate(jdbcTemplate, locationSql, locationArgs);
101 101
   }

+ 4
- 1
dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpointImpl.java Zobrazit soubor

@@ -5,6 +5,7 @@ import org.apache.commons.logging.LogFactory;
5 5
 import se.citerus.dddsample.domain.CarrierMovementId;
6 6
 import se.citerus.dddsample.domain.HandlingEvent;
7 7
 import se.citerus.dddsample.domain.TrackingId;
8
+import se.citerus.dddsample.domain.UnLocode;
8 9
 import se.citerus.dddsample.service.HandlingEventService;
9 10
 import se.citerus.dddsample.service.InvalidEventTypeException;
10 11
 import se.citerus.dddsample.service.UnknownCarrierMovementIdException;
@@ -35,7 +36,9 @@ public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEnd
35 36
       }
36 37
       HandlingEvent.Type type = parseEventType(eventType);
37 38
 
38
-      handlingEventService.register(date, tid, cid, unlocode, type);
39
+      UnLocode ul = new UnLocode(unlocode.substring(0,2), unlocode.substring(2,5));
40
+
41
+      handlingEventService.register(date, tid, cid, ul, type);
39 42
     } catch (ParseException pe) {
40 43
       logger.error("Invalid date format: " + completionTime + ", must be on ISO 8601 format: " + ISO_8601_FORMAT);
41 44
     } catch (UnknownTrackingIdException utid) {

+ 0
- 1
dddsample/src/main/resources/context-persistence.xml Zobrazit soubor

@@ -30,7 +30,6 @@
30 30
     <property name="hibernateProperties">
31 31
       <props>
32 32
         <!-- These are properties that are common for test and production -->
33
-        <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
34 33
         <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
35 34
       </props>
36 35
     </property>

+ 51
- 46
dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java Zobrazit soubor

@@ -8,6 +8,10 @@ import java.text.SimpleDateFormat;
8 8
 import java.util.Date;
9 9
 
10 10
 public class CargoTest extends TestCase {
11
+  private final Location stockholm = new Location(new UnLocode("SE","STO"), "Stockholm");
12
+  private final Location melbourne = new Location(new UnLocode("AU","MEL"), "Melbourne");
13
+  private final Location hongkong = new Location(new UnLocode("CN","HKG"), "Hongkong");
14
+  private final Location hamburg = new Location(new UnLocode("DE","HAM"), "Hamburg");
11 15
 
12 16
   // TODO:
13 17
   // it seems that events are not added to the system by cargo.deliveryHistory().addEvent(),
@@ -15,10 +19,10 @@ public class CargoTest extends TestCase {
15 19
   // work against the repositories or the service layer. The delivery history of a cargo should be
16 20
   // read-only from the cargo end. // PeBa
17 21
 
22
+
23
+
18 24
   public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
19
-    Location destination = new Location("AUMEL");
20
-    Location origin = new Location("SESTO");
21
-    Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, destination);
25
+    Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
22 26
 
23 27
     assertEquals(Location.UNKNOWN, cargo.lastKnownLocation());
24 28
   }
@@ -26,25 +30,25 @@ public class CargoTest extends TestCase {
26 30
   public void testlastKnownLocationReceived() throws Exception {
27 31
     Cargo cargo = populateCargoReceivedStockholm();
28 32
 
29
-    assertEquals(new Location("SESTO"), cargo.lastKnownLocation());
33
+    assertEquals(stockholm, cargo.lastKnownLocation());
30 34
   }
31 35
 
32 36
   public void testlastKnownLocationClaimed() throws Exception {
33 37
     Cargo cargo = populateCargoClaimedMelbourne();
34 38
 
35
-    assertEquals(new Location("AUMEL"), cargo.lastKnownLocation());
39
+    assertEquals(melbourne, cargo.lastKnownLocation());
36 40
   }
37 41
   
38 42
   public void testlastKnownLocationUnloaded() throws Exception {
39 43
     Cargo cargo = populateCargoOffHongKong();
40 44
 
41
-    assertEquals(new Location("CNHGK"), cargo.lastKnownLocation());
45
+    assertEquals(hongkong, cargo.lastKnownLocation());
42 46
   }
43 47
 
44 48
   public void testlastKnownLocationloaded() throws Exception {
45 49
     Cargo cargo = populateCargoOnHamburg();
46 50
 
47
-    assertEquals(new Location("DEHAM"), cargo.lastKnownLocation());
51
+    assertEquals(hamburg, cargo.lastKnownLocation());
48 52
   }
49 53
 
50 54
   public void testAtFinalLocation() throws Exception {
@@ -60,10 +64,10 @@ public class CargoTest extends TestCase {
60 64
   }
61 65
   
62 66
   public void testEquality() throws Exception {
63
-    Cargo c1 = new Cargo(new TrackingId("ABC"), new Location("AAAAA"), new Location("CCCCC"));
64
-    Cargo c2 = new Cargo(new TrackingId("CBA"), new Location("AAAAA"), new Location("CCCCC"));
65
-    Cargo c3 = new Cargo(new TrackingId("ABC"), new Location("AAAAA"), new Location("XXXXX"));
66
-    Cargo c4 = new Cargo(new TrackingId("ABC"), new Location("AAAAA"), new Location("CCCCC"));
67
+    Cargo c1 = new Cargo(new TrackingId("ABC"), stockholm, hongkong);
68
+    Cargo c2 = new Cargo(new TrackingId("CBA"), stockholm, hongkong);
69
+    Cargo c3 = new Cargo(new TrackingId("ABC"), stockholm, melbourne);
70
+    Cargo c4 = new Cargo(new TrackingId("ABC"), stockholm, hongkong);
67 71
 
68 72
     assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c4));
69 73
     assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c3));
@@ -73,9 +77,10 @@ public class CargoTest extends TestCase {
73 77
 
74 78
   // TODO: Generate test data some better way
75 79
   private Cargo populateCargoReceivedStockholm() throws Exception {
76
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
80
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
77 81
 
78
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, new Location("SESTO")));
82
+    HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, stockholm);
83
+    cargo.deliveryHistory().addEvent(he);
79 84
 
80 85
     return cargo;
81 86
   }
@@ -83,89 +88,89 @@ public class CargoTest extends TestCase {
83 88
   private Cargo populateCargoClaimedMelbourne() throws Exception {
84 89
     final Cargo cargo = populateCargoOffMelbourne();
85 90
 
86
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, new Location("AUMEL")));
91
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, melbourne));
87 92
     
88 93
     return cargo;
89 94
   }
90 95
   
91 96
   private Cargo populateCargoOffHongKong() throws Exception {
92
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
97
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
93 98
 
94 99
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
95
-            new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
100
+            new CarrierMovementId("CAR_001"), stockholm, hamburg);
96 101
 
97
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
98
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
102
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
103
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
99 104
 
100 105
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
101
-            new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
106
+            new CarrierMovementId("CAR_001"), hamburg, hongkong);
102 107
 
103
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
104
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
108
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
109
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong));
105 110
 
106 111
     return cargo;
107 112
   }
108 113
 
109 114
   private Cargo populateCargoOnHamburg() throws Exception {
110
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
115
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
111 116
 
112 117
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
113
-            new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
118
+            new CarrierMovementId("CAR_001"), stockholm, hamburg);
114 119
 
115
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
116
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
120
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
121
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
117 122
 
118 123
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
119
-            new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
124
+            new CarrierMovementId("CAR_001"), hamburg, hongkong);
120 125
 
121
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
126
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
122 127
 
123 128
     return cargo;
124 129
   }
125 130
 
126 131
   private Cargo populateCargoOffMelbourne() throws Exception {
127
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
132
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
128 133
 
129 134
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
130
-            new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
135
+            new CarrierMovementId("CAR_001"), stockholm, hamburg);
131 136
 
132
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
133
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
137
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
138
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
134 139
 
135 140
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
136
-            new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
141
+            new CarrierMovementId("CAR_001"), hamburg, hongkong);
137 142
 
138
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
139
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
143
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
144
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong));
140 145
 
141 146
     final CarrierMovement hongKongToMelbourne = new CarrierMovement(
142
-            new CarrierMovementId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
147
+            new CarrierMovementId("CAR_001"), hongkong, melbourne);
143 148
 
144
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, new Location("CNHGK"), hongKongToMelbourne));
145
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, new Location("AUMEL"), hongKongToMelbourne));
149
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongkong, hongKongToMelbourne));
150
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, melbourne, hongKongToMelbourne));
146 151
 
147 152
     return cargo;
148 153
   }
149 154
 
150 155
   private Cargo populateCargoOnHongKong() throws Exception {
151
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
156
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
152 157
 
153 158
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
154
-            new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
159
+            new CarrierMovementId("CAR_001"), stockholm, hamburg);
155 160
 
156
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
157
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
161
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
162
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
158 163
 
159 164
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
160
-            new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
165
+            new CarrierMovementId("CAR_001"), hamburg, hongkong);
161 166
 
162
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
163
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
167
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
168
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong));
164 169
 
165 170
     final CarrierMovement hongKongToMelbourne = new CarrierMovement(
166
-            new CarrierMovementId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
171
+            new CarrierMovementId("CAR_001"), hongkong, melbourne);
167 172
 
168
-    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, new Location("CNHGK"), hongKongToMelbourne));
173
+    cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongkong, hongKongToMelbourne));
169 174
 
170 175
     return cargo;
171 176
   }

+ 7
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/DeliveryHistoryTest.java Zobrazit soubor

@@ -15,11 +15,13 @@ public class DeliveryHistoryTest extends TestCase {
15 15
     assertTrue(dh.eventsOrderedByCompletionTime().isEmpty());
16 16
 
17 17
     DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
18
-    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), new Location("FROMX"), new Location("TOXXX"));
19
-    HandlingEvent he1 = new HandlingEvent(null, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, new Location("TOXXX"));
20
-    HandlingEvent he2 = new HandlingEvent(null, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, new Location("TOXXX"), carrierMovement);
21
-    HandlingEvent he3 = new HandlingEvent(null, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, new Location("FROMX"));
22
-    HandlingEvent he4 = new HandlingEvent(null, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("FROMX"), carrierMovement);
18
+    final Location from = new Location(new UnLocode("FR","OMX"), "From");
19
+    final Location to = new Location(new UnLocode("TO","XXX"), "To");
20
+    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), from, to);
21
+    HandlingEvent he1 = new HandlingEvent(null, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, to);
22
+    HandlingEvent he2 = new HandlingEvent(null, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, to, carrierMovement);
23
+    HandlingEvent he3 = new HandlingEvent(null, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, from);
24
+    HandlingEvent he4 = new HandlingEvent(null, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, from, carrierMovement);
23 25
     dh.addAllEvents(Arrays.asList(he1, he2, he3, he4));
24 26
 
25 27
     List<HandlingEvent> orderEvents = dh.eventsOrderedByCompletionTime();

+ 20
- 24
dddsample/src/test/java/se/citerus/dddsample/domain/HandlingEventTest.java Zobrazit soubor

@@ -8,10 +8,12 @@ import static java.util.Arrays.asList;
8 8
 import java.util.Date;
9 9
 
10 10
 public class HandlingEventTest extends TestCase {
11
+  private final Location origin = new Location(new UnLocode("FR","OMX"), "From");
12
+  private final Location finalDestination = new Location(new UnLocode("TO","YYY"), "To");
13
+  private final Location a5 = new Location(new UnLocode("AA","AAA"), "AAAAA");
14
+  private final Location b5 = new Location(new UnLocode("BB","BBB"), "BBBBB");
11 15
 
12 16
   public void testNewWithCarrierMovement() throws Exception {
13
-    Location origin = new Location("FROMX");
14
-    Location finalDestination = new Location("TOYYY");
15 17
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, finalDestination);
16 18
     CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("C01"), origin, finalDestination);
17 19
 
@@ -39,46 +41,42 @@ public class HandlingEventTest extends TestCase {
39 41
   }
40 42
 
41 43
   public void testNewWithLocation() throws Exception {
42
-    Location origin = new Location("FROMX");
43
-    Location finalDestination = new Location("TOYYY");
44
+    Location origin = this.origin;
45
+    Location finalDestination = this.finalDestination;
44 46
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, finalDestination);
45 47
 
46
-    Location location = new Location("FOOOO");
48
+    Location location = new Location(new UnLocode("FO","OOO"), "Foo");
47 49
     HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), Type.CLAIM, location);
48 50
     assertEquals(location, e1.location());
49 51
   }
50 52
 
51 53
   public void testCurrentLocationLoadEvent() throws Exception {
52
-    Location locationAAA = new Location("AAAAA");
53
-    Location locationBBB = new Location("BBBBB");
54 54
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
55
-    CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
55
+    CarrierMovement cm = new CarrierMovement(carrierMovementId, a5, b5);
56 56
     
57
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), LOAD, locationAAA, cm);
57
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), LOAD, a5, cm);
58 58
     
59
-    assertEquals(locationAAA, ev.location());
59
+    assertEquals(a5, ev.location());
60 60
   }
61 61
   
62 62
   public void testCurrentLocationUnloadEvent() throws Exception {
63
-    Location locationAAA = new Location("AAAAA");
64
-    Location locationBBB = new Location("BBBBB");
65 63
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
66
-    CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
64
+    CarrierMovement cm = new CarrierMovement(carrierMovementId, a5, b5);
67 65
     
68
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), UNLOAD, locationBBB, cm);
66
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), UNLOAD, b5, cm);
69 67
     
70
-    assertEquals(locationBBB, ev.location());
68
+    assertEquals(b5, ev.location());
71 69
   }
72 70
   
73 71
   public void testCurrentLocationReceivedEvent() throws Exception {
74
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), RECEIVE, new Location("ATEST"));
72
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), RECEIVE, a5);
75 73
 
76
-    assertEquals(new Location("ATEST"), ev.location());
74
+    assertEquals(a5, ev.location());
77 75
   }
78 76
   public void testCurrentLocationClaimedEvent() throws Exception {
79
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), CLAIM, new Location("ATEST"));
77
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), CLAIM, a5);
80 78
 
81
-    assertEquals(new Location("ATEST"), ev.location());
79
+    assertEquals(a5, ev.location());
82 80
   }
83 81
   
84 82
   public void testParseType() throws Exception {
@@ -100,13 +98,11 @@ public class HandlingEventTest extends TestCase {
100 98
   public void testEqualsAndSameAs() throws Exception {
101 99
     Date timeOccured = new Date();
102 100
     Date timeRegistered = new Date();
103
-    Location locationAAA = new Location("AAAAA");
104
-    Location locationBBB = new Location("BBBBB");
105 101
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
106
-    CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
102
+    CarrierMovement cm = new CarrierMovement(carrierMovementId, a5, b5);
107 103
 
108
-    HandlingEvent ev1 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, locationAAA, cm);
109
-    HandlingEvent ev2 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, locationAAA, cm);
104
+    HandlingEvent ev1 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, a5, cm);
105
+    HandlingEvent ev2 = new HandlingEvent(null, timeOccured, timeRegistered, LOAD, a5, cm);
110 106
 
111 107
     // Two handling events are not equal() even if all non-uuid fields are identical
112 108
     assertTrue(ev1.equals(ev2));

+ 11
- 19
dddsample/src/test/java/se/citerus/dddsample/domain/LocationTest.java Zobrazit soubor

@@ -2,39 +2,31 @@ package se.citerus.dddsample.domain;
2 2
 
3 3
 import junit.framework.TestCase;
4 4
 
5
-import java.util.Arrays;
6
-import java.util.List;
7
-
8 5
 public class LocationTest extends TestCase {
9 6
 
10 7
   public void testEquals() {
11
-    // Same location string - equal
12
-    assertTrue(new Location("ATEST").equals(new Location("ATEST")));
8
+    // Same UN locode - equal
9
+    assertTrue(new Location(new UnLocode("AT","EST"),"test-name").
10
+        equals(new Location(new UnLocode("AT","EST"),"test-name")));
13 11
 
14
-    // Different location strings - not equal
15
-    assertFalse(new Location("ATEST").equals(new Location("TESTB")));
12
+    // Different UN locodes - not equal
13
+    assertFalse(new Location(new UnLocode("AT","EST"),"test-name").
14
+         equals(new Location(new UnLocode("TE","STB"), "test-name")));
16 15
 
17 16
     // Always equal to itself
18
-    Location location = new Location("ATEST");
17
+    Location location = new Location(new UnLocode("AT","EST"),"test-name");
19 18
     assertTrue(location.equals(location));
20 19
 
21 20
     // Never equal to null
22 21
     assertFalse(location.equals(null));
23 22
 
24
-    // Special NULL location is equal to itself
23
+    // Special UNKNOWN location is equal to itself
25 24
     assertTrue(Location.UNKNOWN.equals(Location.UNKNOWN));
26 25
 
27
-    // These are all invalid UN locodes
28
-    List<String> invalidUnlocodes = Arrays.asList(null, "", "   ", "SHRT", "LOOONG", "WhAt evR 1 12 !!#6/");
29
-    for (String invalid : invalidUnlocodes) {
30
-      failInvalidUnlocode(invalid);
31
-    }
32
-  }
33
-
34
-  private void failInvalidUnlocode(String invalid) {
35 26
     try {
36
-      new Location(invalid);
37
-      fail(invalid + " should not be allowed as UN locode constructor argument");
27
+      new Location(null, null);
28
+      fail("Should not allow any null constructor arguments");
38 29
     } catch (IllegalArgumentException expected) {}
39 30
   }
31
+
40 32
 }

+ 11
- 7
dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java Zobrazit soubor

@@ -10,6 +10,10 @@ import java.util.Date;
10 10
 import java.util.List;
11 11
 
12 12
 public class TrackingScenarioTest extends TestCase {
13
+  private final Location stockholm = new Location(new UnLocode("SE","STO"), "Stockholm");
14
+  private final Location hamburg = new Location(new UnLocode("DE","HAM"), "Hamburg");
15
+  private final Location melbourne = new Location(new UnLocode("AU","MEL"), "Melbourne");
16
+  private final Location hongkong = new Location(new UnLocode("CN","HKG"), "Hongkong");
13 17
 
14 18
   public void testTrackingScenarioStage1() throws Exception {
15 19
 
@@ -30,22 +34,22 @@ public class TrackingScenarioTest extends TestCase {
30 34
 
31 35
   private DeliveryHistory populateDeliveryHistory(Cargo cargo) throws Exception {
32 36
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
33
-            new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
37
+            new CarrierMovementId("CAR_001"), stockholm, hamburg);
34 38
 
35 39
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
36
-            new CarrierMovementId("CAR_002"), new Location("DEHAM"), new Location("CNHKG"));
40
+            new CarrierMovementId("CAR_002"), hamburg, hongkong);
37 41
     DeliveryHistory dh = new DeliveryHistory();
38 42
     dh.addAllEvents(Arrays.asList(
39
-            new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg),
40
-            new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg),
41
-            new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong),
42
-            new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHKG"), hamburgToHongKong)
43
+            new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg),
44
+            new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg),
45
+            new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong),
46
+            new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong)
43 47
     ));
44 48
     return dh;
45 49
   }
46 50
 
47 51
   private Cargo populateCargo() throws Exception {
48
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
52
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
49 53
 
50 54
     return cargo;
51 55
   }

+ 57
- 0
dddsample/src/test/java/se/citerus/dddsample/domain/UnLocodeTest.java Zobrazit soubor

@@ -0,0 +1,57 @@
1
+package se.citerus.dddsample.domain;
2
+
3
+import junit.framework.TestCase;
4
+
5
+public class UnLocodeTest extends TestCase {
6
+
7
+  public void testNew() throws Exception {
8
+    assertValid("AA", "234");
9
+    assertValid("AA", "A9B");
10
+    assertValid("AA", "AAA");
11
+    
12
+    assertInvalid("A", "AAA");
13
+    assertInvalid("AAA", "AAA");
14
+    assertInvalid("AA", "AA");
15
+    assertInvalid("AA", "AAAA");
16
+    assertInvalid("22", "AAA");
17
+    assertInvalid("AA", "111");
18
+    assertInvalid(null, "AAA");
19
+    assertInvalid("AA", null);
20
+    assertInvalid(null, null);
21
+  }
22
+
23
+  public void testIdString() throws Exception {
24
+    assertEquals("ABCDE", new UnLocode("Ab", "cDe").idString());
25
+  }
26
+
27
+  public void testEquals() throws Exception {
28
+    UnLocode allCaps = new UnLocode("AB", "CDE");
29
+    UnLocode mixedCase = new UnLocode("aB", "cDe");
30
+
31
+    assertTrue(allCaps.equals(mixedCase));
32
+    assertTrue(mixedCase.equals(allCaps));
33
+    assertTrue(allCaps.equals(allCaps));
34
+
35
+    assertFalse(allCaps.equals(null));
36
+    assertFalse(allCaps.equals(new UnLocode("FG","HIJ")));
37
+  }
38
+
39
+  public void testHashCode() throws Exception {
40
+    UnLocode allCaps = new UnLocode("AB", "CDE");
41
+    UnLocode mixedCase = new UnLocode("aB", "cDe");
42
+
43
+    assertEquals(allCaps.hashCode(), mixedCase.hashCode());  
44
+  }
45
+  
46
+  private void assertValid(String countryCode, String locationCode) {
47
+    new UnLocode(countryCode, locationCode);
48
+  }
49
+
50
+  private void assertInvalid(String countryCode, String locationCode) {
51
+    try {
52
+      new UnLocode(countryCode, locationCode);
53
+      fail("The combination [" + countryCode + "," + locationCode + "] is not a valid UnLocode");
54
+    } catch (IllegalArgumentException expected) {}
55
+  }
56
+
57
+}

+ 4
- 0
dddsample/src/test/java/se/citerus/dddsample/repository/AbstractRepositoryTest.java Zobrazit soubor

@@ -22,6 +22,10 @@ public abstract class AbstractRepositoryTest extends AbstractTransactionalDataSo
22 22
     transactionManager = new HibernateTransactionManager(sessionFactory);
23 23
   }
24 24
 
25
+  public SessionFactory getSessionFactory() {
26
+    return sessionFactory;
27
+  }
28
+
25 29
   protected void flush() {
26 30
     sessionFactory.getCurrentSession().flush();
27 31
   }

+ 8
- 10
dddsample/src/test/java/se/citerus/dddsample/repository/CargoRepositoryTest.java Zobrazit soubor

@@ -3,12 +3,15 @@ package se.citerus.dddsample.repository;
3 3
 import se.citerus.dddsample.domain.Cargo;
4 4
 import se.citerus.dddsample.domain.Location;
5 5
 import se.citerus.dddsample.domain.TrackingId;
6
+import se.citerus.dddsample.domain.UnLocode;
6 7
 
7 8
 import java.util.Map;
8 9
 
9 10
 public class CargoRepositoryTest extends AbstractRepositoryTest {
10 11
 
11 12
   CargoRepository cargoRepository;
13
+  private final Location stockholm = new Location(new UnLocode("SE","STO"), "Stockholm");
14
+  private final Location melbourne = new Location(new UnLocode("AU","MEL"), "Melbourne");
12 15
 
13 16
   public void setCargoRepository(CargoRepository cargoRepository) {
14 17
     this.cargoRepository = cargoRepository;
@@ -16,26 +19,21 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
16 19
 
17 20
   public void testFindByCargoId() {
18 21
     final TrackingId trackingId = new TrackingId("XYZ");
19
-    final Location origin = new Location("SESTO");
20
-    final Location finalDestination = new Location("AUMEL");
21 22
 
22 23
     Cargo cargo = cargoRepository.find(trackingId);
23 24
 
24 25
     assertEquals(trackingId, cargo.trackingId());
25
-    assertEquals(origin, cargo.origin());
26
-    assertEquals(finalDestination, cargo.finalDestination());
26
+    assertEquals(stockholm, cargo.origin());
27
+    assertEquals(melbourne, cargo.finalDestination());
27 28
     // TODO: verify delivery history
28 29
   }
29 30
 
30 31
   public void testSave() {
31
-    // TODO: introduce Location repository
32
-    Location finalDestination = new Location("TOZZZ");
33
-    Location origin = new Location("FROMZ");
34
-    sessionFactory.getCurrentSession().saveOrUpdate(origin);
35
-    sessionFactory.getCurrentSession().saveOrUpdate(finalDestination);
32
+    sessionFactory.getCurrentSession().saveOrUpdate(stockholm);
33
+    sessionFactory.getCurrentSession().saveOrUpdate(melbourne);
36 34
 
37 35
 
38
-    Cargo cargo = new Cargo(new TrackingId("AAA"), origin, finalDestination);
36
+    Cargo cargo = new Cargo(new TrackingId("AAA"), stockholm, melbourne);
39 37
     cargoRepository.save(cargo);
40 38
 
41 39
     flush();

+ 6
- 10
dddsample/src/test/java/se/citerus/dddsample/repository/CarrierMovementRepositoryTest.java Zobrazit soubor

@@ -1,19 +1,15 @@
1 1
 package se.citerus.dddsample.repository;
2 2
 
3
-import se.citerus.dddsample.domain.CarrierMovementId;
4 3
 import se.citerus.dddsample.domain.CarrierMovement;
4
+import se.citerus.dddsample.domain.CarrierMovementId;
5 5
 import se.citerus.dddsample.domain.Location;
6
+import se.citerus.dddsample.domain.UnLocode;
6 7
 
7
-/**
8
- * Created by IntelliJ IDEA.
9
- * User: Peter Backlund
10
- * Date: 2008-jan-19
11
- * Time: 18:41:50
12
- * To change this template use File | Settings | File Templates.
13
- */
14 8
 public class CarrierMovementRepositoryTest extends AbstractRepositoryTest {
15 9
 
16 10
   CarrierMovementRepository carrierMovementRepository;
11
+  private final Location stockholm = new Location(new UnLocode("SE","STO"), "Stockholm");
12
+  private final Location helsinki = new Location(new UnLocode("FI","HEL"), "Helsinki");
17 13
 
18 14
   public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
19 15
     this.carrierMovementRepository = carrierMovementRepository;
@@ -23,8 +19,8 @@ public class CarrierMovementRepositoryTest extends AbstractRepositoryTest {
23 19
     CarrierMovement carrierMovement = carrierMovementRepository.find(new CarrierMovementId("CAR_001"));
24 20
     assertNotNull(carrierMovement);
25 21
     assertEquals("CAR_001", carrierMovement.carrierId().idString());
26
-    assertEquals(new Location("SESTO"), carrierMovement.from());
27
-    assertEquals(new Location("FIHEL"), carrierMovement.to());
22
+    assertEquals(stockholm, carrierMovement.from());
23
+    assertEquals(helsinki, carrierMovement.to());
28 24
   }
29 25
 
30 26
 }

+ 7
- 7
dddsample/src/test/java/se/citerus/dddsample/repository/HandlingEventRepositoryTest.java Zobrazit soubor

@@ -1,9 +1,6 @@
1 1
 package se.citerus.dddsample.repository;
2 2
 
3
-import se.citerus.dddsample.domain.Cargo;
4
-import se.citerus.dddsample.domain.HandlingEvent;
5
-import se.citerus.dddsample.domain.Location;
6
-import se.citerus.dddsample.domain.TrackingId;
3
+import se.citerus.dddsample.domain.*;
7 4
 
8 5
 import java.util.Date;
9 6
 import java.util.Map;
@@ -12,6 +9,7 @@ public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
12 9
 
13 10
   HandlingEventRepository handlingEventRepository;
14 11
   CargoRepository cargoRepository;
12
+  LocationRepository locationRepository;
15 13
 
16 14
   public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
17 15
     this.handlingEventRepository = handlingEventRepository;
@@ -21,10 +19,12 @@ public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
21 19
     this.cargoRepository = cargoRepository;
22 20
   }
23 21
 
22
+  public void setLocationRepository(LocationRepository locationRepository) {
23
+    this.locationRepository = locationRepository;
24
+  }
25
+
24 26
   public void testSave() {
25
-    // TODO: introduce Location repository
26
-    Location location = new Location("ABCDE");
27
-    sessionFactory.getCurrentSession().saveOrUpdate(location);
27
+    Location location = locationRepository.find(new UnLocode("SE","STO"));
28 28
 
29 29
     Cargo cargo = cargoRepository.find(new TrackingId("XYZ"));
30 30
     Date completionTime = new Date(10);

+ 4
- 2
dddsample/src/test/java/se/citerus/dddsample/repository/LocationRepositoryTest.java Zobrazit soubor

@@ -1,14 +1,16 @@
1 1
 package se.citerus.dddsample.repository;
2 2
 
3 3
 import se.citerus.dddsample.domain.Location;
4
+import se.citerus.dddsample.domain.UnLocode;
4 5
 
5 6
 public class LocationRepositoryTest extends AbstractRepositoryTest {
6 7
   private LocationRepository locationRepository;
7 8
   
8 9
   public void testFind() throws Exception {
9
-    Location location = locationRepository.find("AUMEL");
10
+    final UnLocode melbourne = new UnLocode("AU", "MEL");
11
+    Location location = locationRepository.find(melbourne);
10 12
     assertNotNull(location);
11
-    assertEquals("AUMEL", location.unlocode());
13
+    assertEquals(melbourne, location.unLocode());
12 14
   }
13 15
 
14 16
   public void setLocationRepository(LocationRepository locationRepository) {

+ 15
- 11
dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java Zobrazit soubor

@@ -76,11 +76,15 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
76 76
    * Cargo returned.
77 77
    */
78 78
   public void testCargoServiceFindByTrackingIdScenario() {
79
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("ORIGI"), new Location("DESTI"));
80
-    HandlingEvent claimed = new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.CLAIM, new Location("SESTO"));
81
-    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("MUGER"));
82
-    HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, new Location("SESTO"), carrierMovement);
83
-    HandlingEvent unloaded = new HandlingEvent(cargo, new Date(100), new Date(110), HandlingEvent.Type.UNLOAD, new Location("MUGER"), carrierMovement);
79
+    Location origin = new Location(new UnLocode("OR","IGI"), "Origin");
80
+    Location finalDestination = new Location(new UnLocode("DE","STI"), "Destination");
81
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, finalDestination);
82
+    Location sesto = new Location(new UnLocode("SE","STO"), "Stockholm");
83
+    HandlingEvent claimed = new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.CLAIM, sesto);
84
+    Location to = new Location(new UnLocode("MU","GER"), "München");
85
+    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), sesto, to);
86
+    HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, sesto, carrierMovement);
87
+    HandlingEvent unloaded = new HandlingEvent(cargo, new Date(100), new Date(110), HandlingEvent.Type.UNLOAD, to, carrierMovement);
84 88
     // Add out of order to verify ordering in DTO
85 89
     cargo.deliveryHistory().addAllEvents(Arrays.asList(loaded, unloaded, claimed));
86 90
 
@@ -99,30 +103,30 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
99 103
 
100 104
 
101 105
     assertEquals("XYZ", cargoDTO.getTrackingId());
102
-    assertEquals("ORIGI", cargoDTO.getOrigin());
103
-    assertEquals("DESTI", cargoDTO.getFinalDestination());
104
-    assertEquals("MUGER", cargoDTO.getCurrentLocation());
106
+    assertEquals("ORIGI (Origin)", cargoDTO.getOrigin());
107
+    assertEquals("DESTI (Destination)", cargoDTO.getFinalDestination());
108
+    assertEquals("MUGER (München)", cargoDTO.getCurrentLocation());
105 109
 
106 110
     List<HandlingEventDTO> events = cargoDTO.getEvents();
107 111
     assertEquals(3, events.size());
108 112
 
109 113
     // Claim happened first
110 114
     HandlingEventDTO eventDTO = events.get(0);
111
-    assertEquals("SESTO", eventDTO.getLocation());
115
+    assertEquals("SESTO (Stockholm)", eventDTO.getLocation());
112 116
     assertEquals("CLAIM", eventDTO.getType());
113 117
     assertEquals("", eventDTO.getCarrier());
114 118
     assertEquals(new Date(10), eventDTO.getTime());
115 119
 
116 120
     // Then load
117 121
     eventDTO = events.get(1);
118
-    assertEquals("SESTO", eventDTO.getLocation());
122
+    assertEquals("SESTO (Stockholm)", eventDTO.getLocation());
119 123
     assertEquals("LOAD", eventDTO.getType());
120 124
     assertEquals("CAR_001", eventDTO.getCarrier());
121 125
     assertEquals(new Date(12), eventDTO.getTime());
122 126
 
123 127
     // Finally unload
124 128
     eventDTO = events.get(2);
125
-    assertEquals("MUGER", eventDTO.getLocation());
129
+    assertEquals("MUGER (München)", eventDTO.getLocation());
126 130
     assertEquals("UNLOAD", eventDTO.getType());
127 131
     assertEquals("CAR_001", eventDTO.getCarrier());
128 132
     assertEquals(new Date(100), eventDTO.getTime());

+ 29
- 19
dddsample/src/test/java/se/citerus/dddsample/service/HandlingEventServiceTest.java Zobrazit soubor

@@ -16,15 +16,23 @@ public class HandlingEventServiceTest extends TestCase {
16 16
   private CarrierMovementRepository carrierMovementRepository;
17 17
   private HandlingEventRepository handlingEventRepository;
18 18
   private LocationRepository locationRepository;
19
-  
20
-  private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), new Location("AFROM"), new Location("ABCTO"));
21
-  private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), new Location("XFROM"), new Location("XYZTO"));
19
+
20
+  private Location origin = new Location(new UnLocode("AF","ROM"), "AFROM");
21
+  private Location finalDestination = new Location(new UnLocode("AB","CTO"), "ABCTO");
22
+  private final Cargo cargoABC = new Cargo(new TrackingId("ABC"), origin, finalDestination);
23
+
24
+  private Location xfrom = new Location(new UnLocode("XF","ROM"), "XFROM");
25
+  private Location xyzto = new Location(new UnLocode("XY","ZTO"), "XYZTO");
26
+  private final Cargo cargoXYZ = new Cargo(new TrackingId("XYZ"), xfrom, xyzto);
27
+
28
+  private Location a5 = new Location(new UnLocode("AA","AAA"), "AAAAA");
29
+  private Location b5 = new Location(new UnLocode("BB","BBB"), "BBBBB");
22 30
   private final CarrierMovement cmAAA_BBB = new CarrierMovement(
23
-          new CarrierMovementId("CAR_001"), new Location("AAAAA"), new Location("BBBBB"));
31
+          new CarrierMovementId("CAR_001"), a5, b5);
24 32
   
25
-  private final Location locationSESTO = new Location("SESTO");
26
-  private final Location locationAUMEL = new Location("AUMEL");
27
-  private final Location locationCNHKG = new Location("CNHKG");
33
+  private final Location stockholm = new Location(new UnLocode("SE","STO"), "Stockholm");
34
+  private final Location melbourne = new Location(new UnLocode("AU","MEL"), "Melbourne");
35
+  private final Location hongkong = new Location(new UnLocode("CN","HKG"), "Hongkong");
28 36
 
29 37
   protected void setUp() throws Exception{
30 38
     service = new HandlingEventServiceImpl();
@@ -51,15 +59,16 @@ public class HandlingEventServiceTest extends TestCase {
51 59
 
52 60
     final CarrierMovementId carrierMovementId = new CarrierMovementId("AAA_BBB");
53 61
     expect(carrierMovementRepository.find(carrierMovementId)).andReturn(cmAAA_BBB);
54
-    
55
-    expect(locationRepository.find("SESTO")).andReturn(locationSESTO);
62
+
63
+    final UnLocode unLocode = new UnLocode("SE", "STO");
64
+    expect(locationRepository.find(unLocode)).andReturn(stockholm);
56 65
 
57 66
     // TODO: does not inspect the handling event instance in a sufficient way
58 67
     handlingEventRepository.save(isA(HandlingEvent.class));
59 68
 
60 69
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
61 70
     
62
-    service.register(date, trackingId, carrierMovementId, "SESTO", HandlingEvent.Type.LOAD);
71
+    service.register(date, trackingId, carrierMovementId, unLocode, HandlingEvent.Type.LOAD);
63 72
   }
64 73
 
65 74
   public void testRegisterEventWithoutCarrierMovement() throws Exception {
@@ -70,11 +79,11 @@ public class HandlingEventServiceTest extends TestCase {
70 79
 
71 80
     handlingEventRepository.save(isA(HandlingEvent.class));
72 81
     
73
-    expect(locationRepository.find("SESTO")).andReturn(locationSESTO);
82
+    expect(locationRepository.find(stockholm.unLocode())).andReturn(stockholm);
74 83
 
75 84
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
76 85
 
77
-    service.register(date, trackingId, null, "SESTO", HandlingEvent.Type.CLAIM);
86
+    service.register(date, trackingId, null, stockholm.unLocode(), HandlingEvent.Type.CLAIM);
78 87
   }
79 88
   
80 89
 
@@ -85,14 +94,14 @@ public class HandlingEventServiceTest extends TestCase {
85 94
     expect(carrierMovementRepository.find(carrierMovementId)).andReturn(null);
86 95
 
87 96
     final TrackingId trackingId = new TrackingId("XYZ");
88
-    expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, new Location("FROMX"), new Location("TOYYY")));
97
+    expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, a5, b5));
89 98
 
90
-    expect(locationRepository.find("AUMEL")).andReturn(locationAUMEL);
99
+    expect(locationRepository.find(melbourne.unLocode())).andReturn(melbourne);
91 100
     
92 101
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
93 102
     
94 103
     try {
95
-      service.register(date, trackingId, carrierMovementId, "AUMEL", HandlingEvent.Type.UNLOAD);
104
+      service.register(date, trackingId, carrierMovementId, melbourne.unLocode(), HandlingEvent.Type.UNLOAD);
96 105
       fail("Should not be able to register an event with non-existing carrier movement");
97 106
     } catch (UnknownCarrierMovementIdException expected) {}
98 107
   }
@@ -103,12 +112,12 @@ public class HandlingEventServiceTest extends TestCase {
103 112
     final TrackingId trackingId = new TrackingId("XYZ");
104 113
     expect(cargoRepository.find(trackingId)).andReturn(null);
105 114
 
106
-    expect(locationRepository.find("CNHKG")).andReturn(locationCNHKG);
115
+    expect(locationRepository.find(hongkong.unLocode())).andReturn(hongkong);
107 116
     
108 117
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
109 118
     
110 119
     try {
111
-      service.register(date, trackingId, null, "CNHKG", HandlingEvent.Type.CLAIM);
120
+      service.register(date, trackingId, null, hongkong.unLocode(), HandlingEvent.Type.CLAIM);
112 121
       fail("Should not be able to register an event with non-existing cargo");
113 122
     } catch (UnknownTrackingIdException expected) {}
114 123
   }
@@ -118,12 +127,13 @@ public class HandlingEventServiceTest extends TestCase {
118 127
 
119 128
     final TrackingId trackingId = new TrackingId("XYZ");
120 129
     expect(cargoRepository.find(trackingId)).andReturn(cargoXYZ);
121
-    expect(locationRepository.find("WAY_OFF")).andReturn(null);
130
+    UnLocode wayOff = new UnLocode("XX", "YYY");
131
+    expect(locationRepository.find(wayOff)).andReturn(null);
122 132
     
123 133
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository, locationRepository);
124 134
     
125 135
     try {
126
-      service.register(date, trackingId, null, "WAY_OFF", HandlingEvent.Type.CLAIM);
136
+      service.register(date, trackingId, null, wayOff, HandlingEvent.Type.CLAIM);
127 137
       fail("Should not be able to register an event with non-existing Location");
128 138
     } catch (UnknownLocationException expected) {}
129 139
   }

+ 9
- 9
dddsample/src/test/java/se/citerus/dddsample/web/CargoTrackingControllerTest.java Zobrazit soubor

@@ -9,10 +9,7 @@ import org.springframework.validation.BindingResult;
9 9
 import org.springframework.validation.Errors;
10 10
 import org.springframework.validation.FieldError;
11 11
 import org.springframework.web.servlet.ModelAndView;
12
-import se.citerus.dddsample.domain.Cargo;
13
-import se.citerus.dddsample.domain.HandlingEvent;
14
-import se.citerus.dddsample.domain.Location;
15
-import se.citerus.dddsample.domain.TrackingId;
12
+import se.citerus.dddsample.domain.*;
16 13
 import se.citerus.dddsample.service.CargoService;
17 14
 import se.citerus.dddsample.service.dto.CargoWithHistoryDTO;
18 15
 import se.citerus.dddsample.service.dto.HandlingEventDTO;
@@ -43,19 +40,21 @@ public class CargoTrackingControllerTest extends TestCase {
43 40
   private CargoService getCargoServiceMock() {
44 41
     return new CargoService() {
45 42
       public CargoWithHistoryDTO find(String trackingId) {
46
-        Cargo cargo = new Cargo(new TrackingId(trackingId), new Location("AAAAA"), new Location("BBBBB"));
47
-        HandlingEvent event = new HandlingEvent(cargo, new Date(10L), new Date(20L), HandlingEvent.Type.RECEIVE, new Location("BBBBB"));
43
+        final Location a5 = new Location(new UnLocode("AA","AAA"), "AAAAA");
44
+        final Location b5 = new Location(new UnLocode("BB","BBB"), "BBBBB");
45
+        Cargo cargo = new Cargo(new TrackingId(trackingId), a5, b5);
46
+        HandlingEvent event = new HandlingEvent(cargo, new Date(10L), new Date(20L), HandlingEvent.Type.RECEIVE, b5);
48 47
 //        cargo.handle(event);
49 48
 
50 49
         // TODO: use DTO assemblers
51 50
         CargoWithHistoryDTO cargoDTO = new CargoWithHistoryDTO(
52 51
                 cargo.trackingId().idString(),
53
-                cargo.origin().unlocode(),
54
-                cargo.finalDestination().unlocode(),
52
+                cargo.origin().unLocode().idString(),
53
+                cargo.finalDestination().unLocode().idString(),
55 54
                 "AAAAA"
56 55
         );
57 56
         cargoDTO.addEvent(new HandlingEventDTO(
58
-          event.location().unlocode(),
57
+          event.location().unLocode().idString(),
59 58
           event.type().toString(),
60 59
           null, // TODO: event hierarchy will remove this kind of code
61 60
           event.completionTime()));
@@ -85,6 +84,7 @@ public class CargoTrackingControllerTest extends TestCase {
85 84
 
86 85
   public void testHandlePost() throws Exception {
87 86
     controller.setCargoService(getCargoServiceMock());
87
+    request.addParameter("trackingId","JKL456");
88 88
     request.setMethod("POST");
89 89
 
90 90
     ModelAndView mav = controller.handleRequest(request, response);

+ 5
- 3
dddsample/src/test/java/se/citerus/dddsample/ws/HandlinEventServiceEndpointTest.java Zobrazit soubor

@@ -5,6 +5,7 @@ import static org.easymock.EasyMock.*;
5 5
 import se.citerus.dddsample.domain.CarrierMovementId;
6 6
 import se.citerus.dddsample.domain.HandlingEvent;
7 7
 import se.citerus.dddsample.domain.TrackingId;
8
+import se.citerus.dddsample.domain.UnLocode;
8 9
 import se.citerus.dddsample.service.HandlingEventService;
9 10
 import se.citerus.dddsample.service.UnknownCarrierMovementIdException;
10 11
 import se.citerus.dddsample.service.UnknownTrackingIdException;
@@ -28,7 +29,7 @@ public class HandlinEventServiceEndpointTest extends TestCase {
28 29
   public void testRegisterValidEvent() throws Exception {
29 30
     Date date = new Date(100);
30 31
 
31
-    handlingEventService.register(date, new TrackingId("FOO"), new CarrierMovementId("CAR_456"), "CNHKG", HandlingEvent.Type.LOAD);
32
+    handlingEventService.register(date, new TrackingId("FOO"), new CarrierMovementId("CAR_456"), new UnLocode("CN","HKG"), HandlingEvent.Type.LOAD);
32 33
     replay(handlingEventService);
33 34
 
34 35
     // Tested call
@@ -40,8 +41,9 @@ public class HandlinEventServiceEndpointTest extends TestCase {
40 41
     Date date = new Date(100);
41 42
 
42 43
     TrackingId trackingId = new TrackingId("NOTFOUND");
44
+    UnLocode unlocode = new UnLocode("SE","STO");
43 45
 
44
-      handlingEventService.register(date, trackingId, null, "SESTO", HandlingEvent.Type.CLAIM);
46
+    handlingEventService.register(date, trackingId, null, unlocode, HandlingEvent.Type.CLAIM);
45 47
     expectLastCall().andThrow(new UnknownTrackingIdException(trackingId));
46 48
     replay(handlingEventService);
47 49
 
@@ -55,7 +57,7 @@ public class HandlinEventServiceEndpointTest extends TestCase {
55 57
       TrackingId trackingId = new TrackingId("XYZ");
56 58
       CarrierMovementId carrierMovementId = new CarrierMovementId("NOTFOUND");
57 59
 
58
-      handlingEventService.register(date, trackingId, carrierMovementId, "AUMEL", HandlingEvent.Type.UNLOAD);
60
+      handlingEventService.register(date, trackingId, carrierMovementId, new UnLocode("AU","MEL"), HandlingEvent.Type.UNLOAD);
59 61
       expectLastCall().andThrow(new UnknownCarrierMovementIdException(carrierMovementId));
60 62
       replay(handlingEventService);
61 63