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

Refactored test to reflet introduction of handling event factory

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

+ 25
- 56
dddsample/src/test/java/se/citerus/dddsample/application/ws/HandlinEventServiceEndpointTest.java Просмотреть файл

3
 import junit.framework.TestCase;
3
 import junit.framework.TestCase;
4
 import static org.easymock.EasyMock.*;
4
 import static org.easymock.EasyMock.*;
5
 import se.citerus.dddsample.application.service.InMemTransactionManager;
5
 import se.citerus.dddsample.application.service.InMemTransactionManager;
6
+import se.citerus.dddsample.domain.model.cargo.Cargo;
6
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
+import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
7
 import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
9
 import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
10
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
9
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
11
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
12
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
10
 import se.citerus.dddsample.domain.model.location.UnLocode;
13
 import se.citerus.dddsample.domain.model.location.UnLocode;
11
 import se.citerus.dddsample.domain.service.HandlingEventService;
14
 import se.citerus.dddsample.domain.service.HandlingEventService;
12
 import se.citerus.dddsample.domain.service.UnknownCarrierMovementIdException;
15
 import se.citerus.dddsample.domain.service.UnknownCarrierMovementIdException;
16
+import se.citerus.dddsample.domain.service.UnknownLocationException;
13
 import se.citerus.dddsample.domain.service.UnknownTrackingIdException;
17
 import se.citerus.dddsample.domain.service.UnknownTrackingIdException;
14
 
18
 
15
 import java.text.SimpleDateFormat;
19
 import java.text.SimpleDateFormat;
19
 
23
 
20
   private HandlingEventServiceEndpointImpl endpoint;
24
   private HandlingEventServiceEndpointImpl endpoint;
21
   private HandlingEventService handlingEventService;
25
   private HandlingEventService handlingEventService;
22
-  private HandlingEventFactory handlingEventFactory;
23
   private SimpleDateFormat sdf;
26
   private SimpleDateFormat sdf;
27
+  private HandlingEvent event;
28
+  private Date date = new Date(100);
24
 
29
 
25
   protected void setUp() throws Exception {
30
   protected void setUp() throws Exception {
26
-    handlingEventFactory = new HandlingEventFactory();
27
-    endpoint = new HandlingEventServiceEndpointImpl();
28
-    handlingEventService = createMock(HandlingEventService.class);
29
-    endpoint.setHandlingEventService(handlingEventService);
30
     sdf = new SimpleDateFormat(HandlingEventServiceEndpointImpl.ISO_8601_FORMAT);
31
     sdf = new SimpleDateFormat(HandlingEventServiceEndpointImpl.ISO_8601_FORMAT);
31
-    endpoint.setTransactionManager(new InMemTransactionManager());
32
-  }
33
 
32
 
34
-  public void testRegisterValidEvent() throws Exception {
35
-    Date date = new Date(100);
36
-
37
-    final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, new TrackingId("FOO"), new CarrierMovementId("CAR_456"), new UnLocode("CNHKG"), HandlingEvent.Type.LOAD);
38
-    handlingEventService.register(event);
39
-    replay(handlingEventService);
33
+    endpoint = new HandlingEventServiceEndpointImpl();
40
 
34
 
41
-    // Tested call
42
-    endpoint.register(sdf.format(date), "FOO", "CAR_456", "CNHKG", "LOAD");
43
-  }
35
+    handlingEventService = createMock(HandlingEventService.class);
36
+    endpoint.setHandlingEventService(handlingEventService);
44
 
37
 
38
+    endpoint.setTransactionManager(new InMemTransactionManager());
45
 
39
 
46
-  public void testRegisterUnknownTrackingId() throws Exception {
47
-    Date date = new Date(100);
40
+    Cargo cargo = new Cargo(new TrackingId("FOO"), HONGKONG, NEWYORK);
41
+    CarrierMovement carrierMovement = new CarrierMovement(
42
+      new CarrierMovementId("CAR_456"),
43
+      HONGKONG, TOKYO, new Date(), new Date());
48
 
44
 
49
-    TrackingId trackingId = new TrackingId("NOTFOUND");
50
-    UnLocode unlocode = new UnLocode("SESTO");
45
+    event = new HandlingEvent(
46
+      cargo, date, new Date(), HandlingEvent.Type.LOAD, HONGKONG, carrierMovement
47
+    );
51
 
48
 
52
-    final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, null, unlocode, HandlingEvent.Type.CLAIM);
53
-    handlingEventService.register(event);
54
-    expectLastCall().andThrow(new UnknownTrackingIdException(trackingId));
55
-    replay(handlingEventService);
49
+    HandlingEventFactory handlingEventFactory = new HandlingEventFactory() {
50
+      public HandlingEvent createHandlingEvent(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type) throws UnknownTrackingIdException, UnknownCarrierMovementIdException, UnknownLocationException {
51
+        return event;
52
+      }
53
+    };
56
 
54
 
57
-    // Tested call
58
-    endpoint.register(sdf.format(date), "NOTFOUND", null, "SESTO", "CLAIM");
55
+    endpoint.setHandlingEventFactory(handlingEventFactory);
59
   }
56
   }
60
 
57
 
61
-  public void testRegisterUnknownCarrierMovementId() throws Exception {
62
-    Date date = new Date(100);
63
-
64
-    TrackingId trackingId = new TrackingId("XYZ");
65
-    CarrierMovementId carrierMovementId = new CarrierMovementId("NOTFOUND");
66
-
67
-    final HandlingEvent event = handlingEventFactory.createHandlingEvent(date, trackingId, carrierMovementId, new UnLocode("AUMEL"), HandlingEvent.Type.UNLOAD);
58
+  public void testRegisterValidEvent() throws Exception {
68
     handlingEventService.register(event);
59
     handlingEventService.register(event);
69
-    expectLastCall().andThrow(new UnknownCarrierMovementIdException(carrierMovementId));
70
-    replay(handlingEventService);
71
-
72
-    // Tested call
73
-    endpoint.register(sdf.format(date), "XYZ", "NOTFOUND", "AUMEL", "UNLOAD");
74
-  }
75
-
76
-  public void testRegisterInvalidEventType() throws Exception {
77
-    Date date = new Date(100);
78
-
79
     replay(handlingEventService);
60
     replay(handlingEventService);
80
 
61
 
81
     // Tested call
62
     // Tested call
82
-    // Note: currently, every error is silently swallowed.
83
-    endpoint.register(sdf.format(date), "XYZ", "CAR_333", "AUMEL", "NO_SUCH_EVENT_TYPE");
84
-  }
85
-
86
-  public void testRegisterInvalidDateFormat() throws Exception {
87
-    Date date = new Date(100);
88
-
89
-    replay(handlingEventService);
90
-
91
-    // Tested call
92
-    // Note: currently, every error is silently swallowed.
93
-    endpoint.register("1 2 3 4", "XYZ", "CAR_333", "AUMEL", "LOAD");
63
+    endpoint.register(sdf.format(date), "FOO", "CAR_456", "CNHKG", "LOAD");
94
   }
64
   }
95
 
65
 
96
-
97
   protected void tearDown() throws Exception {
66
   protected void tearDown() throws Exception {
98
     verify(handlingEventService);
67
     verify(handlingEventService);
99
   }
68
   }