Ver código fonte

Introduced UUID, timeRegistered property and sameAs/equals for HandlingEvent.

peter_backlund 18 anos atrás
pai
commit
d9117c08c6

+ 1
- 4
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java Ver arquivo

@@ -87,12 +87,9 @@ public class Cargo {
87 87
 
88 88
   @Override
89 89
   public boolean equals(Object obj) {
90
-    if (obj instanceof Cargo == false) {
90
+    if (!(obj instanceof Cargo)) {
91 91
       return false;
92 92
     }
93
-    if (this == obj) {
94
-      return true;
95
-    }
96 93
     Cargo rhs = (Cargo) obj;
97 94
     return new EqualsBuilder()
98 95
       .append(trackingId, rhs.trackingId)

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java Ver arquivo

@@ -54,7 +54,7 @@ public class DeliveryHistory {
54 54
 
55 55
   private static class HandlingEventByTimeComparator implements Comparator<HandlingEvent> {
56 56
     public int compare(HandlingEvent o1, HandlingEvent o2) {
57
-      return o1.getTime().compareTo(o2.getTime());
57
+      return o1.getTimeOccurred().compareTo(o2.getTimeOccurred());
58 58
     }
59 59
   }
60 60
 }

+ 43
- 18
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java Ver arquivo

@@ -1,12 +1,12 @@
1 1
 package se.citerus.dddsample.domain;
2 2
 
3 3
 import org.apache.commons.lang.builder.EqualsBuilder;
4
-import org.apache.commons.lang.builder.HashCodeBuilder;
5 4
 
6 5
 import javax.persistence.*;
7 6
 import java.util.Date;
8 7
 import java.util.HashSet;
9 8
 import java.util.Set;
9
+import java.util.UUID;
10 10
 
11 11
 /**
12 12
  * HandlingEvent links the type of handling with a CarrierMovement.
@@ -15,14 +15,13 @@ import java.util.Set;
15 15
  * DeliveryHistory), they need to implement Comparable to be able to be sorted
16 16
  * in correct order.
17 17
  *
18
- * TODO: build hierarchy
19
- * TODO: sameAs and UUID-based equals()
18
+ * TODO: build hierarchy of event types
20 19
  */
21 20
 @Entity
22 21
 public class HandlingEvent {
23 22
 
24 23
   @Id
25
-  private Long id;
24
+  private UUID id;
26 25
 
27 26
   @Enumerated
28 27
   private Type type;
@@ -30,29 +29,47 @@ public class HandlingEvent {
30 29
   @ManyToOne
31 30
   private CarrierMovement carrierMovement;
32 31
   
33
-  private Date time;
32
+  private Date timeOccurred;
34 33
 
35
-  @Transient /*TODO: Change to many-to-many if we decide on that approach*/
34
+  private Date timeRegistered;
35
+
36
+  @Transient // TODO: cargo-event relation should not be bidirectional
36 37
   private Set<Cargo> cargos;
37 38
   
38 39
   public enum Type {
39 40
     LOAD, UNLOAD, RECEIVE, CLAIM
40 41
   }
41 42
 
42
-  // Exclude the id field from equals() and hashcode()
43
-  private static final String[] excludedFields = {"id"};
44
-
45
-  public HandlingEvent(Date time, Type type) {
46
-    this(time, type, null);
43
+  public HandlingEvent(Date timeOccurred, Date timeRegistered, Type type) {
44
+    this(timeOccurred, timeRegistered, type, null);
47 45
   }
48 46
 
49
-  public HandlingEvent(Date time, Type type, CarrierMovement carrierMovement) {
50
-    this.time = time;
47
+  public HandlingEvent(Date timeOccurred, Date timeRegistered, Type type, CarrierMovement carrierMovement) {
48
+    this.id = UUID.randomUUID();
49
+    this.timeRegistered = timeRegistered;
50
+    this.timeOccurred = timeOccurred;
51 51
     this.type = type;
52 52
     this.carrierMovement = carrierMovement;
53 53
     this.cargos = new HashSet<Cargo>();
54 54
   }
55 55
 
56
+  /**
57
+   * This determines if two events recieved by the system in fact represent
58
+   * the same real-world event, which may have been reported more than once due to
59
+   * human error, for example.
60
+   *
61
+   * @param other handling event to compare with
62
+   * @return True if these handling events represent the same real-world event.
63
+   */
64
+  public boolean sameAs(HandlingEvent other) {
65
+    return new EqualsBuilder().
66
+            append(this.getTimeOccurred(), other.getTimeOccurred()).
67
+            append(this.getLocation(), other.getLocation()).
68
+            append(this.getType(), other.getType()).
69
+            append(this.getCarrierMovement(), other.getCarrierMovement())
70
+            .isEquals();
71
+  }
72
+
56 73
   public Type getType() {
57 74
     return type;
58 75
   }
@@ -61,10 +78,14 @@ public class HandlingEvent {
61 78
     return carrierMovement;
62 79
   }
63 80
 
64
-  public Date getTime() {
65
-    return time;
81
+  public Date getTimeOccurred() {
82
+    return timeOccurred;
66 83
   }
67
-  
84
+
85
+  public Date getTimeRegistered() {
86
+    return timeRegistered;
87
+  }
88
+
68 89
   /**
69 90
    * Returns the Location of the Cargo. The location is calculated based on the following rules:
70 91
    * <br>For
@@ -114,12 +135,16 @@ public class HandlingEvent {
114 135
 
115 136
   @Override
116 137
   public boolean equals(Object obj) {
117
-    return EqualsBuilder.reflectionEquals(this, obj, excludedFields);
138
+    if (!(obj instanceof HandlingEvent)) {
139
+      return false;
140
+    }
141
+    HandlingEvent other = (HandlingEvent) obj;
142
+    return new EqualsBuilder().append(this.id, other.id).isEquals();
118 143
   }
119 144
 
120 145
   @Override
121 146
   public int hashCode() {
122
-    return HashCodeBuilder.reflectionHashCode(this, excludedFields);
147
+    return id.hashCode();
123 148
   }
124 149
 
125 150
   public static Type parseType(String type) {

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java Ver arquivo

@@ -73,7 +73,7 @@ public class HandlingEventRepositoryInMem implements HandlingEventRepository{
73 73
 
74 74
   
75 75
   private void registerEvent(Cargo cargo, String date, Type type, CarrierMovement carrierMovement) throws ParseException{
76
-    HandlingEvent ev= new HandlingEvent(getDate(date), type, carrierMovement);
76
+    HandlingEvent ev= new HandlingEvent(getDate(date), new Date(), type, carrierMovement);
77 77
     ev.register(toSet(cargo));
78 78
     String id = cargo.trackingId() + "_" + type + "_" + date;
79 79
     

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java Ver arquivo

@@ -33,7 +33,7 @@ public class CargoServiceImpl implements CargoService {
33 33
               event.getLocation().unlocode(),
34 34
               event.getType().toString(),
35 35
               carrierIdString,
36
-              event.getTime()
36
+              event.getTimeOccurred()
37 37
       ));
38 38
     }
39 39
     return dto;

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java Ver arquivo

@@ -20,7 +20,7 @@ public class HandlingEventServiceImpl implements HandlingEventService {
20 20
   @Transactional(readOnly = false)
21 21
   public void register(Date date, String type, String carrierId, String[] trackingIds) {
22 22
     CarrierMovement cm = findCarrier(new CarrierId(carrierId));
23
-    HandlingEvent event = new HandlingEvent(date, HandlingEvent.parseType(type), cm);
23
+    HandlingEvent event = new HandlingEvent(date, new Date(), HandlingEvent.parseType(type), cm);
24 24
     Set<Cargo> cargos = findCargos(trackingIds);
25 25
     event.register(cargos);
26 26
     

+ 20
- 20
dddsample/src/test/java/se/citerus/dddsample/domain/CargoTest.java Ver arquivo

@@ -68,7 +68,7 @@ public class CargoTest extends TestCase {
68 68
   private Cargo populateCargoReceivedStockholm() throws Exception {
69 69
     final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
70 70
 
71
-    cargo.handle(new HandlingEvent(getDate("2007-12-01"), HandlingEvent.Type.RECEIVE, null));
71
+    cargo.handle(new HandlingEvent(getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, null));
72 72
 
73 73
     return cargo;
74 74
   }
@@ -76,7 +76,7 @@ public class CargoTest extends TestCase {
76 76
   private Cargo populateCargoClaimedMelbourne() throws Exception {
77 77
     final Cargo cargo = populateCargoOffMelbourne();
78 78
 
79
-    cargo.handle(new HandlingEvent(getDate("2007-12-09"), HandlingEvent.Type.CLAIM, null));
79
+    cargo.handle(new HandlingEvent(getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, null));
80 80
     
81 81
     return cargo;
82 82
   }
@@ -88,14 +88,14 @@ public class CargoTest extends TestCase {
88 88
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
89 89
             new CarrierId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
90 90
 
91
-    cargo.handle(new HandlingEvent(getDate("2007-12-01"), HandlingEvent.Type.LOAD, stockholmToHamburg));
92
-    cargo.handle(new HandlingEvent(getDate("2007-12-02"), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
91
+    cargo.handle(new HandlingEvent(getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
92
+    cargo.handle(new HandlingEvent(getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
93 93
 
94 94
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
95 95
             new CarrierId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
96 96
 
97
-    cargo.handle(new HandlingEvent(getDate("2007-12-03"), HandlingEvent.Type.LOAD, hamburgToHongKong));
98
-    cargo.handle(new HandlingEvent(getDate("2007-12-04"), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
97
+    cargo.handle(new HandlingEvent(getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
98
+    cargo.handle(new HandlingEvent(getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
99 99
 
100 100
     return cargo;
101 101
   }
@@ -106,13 +106,13 @@ public class CargoTest extends TestCase {
106 106
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
107 107
             new CarrierId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
108 108
 
109
-    cargo.handle(new HandlingEvent(getDate("2007-12-01"), HandlingEvent.Type.LOAD, stockholmToHamburg));
110
-    cargo.handle(new HandlingEvent(getDate("2007-12-02"), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
109
+    cargo.handle(new HandlingEvent(getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
110
+    cargo.handle(new HandlingEvent(getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
111 111
 
112 112
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
113 113
             new CarrierId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
114 114
 
115
-    cargo.handle(new HandlingEvent(getDate("2007-12-03"), HandlingEvent.Type.LOAD, hamburgToHongKong));
115
+    cargo.handle(new HandlingEvent(getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
116 116
 
117 117
     return cargo;
118 118
   }
@@ -123,20 +123,20 @@ public class CargoTest extends TestCase {
123 123
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
124 124
             new CarrierId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
125 125
 
126
-    cargo.handle(new HandlingEvent(getDate("2007-12-01"), HandlingEvent.Type.LOAD, stockholmToHamburg));
127
-    cargo.handle(new HandlingEvent(getDate("2007-12-02"), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
126
+    cargo.handle(new HandlingEvent(getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
127
+    cargo.handle(new HandlingEvent(getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
128 128
 
129 129
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
130 130
             new CarrierId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
131 131
 
132
-    cargo.handle(new HandlingEvent(getDate("2007-12-03"), HandlingEvent.Type.LOAD, hamburgToHongKong));
133
-    cargo.handle(new HandlingEvent(getDate("2007-12-04"), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
132
+    cargo.handle(new HandlingEvent(getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
133
+    cargo.handle(new HandlingEvent(getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
134 134
 
135 135
     final CarrierMovement hongKongToMelbourne = new CarrierMovement(
136 136
             new CarrierId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
137 137
 
138
-    cargo.handle(new HandlingEvent(getDate("2007-12-05"), HandlingEvent.Type.LOAD, hongKongToMelbourne));
139
-    cargo.handle(new HandlingEvent(getDate("2007-12-07"), HandlingEvent.Type.UNLOAD, hongKongToMelbourne));
138
+    cargo.handle(new HandlingEvent(getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongKongToMelbourne));
139
+    cargo.handle(new HandlingEvent(getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, hongKongToMelbourne));
140 140
 
141 141
     return cargo;
142 142
   }
@@ -147,19 +147,19 @@ public class CargoTest extends TestCase {
147 147
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
148 148
             new CarrierId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
149 149
 
150
-    cargo.handle(new HandlingEvent(getDate("2007-12-01"), HandlingEvent.Type.LOAD, stockholmToHamburg));
151
-    cargo.handle(new HandlingEvent(getDate("2007-12-02"), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
150
+    cargo.handle(new HandlingEvent(getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
151
+    cargo.handle(new HandlingEvent(getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
152 152
 
153 153
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
154 154
             new CarrierId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
155 155
 
156
-    cargo.handle(new HandlingEvent(getDate("2007-12-03"), HandlingEvent.Type.LOAD, hamburgToHongKong));
157
-    cargo.handle(new HandlingEvent(getDate("2007-12-04"), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
156
+    cargo.handle(new HandlingEvent(getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
157
+    cargo.handle(new HandlingEvent(getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
158 158
 
159 159
     final CarrierMovement hongKongToMelbourne = new CarrierMovement(
160 160
             new CarrierId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
161 161
 
162
-    cargo.handle(new HandlingEvent(getDate("2007-12-05"), HandlingEvent.Type.LOAD, hongKongToMelbourne));
162
+    cargo.handle(new HandlingEvent(getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongKongToMelbourne));
163 163
 
164 164
     return cargo;
165 165
   }

+ 6
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/DeliveryHistoryTest.java Ver arquivo

@@ -4,19 +4,20 @@ import junit.framework.TestCase;
4 4
 
5 5
 import java.text.DateFormat;
6 6
 import java.text.SimpleDateFormat;
7
+import java.util.Date;
7 8
 import java.util.List;
8 9
 
9 10
 public class DeliveryHistoryTest extends TestCase {
10 11
 
11
-  public void testEvensOrderedByTime() throws Exception {
12
+  public void testEvensOrderedByTimeOccured() throws Exception {
12 13
     DeliveryHistory dh = new DeliveryHistory();
13 14
     assertTrue(dh.eventsOrderedByTime().isEmpty());
14 15
 
15 16
     DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
16
-    HandlingEvent he1 = new HandlingEvent(df.parse("2010-01-03"), HandlingEvent.Type.RECEIVE);
17
-    HandlingEvent he2 = new HandlingEvent(df.parse("2010-01-01"), HandlingEvent.Type.LOAD);
18
-    HandlingEvent he3 = new HandlingEvent(df.parse("2010-01-04"), HandlingEvent.Type.CLAIM);
19
-    HandlingEvent he4 = new HandlingEvent(df.parse("2010-01-02"), HandlingEvent.Type.UNLOAD);
17
+    HandlingEvent he1 = new HandlingEvent(df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE);
18
+    HandlingEvent he2 = new HandlingEvent(df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD);
19
+    HandlingEvent he3 = new HandlingEvent(df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM);
20
+    HandlingEvent he4 = new HandlingEvent(df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD);
20 21
     dh.addEvent(he1, he2, he3, he4);
21 22
 
22 23
     List<HandlingEvent> orderEvents = dh.eventsOrderedByTime();

+ 19
- 37
dddsample/src/test/java/se/citerus/dddsample/domain/HandlingEventTest.java Ver arquivo

@@ -3,10 +3,7 @@ package se.citerus.dddsample.domain;
3 3
 import junit.framework.TestCase;
4 4
 import se.citerus.dddsample.domain.HandlingEvent.Type;
5 5
 
6
-import java.util.Calendar;
7 6
 import java.util.Date;
8
-import java.util.HashSet;
9
-import java.util.Set;
10 7
 
11 8
 public class HandlingEventTest extends TestCase {
12 9
   public void testCurrentLocationLoadEvent() throws Exception {
@@ -15,7 +12,7 @@ public class HandlingEventTest extends TestCase {
15 12
     CarrierId carrierId = new CarrierId("CAR_001");
16 13
     CarrierMovement cm = new CarrierMovement(carrierId, locationAAA, locationBBB);
17 14
     
18
-    HandlingEvent ev = new HandlingEvent(null, HandlingEvent.Type.LOAD, cm);
15
+    HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.LOAD, cm);
19 16
     
20 17
     assertEquals(locationAAA, ev.getLocation());
21 18
   }
@@ -26,18 +23,18 @@ public class HandlingEventTest extends TestCase {
26 23
     CarrierId carrierId = new CarrierId("CAR_001");
27 24
     CarrierMovement cm = new CarrierMovement(carrierId, locationAAA, locationBBB);
28 25
     
29
-    HandlingEvent ev = new HandlingEvent(null, HandlingEvent.Type.UNLOAD, cm);
26
+    HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.UNLOAD, cm);
30 27
     
31 28
     assertEquals(locationBBB, ev.getLocation());
32 29
   }
33 30
   
34 31
   public void testCurrentLocationReceivedEvent() throws Exception {
35
-    HandlingEvent ev = new HandlingEvent(null, HandlingEvent.Type.RECEIVE, null);
32
+    HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.RECEIVE, null);
36 33
 
37 34
     assertEquals(Location.UNKNOWN, ev.getLocation());
38 35
   }
39 36
   public void testCurrentLocationClaimedEvent() throws Exception {
40
-    HandlingEvent ev = new HandlingEvent(null, HandlingEvent.Type.CLAIM, null);
37
+    HandlingEvent ev = new HandlingEvent(new Date(), new Date(), HandlingEvent.Type.CLAIM, null);
41 38
 
42 39
     assertEquals(Location.UNKNOWN, ev.getLocation());
43 40
   }
@@ -58,39 +55,24 @@ public class HandlingEventTest extends TestCase {
58 55
     }
59 56
   }
60 57
   
61
-  public void testEquality() throws Exception {
62
-    Date date = Calendar.getInstance().getTime();
58
+  public void testEqualsAndSameAs() throws Exception {
59
+    Date timeOccured = new Date();
60
+    Date timeRegistered = new Date();
63 61
     Location locationAAA = new Location("AAA");
64 62
     Location locationBBB = new Location("BBB");
65 63
     CarrierId carrierId = new CarrierId("CAR_001");
66 64
     CarrierMovement cm = new CarrierMovement(carrierId, locationAAA, locationBBB);
67
-    
68
-    Cargo cargo1 = new Cargo(new TrackingId("ABC"), new Location("A"), new Location("C"));
69
-    Cargo cargo2 = new Cargo(new TrackingId("CBA"), new Location("C"), new Location("A"));
70
-    Cargo cargo3 = new Cargo(new TrackingId("CBA"), new Location("C"), new Location("A")); //Identical to cargo2
71
-    
72
-    Set<Cargo> cargos1 = new HashSet<Cargo>();
73
-    cargos1.add(cargo1);
74
-    
75
-    Set<Cargo> cargos2 = new HashSet<Cargo>();
76
-    cargos2.add(cargo1);
77
-    cargos2.add(cargo2);
78
-    
79
-    Set<Cargo> cargos3 = new HashSet<Cargo>();
80
-    cargos3.add(cargo1);
81
-    cargos3.add(cargo3);
82
-    
83
-    
84
-    HandlingEvent ev1 = new HandlingEvent(date, HandlingEvent.Type.LOAD, cm);
85
-    ev1.register(cargos1);
86
-    
87
-    HandlingEvent ev2 = new HandlingEvent(date, HandlingEvent.Type.LOAD, cm);
88
-    ev2.register(cargos2);
89
-    
90
-    HandlingEvent ev3 = new HandlingEvent(date, HandlingEvent.Type.LOAD, cm);
91
-    ev3.register(cargos2);  
92
-    
93
-    assertFalse("HandlingEvents should not be considered equal if the Set of Cargo is not equal", ev1.equals(ev2));
94
-    assertTrue("HandlingEvents should be considered equal if the Set of Cargo is equal", ev2.equals(ev3));
65
+
66
+    HandlingEvent ev1 = new HandlingEvent(timeOccured, timeRegistered, HandlingEvent.Type.LOAD, cm);
67
+    HandlingEvent ev2 = new HandlingEvent(timeOccured, timeRegistered, HandlingEvent.Type.LOAD, cm);
68
+
69
+    // They are the same real-world event
70
+    assertTrue(ev1.sameAs(ev2));
71
+    assertTrue(ev2.sameAs(ev1));
72
+
73
+    // Two handling events are not equal() even if all non-uuid fields are identical
74
+    assertFalse(ev1.equals(ev2));
75
+    assertFalse(ev2.equals(ev1));
95 76
   }
77
+
96 78
 }

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/domain/TrackingScenarioTest.java Ver arquivo

@@ -33,14 +33,14 @@ public class TrackingScenarioTest extends TestCase {
33 33
     final CarrierMovement stockholmToHamburg = new CarrierMovement(
34 34
             new CarrierId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
35 35
 
36
-    cargo.handle(new HandlingEvent(getDate("2007-12-01"), HandlingEvent.Type.LOAD, stockholmToHamburg));
37
-    cargo.handle(new HandlingEvent(getDate("2007-12-02"), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
36
+    cargo.handle(new HandlingEvent(getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholmToHamburg));
37
+    cargo.handle(new HandlingEvent(getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, stockholmToHamburg));
38 38
 
39 39
     final CarrierMovement hamburgToHongKong = new CarrierMovement(
40 40
             new CarrierId("CAR_002"), new Location("DEHAM"), new Location("CNHKG"));
41 41
 
42
-    cargo.handle(new HandlingEvent(getDate("2007-12-03"), HandlingEvent.Type.LOAD, hamburgToHongKong));
43
-    cargo.handle(new HandlingEvent(getDate("2007-12-05"), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
42
+    cargo.handle(new HandlingEvent(getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburgToHongKong));
43
+    cargo.handle(new HandlingEvent(getDate("2007-12-05"), new Date(), HandlingEvent.Type.UNLOAD, hamburgToHongKong));
44 44
 
45 45
     return cargo;
46 46
   }

+ 3
- 2
dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java Ver arquivo

@@ -37,7 +37,7 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
37 37
     this.sessionFactory = sessionFactory;
38 38
   }
39 39
 
40
-  protected void onSetUp() throws Exception {
40
+  protected void onSetUp() {
41 41
     Session session = createMock(Session.class);
42 42
     Connection connection = createMock(Connection.class);
43 43
     Transaction transaction = createMock(Transaction.class);
@@ -69,7 +69,7 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
69 69
         Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("ORIG"), new Location("DEST"));
70 70
         CarrierMovement cm = new CarrierMovement(new CarrierId("CAR_001"), new Location("FROM"), new Location("TO"));
71 71
         cargo.getDeliveryHistory().addEvent(
72
-                new HandlingEvent(new Date(10), HandlingEvent.Type.CLAIM, cm)
72
+                new HandlingEvent(new Date(10L), new Date(20L), HandlingEvent.Type.CLAIM, cm)
73 73
         );
74 74
         return cargo;
75 75
       }
@@ -109,6 +109,7 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
109 109
 
110 110
   protected void onTearDown() throws Exception {
111 111
     verify(cargoRepository, sessionFactory);
112
+    reset(cargoRepository, sessionFactory);
112 113
   }
113 114
 
114 115
   /**

+ 3
- 10
dddsample/src/test/java/se/citerus/dddsample/service/HandlingEventServiceTest.java Ver arquivo

@@ -9,8 +9,6 @@ import se.citerus.dddsample.repository.HandlingEventRepository;
9 9
 
10 10
 import java.util.Calendar;
11 11
 import java.util.Date;
12
-import java.util.HashSet;
13
-import java.util.Set;
14 12
 
15 13
 public class HandlingEventServiceTest extends TestCase {
16 14
   private HandlingEventServiceImpl service;
@@ -43,14 +41,9 @@ public class HandlingEventServiceTest extends TestCase {
43 41
     expect(cargoRepository.find(new TrackingId("ABC"))).andReturn(cargoABC);
44 42
     expect(cargoRepository.find(new TrackingId("XYZ"))).andReturn(cargoXYZ);
45 43
     expect(carrierMovementRepository.find(new CarrierId("AAA_BBB"))).andReturn(cmAAA_BBB);
46
-    
47
-    HandlingEvent event = new HandlingEvent(date, HandlingEvent.parseType(type), cmAAA_BBB);
48
-    Set<Cargo> cargos = new HashSet<Cargo>();
49
-    cargos.add(cargoABC);
50
-    cargos.add(cargoXYZ);
51
-    event.register(cargos);
52
-    
53
-    handlingEventRepository.save(event);
44
+
45
+    // TODO: does not inspect the handling event instance in a sufficient way
46
+    handlingEventRepository.save(isA(HandlingEvent.class));
54 47
     
55 48
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
56 49
     

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/web/CargoTrackingControllerTest.java Ver arquivo

@@ -44,7 +44,7 @@ public class CargoTrackingControllerTest extends TestCase {
44 44
     return new CargoService() {
45 45
       public CargoWithHistoryDTO find(String trackingId) {
46 46
         Cargo cargo = new Cargo(new TrackingId(trackingId), new Location("AAA"), new Location("BBB"));
47
-        HandlingEvent event = new HandlingEvent(new Date(10), HandlingEvent.Type.RECEIVE);
47
+        HandlingEvent event = new HandlingEvent(new Date(10L), new Date(20L), HandlingEvent.Type.RECEIVE);
48 48
         cargo.getDeliveryHistory().addEvent(event);
49 49
 
50 50
         // TODO: use DTO assemblers
@@ -58,7 +58,7 @@ public class CargoTrackingControllerTest extends TestCase {
58 58
           event.getLocation().unlocode(),
59 59
           event.getType().toString(),
60 60
           null, // TODO: event hierarchy will remove this kind of code
61
-          event.getTime()));
61
+          event.getTimeOccurred()));
62 62
         return cargoDTO;
63 63
       }
64 64
     };