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

Suggestion for handling domain validation as close to each domain object as possible - Location now requires UN locode argument to constructor to match a certain regexp, and each HandlingEvent.Type may answer type.requiresCarrierMovement() and type.prohibitsCarrierMovement(), evaluated from HandlingEvent constructor.

peter_backlund 18 лет назад
Родитель
Сommit
13bc89c5e9

+ 54
- 35
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java Просмотреть файл

@@ -2,8 +2,6 @@ package se.citerus.dddsample.domain;
2 2
 
3 3
 import org.apache.commons.lang.Validate;
4 4
 import org.apache.commons.lang.builder.HashCodeBuilder;
5
-import org.apache.commons.lang.builder.ToStringBuilder;
6
-import org.apache.commons.lang.builder.ToStringStyle;
7 5
 
8 6
 import javax.persistence.*;
9 7
 import java.util.Comparator;
@@ -12,16 +10,13 @@ import java.util.Date;
12 10
 /**
13 11
  * A HandlingEvent is used to register the event when, for instance, a cargo is unloaded from a carrier at a some loacation at a given time. The
14 12
  * HandlingEvent's are sent from different Incident Logging Applications some time after the event occured and contain information about the
15
- * {@link TrackingID}, {@link Location}, timestamp of the completion of the event, and possibly, if applicable a {@link CarrierMovement}.
13
+ * {@link TrackingId}, {@link Location}, timestamp of the completion of the event, and possibly, if applicable a {@link CarrierMovement}.
16 14
  * <br><br>
17
- * HandlingEvent's could contain information about a {@link CarrierMovement} and if so, the event type must be either {@link Type.LOAD} or 
15
+ * HandlingEvent's could contain information about a {@link CarrierMovement} and if so, the event type must be either {@link Type.LOAD} or
18 16
  * {@link Type.UNLOAD}. All other events must be of {@link Type.RECEIVE}, {@link Type.CLAIM} or {@link Type.CUSTOMS}.
19 17
  */
20 18
 @Entity
21 19
 public class HandlingEvent {
22
-  private static final Type[] VALID_TYPES_WITH_CARRIERMOVEMENT = new Type[]{Type.LOAD, Type.UNLOAD};
23
-
24
-  private static final Type[] VALID_TYPES_NO_CARRIERMOVEMENT = new Type[]{Type.CLAIM, Type.RECEIVE, Type.CUSTOMS};
25 20
 
26 21
   /**
27 22
    * Comparator used to be able to sort HandlingEvents according to their completion time
@@ -54,18 +49,42 @@ public class HandlingEvent {
54 49
   private Cargo cargo;
55 50
 
56 51
   public enum Type {
57
-    LOAD, UNLOAD, RECEIVE, CLAIM, CUSTOMS
52
+    LOAD(true),
53
+    UNLOAD(true),
54
+    RECEIVE(false),
55
+    CLAIM(false),
56
+    CUSTOMS(false);
57
+
58
+    private boolean carrierMovementRequired;
59
+
60
+    private Type(boolean carrierMovementRequired) {
61
+      this.carrierMovementRequired = carrierMovementRequired;
62
+    }
63
+
64
+    /**
65
+     * @return True if a carrier movement association is required for this event type.
66
+     */
67
+    public boolean requiresCarrierMovement() {
68
+      return carrierMovementRequired;
69
+    }
70
+
71
+    /**
72
+     * @return True if a carrier movement association is prohibited for this event type.
73
+     */
74
+    public boolean prohibitsCarrierMovement() {
75
+      return !requiresCarrierMovement();
76
+    }
58 77
   }
59 78
 
60 79
 
61 80
   /**
62 81
    * Constructor for events that do not have a carrier movement associated.
63 82
    *
64
-   * @param cargo cargo
65
-   * @param completionTime completion time
83
+   * @param cargo            cargo
84
+   * @param completionTime   completion time
66 85
    * @param registrationTime registration time
67
-   * @param type type of event. Legal values are CLAIM, RECIEVE and CUSTOMS
68
-   * @param location where the event took place
86
+   * @param type             type of event. Legal values are CLAIM, RECIEVE and CUSTOMS
87
+   * @param location         where the event took place
69 88
    */
70 89
   public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type, Location location) {
71 90
     this.registrationTime = registrationTime;
@@ -73,8 +92,8 @@ public class HandlingEvent {
73 92
     this.type = type;
74 93
     this.cargo = cargo;
75 94
     this.location = location;
76
-    
77
-    validateType(type, VALID_TYPES_NO_CARRIERMOVEMENT);
95
+
96
+    validateType();
78 97
   }
79 98
 
80 99
   /**
@@ -83,12 +102,12 @@ public class HandlingEvent {
83 102
    * the location is the starting point of the movement, if the type is UNLOAD the location
84 103
    * is the end point.
85 104
    *
86
-   * @param cargo cargo
87
-   * @param completionTime completion time
105
+   * @param cargo            cargo
106
+   * @param completionTime   completion time
88 107
    * @param registrationTime registration time
89
-   * @param type type of event. Legal values are LOAD and UNLOAD
90
-   * @param location where the event took place
91
-   * @param carrierMovement carrier movement.
108
+   * @param type             type of event. Legal values are LOAD and UNLOAD
109
+   * @param location         where the event took place
110
+   * @param carrierMovement  carrier movement.
92 111
    */
93 112
   public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type, Location location, CarrierMovement carrierMovement) {
94 113
     this.registrationTime = registrationTime;
@@ -97,9 +116,9 @@ public class HandlingEvent {
97 116
     this.cargo = cargo;
98 117
     this.location = location;
99 118
     this.carrierMovement = carrierMovement;
100
-    
101
-    validateType(type, VALID_TYPES_WITH_CARRIERMOVEMENT);
119
+
102 120
     Validate.notNull(carrierMovement, "CarrierMovementId must not be null for this type of event");
121
+    validateType();
103 122
   }
104 123
 
105 124
 
@@ -145,8 +164,8 @@ public class HandlingEvent {
145 164
     }
146 165
     HandlingEvent other = (HandlingEvent) object;
147 166
     return this.location.equals(other.location) &&
148
-           this.completionTime.equals(other.completionTime) &&
149
-           this.type.equals(other.type);
167
+            this.completionTime.equals(other.completionTime) &&
168
+            this.type.equals(other.type);
150 169
   }
151 170
 
152 171
   /**
@@ -170,21 +189,21 @@ public class HandlingEvent {
170 189
   }
171 190
 
172 191
   /**
173
-   * Private helper that validate a HandlingEvent type agains an array of valid types
174
-   * 
175
-   * @param type The type that should be validated
176
-   * @param validTypes The list of valid types
192
+   * Validate that the event type is compatible with the carrier movement value.
193
+   * <p/>
194
+   * Only certain types of events may be associated with a carrier movement.
177 195
    */
178
-  private void validateType(Type type, Type[] validTypes) {
179
-    for (Type validType : validTypes) {
180
-      if (type.equals(validType)){
181
-        return;
182
-      }
196
+  private void validateType() {
197
+    if (type.requiresCarrierMovement() && carrierMovement == null) {
198
+      throw new IllegalArgumentException("Carrier movement is required for event type " + type);
199
+    }
200
+    if (type.prohibitsCarrierMovement() && carrierMovement != null) {
201
+      throw new IllegalArgumentException("Carrier movement is not allowed with event type " + type);
183 202
     }
184
-    throw new IllegalArgumentException("Illegal event type " + type + ". Valid types are: " + ToStringBuilder.reflectionToString(validTypes, ToStringStyle.NO_FIELD_NAMES_STYLE));
185 203
   }
186
-  
204
+
187 205
   // Needed by Hibernate
188
-  HandlingEvent() {}
206
+  HandlingEvent() {
207
+  }
189 208
 
190 209
 }

+ 25
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/Location.java Просмотреть файл

@@ -1,15 +1,14 @@
1 1
 package se.citerus.dddsample.domain;
2 2
 
3
+import org.apache.commons.lang.Validate;
4
+
3 5
 import javax.persistence.Entity;
4 6
 import javax.persistence.GeneratedValue;
5 7
 import javax.persistence.Id;
8
+import java.util.regex.Pattern;
6 9
 
7 10
 @Entity
8 11
 public class Location {
9
-  /**
10
-   * Special Location object that marks an unknown location.
11
-   */
12
-  public static final Location UNKNOWN = new Location("Unknown");
13 12
 
14 13
   @Id
15 14
   @GeneratedValue
@@ -17,7 +16,29 @@ public class Location {
17 16
 
18 17
   private String unlocode;
19 18
 
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}");
23
+
24
+  /**
25
+   * Special Location object that marks an unknown location.
26
+   */
27
+  public static final Location UNKNOWN = new Location();
28
+
29
+  // Internal constructor
30
+  private Location() {
31
+    this.unlocode = "Unknown";
32
+  }
33
+
34
+  /**
35
+   * @param unlocode UN locode
36
+   * @throws IllegalArgumentException if the UN locode is anything other than five letters of the US alphabet
37
+   */
20 38
   public Location(String unlocode) {
39
+    Validate.notNull(unlocode);
40
+    Validate.isTrue(unlocodePattern.matcher(unlocode).matches(),
41
+            "\"" + unlocode + "\" is not a valid UN Locode");
21 42
     this.unlocode = unlocode;
22 43
   }
23 44
 
@@ -60,7 +81,4 @@ public class Location {
60 81
     return unlocode;
61 82
   }
62 83
 
63
-  // Needed by Hibernate
64
-  Location() {}
65
-
66 84
 }

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java Просмотреть файл

@@ -60,10 +60,10 @@ public class CargoTest extends TestCase {
60 60
   }
61 61
   
62 62
   public void testEquality() throws Exception {
63
-    Cargo c1 = new Cargo(new TrackingId("ABC"), new Location("A"), new Location("C"));
64
-    Cargo c2 = new Cargo(new TrackingId("CBA"), new Location("A"), new Location("C"));
65
-    Cargo c3 = new Cargo(new TrackingId("ABC"), new Location("A"), new Location("X"));
66
-    Cargo c4 = new Cargo(new TrackingId("ABC"), new Location("A"), new Location("C"));
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 67
 
68 68
     assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c4));
69 69
     assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c3));

+ 5
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/DeliveryHistoryTest.java Просмотреть файл

@@ -15,11 +15,11 @@ 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("FROM"), new Location("TO"));
19
-    HandlingEvent he1 = new HandlingEvent(null, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, new Location("TO"));
20
-    HandlingEvent he2 = new HandlingEvent(null, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, new Location("TO"), carrierMovement);
21
-    HandlingEvent he3 = new HandlingEvent(null, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, new Location("FROM"));
22
-    HandlingEvent he4 = new HandlingEvent(null, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("FROM"), carrierMovement);
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);
23 23
     dh.addAllEvents(Arrays.asList(he1, he2, he3, he4));
24 24
 
25 25
     List<HandlingEvent> orderEvents = dh.eventsOrderedByCompletionTime();

+ 26
- 19
dddsample/src/test/java/se/citerus/dddsample/domain/HandlingEventTest.java Просмотреть файл

@@ -10,8 +10,8 @@ import java.util.Date;
10 10
 public class HandlingEventTest extends TestCase {
11 11
 
12 12
   public void testNewWithCarrierMovement() throws Exception {
13
-    Location origin = new Location("FROM");
14
-    Location finalDestination = new Location("TO");
13
+    Location origin = new Location("FROMX");
14
+    Location finalDestination = new Location("TOYYY");
15 15
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, finalDestination);
16 16
     CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("C01"), origin, finalDestination);
17 17
 
@@ -20,30 +20,37 @@ public class HandlingEventTest extends TestCase {
20 20
 
21 21
     HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, finalDestination, carrierMovement);
22 22
     assertEquals(finalDestination, e2.location());
23
-    
23
+
24
+      // These event types prohibit a carrier movement association
24 25
     for (Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
25 26
       try {
26 27
         new HandlingEvent(cargo, new Date(), new Date(), type, origin, carrierMovement);
27
-        fail("Handling event with carrier movement and type " + type + " is not legal");
28
+        fail("Handling event type " + type + " prohibits carrier movement");
28 29
       } catch (IllegalArgumentException expected) {}
29 30
     }
31
+
32
+      // These event types requires a carrier movement association
33
+    for (Type type : asList(LOAD, UNLOAD)) {
34
+        try {
35
+          new HandlingEvent(cargo, new Date(), new Date(), type, origin);
36
+            fail("Handling event type " + type + " requires carrier movement");
37
+        } catch (IllegalArgumentException expected) {}
38
+    }
30 39
   }
31 40
 
32 41
   public void testNewWithLocation() throws Exception {
33
-    Location origin = new Location("FROM");
34
-    Location finalDestination = new Location("TO");
42
+    Location origin = new Location("FROMX");
43
+    Location finalDestination = new Location("TOYYY");
35 44
     Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, finalDestination);
36 45
 
37
-    Location location = new Location("FOO");
46
+    Location location = new Location("FOOOO");
38 47
     HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), Type.CLAIM, location);
39 48
     assertEquals(location, e1.location());
40
-
41
-    
42 49
   }
43 50
 
44 51
   public void testCurrentLocationLoadEvent() throws Exception {
45
-    Location locationAAA = new Location("AAA");
46
-    Location locationBBB = new Location("BBB");
52
+    Location locationAAA = new Location("AAAAA");
53
+    Location locationBBB = new Location("BBBBB");
47 54
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
48 55
     CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
49 56
     
@@ -53,8 +60,8 @@ public class HandlingEventTest extends TestCase {
53 60
   }
54 61
   
55 62
   public void testCurrentLocationUnloadEvent() throws Exception {
56
-    Location locationAAA = new Location("AAA");
57
-    Location locationBBB = new Location("BBB");
63
+    Location locationAAA = new Location("AAAAA");
64
+    Location locationBBB = new Location("BBBBB");
58 65
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
59 66
     CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
60 67
     
@@ -64,14 +71,14 @@ public class HandlingEventTest extends TestCase {
64 71
   }
65 72
   
66 73
   public void testCurrentLocationReceivedEvent() throws Exception {
67
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), RECEIVE, new Location("TEST"));
74
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), RECEIVE, new Location("ATEST"));
68 75
 
69
-    assertEquals(new Location("TEST"), ev.location());
76
+    assertEquals(new Location("ATEST"), ev.location());
70 77
   }
71 78
   public void testCurrentLocationClaimedEvent() throws Exception {
72
-    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), CLAIM, new Location("TEST"));
79
+    HandlingEvent ev = new HandlingEvent(null, new Date(), new Date(), CLAIM, new Location("ATEST"));
73 80
 
74
-    assertEquals(new Location("TEST"), ev.location());
81
+    assertEquals(new Location("ATEST"), ev.location());
75 82
   }
76 83
   
77 84
   public void testParseType() throws Exception {
@@ -93,8 +100,8 @@ public class HandlingEventTest extends TestCase {
93 100
   public void testEqualsAndSameAs() throws Exception {
94 101
     Date timeOccured = new Date();
95 102
     Date timeRegistered = new Date();
96
-    Location locationAAA = new Location("AAA");
97
-    Location locationBBB = new Location("BBB");
103
+    Location locationAAA = new Location("AAAAA");
104
+    Location locationBBB = new Location("BBBBB");
98 105
     CarrierMovementId carrierMovementId = new CarrierMovementId("CAR_001");
99 106
     CarrierMovement cm = new CarrierMovement(carrierMovementId, locationAAA, locationBBB);
100 107
 

+ 17
- 8
dddsample/src/test/java/se/citerus/dddsample/domain/LocationTest.java Просмотреть файл

@@ -2,17 +2,20 @@ 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
+
5 8
 public class LocationTest extends TestCase {
6 9
 
7 10
   public void testEquals() {
8 11
     // Same location string - equal
9
-    assertTrue(new Location("TEST").equals(new Location("TEST")));
12
+    assertTrue(new Location("ATEST").equals(new Location("ATEST")));
10 13
 
11 14
     // Different location strings - not equal
12
-    assertFalse(new Location("TEST").equals(new Location("ANOTHER_TEST")));
15
+    assertFalse(new Location("ATEST").equals(new Location("TESTB")));
13 16
 
14 17
     // Always equal to itself
15
-    Location location = new Location("TEST");
18
+    Location location = new Location("ATEST");
16 19
     assertTrue(location.equals(location));
17 20
 
18 21
     // Never equal to null
@@ -21,11 +24,17 @@ public class LocationTest extends TestCase {
21 24
     // Special NULL location is equal to itself
22 25
     assertTrue(Location.UNKNOWN.equals(Location.UNKNOWN));
23 26
 
24
-    // No other location should be equal to the NULL location
25
-    assertFalse(new Location(null).equals(Location.UNKNOWN));
26
-    assertFalse(new Location("").equals(Location.UNKNOWN));
27
-    assertFalse(new Location("   ").equals(Location.UNKNOWN));
28
-    assertFalse(new Location("   FOO  BAR ").equals(Location.UNKNOWN));
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
+    }
29 32
   }
30 33
 
34
+  private void failInvalidUnlocode(String invalid) {
35
+    try {
36
+      new Location(invalid);
37
+      fail(invalid + " should not be allowed as UN locode constructor argument");
38
+    } catch (IllegalArgumentException expected) {}
39
+  }
31 40
 }

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/repository/CargoRepositoryTest.java Просмотреть файл

@@ -29,8 +29,8 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
29 29
 
30 30
   public void testSave() {
31 31
     // TODO: introduce Location repository
32
-    Location finalDestination = new Location("TO");
33
-    Location origin = new Location("FROM");
32
+    Location finalDestination = new Location("TOZZZ");
33
+    Location origin = new Location("FROMZ");
34 34
     sessionFactory.getCurrentSession().saveOrUpdate(origin);
35 35
     sessionFactory.getCurrentSession().saveOrUpdate(finalDestination);
36 36
 

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/repository/HandlingEventRepositoryTest.java Просмотреть файл

@@ -23,7 +23,7 @@ public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
23 23
 
24 24
   public void testSave() {
25 25
     // TODO: introduce Location repository
26
-    Location location = new Location("ABC");
26
+    Location location = new Location("ABCDE");
27 27
     sessionFactory.getCurrentSession().saveOrUpdate(location);
28 28
 
29 29
     Cargo cargo = cargoRepository.find(new TrackingId("XYZ"));

+ 3
- 5
dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java Просмотреть файл

@@ -1,8 +1,6 @@
1 1
 package se.citerus.dddsample.service;
2 2
 
3 3
 import static org.easymock.EasyMock.*;
4
-
5
-import org.apache.commons.lang.ArrayUtils;
6 4
 import org.easymock.IAnswer;
7 5
 import org.hibernate.FlushMode;
8 6
 import org.hibernate.SessionFactory;
@@ -78,7 +76,7 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
78 76
    * Cargo returned.
79 77
    */
80 78
   public void testCargoServiceFindByTrackingIdScenario() {
81
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("ORIG"), new Location("DEST"));
79
+    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("ORIGI"), new Location("DESTI"));
82 80
     HandlingEvent claimed = new HandlingEvent(cargo, new Date(10), new Date(20), HandlingEvent.Type.CLAIM, new Location("SESTO"));
83 81
     CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("MUGER"));
84 82
     HandlingEvent loaded = new HandlingEvent(cargo, new Date(12), new Date(25), HandlingEvent.Type.LOAD, new Location("SESTO"), carrierMovement);
@@ -101,8 +99,8 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
101 99
 
102 100
 
103 101
     assertEquals("XYZ", cargoDTO.getTrackingId());
104
-    assertEquals("ORIG", cargoDTO.getOrigin());
105
-    assertEquals("DEST", cargoDTO.getFinalDestination());
102
+    assertEquals("ORIGI", cargoDTO.getOrigin());
103
+    assertEquals("DESTI", cargoDTO.getFinalDestination());
106 104
     assertEquals("MUGER", cargoDTO.getCurrentLocation());
107 105
 
108 106
     List<HandlingEventDTO> events = cargoDTO.getEvents();

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/web/CargoTrackingControllerTest.java Просмотреть файл

@@ -43,8 +43,8 @@ public class CargoTrackingControllerTest extends TestCase {
43 43
   private CargoService getCargoServiceMock() {
44 44
     return new CargoService() {
45 45
       public CargoWithHistoryDTO find(String trackingId) {
46
-        Cargo cargo = new Cargo(new TrackingId(trackingId), new Location("AAA"), new Location("BBB"));
47
-        HandlingEvent event = new HandlingEvent(cargo, new Date(10L), new Date(20L), HandlingEvent.Type.RECEIVE, new Location("BBB"));
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"));
48 48
 //        cargo.handle(event);
49 49
 
50 50
         // TODO: use DTO assemblers
@@ -52,7 +52,7 @@ public class CargoTrackingControllerTest extends TestCase {
52 52
                 cargo.trackingId().idString(),
53 53
                 cargo.origin().unlocode(),
54 54
                 cargo.finalDestination().unlocode(),
55
-                "AAA"
55
+                "AAAAA"
56 56
         );
57 57
         cargoDTO.addEvent(new HandlingEventDTO(
58 58
           event.location().unlocode(),
@@ -93,7 +93,7 @@ public class CargoTrackingControllerTest extends TestCase {
93 93
     // Errors, command are two standard map attributes, the third should be the cargo object
94 94
     assertEquals(3, mav.getModel().size());
95 95
     CargoWithHistoryDTO cargo = (CargoWithHistoryDTO) mav.getModel().get("cargo");
96
-    assertEquals("AAA", cargo.getCurrentLocation());
96
+    assertEquals("AAAAA", cargo.getCurrentLocation());
97 97
   }
98 98
 
99 99
   public void testUnknownCargo() throws Exception {