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

Introduced OperatorCode on HandlingEvent to align it more closely with the domain event pattern.

peter_backlund 17 лет назад
Родитель
Сommit
4037c2bdae

+ 3
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/application/handling/HandlingEventService.java Просмотреть файл

3
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
3
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
4
 import se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException;
4
 import se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException;
5
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
5
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
6
+import se.citerus.dddsample.tracking.core.domain.model.handling.OperatorCode;
6
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
7
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
7
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
8
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
8
 
9
 
22
    * @param voyageNumber   voyage number
23
    * @param voyageNumber   voyage number
23
    * @param unLocode       UN locode for the location where the event occurred
24
    * @param unLocode       UN locode for the location where the event occurred
24
    * @param type           type of event
25
    * @param type           type of event
26
+   * @param operatorCode
25
    * @throws se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException
27
    * @throws se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException
26
    *          if a handling event that represents an actual event that's relevant to a cargo we're tracking
28
    *          if a handling event that represents an actual event that's relevant to a cargo we're tracking
27
    *          can't be created from the parameters
29
    *          can't be created from the parameters
30
                              TrackingId trackingId,
32
                              TrackingId trackingId,
31
                              VoyageNumber voyageNumber,
33
                              VoyageNumber voyageNumber,
32
                              UnLocode unLocode,
34
                              UnLocode unLocode,
33
-                             HandlingEvent.Type type) throws CannotCreateHandlingEventException;
35
+                             HandlingEvent.Type type, OperatorCode operatorCode) throws CannotCreateHandlingEventException;
34
 
36
 
35
 }
37
 }

+ 3
- 6
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/application/handling/HandlingEventServiceImpl.java Просмотреть файл

7
 import org.springframework.transaction.annotation.Transactional;
7
 import org.springframework.transaction.annotation.Transactional;
8
 import se.citerus.dddsample.tracking.core.application.event.SystemEvents;
8
 import se.citerus.dddsample.tracking.core.application.event.SystemEvents;
9
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
9
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
10
-import se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException;
11
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
12
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
13
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
10
+import se.citerus.dddsample.tracking.core.domain.model.handling.*;
14
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
11
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
15
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
12
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
16
 
13
 
37
   @Transactional
34
   @Transactional
38
   public void registerHandlingEvent(final Date completionTime, final TrackingId trackingId,
35
   public void registerHandlingEvent(final Date completionTime, final TrackingId trackingId,
39
                                     final VoyageNumber voyageNumber, final UnLocode unLocode,
36
                                     final VoyageNumber voyageNumber, final UnLocode unLocode,
40
-                                    final HandlingEvent.Type type) throws CannotCreateHandlingEventException {
37
+                                    final HandlingEvent.Type type, final OperatorCode operatorCode) throws CannotCreateHandlingEventException {
41
 
38
 
42
     /* Using a factory to create a HandlingEvent (aggregate). This is where
39
     /* Using a factory to create a HandlingEvent (aggregate). This is where
43
        it is determined wether the incoming data, the attempt, actually is capable
40
        it is determined wether the incoming data, the attempt, actually is capable
44
        of representing a real handling handlingEvent. */
41
        of representing a real handling handlingEvent. */
45
     final HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(
42
     final HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(
46
-      completionTime, trackingId, voyageNumber, unLocode, type
43
+      completionTime, trackingId, voyageNumber, unLocode, type, operatorCode
47
     );
44
     );
48
 
45
 
49
     /* Store the new handling handlingEvent, which updates the persistent
46
     /* Store the new handling handlingEvent, which updates the persistent

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

12
 import org.springframework.web.context.support.WebApplicationContextUtils;
12
 import org.springframework.web.context.support.WebApplicationContextUtils;
13
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
13
 import static se.citerus.dddsample.tracking.core.application.util.DateTestUtil.toDate;
14
 import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
14
 import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
15
-import se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException;
16
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
17
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
18
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
15
+import se.citerus.dddsample.tracking.core.domain.model.handling.*;
19
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
16
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
20
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
17
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
21
 import se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations;
18
 import se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations;
49
 
46
 
50
   private static void loadHandlingEventData(JdbcTemplate jdbcTemplate) {
47
   private static void loadHandlingEventData(JdbcTemplate jdbcTemplate) {
51
     String handlingEventSql =
48
     String handlingEventSql =
52
-      "insert into HandlingEvent (sequence_number, completionTime, registrationTime, type, location_id, voyage_id, cargo_id) " +
53
-        "values (?, ?, ?, ?, ?, ?, ?)";
49
+      "insert into HandlingEvent (sequence_number, completionTime, registrationTime, type, location_id, voyage_id, cargo_id, operator_code) " +
50
+        "values (?, ?, ?, ?, ?, ?, ?,?)";
54
 
51
 
55
     Object[][] handlingEventArgs = {
52
     Object[][] handlingEventArgs = {
56
       //XYZ (SESTO-FIHEL-DEHAM-CNHKG-JPTOK-AUMEL)
53
       //XYZ (SESTO-FIHEL-DEHAM-CNHKG-JPTOK-AUMEL)
57
-      {1, ts(0), ts((0)), "RECEIVE", 1, null, 1},
58
-      {2, ts((4)), ts((5)), "LOAD", 1, 1, 1},
59
-      {3, ts((14)), ts((14)), "UNLOAD", 5, 1, 1},
60
-      {4, ts((15)), ts((15)), "LOAD", 5, 1, 1},
61
-      {5, ts((30)), ts((30)), "UNLOAD", 6, 1, 1},
62
-      {6, ts((33)), ts((33)), "LOAD", 6, 1, 1},
63
-      {7, ts((34)), ts((34)), "UNLOAD", 3, 1, 1},
64
-      {8, ts((60)), ts((60)), "LOAD", 3, 1, 1},
65
-      {9, ts((70)), ts((71)), "UNLOAD", 4, 1, 1},
66
-      {10, ts((75)), ts((75)), "LOAD", 4, 1, 1},
67
-      {11, ts((88)), ts((88)), "UNLOAD", 2, 1, 1},
68
-      {12, ts((100)), ts((102)), "CLAIM", 2, null, 1},
54
+      {1, ts(0), ts((0)), "RECEIVE", 1, null, 1, null},
55
+      {2, ts((4)), ts((5)), "LOAD", 1, 1, 1, "AS34F"},
56
+      {3, ts((14)), ts((14)), "UNLOAD", 5, 1, 1, "AS34F"},
57
+      {4, ts((15)), ts((15)), "LOAD", 5, 1, 1, "AS34F"},
58
+      {5, ts((30)), ts((30)), "UNLOAD", 6, 1, 1, "AS34F"},
59
+      {6, ts((33)), ts((33)), "LOAD", 6, 1, 1, "AS34F"},
60
+      {7, ts((34)), ts((34)), "UNLOAD", 3, 1, 1, "AS34F"},
61
+      {8, ts((60)), ts((60)), "LOAD", 3, 1, 1, "AS34F"},
62
+      {9, ts((70)), ts((71)), "UNLOAD", 4, 1, 1, "AS34F"},
63
+      {10, ts((75)), ts((75)), "LOAD", 4, 1, 1, "AS34F"},
64
+      {11, ts((88)), ts((88)), "UNLOAD", 2, 1, 1, "AS34F"},
65
+      {12, ts((100)), ts((102)), "CLAIM", 2, null, 1, null},
69
 
66
 
70
       //ZYX (AUMEL - USCHI - DEHAM -)
67
       //ZYX (AUMEL - USCHI - DEHAM -)
71
-      {13, ts((200)), ts((201)), "RECEIVE", 2, null, 3},
72
-      {14, ts((202)), ts((202)), "LOAD", 2, 2, 3},
73
-      {15, ts((208)), ts((208)), "UNLOAD", 7, 2, 3},
74
-      {16, ts((212)), ts((212)), "LOAD", 7, 2, 3},
75
-      {17, ts((230)), ts((230)), "UNLOAD", 6, 2, 3},
76
-      {18, ts((235)), ts((235)), "LOAD", 6, 2, 3},
68
+      {13, ts((200)), ts((201)), "RECEIVE", 2, null, 3, null},
69
+      {14, ts((202)), ts((202)), "LOAD", 2, 2, 3, "AS34F"},
70
+      {15, ts((208)), ts((208)), "UNLOAD", 7, 2, 3, "AS34F"},
71
+      {16, ts((212)), ts((212)), "LOAD", 7, 2, 3, "AS34F"},
72
+      {17, ts((230)), ts((230)), "UNLOAD", 6, 2, 3, "AS34F"},
73
+      {18, ts((235)), ts((235)), "LOAD", 6, 2, 3, "AS34F"},
77
 
74
 
78
       //ABC
75
       //ABC
79
-      {19, ts((20)), ts((21)), "CLAIM", 2, null, 2},
76
+      {19, ts((20)), ts((21)), "CLAIM", 2, null, 2, null},
80
 
77
 
81
       //CBA
78
       //CBA
82
-      {20, ts((0)), ts((1)), "RECEIVE", 2, null, 4},
83
-      {21, ts((10)), ts((11)), "LOAD", 2, 2, 4},
84
-      {22, ts((20)), ts((21)), "UNLOAD", 7, 2, 4},
79
+      {20, ts((0)), ts((1)), "RECEIVE", 2, null, 4, null},
80
+      {21, ts((10)), ts((11)), "LOAD", 2, 2, 4, "AS34F"},
81
+      {22, ts((20)), ts((21)), "UNLOAD", 7, 2, 4, "AS34F"},
85
 
82
 
86
       //FGH
83
       //FGH
87
-      {23, ts(100), ts(160), "RECEIVE", 3, null, 5},
88
-      {24, ts(150), ts(110), "LOAD", 3, 3, 5},
84
+      {23, ts(100), ts(160), "RECEIVE", 3, null, 5, null},
85
+      {24, ts(150), ts(110), "LOAD", 3, 3, 5, "AS34F"},
89
 
86
 
90
       // JKL
87
       // JKL
91
-      {25, ts(200), ts(220), "RECEIVE", 6, null, 6},
92
-      {26, ts(300), ts(330), "LOAD", 6, 3, 6},
88
+      {25, ts(200), ts(220), "RECEIVE", 6, null, 6, null},
89
+      {26, ts(300), ts(330), "LOAD", 6, 3, 6, "AS34F"},
93
       {27, ts(400), ts(440), "UNLOAD", 5, 3, 6}  // Unexpected event
90
       {27, ts(400), ts(440), "UNLOAD", 5, 3, 6}  // Unexpected event
94
     };
91
     };
95
     executeUpdate(jdbcTemplate, handlingEventSql, handlingEventArgs);
92
     executeUpdate(jdbcTemplate, handlingEventSql, handlingEventArgs);
235
 
232
 
236
         try {
233
         try {
237
           HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
234
           HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
238
-            toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.RECEIVE
235
+            toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.RECEIVE, new OperatorCode("ABCDE")
239
           );
236
           );
240
           session.save(event1);
237
           session.save(event1);
241
 
238
 
242
           HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
239
           HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
243
-            toDate("2009-03-02"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD
240
+            toDate("2009-03-02"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD, new OperatorCode("ABCDE")
244
           );
241
           );
245
           session.save(event2);
242
           session.save(event2);
246
 
243
 
247
           HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
244
           HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
248
-            toDate("2009-03-05"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
245
+            toDate("2009-03-05"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD, new OperatorCode("ABCDE")
249
           );
246
           );
250
           session.save(event3);
247
           session.save(event3);
251
         } catch (CannotCreateHandlingEventException e) {
248
         } catch (CannotCreateHandlingEventException e) {
273
 
270
 
274
         try {
271
         try {
275
           HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
272
           HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
276
-            toDate("2009-03-01"), trackingId1, null, HANGZOU.unLocode(), HandlingEvent.Type.RECEIVE
273
+            toDate("2009-03-01"), trackingId1, null, HANGZOU.unLocode(), HandlingEvent.Type.RECEIVE, new OperatorCode("ABCDE")
277
           );
274
           );
278
           session.save(event1);
275
           session.save(event1);
279
 
276
 
280
           HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
277
           HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
281
-            toDate("2009-03-03"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), HANGZOU.unLocode(), HandlingEvent.Type.LOAD
278
+            toDate("2009-03-03"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), HANGZOU.unLocode(), HandlingEvent.Type.LOAD, new OperatorCode("ABCDE")
282
           );
279
           );
283
           session.save(event2);
280
           session.save(event2);
284
 
281
 
285
           HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
282
           HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
286
-            toDate("2009-03-05"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
283
+            toDate("2009-03-05"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD, new OperatorCode("ABCDE")
287
           );
284
           );
288
           session.save(event3);
285
           session.save(event3);
289
 
286
 
290
           HandlingEvent event4 = handlingEventFactory.createHandlingEvent(
287
           HandlingEvent event4 = handlingEventFactory.createHandlingEvent(
291
-            toDate("2009-03-06"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.LOAD
288
+            toDate("2009-03-06"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.LOAD, new OperatorCode("ABCDE")
292
           );
289
           );
293
           session.save(event4);
290
           session.save(event4);
294
 
291
 

+ 6
- 0
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/handling/HandlingReportParser.java Просмотреть файл

4
 import org.apache.commons.lang.StringUtils;
4
 import org.apache.commons.lang.StringUtils;
5
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
5
 import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
6
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
6
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
7
+import se.citerus.dddsample.tracking.core.domain.model.handling.OperatorCode;
7
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
8
 import se.citerus.dddsample.tracking.core.domain.model.location.UnLocode;
8
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
9
 import se.citerus.dddsample.tracking.core.domain.model.voyage.VoyageNumber;
9
 
10
 
83
 
84
 
84
     return completionTime.toGregorianCalendar().getTime();
85
     return completionTime.toGregorianCalendar().getTime();
85
   }
86
   }
87
+
88
+  public static OperatorCode parseOperatorCode() {
89
+    // TODO stubbed atm
90
+    return new OperatorCode("ABCDE");
91
+  }
86
 }
92
 }

+ 1
- 1
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/application/event/CargoUpdaterTest.java Просмотреть файл

52
       cargo.trackingId(),
52
       cargo.trackingId(),
53
       HONGKONG_TO_NEW_YORK.voyageNumber(),
53
       HONGKONG_TO_NEW_YORK.voyageNumber(),
54
       HONGKONG.unLocode(),
54
       HONGKONG.unLocode(),
55
-      LOAD
55
+      LOAD, new OperatorCode("ABCDE")
56
     );
56
     );
57
     handlingEventRepository.store(handlingEvent);
57
     handlingEventRepository.store(handlingEvent);
58
 
58
 

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

10
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
10
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
11
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
11
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
12
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
12
 import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
13
+import se.citerus.dddsample.tracking.core.domain.model.handling.OperatorCode;
13
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
14
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
14
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
15
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
15
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM001;
16
 import static se.citerus.dddsample.tracking.core.domain.model.voyage.SampleVoyages.CM001;
51
 
52
 
52
     replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
53
     replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
53
 
54
 
54
-    service.registerHandlingEvent(new Date(), cargo.trackingId(), CM001.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD);
55
+    service.registerHandlingEvent(new Date(), cargo.trackingId(), CM001.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD, new OperatorCode("ABCDE"));
55
   }
56
   }
56
 
57
 
57
 }
58
 }

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

24
 
24
 
25
   public void testNewWithCarrierMovement() throws Exception {
25
   public void testNewWithCarrierMovement() throws Exception {
26
 
26
 
27
-    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, CM003);
27
+    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, CM003, new OperatorCode("ABCDE"));
28
     assertEquals(HONGKONG, e1.location());
28
     assertEquals(HONGKONG, e1.location());
29
 
29
 
30
-    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, CM003);
30
+    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, CM003, new OperatorCode("ABCDE"));
31
     assertEquals(NEWYORK, e2.location());
31
     assertEquals(NEWYORK, e2.location());
32
 
32
 
33
     // These event types prohibit a carrier movement association
33
     // These event types prohibit a carrier movement association
34
     for (HandlingEvent.Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
34
     for (HandlingEvent.Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
35
       try {
35
       try {
36
-        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, CM003);
36
+        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, CM003, new OperatorCode("ABCDE"));
37
         fail("Handling event type " + type + " prohibits carrier movement");
37
         fail("Handling event type " + type + " prohibits carrier movement");
38
       } catch (IllegalArgumentException expected) {
38
       } catch (IllegalArgumentException expected) {
39
       }
39
       }
42
     // These event types requires a carrier movement association
42
     // These event types requires a carrier movement association
43
     for (HandlingEvent.Type type : asList(LOAD, UNLOAD)) {
43
     for (HandlingEvent.Type type : asList(LOAD, UNLOAD)) {
44
       try {
44
       try {
45
-        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, null);
45
+        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, null, new OperatorCode("ABCDE"));
46
         fail("Handling event type " + type + " requires carrier movement");
46
         fail("Handling event type " + type + " requires carrier movement");
47
       } catch (IllegalArgumentException expected) {
47
       } catch (IllegalArgumentException expected) {
48
       }
48
       }
56
 
56
 
57
   public void testCurrentLocationLoadEvent() throws Exception {
57
   public void testCurrentLocationLoadEvent() throws Exception {
58
 
58
 
59
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, CM004);
59
+    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, CM004, new OperatorCode("ABCDE"));
60
 
60
 
61
     assertEquals(CHICAGO, ev.location());
61
     assertEquals(CHICAGO, ev.location());
62
   }
62
   }
63
 
63
 
64
   public void testCurrentLocationUnloadEvent() throws Exception {
64
   public void testCurrentLocationUnloadEvent() throws Exception {
65
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, CM004);
65
+    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, CM004, new OperatorCode("ABCDE"));
66
 
66
 
67
     assertEquals(HAMBURG, ev.location());
67
     assertEquals(HAMBURG, ev.location());
68
   }
68
   }
99
     Date timeOccured = new Date();
99
     Date timeOccured = new Date();
100
     Date timeRegistered = new Date();
100
     Date timeRegistered = new Date();
101
 
101
 
102
-    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
103
-    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
102
+    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005, new OperatorCode("ABCDE"));
103
+    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005, new OperatorCode("ABCDE"));
104
 
104
 
105
-    // Two handling events are not equal() even if all non-uuid fields are identical
106
     assertTrue(ev1.equals(ev2));
105
     assertTrue(ev1.equals(ev2));
107
     assertTrue(ev2.equals(ev1));
106
     assertTrue(ev2.equals(ev1));
108
 
107
 
109
     assertTrue(ev1.equals(ev1));
108
     assertTrue(ev1.equals(ev1));
110
 
109
 
110
+    //noinspection ObjectEqualsNull
111
     assertFalse(ev2.equals(null));
111
     assertFalse(ev2.equals(null));
112
+
112
     assertFalse(ev2.equals(new Object()));
113
     assertFalse(ev2.equals(new Object()));
113
   }
114
   }
114
 
115
 

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

31
       addMovement(SHANGHAI, new Date(1), new Date(2)).
31
       addMovement(SHANGHAI, new Date(1), new Date(2)).
32
       addMovement(DALLAS, new Date(3), new Date(4)).
32
       addMovement(DALLAS, new Date(3), new Date(4)).
33
       build();
33
       build();
34
-    event1 = new HandlingEvent(cargo, toDate("2009-03-05"), toDate("2009-03-05"), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
35
-    event1duplicate = new HandlingEvent(cargo, toDate("2009-03-05"), toDate("2009-03-07"), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
36
-    event2 = new HandlingEvent(cargo, toDate("2009-03-10"), toDate("2009-03-06"), HandlingEvent.Type.UNLOAD, DALLAS, voyage);
37
-    eventOfCargo2 = new HandlingEvent(cargo2, toDate("2009-03-11"), toDate("2009-03-08"), HandlingEvent.Type.LOAD, GOTHENBURG, voyage);
34
+    event1 = new HandlingEvent(cargo, toDate("2009-03-05"), toDate("2009-03-05"), HandlingEvent.Type.LOAD, SHANGHAI, voyage, new OperatorCode("ABCDE"));
35
+    event1duplicate = new HandlingEvent(cargo, toDate("2009-03-05"), toDate("2009-03-07"), HandlingEvent.Type.LOAD, SHANGHAI, voyage, new OperatorCode("ABCDE"));
36
+    event2 = new HandlingEvent(cargo, toDate("2009-03-10"), toDate("2009-03-06"), HandlingEvent.Type.UNLOAD, DALLAS, voyage, new OperatorCode("ABCDE"));
37
+    eventOfCargo2 = new HandlingEvent(cargo2, toDate("2009-03-11"), toDate("2009-03-08"), HandlingEvent.Type.LOAD, GOTHENBURG, voyage, new OperatorCode("ABCDE"));
38
   }
38
   }
39
 
39
 
40
   public void testDistinctEventsByCompletionTime() {
40
   public void testDistinctEventsByCompletionTime() {

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

8
 import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
8
 import se.citerus.dddsample.tracking.core.domain.model.cargo.*;
9
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.*;
9
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.RoutingStatus.*;
10
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.*;
10
 import static se.citerus.dddsample.tracking.core.domain.model.cargo.TransportStatus.*;
11
-import se.citerus.dddsample.tracking.core.domain.model.handling.CannotCreateHandlingEventException;
12
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
11
+import se.citerus.dddsample.tracking.core.domain.model.handling.*;
13
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
12
 import static se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent.Type.*;
14
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventFactory;
15
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
16
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
13
 import se.citerus.dddsample.tracking.core.domain.model.location.Location;
17
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
14
 import se.citerus.dddsample.tracking.core.domain.model.location.LocationRepository;
18
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
15
 import static se.citerus.dddsample.tracking.core.domain.model.location.SampleLocations.*;
383
 
380
 
384
   private void updateHandlingEventAggregate(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
381
   private void updateHandlingEventAggregate(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
385
     VoyageNumber voyageNumber = voyage != null ? voyage.voyageNumber() : null;
382
     VoyageNumber voyageNumber = voyage != null ? voyage.voyageNumber() : null;
386
-    HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(completionTime, trackingId, voyageNumber, location.unLocode(), type);
383
+    HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(completionTime, trackingId, voyageNumber, location.unLocode(), type, new OperatorCode("ABCDE"));
387
     handlingEventRepository.store(handlingEvent);
384
     handlingEventRepository.store(handlingEvent);
388
   }
385
   }
389
 
386