|
|
@@ -1,78 +0,0 @@
|
|
1
|
|
-package se.citerus.dddsample.domain.model.cargo;
|
|
2
|
|
-
|
|
3
|
|
-import junit.framework.TestCase;
|
|
4
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
|
|
5
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
|
|
6
|
|
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
7
|
|
-import se.citerus.dddsample.domain.model.location.Location;
|
|
8
|
|
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
9
|
|
-
|
|
10
|
|
-import java.text.DateFormat;
|
|
11
|
|
-import java.text.SimpleDateFormat;
|
|
12
|
|
-import java.util.*;
|
|
13
|
|
-
|
|
14
|
|
-public class DeliveryHistoryTest extends TestCase {
|
|
15
|
|
-
|
|
16
|
|
- private Cargo cargo = new Cargo(new TrackingId("XYZ"), HONGKONG, NEWYORK);
|
|
17
|
|
-
|
|
18
|
|
- public void testEvensOrderedByTimeOccured() throws Exception {
|
|
19
|
|
-
|
|
20
|
|
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
21
|
|
- CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), HONGKONG, NEWYORK, new Date(), new Date());
|
|
22
|
|
- HandlingEvent he1 = new HandlingEvent(cargo, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, NEWYORK);
|
|
23
|
|
- HandlingEvent he2 = new HandlingEvent(cargo, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, NEWYORK, carrierMovement);
|
|
24
|
|
- HandlingEvent he3 = new HandlingEvent(cargo, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, HONGKONG);
|
|
25
|
|
- HandlingEvent he4 = new HandlingEvent(cargo, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, carrierMovement);
|
|
26
|
|
- DeliveryHistory dh = new DeliveryHistory(Arrays.asList(he1, he2, he3, he4));
|
|
27
|
|
-
|
|
28
|
|
- List<HandlingEvent> orderEvents = dh.eventsOrderedByCompletionTime();
|
|
29
|
|
- assertEquals(4, orderEvents.size());
|
|
30
|
|
- assertSame(he2, orderEvents.get(0));
|
|
31
|
|
- assertSame(he4, orderEvents.get(1));
|
|
32
|
|
- assertSame(he1, orderEvents.get(2));
|
|
33
|
|
- assertSame(he3, orderEvents.get(3));
|
|
34
|
|
- }
|
|
35
|
|
-
|
|
36
|
|
- public void testCargoStatusFromLastHandlingEvent() {
|
|
37
|
|
- Set<HandlingEvent> events = new HashSet<HandlingEvent>();
|
|
38
|
|
- DeliveryHistory deliveryHistory = new DeliveryHistory(events);
|
|
39
|
|
-
|
|
40
|
|
- assertEquals(StatusCode.NOT_RECEIVED, deliveryHistory.status());
|
|
41
|
|
-
|
|
42
|
|
- events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
|
|
43
|
|
- deliveryHistory = new DeliveryHistory(events);
|
|
44
|
|
- assertEquals(StatusCode.IN_PORT, deliveryHistory.status());
|
|
45
|
|
-
|
|
46
|
|
- CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("ABC"), HAMBURG, HAMBURG, new Date(), new Date());
|
|
47
|
|
- events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, carrierMovement));
|
|
48
|
|
- deliveryHistory = new DeliveryHistory(events);
|
|
49
|
|
- assertEquals(StatusCode.ONBOARD_CARRIER, deliveryHistory.status());
|
|
50
|
|
-
|
|
51
|
|
- events.add(new HandlingEvent(cargo, new Date(30), new Date(31), HandlingEvent.Type.UNLOAD, HAMBURG, carrierMovement));
|
|
52
|
|
- deliveryHistory = new DeliveryHistory(events);
|
|
53
|
|
- assertEquals(StatusCode.IN_PORT, deliveryHistory.status());
|
|
54
|
|
-
|
|
55
|
|
- events.add(new HandlingEvent(cargo, new Date(40), new Date(41), HandlingEvent.Type.CLAIM, HAMBURG));
|
|
56
|
|
- deliveryHistory = new DeliveryHistory(events);
|
|
57
|
|
- assertEquals(StatusCode.CLAIMED, deliveryHistory.status());
|
|
58
|
|
- }
|
|
59
|
|
-
|
|
60
|
|
- public void testCurrentLocation() throws Exception {
|
|
61
|
|
- Set<HandlingEvent> events = new HashSet<HandlingEvent>();
|
|
62
|
|
- DeliveryHistory deliveryHistory = new DeliveryHistory(events);
|
|
63
|
|
-
|
|
64
|
|
- assertEquals(Location.UNKNOWN, deliveryHistory.currentLocation());
|
|
65
|
|
-
|
|
66
|
|
- events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
|
|
67
|
|
- deliveryHistory = new DeliveryHistory(events);
|
|
68
|
|
-
|
|
69
|
|
- assertEquals(HAMBURG, deliveryHistory.currentLocation());
|
|
70
|
|
-
|
|
71
|
|
- CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("ABC"), HAMBURG, HAMBURG, new Date(), new Date());
|
|
72
|
|
- events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, carrierMovement));
|
|
73
|
|
- deliveryHistory = new DeliveryHistory(events);
|
|
74
|
|
-
|
|
75
|
|
- assertEquals(Location.UNKNOWN, deliveryHistory.currentLocation());
|
|
76
|
|
- }
|
|
77
|
|
-
|
|
78
|
|
-}
|