|
|
@@ -1,29 +1,68 @@
|
|
1
|
1
|
package se.citerus.dddsample.domain.model.cargo;
|
|
2
|
2
|
|
|
3
|
3
|
import junit.framework.TestCase;
|
|
4
|
|
-import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
|
|
5
|
|
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
|
|
|
4
|
+import static se.citerus.dddsample.DateTestUtil.toDate;
|
|
|
5
|
+import se.citerus.dddsample.domain.model.carrier.Voyage;
|
|
|
6
|
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
|
|
|
7
|
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
6
|
8
|
|
|
7
|
|
-import java.util.Date;
|
|
|
9
|
+import java.util.Arrays;
|
|
8
|
10
|
|
|
9
|
11
|
public class RouteSpecificationTest extends TestCase {
|
|
10
|
12
|
|
|
11
|
|
- public void testIsSatisfiedBySuccess() {
|
|
12
|
|
- RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, CHICAGO, new Date());
|
|
13
|
|
- Itinerary itinerary = new Itinerary();
|
|
|
13
|
+ final Voyage hongKongTokyoNewYork = new Voyage.Builder(
|
|
|
14
|
+ new VoyageNumber("V001"), HONGKONG).
|
|
|
15
|
+ addMovement(TOKYO, toDate("2009-02-01"), toDate("2009-02-05")).
|
|
|
16
|
+ addMovement(NEWYORK, toDate("2009-02-06"), toDate("2009-02-10")).
|
|
|
17
|
+ addMovement(HONGKONG, toDate("2009-02-11"), toDate("2009-02-14")).
|
|
|
18
|
+ build();
|
|
|
19
|
+
|
|
|
20
|
+ final Voyage dallasNewYorkChicago = new Voyage.Builder(
|
|
|
21
|
+ new VoyageNumber("V002"), DALLAS).
|
|
|
22
|
+ addMovement(NEWYORK, toDate("2009-02-06"), toDate("2009-02-07")).
|
|
|
23
|
+ addMovement(CHICAGO, toDate("2009-02-12"), toDate("2009-02-20")).
|
|
|
24
|
+ build();
|
|
|
25
|
+
|
|
|
26
|
+ // TODO:
|
|
|
27
|
+ // it shouldn't be possible to create Legs that have load/unload locations
|
|
|
28
|
+ // and/or dates that don't match the voyage's carrier movements.
|
|
|
29
|
+ final Itinerary itinerary = new Itinerary(Arrays.asList(
|
|
|
30
|
+ new Leg(hongKongTokyoNewYork, HONGKONG, NEWYORK,
|
|
|
31
|
+ toDate("2009-02-01"), toDate("2009-02-10")),
|
|
|
32
|
+ new Leg(dallasNewYorkChicago, NEWYORK, CHICAGO,
|
|
|
33
|
+ toDate("2009-02-12"), toDate("2009-02-20")))
|
|
|
34
|
+ );
|
|
|
35
|
+
|
|
|
36
|
+ public void testIsSatisfiedBy_Success() {
|
|
|
37
|
+ RouteSpecification routeSpecification = new RouteSpecification(
|
|
|
38
|
+ HONGKONG, CHICAGO, toDate("2009-03-01")
|
|
|
39
|
+ );
|
|
|
40
|
+
|
|
14
|
41
|
assertTrue(routeSpecification.isSatisfiedBy(itinerary));
|
|
15
|
42
|
}
|
|
16
|
43
|
|
|
17
|
|
- public void testIsSatisfiedByInvalidDate() {
|
|
18
|
|
- // TODO
|
|
|
44
|
+ public void testIsSatisfiedBy_WrongOrigin() {
|
|
|
45
|
+ RouteSpecification routeSpecification = new RouteSpecification(
|
|
|
46
|
+ HANGZOU, CHICAGO, toDate("2009-03-01")
|
|
|
47
|
+ );
|
|
|
48
|
+
|
|
|
49
|
+ assertFalse(routeSpecification.isSatisfiedBy(itinerary));
|
|
19
|
50
|
}
|
|
20
|
51
|
|
|
21
|
|
- public void testIsSatisfiedByInvalidOrigin() {
|
|
22
|
|
- // TODO
|
|
|
52
|
+ public void testIsSatisfiedBy_WrongDestination() {
|
|
|
53
|
+ RouteSpecification routeSpecification = new RouteSpecification(
|
|
|
54
|
+ HONGKONG, DALLAS, toDate("2009-03-01")
|
|
|
55
|
+ );
|
|
|
56
|
+
|
|
|
57
|
+ assertFalse(routeSpecification.isSatisfiedBy(itinerary));
|
|
23
|
58
|
}
|
|
24
|
59
|
|
|
25
|
|
- public void testIsSatisfiedByInvalidDestination() {
|
|
26
|
|
- // TODO
|
|
|
60
|
+ public void testIsSatisfiedBy_MissedDeadline() {
|
|
|
61
|
+ RouteSpecification routeSpecification = new RouteSpecification(
|
|
|
62
|
+ HONGKONG, CHICAGO, toDate("2009-02-15")
|
|
|
63
|
+ );
|
|
|
64
|
+
|
|
|
65
|
+ assertFalse(routeSpecification.isSatisfiedBy(itinerary));
|
|
27
|
66
|
}
|
|
28
|
67
|
|
|
29
|
68
|
}
|