View Javadoc

1   package se.citerus.dddsample.domain.model.voyage;
2   
3   import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
4   import se.citerus.dddsample.domain.model.location.Location;
5   import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
6   
7   import java.lang.reflect.Field;
8   import java.util.*;
9   
10  /**
11   * Sample carrier movements, for test purposes.
12   *
13   */
14  public class SampleVoyages {
15  
16    public static final Voyage CM001 = createVoyage("CM001", STOCKHOLM, HAMBURG);
17    public static final Voyage CM002 = createVoyage("CM002", HAMBURG, HONGKONG);
18    public static final Voyage CM003 = createVoyage("CM003", HONGKONG, NEWYORK);
19    public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
20    public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
21    public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
22    private static Voyage createVoyage(String id, Location from, Location to) {
23      return new Voyage(new VoyageNumber(id), new Schedule(Arrays.asList(
24        new CarrierMovement(from, to, new Date(), new Date())
25      )));
26    }
27  
28    // TODO CM00[1-6] and createVoyage are deprecated. Remove and refactor tests.
29  
30    public final static Voyage v100 = new Voyage.Builder(new VoyageNumber("V100"), HONGKONG).
31      addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05")).
32      addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-09")).
33      build();
34    public final static Voyage v200 = new Voyage.Builder(new VoyageNumber("V200"), TOKYO).
35        addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08")).
36        addMovement(CHICAGO, toDate("2009-03-10"), toDate("2009-03-14")).
37        addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16")).
38        build();
39    public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
40          addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
41          addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
42          addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
43          addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
44          build();
45    public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
46            addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
47            addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
48            addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22")).
49            build();
50  
51    /**
52     * Voyage number 0100S (by ship)
53     *
54     * Hongkong - Hangzou - Tokyo - Melbourne - New York
55     */
56    public static final Voyage HONGKONG_TO_NEW_YORK =
57      new Voyage.Builder(new VoyageNumber("0100S"), HONGKONG).
58        addMovement(HANGZOU, toDate("2008-10-01", "12:00"), toDate("2008-10-03", "14:30")).
59        addMovement(TOKYO, toDate("2008-10-03", "21:00"), toDate("2008-10-06", "06:15")).
60        addMovement(MELBOURNE, toDate("2008-10-06", "11:00"), toDate("2008-10-12", "11:30")).
61        addMovement(NEWYORK, toDate("2008-10-14", "12:00"), toDate("2008-10-23", "23:10")).
62        build();
63  
64  
65    /**
66     * Voyage number 0200T (by train)
67     *
68     * New York - Chicago - Dallas
69     */
70    public static final Voyage NEW_YORK_TO_DALLAS =
71      new Voyage.Builder(new VoyageNumber("0200T"), NEWYORK).
72        addMovement(CHICAGO, toDate("2008-10-24", "07:00"), toDate("2008-10-24", "17:45")).
73        addMovement(DALLAS, toDate("2008-10-24", "21:25"), toDate("2008-10-25", "19:30")).
74        build();
75  
76    /**
77     * Voyage number 0300A (by airplane)
78     *
79     * Dallas - Hamburg - Stockholm - Helsinki
80     */
81    public static final Voyage DALLAS_TO_HELSINKI =
82      new Voyage.Builder(new VoyageNumber("0300A"), DALLAS).
83        addMovement(HAMBURG, toDate("2008-10-29", "03:30"), toDate("2008-10-31", "14:00")).
84        addMovement(STOCKHOLM, toDate("2008-11-01", "15:20"), toDate("2008-11-01", "18:40")).
85        addMovement(HELSINKI, toDate("2008-11-02", "09:00"), toDate("2008-11-02", "11:15")).
86        build();
87  
88    /**
89     * Voyage number 0301S (by ship)
90     *
91     * Dallas - Hamburg - Stockholm - Helsinki, alternate route
92     */
93    public static final Voyage DALLAS_TO_HELSINKI_ALT =
94      new Voyage.Builder(new VoyageNumber("0301S"), DALLAS).
95        addMovement(HELSINKI, toDate("2008-10-29", "03:30"), toDate("2008-11-05", "15:45")).
96        build();
97  
98    /**
99     * Voyage number 0400S (by ship)
100    *
101    * Helsinki - Rotterdam - Shanghai - Hongkong
102    *
103    */
104   public static final Voyage HELSINKI_TO_HONGKONG =
105     new Voyage.Builder(new VoyageNumber("0400S"), HELSINKI).
106       addMovement(ROTTERDAM, toDate("2008-11-04", "05:50"), toDate("2008-11-06", "14:10")).
107       addMovement(SHANGHAI, toDate("2008-11-10", "21:45"), toDate("2008-11-22", "16:40")).
108       addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37")).
109       build();
110 
111   public static final Map<VoyageNumber, Voyage> ALL = new HashMap();
112 
113   static {
114     for (Field field : SampleVoyages.class.getDeclaredFields()) {
115       if (field.getType().equals(Voyage.class)) {
116         try {
117           Voyage voyage = (Voyage) field.get(null);
118           ALL.put(voyage.voyageNumber(), voyage);
119         } catch (IllegalAccessException e) {
120           throw new RuntimeException(e);
121         }
122       }
123     }
124   }
125 
126   public static List<Voyage> getAll() {
127     return new ArrayList(ALL.values());
128   }
129 
130   public static Voyage lookup(VoyageNumber voyageNumber) {
131     return ALL.get(voyageNumber);
132   }
133   
134 }