|
|
@@ -8,6 +8,10 @@ import java.text.SimpleDateFormat;
|
|
8
|
8
|
import java.util.Date;
|
|
9
|
9
|
|
|
10
|
10
|
public class CargoTest extends TestCase {
|
|
|
11
|
+ private final Location stockholm = new Location(new UnLocode("SE","STO"), "Stockholm");
|
|
|
12
|
+ private final Location melbourne = new Location(new UnLocode("AU","MEL"), "Melbourne");
|
|
|
13
|
+ private final Location hongkong = new Location(new UnLocode("CN","HKG"), "Hongkong");
|
|
|
14
|
+ private final Location hamburg = new Location(new UnLocode("DE","HAM"), "Hamburg");
|
|
11
|
15
|
|
|
12
|
16
|
// TODO:
|
|
13
|
17
|
// it seems that events are not added to the system by cargo.deliveryHistory().addEvent(),
|
|
|
@@ -15,10 +19,10 @@ public class CargoTest extends TestCase {
|
|
15
|
19
|
// work against the repositories or the service layer. The delivery history of a cargo should be
|
|
16
|
20
|
// read-only from the cargo end. // PeBa
|
|
17
|
21
|
|
|
|
22
|
+
|
|
|
23
|
+
|
|
18
|
24
|
public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
|
|
19
|
|
- Location destination = new Location("AUMEL");
|
|
20
|
|
- Location origin = new Location("SESTO");
|
|
21
|
|
- Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, destination);
|
|
|
25
|
+ Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
|
|
22
|
26
|
|
|
23
|
27
|
assertEquals(Location.UNKNOWN, cargo.lastKnownLocation());
|
|
24
|
28
|
}
|
|
|
@@ -26,25 +30,25 @@ public class CargoTest extends TestCase {
|
|
26
|
30
|
public void testlastKnownLocationReceived() throws Exception {
|
|
27
|
31
|
Cargo cargo = populateCargoReceivedStockholm();
|
|
28
|
32
|
|
|
29
|
|
- assertEquals(new Location("SESTO"), cargo.lastKnownLocation());
|
|
|
33
|
+ assertEquals(stockholm, cargo.lastKnownLocation());
|
|
30
|
34
|
}
|
|
31
|
35
|
|
|
32
|
36
|
public void testlastKnownLocationClaimed() throws Exception {
|
|
33
|
37
|
Cargo cargo = populateCargoClaimedMelbourne();
|
|
34
|
38
|
|
|
35
|
|
- assertEquals(new Location("AUMEL"), cargo.lastKnownLocation());
|
|
|
39
|
+ assertEquals(melbourne, cargo.lastKnownLocation());
|
|
36
|
40
|
}
|
|
37
|
41
|
|
|
38
|
42
|
public void testlastKnownLocationUnloaded() throws Exception {
|
|
39
|
43
|
Cargo cargo = populateCargoOffHongKong();
|
|
40
|
44
|
|
|
41
|
|
- assertEquals(new Location("CNHGK"), cargo.lastKnownLocation());
|
|
|
45
|
+ assertEquals(hongkong, cargo.lastKnownLocation());
|
|
42
|
46
|
}
|
|
43
|
47
|
|
|
44
|
48
|
public void testlastKnownLocationloaded() throws Exception {
|
|
45
|
49
|
Cargo cargo = populateCargoOnHamburg();
|
|
46
|
50
|
|
|
47
|
|
- assertEquals(new Location("DEHAM"), cargo.lastKnownLocation());
|
|
|
51
|
+ assertEquals(hamburg, cargo.lastKnownLocation());
|
|
48
|
52
|
}
|
|
49
|
53
|
|
|
50
|
54
|
public void testAtFinalLocation() throws Exception {
|
|
|
@@ -60,10 +64,10 @@ public class CargoTest extends TestCase {
|
|
60
|
64
|
}
|
|
61
|
65
|
|
|
62
|
66
|
public void testEquality() throws Exception {
|
|
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
|
+ Cargo c1 = new Cargo(new TrackingId("ABC"), stockholm, hongkong);
|
|
|
68
|
+ Cargo c2 = new Cargo(new TrackingId("CBA"), stockholm, hongkong);
|
|
|
69
|
+ Cargo c3 = new Cargo(new TrackingId("ABC"), stockholm, melbourne);
|
|
|
70
|
+ Cargo c4 = new Cargo(new TrackingId("ABC"), stockholm, hongkong);
|
|
67
|
71
|
|
|
68
|
72
|
assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c4));
|
|
69
|
73
|
assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c3));
|
|
|
@@ -73,9 +77,10 @@ public class CargoTest extends TestCase {
|
|
73
|
77
|
|
|
74
|
78
|
// TODO: Generate test data some better way
|
|
75
|
79
|
private Cargo populateCargoReceivedStockholm() throws Exception {
|
|
76
|
|
- final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
|
|
|
80
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
|
|
77
|
81
|
|
|
78
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, new Location("SESTO")));
|
|
|
82
|
+ HandlingEvent he = new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.RECEIVE, stockholm);
|
|
|
83
|
+ cargo.deliveryHistory().addEvent(he);
|
|
79
|
84
|
|
|
80
|
85
|
return cargo;
|
|
81
|
86
|
}
|
|
|
@@ -83,89 +88,89 @@ public class CargoTest extends TestCase {
|
|
83
|
88
|
private Cargo populateCargoClaimedMelbourne() throws Exception {
|
|
84
|
89
|
final Cargo cargo = populateCargoOffMelbourne();
|
|
85
|
90
|
|
|
86
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, new Location("AUMEL")));
|
|
|
91
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-09"), new Date(), HandlingEvent.Type.CLAIM, melbourne));
|
|
87
|
92
|
|
|
88
|
93
|
return cargo;
|
|
89
|
94
|
}
|
|
90
|
95
|
|
|
91
|
96
|
private Cargo populateCargoOffHongKong() throws Exception {
|
|
92
|
|
- final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
|
|
|
97
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
|
|
93
|
98
|
|
|
94
|
99
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
95
|
|
- new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
|
|
|
100
|
+ new CarrierMovementId("CAR_001"), stockholm, hamburg);
|
|
96
|
101
|
|
|
97
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
|
|
98
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
|
|
|
102
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
|
|
|
103
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
|
|
99
|
104
|
|
|
100
|
105
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
101
|
|
- new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
|
|
|
106
|
+ new CarrierMovementId("CAR_001"), hamburg, hongkong);
|
|
102
|
107
|
|
|
103
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
|
|
104
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
|
|
|
108
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
|
|
|
109
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong));
|
|
105
|
110
|
|
|
106
|
111
|
return cargo;
|
|
107
|
112
|
}
|
|
108
|
113
|
|
|
109
|
114
|
private Cargo populateCargoOnHamburg() throws Exception {
|
|
110
|
|
- final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
|
|
|
115
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
|
|
111
|
116
|
|
|
112
|
117
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
113
|
|
- new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
|
|
|
118
|
+ new CarrierMovementId("CAR_001"), stockholm, hamburg);
|
|
114
|
119
|
|
|
115
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
|
|
116
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
|
|
|
120
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
|
|
|
121
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
|
|
117
|
122
|
|
|
118
|
123
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
119
|
|
- new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
|
|
|
124
|
+ new CarrierMovementId("CAR_001"), hamburg, hongkong);
|
|
120
|
125
|
|
|
121
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
|
|
|
126
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
|
|
122
|
127
|
|
|
123
|
128
|
return cargo;
|
|
124
|
129
|
}
|
|
125
|
130
|
|
|
126
|
131
|
private Cargo populateCargoOffMelbourne() throws Exception {
|
|
127
|
|
- final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
|
|
|
132
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
|
|
128
|
133
|
|
|
129
|
134
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
130
|
|
- new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
|
|
|
135
|
+ new CarrierMovementId("CAR_001"), stockholm, hamburg);
|
|
131
|
136
|
|
|
132
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
|
|
133
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
|
|
|
137
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
|
|
|
138
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
|
|
134
|
139
|
|
|
135
|
140
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
136
|
|
- new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
|
|
|
141
|
+ new CarrierMovementId("CAR_001"), hamburg, hongkong);
|
|
137
|
142
|
|
|
138
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
|
|
139
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
|
|
|
143
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
|
|
|
144
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong));
|
|
140
|
145
|
|
|
141
|
146
|
final CarrierMovement hongKongToMelbourne = new CarrierMovement(
|
|
142
|
|
- new CarrierMovementId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
|
|
|
147
|
+ new CarrierMovementId("CAR_001"), hongkong, melbourne);
|
|
143
|
148
|
|
|
144
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, new Location("CNHGK"), hongKongToMelbourne));
|
|
145
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, new Location("AUMEL"), hongKongToMelbourne));
|
|
|
149
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongkong, hongKongToMelbourne));
|
|
|
150
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-07"), new Date(), HandlingEvent.Type.UNLOAD, melbourne, hongKongToMelbourne));
|
|
146
|
151
|
|
|
147
|
152
|
return cargo;
|
|
148
|
153
|
}
|
|
149
|
154
|
|
|
150
|
155
|
private Cargo populateCargoOnHongKong() throws Exception {
|
|
151
|
|
- final Cargo cargo = new Cargo(new TrackingId("XYZ"), new Location("SESTO"), new Location("AUMEL"));
|
|
|
156
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), stockholm, melbourne);
|
|
152
|
157
|
|
|
153
|
158
|
final CarrierMovement stockholmToHamburg = new CarrierMovement(
|
|
154
|
|
- new CarrierMovementId("CAR_001"), new Location("SESTO"), new Location("DEHAM"));
|
|
|
159
|
+ new CarrierMovementId("CAR_001"), stockholm, hamburg);
|
|
155
|
160
|
|
|
156
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, new Location("SESTO"), stockholmToHamburg));
|
|
157
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, new Location("DEHAM"), stockholmToHamburg));
|
|
|
161
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-01"), new Date(), HandlingEvent.Type.LOAD, stockholm, stockholmToHamburg));
|
|
|
162
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-02"), new Date(), HandlingEvent.Type.UNLOAD, hamburg, stockholmToHamburg));
|
|
158
|
163
|
|
|
159
|
164
|
final CarrierMovement hamburgToHongKong = new CarrierMovement(
|
|
160
|
|
- new CarrierMovementId("CAR_001"), new Location("DEHAM"), new Location("CNHGK"));
|
|
|
165
|
+ new CarrierMovementId("CAR_001"), hamburg, hongkong);
|
|
161
|
166
|
|
|
162
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, new Location("DEHAM"), hamburgToHongKong));
|
|
163
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, new Location("CNHGK"), hamburgToHongKong));
|
|
|
167
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-03"), new Date(), HandlingEvent.Type.LOAD, hamburg, hamburgToHongKong));
|
|
|
168
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-04"), new Date(), HandlingEvent.Type.UNLOAD, hongkong, hamburgToHongKong));
|
|
164
|
169
|
|
|
165
|
170
|
final CarrierMovement hongKongToMelbourne = new CarrierMovement(
|
|
166
|
|
- new CarrierMovementId("CAR_001"), new Location("CNHGK"), new Location("AUMEL"));
|
|
|
171
|
+ new CarrierMovementId("CAR_001"), hongkong, melbourne);
|
|
167
|
172
|
|
|
168
|
|
- cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, new Location("CNHGK"), hongKongToMelbourne));
|
|
|
173
|
+ cargo.deliveryHistory().addEvent(new HandlingEvent(cargo, getDate("2007-12-05"), new Date(), HandlingEvent.Type.LOAD, hongkong, hongKongToMelbourne));
|
|
169
|
174
|
|
|
170
|
175
|
return cargo;
|
|
171
|
176
|
}
|