peter_backlund 17 лет назад
Родитель
Сommit
af8d76faad
47 измененных файлов: 0 добавлений и 3292 удалений
  1. 0
    51
      dddsample/src/test/java/se/citerus/dddsample/application/booking/BookingServiceTest.java
  2. 0
    57
      dddsample/src/test/java/se/citerus/dddsample/application/handling/HandlingEventServiceTest.java
  3. 0
    31
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoFactoryTest.java
  4. 0
    292
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java
  5. 0
    21
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CustomsZoneTest.java
  6. 0
    181
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java
  7. 0
    116
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java
  8. 0
    54
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/LegTest.java
  9. 0
    101
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/RouteSpecificationTest.java
  10. 0
    15
      dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/TrackingIdTest.java
  11. 0
    128
      dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java
  12. 0
    115
      dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java
  13. 0
    77
      dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingHistoryTest.java
  14. 0
    37
      dddsample/src/test/java/se/citerus/dddsample/domain/model/location/LocationTest.java
  15. 0
    56
      dddsample/src/test/java/se/citerus/dddsample/domain/model/location/UnLocodeTest.java
  16. 0
    53
      dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/CarrierMovementTest.java
  17. 0
    28
      dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/ScheduleTest.java
  18. 0
    28
      dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/VoyageNumberTest.java
  19. 0
    19
      dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/VoyageTest.java
  20. 0
    7
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/AlwaysFalseSpec.java
  21. 0
    7
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/AlwaysTrueSpec.java
  22. 0
    24
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/AndSpecificationTest.java
  23. 0
    18
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/NotSpecificationTest.java
  24. 0
    24
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/OrSpecificationTest.java
  25. 0
    40
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/experimental/EntitySupportTest.java
  26. 0
    43
      dddsample/src/test/java/se/citerus/dddsample/domain/shared/experimental/ValueObjectSupportTest.java
  27. 0
    22
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/TrackingIdGeneratorTest.java
  28. 0
    78
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/AbstractRepositoryTest.java
  29. 0
    180
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  30. 0
    71
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java
  31. 0
    31
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/LocationRepositoryTest.java
  32. 0
    27
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/VoyageRepositoryTest.java
  33. 0
    84
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java
  34. 0
    69
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/HandlingEventRepositoryInMem.java
  35. 0
    25
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/LocationRepositoryInMem.java
  36. 0
    14
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/VoyageRepositoryInMem.java
  37. 0
    80
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java
  38. 0
    58
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/CargoRoutingDTOAssemblerTest.java
  39. 0
    86
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/ItineraryCandidateDTOAssemblerTest.java
  40. 0
    31
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/LocationDTOAssemblerTest.java
  41. 0
    29
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminControllerTest.java
  42. 0
    48
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java
  43. 0
    96
      dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java
  44. 0
    70
      dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingViewAdapterTest.java
  45. 0
    37
      dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/TrackCommandValidatorTest.java
  46. 0
    426
      dddsample/src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java
  47. 0
    107
      dddsample/src/test/java/se/citerus/dddsample/scenario/VoyageRescheduledScenarioTest.java

+ 0
- 51
dddsample/src/test/java/se/citerus/dddsample/application/booking/BookingServiceTest.java Просмотреть файл

1
-package se.citerus.dddsample.application.booking;
2
-
3
-import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
-import se.citerus.dddsample.domain.model.cargo.*;
6
-import se.citerus.dddsample.domain.model.location.LocationRepository;
7
-import static se.citerus.dddsample.domain.model.location.SampleLocations.CHICAGO;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
9
-import se.citerus.dddsample.domain.model.location.UnLocode;
10
-import se.citerus.dddsample.domain.service.RoutingService;
11
-
12
-import java.util.Date;
13
-
14
-public class BookingServiceTest extends TestCase {
15
-
16
-  BookingServiceImpl bookingService;
17
-  CargoRepository cargoRepository;
18
-  LocationRepository locationRepository;
19
-  RoutingService routingService;
20
-  TrackingIdGenerator trackingIdGenerator;
21
-
22
-  protected void setUp() throws Exception {
23
-    cargoRepository = createMock(CargoRepository.class);
24
-    locationRepository = createMock(LocationRepository.class);
25
-    routingService = createMock(RoutingService.class);
26
-    trackingIdGenerator = createMock(TrackingIdGenerator.class);
27
-    CargoFactory cargoFactory = new CargoFactory(locationRepository, trackingIdGenerator);
28
-    bookingService = new BookingServiceImpl(routingService, cargoFactory, cargoRepository, locationRepository);
29
-  }
30
-
31
-  public void testRegisterNew() {
32
-    TrackingId expectedTrackingId = new TrackingId("TRK1");
33
-    UnLocode fromUnlocode = new UnLocode("USCHI");
34
-    UnLocode toUnlocode = new UnLocode("SESTO");
35
-
36
-    expect(trackingIdGenerator.nextTrackingId()).andReturn(expectedTrackingId);
37
-    expect(locationRepository.find(fromUnlocode)).andReturn(CHICAGO);
38
-    expect(locationRepository.find(toUnlocode)).andReturn(STOCKHOLM);
39
-
40
-    cargoRepository.store(isA(Cargo.class));
41
-
42
-    replay(cargoRepository, locationRepository, trackingIdGenerator);
43
-
44
-    TrackingId trackingId = bookingService.bookNewCargo(fromUnlocode, toUnlocode, new Date());
45
-    assertEquals(expectedTrackingId, trackingId);
46
-  }
47
-
48
-  protected void tearDown() throws Exception {
49
-    verify(cargoRepository, locationRepository, trackingIdGenerator);
50
-  }
51
-}

+ 0
- 57
dddsample/src/test/java/se/citerus/dddsample/application/handling/HandlingEventServiceTest.java Просмотреть файл

1
-package se.citerus.dddsample.application.handling;
2
-
3
-import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
-import se.citerus.dddsample.application.event.SystemEvents;
6
-import se.citerus.dddsample.domain.model.cargo.Cargo;
7
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
8
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
9
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
10
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
11
-import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
12
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
13
-import se.citerus.dddsample.domain.model.location.LocationRepository;
14
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
15
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
16
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
17
-
18
-import java.util.Date;
19
-
20
-public class HandlingEventServiceTest extends TestCase {
21
-  private HandlingEventServiceImpl service;
22
-  private SystemEvents systemEvents;
23
-  private CargoRepository cargoRepository;
24
-  private VoyageRepository voyageRepository;
25
-  private HandlingEventRepository handlingEventRepository;
26
-  private LocationRepository locationRepository;
27
-
28
-  private final Cargo cargo = new Cargo(new TrackingId("ABC"), new RouteSpecification(HAMBURG, TOKYO, new Date()));
29
-
30
-  protected void setUp() throws Exception {
31
-    cargoRepository = createMock(CargoRepository.class);
32
-    voyageRepository = createMock(VoyageRepository.class);
33
-    handlingEventRepository = createMock(HandlingEventRepository.class);
34
-    locationRepository = createMock(LocationRepository.class);
35
-    systemEvents = createMock(SystemEvents.class);
36
-
37
-    HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
38
-    service = new HandlingEventServiceImpl(handlingEventRepository, systemEvents, handlingEventFactory);
39
-  }
40
-
41
-  protected void tearDown() throws Exception {
42
-    verify(cargoRepository, voyageRepository, handlingEventRepository, systemEvents);
43
-  }
44
-
45
-  public void testRegisterEvent() throws Exception {
46
-    expect(cargoRepository.find(cargo.trackingId())).andReturn(cargo);
47
-    expect(voyageRepository.find(CM001.voyageNumber())).andReturn(CM001);
48
-    expect(locationRepository.find(STOCKHOLM.unLocode())).andReturn(STOCKHOLM);
49
-    handlingEventRepository.store(isA(HandlingEvent.class));
50
-    systemEvents.notifyOfHandlingEvent(isA(HandlingEvent.class));
51
-
52
-    replay(cargoRepository, voyageRepository, handlingEventRepository, locationRepository, systemEvents);
53
-
54
-    service.registerHandlingEvent(new Date(), cargo.trackingId(), CM001.voyageNumber(), STOCKHOLM.unLocode(), HandlingEvent.Type.LOAD);
55
-  }
56
-
57
-}

+ 0
- 31
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoFactoryTest.java Просмотреть файл

1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-aug-08
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.domain.model.cargo;
8
-
9
-import static org.junit.Assert.assertEquals;
10
-import static org.junit.Assert.assertNotNull;
11
-import org.junit.Test;
12
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
13
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HONGKONG;
14
-import static se.citerus.dddsample.domain.model.location.SampleLocations.ROTTERDAM;
15
-import se.citerus.dddsample.infrastructure.persistence.TrackingIdGeneratorInMem;
16
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
17
-
18
-public class CargoFactoryTest {
19
-
20
-  @Test
21
-  public void createNewCargo() {
22
-    CargoFactory cargoFactory = new CargoFactory(new LocationRepositoryInMem(), new TrackingIdGeneratorInMem());
23
-    Cargo cargo = cargoFactory.newCargo(
24
-      HONGKONG.unLocode(), ROTTERDAM.unLocode(), toDate("2009-07-01")
25
-    );
26
-    assertNotNull(cargo);
27
-    assertNotNull(cargo.trackingId());
28
-    assertEquals(cargo.routeSpecification(), new RouteSpecification(HONGKONG, ROTTERDAM, toDate("2009-07-01")));
29
-  }
30
-
31
-}

+ 0
- 292
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CargoTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
5
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
6
-import static se.citerus.dddsample.domain.model.cargo.TransportStatus.NOT_RECEIVED;
7
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
8
-import se.citerus.dddsample.domain.model.location.Location;
9
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
10
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
11
-import se.citerus.dddsample.domain.model.voyage.Voyage;
12
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
13
-
14
-import java.util.Arrays;
15
-import java.util.Date;
16
-
17
-public class CargoTest extends TestCase {
18
-
19
-  private Voyage crazyVoyage = new Voyage.Builder(new VoyageNumber("0123"),
20
-    STOCKHOLM).
21
-    addMovement(HAMBURG, new Date(), new Date()).
22
-    addMovement(HONGKONG, new Date(), new Date()).
23
-    addMovement(MELBOURNE, new Date(), new Date()).
24
-    build();
25
-
26
-  private Voyage pacific = new Voyage.Builder(new VoyageNumber("4567"),
27
-    SHANGHAI).
28
-    addMovement(LONGBEACH, new Date(), new Date()).
29
-    addMovement(SEATTLE, new Date(), new Date()).
30
-    build();
31
-
32
-  private Voyage transcontinental = new Voyage.Builder(new VoyageNumber("4567"),
33
-    LONGBEACH).
34
-    addMovement(CHICAGO, new Date(), new Date()).
35
-    addMovement(NEWYORK, new Date(), new Date()).
36
-    build();
37
-
38
-  private Voyage northernRail = new Voyage.Builder(new VoyageNumber("8901"),
39
-    SEATTLE).
40
-    addMovement(CHICAGO, new Date(), new Date()).
41
-    addMovement(NEWYORK, new Date(), new Date()).
42
-    build();
43
-
44
-  public void testConstruction() {
45
-    TrackingId trackingId = new TrackingId("XYZ");
46
-    Date arrivalDeadline = toDate("2009-03-13");
47
-    RouteSpecification routeSpecification = new RouteSpecification(
48
-      STOCKHOLM, MELBOURNE, arrivalDeadline
49
-    );
50
-
51
-    Cargo cargo = new Cargo(trackingId, routeSpecification);
52
-
53
-    assertEquals(NOT_ROUTED, cargo.routingStatus());
54
-    assertEquals(NOT_RECEIVED, cargo.transportStatus());
55
-    assertEquals(Location.UNKNOWN, cargo.lastKnownLocation());
56
-    assertEquals(Voyage.NONE, cargo.currentVoyage());
57
-  }
58
-
59
-  public void testRoutingStatus() throws Exception {
60
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
61
-    final Itinerary good = new Itinerary(Leg.deriveLeg(northernRail, SEATTLE, NEWYORK));
62
-    final Itinerary bad = new Itinerary(Leg.deriveLeg(crazyVoyage, HAMBURG, HONGKONG));
63
-    final RouteSpecification acceptOnlyGood = new RouteSpecification(cargo.routeSpecification().origin(), cargo.routeSpecification().destination(), new Date()) {
64
-      @Override
65
-      public boolean isSatisfiedBy(Itinerary itinerary) {
66
-        return itinerary == good;
67
-      }
68
-    };
69
-
70
-    cargo.specifyNewRoute(acceptOnlyGood);
71
-
72
-    assertEquals(NOT_ROUTED, cargo.routingStatus());
73
-
74
-    cargo.assignToRoute(bad);
75
-    assertEquals(MISROUTED, cargo.routingStatus());
76
-
77
-    cargo.assignToRoute(good);
78
-    assertEquals(ROUTED, cargo.routingStatus());
79
-  }
80
-
81
-  public void testlastKnownLocationUnknownWhenNoEvents() throws Exception {
82
-    Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
83
-
84
-    assertEquals(Location.UNKNOWN, cargo.lastKnownLocation());
85
-  }
86
-
87
-  public void testlastKnownLocationReceived() throws Exception {
88
-    Cargo cargo = populateCargoReceivedStockholm();
89
-
90
-    assertEquals(STOCKHOLM, cargo.lastKnownLocation());
91
-  }
92
-
93
-  public void testlastKnownLocationClaimed() throws Exception {
94
-    Cargo cargo = populateCargoClaimedMelbourne();
95
-
96
-    assertEquals(MELBOURNE, cargo.lastKnownLocation());
97
-  }
98
-
99
-  public void testlastKnownLocationUnloaded() throws Exception {
100
-    Cargo cargo = populateCargoOffHongKong();
101
-
102
-    assertEquals(HONGKONG, cargo.lastKnownLocation());
103
-  }
104
-
105
-  public void testlastKnownLocationloaded() throws Exception {
106
-    Cargo cargo = populateCargoOnHamburg();
107
-
108
-    assertEquals(HAMBURG, cargo.lastKnownLocation());
109
-  }
110
-
111
-  public void testEquality() throws Exception {
112
-    RouteSpecification spec1 = new RouteSpecification(STOCKHOLM, HONGKONG, new Date());
113
-    RouteSpecification spec2 = new RouteSpecification(STOCKHOLM, MELBOURNE, new Date());
114
-    Cargo c1 = new Cargo(new TrackingId("ABC"), spec1);
115
-    Cargo c2 = new Cargo(new TrackingId("CBA"), spec1);
116
-    Cargo c3 = new Cargo(new TrackingId("ABC"), spec2);
117
-    Cargo c4 = new Cargo(new TrackingId("ABC"), spec1);
118
-
119
-    assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c4));
120
-    assertTrue("Cargos should be equal when TrackingIDs are equal", c1.equals(c3));
121
-    assertTrue("Cargos should be equal when TrackingIDs are equal", c3.equals(c4));
122
-    assertFalse("Cargos are not equal when TrackingID differ", c1.equals(c2));
123
-  }
124
-
125
-  public void testIsUnloadedAtFinalDestination() throws Exception {
126
-    Cargo cargo = setUpCargoWithItinerary(HANGZOU, TOKYO, NEWYORK);
127
-    assertFalse(cargo.isReadyToClaim());
128
-
129
-    // Adding an event unrelated to unloading at final destination
130
-    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU));
131
-    assertFalse(cargo.isReadyToClaim());
132
-
133
-    Voyage voyage = new Voyage.Builder(new VoyageNumber("0123"), HANGZOU).
134
-      addMovement(NEWYORK, new Date(), new Date()).
135
-      build();
136
-
137
-    // Adding an unload event, but not at the final destination
138
-    cargo.handled(new HandlingActivity(UNLOAD, TOKYO, voyage));
139
-    assertFalse(cargo.isReadyToClaim());
140
-
141
-    // Adding an event in the final destination, but not unload
142
-    cargo.handled(new HandlingActivity(CUSTOMS, NEWYORK));
143
-    assertFalse(cargo.isReadyToClaim());
144
-
145
-    // Finally, cargo is unloaded at final destination
146
-    cargo.handled(new HandlingActivity(UNLOAD, NEWYORK, voyage));
147
-    assertTrue(cargo.isReadyToClaim());
148
-  }
149
-
150
-  private Cargo populateCargoReceivedStockholm() throws Exception {
151
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
152
-    cargo.handled(new HandlingActivity(RECEIVE, STOCKHOLM));
153
-    return cargo;
154
-  }
155
-
156
-  private Cargo populateCargoClaimedMelbourne() throws Exception {
157
-    final Cargo cargo = populateCargoOffMelbourne();
158
-
159
-    cargo.handled(new HandlingActivity(CLAIM, MELBOURNE));
160
-    return cargo;
161
-  }
162
-
163
-  private Cargo populateCargoOffHongKong() throws Exception {
164
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
165
-    
166
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
167
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
168
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
169
-    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage));
170
-    return cargo;
171
-  }
172
-
173
-  private Cargo populateCargoOnHamburg() throws Exception {
174
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
175
-    
176
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
177
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
178
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
179
-    return cargo;
180
-  }
181
-
182
-  private Cargo populateCargoOffMelbourne() throws Exception {
183
-    final Cargo cargo = setUpCargoWithItinerary(STOCKHOLM, HAMBURG, MELBOURNE);
184
-
185
-    cargo.handled(new HandlingActivity(LOAD, STOCKHOLM, crazyVoyage));
186
-    cargo.handled(new HandlingActivity(UNLOAD, HAMBURG, crazyVoyage));
187
-    cargo.handled(new HandlingActivity(LOAD, HAMBURG, crazyVoyage));
188
-    cargo.handled(new HandlingActivity(UNLOAD, HONGKONG, crazyVoyage));
189
-    cargo.handled(new HandlingActivity(LOAD, HONGKONG, crazyVoyage));
190
-    cargo.handled(new HandlingActivity(UNLOAD, MELBOURNE, crazyVoyage));
191
-
192
-    return cargo;
193
-  }
194
-
195
-  public void testIsMisdirected() throws Exception {
196
-    //A cargo with no itinerary is not misdirected
197
-    Cargo cargo = new Cargo(new TrackingId("TRKID"), new RouteSpecification(SHANGHAI, GOTHENBURG, new Date()));
198
-    assertFalse(cargo.isMisdirected());
199
-
200
-    cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
201
-
202
-    //A cargo with no handling events is not misdirected
203
-    assertFalse(cargo.isMisdirected());
204
-
205
-    //Happy path
206
-    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI));
207
-    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage));
208
-    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage));
209
-    cargo.handled(new HandlingActivity(LOAD, ROTTERDAM, crazyVoyage));
210
-    cargo.handled(new HandlingActivity(UNLOAD, GOTHENBURG, crazyVoyage));
211
-    cargo.handled(new HandlingActivity(CLAIM, GOTHENBURG));
212
-    cargo.handled(new HandlingActivity(CUSTOMS, GOTHENBURG));
213
-    assertFalse(cargo.isMisdirected());
214
-
215
-    //Try a couple of failing ones
216
-
217
-    cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
218
-
219
-    cargo.handled(new HandlingActivity(RECEIVE, HANGZOU));
220
-    assertTrue(cargo.isMisdirected());
221
-
222
-
223
-
224
-    cargo = setUpCargoWithItinerary(SHANGHAI, ROTTERDAM, GOTHENBURG);
225
-
226
-    cargo.handled(new HandlingActivity(RECEIVE, SHANGHAI));
227
-    cargo.handled(new HandlingActivity(LOAD, SHANGHAI, crazyVoyage));
228
-    cargo.handled(new HandlingActivity(UNLOAD, ROTTERDAM, crazyVoyage));
229
-    cargo.handled(new HandlingActivity(CLAIM, ROTTERDAM));
230
-
231
-    assertTrue(cargo.isMisdirected());
232
-  }
233
-
234
-  public void testCustomsClearancePoint() {
235
-    //cargo destination NYC
236
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"),
237
-      new RouteSpecification(SHANGHAI, NEWYORK, new Date()));
238
-
239
-    //SHA-LGB-NYC
240
-    cargo.assignToRoute(new Itinerary(
241
-      Leg.deriveLeg(pacific, SHANGHAI, LONGBEACH),
242
-      Leg.deriveLeg(transcontinental, LONGBEACH, NEWYORK)));
243
-    assertEquals(LONGBEACH, cargo.customsClearancePoint());
244
-
245
-    //SHA-SEA-NYC
246
-    cargo.assignToRoute(new Itinerary(
247
-      Leg.deriveLeg(pacific, SHANGHAI, SEATTLE),
248
-      Leg.deriveLeg(northernRail, SEATTLE, NEWYORK)));
249
-    assertEquals(SEATTLE, cargo.customsClearancePoint());
250
-
251
-    //cargo destination LGB
252
-    //SHA-LGB
253
-    cargo.specifyNewRoute(new RouteSpecification(SHANGHAI, LONGBEACH, new Date()));
254
-    cargo.assignToRoute(new Itinerary(
255
-      Leg.deriveLeg(pacific, SHANGHAI, LONGBEACH)));
256
-    assertEquals(LONGBEACH, cargo.customsClearancePoint());
257
-
258
-    //Cargo destination HAMBURG
259
-    //SHA-LGB-NYC This itinerary does not take
260
-    // the cargo into its CustomsZone, so no clearancePoint.
261
-    cargo.specifyNewRoute(new RouteSpecification(SHANGHAI, HAMBURG, new Date()));
262
-    cargo.assignToRoute(new Itinerary(
263
-      Leg.deriveLeg(pacific, SHANGHAI, LONGBEACH),
264
-      Leg.deriveLeg(transcontinental, LONGBEACH, NEWYORK)));
265
-    assertNull(cargo.customsClearancePoint());
266
-
267
-    //Cargo destination NEWYORK on SHA-LGB-CHI
268
-    //This itinerary does not take the cargo to its destination,
269
-    //but it does enter the CustomsZone, so it has a clearancePoint.
270
-    cargo.specifyNewRoute(new RouteSpecification(SHANGHAI, NEWYORK, new Date()));
271
-    cargo.assignToRoute(new Itinerary(
272
-      Leg.deriveLeg(pacific, SHANGHAI, LONGBEACH),
273
-      Leg.deriveLeg(transcontinental, LONGBEACH, CHICAGO)));
274
-    assertEquals(LONGBEACH, cargo.customsClearancePoint());
275
-
276
-  }
277
-
278
-  private Cargo setUpCargoWithItinerary(Location origin, Location midpoint, Location destination) {
279
-    Cargo cargo = new Cargo(new TrackingId("CARGO1"), new RouteSpecification(origin, destination, new Date()));
280
-
281
-    Itinerary itinerary = new Itinerary(
282
-      Arrays.asList(
283
-        new Leg(crazyVoyage, origin, midpoint, new Date(), new Date()),
284
-        new Leg(crazyVoyage, midpoint, destination, new Date(), new Date())
285
-      )
286
-    );
287
-
288
-    cargo.assignToRoute(itinerary);
289
-    return cargo;
290
-  }
291
-
292
-}

+ 0
- 21
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/CustomsZoneTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
5
-
6
-public class CustomsZoneTest extends TestCase {
7
-
8
-  public void testIncludes() {
9
-    assertTrue(US.includes(DALLAS));
10
-    assertFalse(EU.includes(NEWYORK));
11
-  }
12
-
13
-  public void testEntryPoint() {
14
-    assertEquals(LONGBEACH, US.entryPoint(SHANGHAI, LONGBEACH, CHICAGO));
15
-  }
16
-
17
-  public void testClearancePoint() {
18
-    assertEquals(LONGBEACH, US.entryPoint(SHANGHAI, LONGBEACH, CHICAGO));
19
-  }
20
-
21
-}

+ 0
- 181
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
5
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.MISROUTED;
6
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.ROUTED;
7
-import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
8
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
9
-import se.citerus.dddsample.domain.model.location.Location;
10
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
11
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
12
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
13
-import se.citerus.dddsample.domain.model.voyage.Voyage;
14
-
15
-import java.util.Date;
16
-
17
-public class DeliveryTest extends TestCase {
18
-
19
-  Delivery delivery;
20
-  Projections projections;
21
-  Itinerary itinerary;
22
-  RouteSpecification routeSpecification;
23
-
24
-  @Override
25
-  protected void setUp() throws Exception {
26
-    routeSpecification = new RouteSpecification(HANGZOU, STOCKHOLM, toDate("2008-11-03"));
27
-    itinerary = new Itinerary(
28
-      Leg.deriveLeg(HONGKONG_TO_NEW_YORK, HANGZOU, NEWYORK),
29
-      Leg.deriveLeg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS),
30
-      Leg.deriveLeg(DALLAS_TO_HELSINKI, DALLAS, STOCKHOLM)
31
-    );
32
-    delivery = Delivery.initial();
33
-    projections = new Projections(delivery, itinerary, routeSpecification);
34
-    Thread.sleep(1);
35
-  }
36
-
37
-  public void testDerivedFromRouteSpecificationAndItinerary() throws Exception {
38
-    assertEquals(ROUTED, delivery.routingStatus(itinerary, routeSpecification));
39
-    assertEquals(Voyage.NONE, delivery.currentVoyage());
40
-    assertFalse(delivery.isMisdirected(itinerary, routeSpecification));
41
-    assertFalse(delivery.isUnloadedAtDestination(routeSpecification));
42
-    assertEquals(Location.UNKNOWN, delivery.lastKnownLocation());
43
-    assertEquals(NOT_RECEIVED, delivery.transportStatus());
44
-    assertTrue(delivery.calculatedAt().before(new Date()));
45
-
46
-    assertEquals(new HandlingActivity(RECEIVE, HANGZOU), projections.nextExpectedActivity());
47
-    assertEquals(DALLAS_TO_HELSINKI.schedule().arrivalTimeAt(STOCKHOLM), projections.estimatedTimeOfArrival());
48
-  }
49
-
50
-  public void testUpdateOnHandlingHappyPath() {
51
-    // 1. Receive
52
-
53
-    HandlingActivity handlingActivity = new HandlingActivity(RECEIVE, HANGZOU);
54
-    Delivery newDelivery = Delivery.whenHandled(handlingActivity);
55
-    Projections newProjections = new Projections(newDelivery, itinerary, routeSpecification);
56
-
57
-    // Changed on handling
58
-    assertEquals(Voyage.NONE, newDelivery.currentVoyage());
59
-    assertEquals(HANGZOU, newDelivery.lastKnownLocation());
60
-    assertEquals(IN_PORT, newDelivery.transportStatus());
61
-
62
-    // Changed on handling and/or (re-)routing
63
-    assertEquals(new HandlingActivity(LOAD, HANGZOU, HONGKONG_TO_NEW_YORK), newProjections.nextExpectedActivity());
64
-    assertFalse(newDelivery.isMisdirected(itinerary, routeSpecification));
65
-    assertFalse(newDelivery.isUnloadedAtDestination(routeSpecification));
66
-
67
-    // Changed on (re-)routing
68
-    assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
69
-    assertEquals(DALLAS_TO_HELSINKI.schedule().arrivalTimeAt(STOCKHOLM), newProjections.estimatedTimeOfArrival());
70
-
71
-    // Updated on every calculation
72
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
73
-
74
-    // 2. Load
75
-
76
-    handlingActivity = new HandlingActivity(LOAD, HANGZOU, HONGKONG_TO_NEW_YORK);
77
-    newDelivery = Delivery.whenHandled(handlingActivity);
78
-    newProjections = new Projections(newDelivery, itinerary, routeSpecification);
79
-
80
-    assertEquals(HONGKONG_TO_NEW_YORK, newDelivery.currentVoyage());
81
-    assertEquals(HANGZOU, newDelivery.lastKnownLocation());
82
-    assertEquals(ONBOARD_CARRIER, newDelivery.transportStatus());
83
-
84
-    assertEquals(new HandlingActivity(UNLOAD, NEWYORK, HONGKONG_TO_NEW_YORK), newProjections.nextExpectedActivity());
85
-    assertFalse(newDelivery.isMisdirected(itinerary, routeSpecification));
86
-    assertFalse(newDelivery.isUnloadedAtDestination(routeSpecification));
87
-
88
-    assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
89
-    assertEquals(DALLAS_TO_HELSINKI.schedule().arrivalTimeAt(STOCKHOLM), newProjections.estimatedTimeOfArrival());
90
-
91
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
92
-
93
-    // Skipping intermediate load/unloads
94
-
95
-    // 3. Unload
96
-
97
-    handlingActivity = new HandlingActivity(UNLOAD, STOCKHOLM, DALLAS_TO_HELSINKI);
98
-    newDelivery = Delivery.whenHandled(handlingActivity);
99
-    newProjections = new Projections(newDelivery, itinerary, routeSpecification);
100
-
101
-    assertEquals(Voyage.NONE, newDelivery.currentVoyage());
102
-    assertEquals(STOCKHOLM, newDelivery.lastKnownLocation());
103
-    assertEquals(IN_PORT, newDelivery.transportStatus());
104
-
105
-    assertEquals(new HandlingActivity(CLAIM, STOCKHOLM), newProjections.nextExpectedActivity());
106
-    assertFalse(newDelivery.isMisdirected(itinerary, routeSpecification));
107
-    assertTrue(newDelivery.isUnloadedAtDestination(routeSpecification));
108
-
109
-    assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
110
-    assertEquals(DALLAS_TO_HELSINKI.schedule().arrivalTimeAt(STOCKHOLM), newProjections.estimatedTimeOfArrival());
111
-
112
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
113
-
114
-    // 4. Claim
115
-
116
-    handlingActivity = new HandlingActivity(CLAIM, STOCKHOLM);
117
-    newDelivery = Delivery.whenHandled(handlingActivity);
118
-    newProjections = new Projections(newDelivery, itinerary, routeSpecification);
119
-
120
-    assertEquals(Voyage.NONE, newDelivery.currentVoyage());
121
-    assertEquals(STOCKHOLM, newDelivery.lastKnownLocation());
122
-    assertEquals(CLAIMED, newDelivery.transportStatus());
123
-
124
-    assertNull(newProjections.nextExpectedActivity());
125
-    assertFalse(newDelivery.isMisdirected(itinerary, routeSpecification));
126
-    assertTrue(newDelivery.isUnloadedAtDestination(routeSpecification));
127
-
128
-    assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
129
-    assertEquals(DALLAS_TO_HELSINKI.schedule().arrivalTimeAt(STOCKHOLM), newProjections.estimatedTimeOfArrival());
130
-
131
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
132
-  }
133
-
134
-  public void testUpdateOnHandlingWhenMisdirected() {
135
-    // Unload in Hamburg, which is the wrong location
136
-    HandlingActivity handlingActivity = new HandlingActivity(UNLOAD, HAMBURG, DALLAS_TO_HELSINKI);
137
-    Delivery newDelivery = Delivery.whenHandled(handlingActivity);
138
-    Projections newProjections = new Projections(newDelivery, itinerary, routeSpecification);
139
-
140
-    assertEquals(Voyage.NONE, newDelivery.currentVoyage());
141
-    assertEquals(HAMBURG, newDelivery.lastKnownLocation());
142
-    assertEquals(IN_PORT, newDelivery.transportStatus());
143
-
144
-    // Next handling activity is undefined. Need a new itinerary to know what to do.
145
-    assertNull(newProjections.nextExpectedActivity());
146
-    
147
-    assertTrue(newDelivery.isMisdirected(itinerary, routeSpecification));
148
-    assertFalse(newDelivery.isUnloadedAtDestination(routeSpecification));
149
-
150
-    assertEquals(ROUTED, newDelivery.routingStatus(itinerary, routeSpecification));
151
-
152
-    // ETA is undefined at this time
153
-    assertNull(newProjections.estimatedTimeOfArrival());
154
-
155
-    assertTrue(delivery.calculatedAt().before(newDelivery.calculatedAt()));
156
-
157
-    // New route specification, old itinerary
158
-    RouteSpecification newRouteSpecification = routeSpecification.withOrigin(HAMBURG);
159
-    newProjections = new Projections(newDelivery, itinerary, newRouteSpecification);
160
-    assertEquals(MISROUTED, newDelivery.routingStatus(itinerary, newRouteSpecification));
161
-
162
-    // TODO is it really misdirected at this point?
163
-    assertTrue(newDelivery.isMisdirected(itinerary, newRouteSpecification));
164
-
165
-    assertNull(newProjections.nextExpectedActivity());
166
-
167
-    Itinerary newItinerary = new Itinerary(
168
-      Leg.deriveLeg(DALLAS_TO_HELSINKI, HAMBURG, STOCKHOLM)
169
-    );
170
-
171
-    newProjections = new Projections(newDelivery, newItinerary, newRouteSpecification);
172
-
173
-    assertEquals(ROUTED, newDelivery.routingStatus(newItinerary, newRouteSpecification));
174
-    // TODO is it really misdirected here?
175
-    assertTrue(newDelivery.isMisdirected(newItinerary, newRouteSpecification));
176
-    assertEquals(IN_PORT, newDelivery.transportStatus());
177
-    //assertEquals(new HandlingActivity(LOAD, HAMBURG, DALLAS_TO_HELSINKI), newProjections.nextExpectedActivity());
178
-    assertNull(newProjections.nextExpectedActivity());
179
-  }
180
-
181
-}

+ 0
- 116
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/ItineraryTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
5
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
6
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
7
-import se.citerus.dddsample.domain.model.voyage.Voyage;
8
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
9
-
10
-import java.util.ArrayList;
11
-import java.util.Arrays;
12
-import java.util.Date;
13
-import java.util.List;
14
-
15
-public class ItineraryTest extends TestCase {
16
-
17
-  Voyage voyage, wrongVoyage, pacific, transcontinental;
18
-
19
-  protected void setUp() throws Exception {
20
-
21
-    pacific = new Voyage.Builder(new VoyageNumber("4567"), SHANGHAI).
22
-      addMovement(LONGBEACH, new Date(), new Date()).
23
-      build();
24
-
25
-    transcontinental = new Voyage.Builder(new VoyageNumber("4567"), LONGBEACH).
26
-      addMovement(CHICAGO, new Date(), new Date()).
27
-      addMovement(NEWYORK, new Date(), new Date()).
28
-      build();
29
-
30
-    voyage = new Voyage.Builder(new VoyageNumber("0123"), SHANGHAI).
31
-      addMovement(ROTTERDAM, new Date(), new Date()).
32
-      addMovement(GOTHENBURG, new Date(), new Date()).
33
-      build();
34
-
35
-    wrongVoyage = new Voyage.Builder(new VoyageNumber("666"), NEWYORK).
36
-      addMovement(STOCKHOLM, new Date(), new Date()).
37
-      addMovement(HELSINKI, new Date(), new Date()).
38
-      build();
39
-  }
40
-
41
-  public void testIfCargoIsOnTrack() {
42
-
43
-    Itinerary itinerary = new Itinerary(
44
-      Arrays.asList(
45
-        new Leg(voyage, SHANGHAI, ROTTERDAM, new Date(), new Date()),
46
-        new Leg(voyage, ROTTERDAM, GOTHENBURG, new Date(), new Date())
47
-      )
48
-    );
49
-
50
-    // HandlingActivity.Load(cargo, RECEIVE, SHANGHAI, toDate("2009-05-03"))
51
-    //Happy path
52
-    HandlingActivity receiveShanghai = new HandlingActivity(RECEIVE, SHANGHAI);
53
-    assertTrue(itinerary.isExpected(receiveShanghai));
54
-
55
-    HandlingActivity loadShanghai = new HandlingActivity(LOAD, SHANGHAI, voyage);
56
-    assertTrue(itinerary.isExpected(loadShanghai));
57
-
58
-    HandlingActivity unloadRotterdam = new HandlingActivity(UNLOAD, ROTTERDAM, voyage);
59
-    assertTrue(itinerary.isExpected(unloadRotterdam));
60
-
61
-    HandlingActivity loadRotterdam = new HandlingActivity(LOAD, ROTTERDAM, voyage);
62
-    assertTrue(itinerary.isExpected(loadRotterdam));
63
-
64
-    HandlingActivity unloadGothenburg = new HandlingActivity(UNLOAD, GOTHENBURG, voyage);
65
-    assertTrue(itinerary.isExpected(unloadGothenburg));
66
-
67
-    HandlingActivity claimGothenburg = new HandlingActivity(CLAIM, GOTHENBURG);
68
-    assertTrue(itinerary.isExpected(claimGothenburg));
69
-
70
-    //TODO Customs event can only be interpreted properly by knowing the destination of the cargo.
71
-    // This can be inferred from the Itinerary, but it isn't definitive. So, do we answer based on
72
-    // the end of the itinerary (even though this would probably not be used in the app) or do we
73
-    // ignore this at itinerary level somehow and leave it purely as a cargo responsibility.
74
-    // (See customsClearancePoint tests in CargoTest)
75
-//    HandlingActivity customsGothenburg = new HandlingActivity(CUSTOMS, GOTHENBURG);
76
-//    assertTrue(itinerary.isExpected(customsGothenburg));
77
-
78
-    //Received at the wrong location
79
-    HandlingActivity receiveHangzou = new HandlingActivity(RECEIVE, HANGZOU);
80
-    assertFalse(itinerary.isExpected(receiveHangzou));
81
-
82
-    //Loaded to onto the wrong ship, correct location
83
-    HandlingActivity loadRotterdam666 = new HandlingActivity(LOAD, ROTTERDAM, wrongVoyage);
84
-    assertFalse(itinerary.isExpected(loadRotterdam666));
85
-
86
-    //Unloaded from the wrong ship in the wrong location
87
-    HandlingActivity unloadHelsinki = new HandlingActivity(UNLOAD, HELSINKI, wrongVoyage);
88
-    assertFalse(itinerary.isExpected(unloadHelsinki));
89
-
90
-    HandlingActivity claimRotterdam = new HandlingActivity(CLAIM, ROTTERDAM);
91
-    assertFalse(itinerary.isExpected(claimRotterdam));
92
-
93
-    //Unrouted Cargo shouldn't go anywhere or do anything
94
-    assertFalse(Itinerary.EMPTY_ITINERARY.isExpected(receiveShanghai));
95
-    assertFalse(Itinerary.EMPTY_ITINERARY.isExpected(loadShanghai));
96
-
97
-  }
98
-
99
-  public void testCreateItinerary() throws Exception {
100
-    try {
101
-      new Itinerary(new ArrayList<Leg>());
102
-      fail("An empty itinerary is not OK");
103
-    } catch (IllegalArgumentException iae) {
104
-      //Expected
105
-    }
106
-
107
-    try {
108
-      List<Leg> legs = null;
109
-      new Itinerary(legs);
110
-      fail("Null itinerary is not OK");
111
-    } catch (IllegalArgumentException iae) {
112
-      //Expected
113
-    }
114
-  }
115
-
116
-}

+ 0
- 54
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/LegTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import static org.junit.Assert.assertEquals;
4
-import org.junit.Test;
5
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
6
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
7
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.NEW_YORK_TO_DALLAS;
8
-import se.citerus.dddsample.domain.model.voyage.Voyage;
9
-
10
-public class LegTest {
11
-
12
-  final Voyage voyage = NEW_YORK_TO_DALLAS;
13
-
14
-  @Test(expected = NullPointerException.class)
15
-  public void testConstructor() throws Exception {
16
-    Leg.deriveLeg(null, null, null);
17
-  }
18
-
19
-  @Test
20
-  public void legThatFollowsPartOfAVoyage() {
21
-    Leg chicagoToDallas = Leg.deriveLeg(voyage, CHICAGO, DALLAS);
22
-
23
-    assertEquals(chicagoToDallas.loadTime(), toDate("2008-10-24", "21:25"));
24
-    assertEquals(chicagoToDallas.loadLocation(), CHICAGO);
25
-    assertEquals(chicagoToDallas.unloadTime(), toDate("2008-10-25", "19:30"));
26
-    assertEquals(chicagoToDallas.unloadLocation(), DALLAS);
27
-  }
28
-
29
-  @Test
30
-  public void legThatFollowsAnEntireVoyage() {
31
-    Leg chicagoToDallas = Leg.deriveLeg(voyage, NEWYORK, DALLAS);
32
-
33
-    assertEquals(chicagoToDallas.loadTime(), toDate("2008-10-24", "07:00"));
34
-    assertEquals(chicagoToDallas.loadLocation(), NEWYORK);
35
-    assertEquals(chicagoToDallas.unloadTime(), toDate("2008-10-25", "19:30"));
36
-    assertEquals(chicagoToDallas.unloadLocation(), DALLAS);
37
-  }
38
-
39
-  @Test(expected = IllegalArgumentException.class)
40
-  public void locationsInWrongOrder() {
41
-    Leg.deriveLeg(voyage, DALLAS, CHICAGO);
42
-  }
43
-
44
-  @Test(expected = IllegalArgumentException.class)
45
-  public void endLocationNotOnVoyage() {
46
-    Leg.deriveLeg(voyage, CHICAGO, HELSINKI);
47
-  }
48
-
49
-  @Test(expected = IllegalArgumentException.class)
50
-  public void startLocationNotOnVoyage() {
51
-    Leg.deriveLeg(voyage, HONGKONG, DALLAS);
52
-  }
53
-
54
-}

+ 0
- 101
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/RouteSpecificationTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
6
-import se.citerus.dddsample.domain.model.voyage.Voyage;
7
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
8
-
9
-import java.util.Arrays;
10
-
11
-public class RouteSpecificationTest extends TestCase {
12
-
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
-
41
-    assertTrue(routeSpecification.isSatisfiedBy(itinerary));
42
-  }
43
-
44
-  public void testIsSatisfiedBy_WrongOrigin() {
45
-    RouteSpecification routeSpecification = new RouteSpecification(
46
-      HANGZOU, CHICAGO, toDate("2009-03-01")
47
-    );
48
-
49
-    assertFalse(routeSpecification.isSatisfiedBy(itinerary));
50
-  }
51
-
52
-  public void testIsSatisfiedBy_WrongDestination() {
53
-    RouteSpecification routeSpecification = new RouteSpecification(
54
-      HONGKONG, DALLAS, toDate("2009-03-01")
55
-    );
56
-
57
-    assertFalse(routeSpecification.isSatisfiedBy(itinerary));
58
-  }
59
-
60
-  public void testIsSatisfiedBy_MissedDeadline() {
61
-    RouteSpecification routeSpecification = new RouteSpecification(
62
-      HONGKONG, CHICAGO, toDate("2009-02-15")
63
-    );
64
-
65
-    assertFalse(routeSpecification.isSatisfiedBy(itinerary));
66
-  }
67
-
68
-  public void testEquals() {
69
-    RouteSpecification HKG_DAL = new RouteSpecification(
70
-      HONGKONG, DALLAS, toDate("2009-03-01")
71
-    );
72
-    RouteSpecification HKG_DAL_AGAIN = new RouteSpecification(
73
-      HONGKONG, DALLAS, toDate("2009-03-01")
74
-    );
75
-    RouteSpecification SHA_DAL = new RouteSpecification(
76
-      SHANGHAI, DALLAS, toDate("2009-03-01")
77
-    );
78
-    RouteSpecification HKG_CHI = new RouteSpecification(
79
-      HONGKONG, CHICAGO, toDate("2009-03-01")
80
-    );
81
-    RouteSpecification HKG_DAL_LATERARRIVAL = new RouteSpecification(
82
-      HONGKONG, DALLAS, toDate("2009-03-15")
83
-    );
84
-
85
-    assertEquals(HKG_DAL, HKG_DAL_AGAIN);
86
-    assertFalse(HKG_DAL.equals(SHA_DAL));
87
-    assertFalse(HKG_DAL.equals(HKG_CHI));
88
-    assertFalse(HKG_DAL.equals(HKG_DAL_LATERARRIVAL));
89
-  }
90
-
91
-  public void testDeriveWithNewDestination() {
92
-    RouteSpecification original = new RouteSpecification(
93
-      HONGKONG, DALLAS, toDate("2009-03-01")
94
-    );
95
-    RouteSpecification desired = new RouteSpecification(
96
-      HONGKONG, CHICAGO, toDate("2009-03-01")
97
-    );
98
-    assertEquals(desired, original.withDestination(CHICAGO));
99
-  }
100
-
101
-}

+ 0
- 15
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/TrackingIdTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class TrackingIdTest extends TestCase {
6
-
7
-  public void testConstructor() throws Exception {
8
-    try {
9
-      new TrackingId(null);
10
-      fail("Should not accept null constructor arguments");
11
-    } catch (IllegalArgumentException expected) {
12
-    }
13
-  }
14
-
15
-}

+ 0
- 128
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
-import se.citerus.dddsample.domain.model.cargo.Cargo;
6
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
7
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
8
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
9
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type;
10
-import se.citerus.dddsample.domain.model.location.LocationRepository;
11
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
12
-import se.citerus.dddsample.domain.model.location.UnLocode;
13
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
14
-import se.citerus.dddsample.domain.model.voyage.Voyage;
15
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
16
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
17
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
18
-import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
19
-
20
-import java.util.Date;
21
-
22
-public class HandlingEventFactoryTest extends TestCase {
23
-
24
-  HandlingEventFactory factory;
25
-  CargoRepository cargoRepository;
26
-  VoyageRepository voyageRepository;
27
-  LocationRepository locationRepository;
28
-  TrackingId trackingId;
29
-  Cargo cargo;
30
-
31
-  protected void setUp() throws Exception {
32
-
33
-    cargoRepository = createMock(CargoRepository.class);
34
-    voyageRepository = new VoyageRepositoryInMem();
35
-    locationRepository = new LocationRepositoryInMem();
36
-    factory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
37
-
38
-
39
-    trackingId = new TrackingId("ABC");
40
-    RouteSpecification routeSpecification = new RouteSpecification(TOKYO, HELSINKI, new Date());
41
-    cargo = new Cargo(trackingId, routeSpecification);
42
-  }
43
-
44
-  public void testCreateHandlingEventWithCarrierMovement() throws Exception {
45
-    expect(cargoRepository.find(trackingId)).andReturn(cargo);
46
-
47
-    replay(cargoRepository);
48
-
49
-    VoyageNumber voyageNumber = CM001.voyageNumber();
50
-    UnLocode unLocode = STOCKHOLM.unLocode();
51
-    HandlingEvent handlingEvent = factory.createHandlingEvent(
52
-      new Date(), new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD
53
-    );
54
-
55
-    assertNotNull(handlingEvent);
56
-    assertEquals(STOCKHOLM, handlingEvent.location());
57
-    assertEquals(CM001, handlingEvent.voyage());
58
-    assertEquals(cargo, handlingEvent.cargo());
59
-    assertEquals(new Date(100), handlingEvent.completionTime());
60
-    assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
61
-  }
62
-
63
-  public void testCreateHandlingEventWithoutCarrierMovement() throws Exception {
64
-    expect(cargoRepository.find(trackingId)).andReturn(cargo);
65
-
66
-    replay(cargoRepository);
67
-
68
-    UnLocode unLocode = STOCKHOLM.unLocode();
69
-    HandlingEvent handlingEvent = factory.createHandlingEvent(
70
-      new Date(), new Date(100), trackingId, null, unLocode, Type.CLAIM
71
-    );
72
-
73
-    assertNotNull(handlingEvent);
74
-    assertEquals(STOCKHOLM, handlingEvent.location());
75
-    assertEquals(Voyage.NONE, handlingEvent.voyage());
76
-    assertEquals(cargo, handlingEvent.cargo());
77
-    assertEquals(new Date(100), handlingEvent.completionTime());
78
-    assertTrue(handlingEvent.registrationTime().before(new Date(System.currentTimeMillis() + 1)));
79
-  }
80
-
81
-  public void testCreateHandlingEventUnknownLocation() throws Exception {
82
-    expect(cargoRepository.find(trackingId)).andReturn(cargo);
83
-
84
-    replay(cargoRepository);
85
-
86
-    UnLocode invalid = new UnLocode("NOEXT");
87
-    try {
88
-      factory.createHandlingEvent(
89
-        new Date(), new Date(100), trackingId, CM001.voyageNumber(), invalid, Type.LOAD
90
-      );
91
-      fail("Expected UnknownLocationException");
92
-    } catch (UnknownLocationException expected) {
93
-    }
94
-  }
95
-
96
-  public void testCreateHandlingEventUnknownCarrierMovement() throws Exception {
97
-    expect(cargoRepository.find(trackingId)).andReturn(cargo);
98
-
99
-    replay(cargoRepository);
100
-
101
-    try {
102
-      VoyageNumber invalid = new VoyageNumber("XXX");
103
-      factory.createHandlingEvent(
104
-        new Date(), new Date(100), trackingId, invalid, STOCKHOLM.unLocode(), Type.LOAD
105
-      );
106
-      fail("Expected UnknownVoyageException");
107
-    } catch (UnknownVoyageException expected) {
108
-    }
109
-  }
110
-
111
-  public void testCreateHandlingEventUnknownTrackingId() throws Exception {
112
-    expect(cargoRepository.find(trackingId)).andReturn(null);
113
-
114
-    replay(cargoRepository);
115
-
116
-    try {
117
-      factory.createHandlingEvent(
118
-        new Date(), new Date(100), trackingId, CM001.voyageNumber(), STOCKHOLM.unLocode(), Type.LOAD
119
-      );
120
-      fail("Expected UnknownCargoException");
121
-    } catch (UnknownCargoException expected) {
122
-    }
123
-  }
124
-
125
-  protected void tearDown() throws Exception {
126
-    verify(cargoRepository);
127
-  }
128
-}

+ 0
- 115
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import junit.framework.TestCase;
4
-import se.citerus.dddsample.domain.model.cargo.Cargo;
5
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
6
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9
-import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
10
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM003;
11
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM004;
12
-
13
-import static java.util.Arrays.asList;
14
-import java.util.Date;
15
-
16
-public class HandlingEventTest extends TestCase {
17
-  private Cargo cargo;
18
-
19
-  protected void setUp() throws Exception {
20
-    TrackingId trackingId = new TrackingId("XYZ");
21
-    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, NEWYORK, new Date());
22
-    cargo = new Cargo(trackingId, routeSpecification);
23
-  }
24
-
25
-  public void testNewWithCarrierMovement() throws Exception {
26
-
27
-    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), LOAD, HONGKONG, CM003);
28
-    assertEquals(HONGKONG, e1.location());
29
-
30
-    HandlingEvent e2 = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, NEWYORK, CM003);
31
-    assertEquals(NEWYORK, e2.location());
32
-
33
-    // These event types prohibit a carrier movement association
34
-    for (HandlingEvent.Type type : asList(CLAIM, RECEIVE, CUSTOMS)) {
35
-      try {
36
-        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, CM003);
37
-        fail("Handling event type " + type + " prohibits carrier movement");
38
-      } catch (IllegalArgumentException expected) {
39
-      }
40
-    }
41
-
42
-    // These event types requires a carrier movement association
43
-    for (HandlingEvent.Type type : asList(LOAD, UNLOAD)) {
44
-      try {
45
-        new HandlingEvent(cargo, new Date(), new Date(), type, HONGKONG, null);
46
-        fail("Handling event type " + type + " requires carrier movement");
47
-      } catch (IllegalArgumentException expected) {
48
-      }
49
-    }
50
-  }
51
-
52
-  public void testNewWithLocation() throws Exception {
53
-    HandlingEvent e1 = new HandlingEvent(cargo, new Date(), new Date(), HandlingEvent.Type.CLAIM, HELSINKI);
54
-    assertEquals(HELSINKI, e1.location());
55
-  }
56
-
57
-  public void testCurrentLocationLoadEvent() throws Exception {
58
-
59
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), LOAD, CHICAGO, CM004);
60
-
61
-    assertEquals(CHICAGO, ev.location());
62
-  }
63
-
64
-  public void testCurrentLocationUnloadEvent() throws Exception {
65
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), UNLOAD, HAMBURG, CM004);
66
-
67
-    assertEquals(HAMBURG, ev.location());
68
-  }
69
-
70
-  public void testCurrentLocationReceivedEvent() throws Exception {
71
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), RECEIVE, CHICAGO);
72
-
73
-    assertEquals(CHICAGO, ev.location());
74
-  }
75
-
76
-  public void testCurrentLocationClaimedEvent() throws Exception {
77
-    HandlingEvent ev = new HandlingEvent(cargo, new Date(), new Date(), CLAIM, CHICAGO);
78
-
79
-    assertEquals(CHICAGO, ev.location());
80
-  }
81
-
82
-  public void testParseType() throws Exception {
83
-    assertEquals(CLAIM, valueOf("CLAIM"));
84
-    assertEquals(LOAD, valueOf("LOAD"));
85
-    assertEquals(UNLOAD, valueOf("UNLOAD"));
86
-    assertEquals(RECEIVE, valueOf("RECEIVE"));
87
-  }
88
-
89
-  public void testParseTypeIllegal() throws Exception {
90
-    try {
91
-      valueOf("NOT_A_HANDLING_EVENT_TYPE");
92
-      assertTrue("Expected IllegaArgumentException to be thrown", false);
93
-    } catch (IllegalArgumentException e) {
94
-      // All's well
95
-    }
96
-  }
97
-
98
-  public void testEqualsAndSameAs() throws Exception {
99
-    Date timeOccured = new Date();
100
-    Date timeRegistered = new Date();
101
-
102
-    HandlingEvent ev1 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
103
-    HandlingEvent ev2 = new HandlingEvent(cargo, timeOccured, timeRegistered, LOAD, CHICAGO, SampleVoyages.CM005);
104
-
105
-    // Two handling events are not equal() even if all non-uuid fields are identical
106
-    assertTrue(ev1.equals(ev2));
107
-    assertTrue(ev2.equals(ev1));
108
-
109
-    assertTrue(ev1.equals(ev1));
110
-
111
-    assertFalse(ev2.equals(null));
112
-    assertFalse(ev2.equals(new Object()));
113
-  }
114
-
115
-}

+ 0
- 77
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingHistoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
5
-import se.citerus.dddsample.domain.model.cargo.Cargo;
6
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
7
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9
-import se.citerus.dddsample.domain.model.voyage.Voyage;
10
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
11
-
12
-import static java.util.Arrays.asList;
13
-import java.util.Date;
14
-
15
-
16
-public class HandlingHistoryTest extends TestCase {
17
-  Cargo cargo;
18
-  Cargo cargo2;
19
-  Voyage voyage;
20
-  HandlingEvent event1;
21
-  HandlingEvent event1duplicate;
22
-  HandlingEvent event2;
23
-  HandlingEvent eventOfCargo2;
24
-  HandlingHistory handlingHistory;
25
-
26
-  protected void setUp() throws Exception {
27
-    cargo = new Cargo(new TrackingId("ABC"), new RouteSpecification(SHANGHAI, DALLAS, toDate("2009-04-01")));
28
-    cargo2 = new Cargo(new TrackingId("DEF"), new RouteSpecification(SHANGHAI, NEWYORK, toDate("2009-04-15")));
29
-
30
-    voyage = new Voyage.Builder(new VoyageNumber("X25"), HONGKONG).
31
-      addMovement(SHANGHAI, new Date(), new Date()).
32
-      addMovement(DALLAS, new Date(), new Date()).
33
-      build();
34
-    event1 = new HandlingEvent(cargo, toDate("2009-03-05"), toDate("2009-03-05"), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
35
-    event1duplicate = new HandlingEvent(cargo, toDate("2009-03-05"), toDate("2009-03-07"), HandlingEvent.Type.LOAD, SHANGHAI, voyage);
36
-    event2 = new HandlingEvent(cargo, toDate("2009-03-10"), toDate("2009-03-06"), HandlingEvent.Type.UNLOAD, DALLAS, voyage);
37
-    eventOfCargo2 = new HandlingEvent(cargo2, toDate("2009-03-11"), toDate("2009-03-08"), HandlingEvent.Type.LOAD, GOTHENBURG, voyage);
38
-  }
39
-
40
-  public void testDistinctEventsByCompletionTime() {
41
-    handlingHistory = HandlingHistory.fromEvents(asList(event2, event1, event1duplicate));
42
-
43
-    assertEquals(asList(event1, event2), handlingHistory.distinctEventsByCompletionTime());
44
-  }
45
-
46
-  public void testMostRecentlyCompletedEvent() {
47
-    handlingHistory = HandlingHistory.fromEvents(asList(event2, event1, event1duplicate));
48
-
49
-    assertEquals(event2, handlingHistory.mostRecentlyCompletedEvent());
50
-  }
51
-
52
-  public void testMostRecentLoadOrUnload() {
53
-    // TODO
54
-    HandlingEvent event3Customs = new HandlingEvent(cargo, toDate("2009-03-11"), toDate("2009-03-11"), HandlingEvent.Type.CUSTOMS, DALLAS);
55
-    handlingHistory = HandlingHistory.fromEvents(asList(event2, event1, event1duplicate, event3Customs));
56
-
57
-    assertEquals(event3Customs, handlingHistory.mostRecentlyCompletedEvent());
58
-    assertEquals(event2, handlingHistory.mostRecentPhysicalHandling());
59
-  }
60
-
61
-  public void testUniqueCargoOfEvents() {
62
-    try {
63
-      handlingHistory = HandlingHistory.fromEvents(asList(event1, event2, eventOfCargo2));
64
-      fail("A handling history should only accept handling events for a single unique cargo");
65
-    } catch (IllegalArgumentException expected) {
66
-    }
67
-  }
68
-
69
-  public void testCargo() {
70
-    handlingHistory = HandlingHistory.fromEvents(asList(event1, event2));
71
-    assertEquals(cargo, handlingHistory.cargo());
72
-
73
-    handlingHistory = HandlingHistory.fromEvents(asList(eventOfCargo2));
74
-    assertEquals(cargo2, handlingHistory.cargo());
75
-  }
76
-
77
-}

+ 0
- 37
dddsample/src/test/java/se/citerus/dddsample/domain/model/location/LocationTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import junit.framework.TestCase;
4
-
5
-import java.util.TimeZone;
6
-
7
-public class LocationTest extends TestCase {
8
-  private static final TimeZone CET = TimeZone.getTimeZone("Europe/Amsterdam");
9
-
10
-  public void testEquals() {
11
-
12
-    // Same UN locode - equal
13
-    assertTrue(new Location(new UnLocode("ATEST"), "test-name", CET, null).
14
-      equals(new Location(new UnLocode("ATEST"), "test-name", CET, null)));
15
-
16
-    // Different UN locodes - not equal
17
-    assertFalse(new Location(new UnLocode("ATEST"), "test-name", CET, null).
18
-      equals(new Location(new UnLocode("TESTB"), "test-name", CET, null)));
19
-
20
-    // Always equal to itself
21
-    Location location = new Location(new UnLocode("ATEST"), "test-name", CET, null);
22
-    assertTrue(location.equals(location));
23
-
24
-    // Never equal to null
25
-    assertFalse(location.equals(null));
26
-
27
-    // Special UNKNOWN location is equal to itself
28
-    assertTrue(Location.UNKNOWN.equals(Location.UNKNOWN));
29
-
30
-    try {
31
-      new Location(null, null, null, null);
32
-      fail("Should not allow any null constructor arguments");
33
-    } catch (IllegalArgumentException expected) {
34
-    }
35
-  }
36
-
37
-}

+ 0
- 56
dddsample/src/test/java/se/citerus/dddsample/domain/model/location/UnLocodeTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class UnLocodeTest extends TestCase {
6
-
7
-  public void testNew() throws Exception {
8
-    assertValid("AA234");
9
-    assertValid("AAA9B");
10
-    assertValid("AAAAA");
11
-
12
-    assertInvalid("AAAA");
13
-    assertInvalid("AAAAAA");
14
-    assertInvalid("AAAA");
15
-    assertInvalid("AAAAAA");
16
-    assertInvalid("22AAA");
17
-    assertInvalid("AA111");
18
-    assertInvalid(null);
19
-  }
20
-
21
-  public void testStringValue() throws Exception {
22
-    assertEquals("ABCDE", new UnLocode("AbcDe").stringValue());
23
-  }
24
-
25
-  public void testEquals() throws Exception {
26
-    UnLocode allCaps = new UnLocode("ABCDE");
27
-    UnLocode mixedCase = new UnLocode("aBcDe");
28
-
29
-    assertTrue(allCaps.equals(mixedCase));
30
-    assertTrue(mixedCase.equals(allCaps));
31
-    assertTrue(allCaps.equals(allCaps));
32
-
33
-    assertFalse(allCaps.equals(null));
34
-    assertFalse(allCaps.equals(new UnLocode("FGHIJ")));
35
-  }
36
-
37
-  public void testHashCode() throws Exception {
38
-    UnLocode allCaps = new UnLocode("ABCDE");
39
-    UnLocode mixedCase = new UnLocode("aBcDe");
40
-
41
-    assertEquals(allCaps.hashCode(), mixedCase.hashCode());
42
-  }
43
-
44
-  private void assertValid(String unlocode) {
45
-    new UnLocode(unlocode);
46
-  }
47
-
48
-  private void assertInvalid(String unlocode) {
49
-    try {
50
-      new UnLocode(unlocode);
51
-      fail("The combination [" + unlocode + "] is not a valid UnLocode");
52
-    } catch (IllegalArgumentException expected) {
53
-    }
54
-  }
55
-
56
-}

+ 0
- 53
dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/CarrierMovementTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
6
-
7
-import java.util.Date;
8
-
9
-public class CarrierMovementTest extends TestCase {
10
-
11
-  public void testConstructor() throws Exception {
12
-    try {
13
-      new CarrierMovement(null, null, new Date(), new Date());
14
-      fail("Should not accept null constructor arguments");
15
-    } catch (IllegalArgumentException expected) {
16
-    }
17
-
18
-    try {
19
-      new CarrierMovement(null, null, new Date(), new Date());
20
-      fail("Should not accept null constructor arguments");
21
-    } catch (IllegalArgumentException expected) {
22
-    }
23
-
24
-    try {
25
-      new CarrierMovement(STOCKHOLM, null, new Date(), new Date());
26
-      fail("Should not accept null constructor arguments");
27
-    } catch (IllegalArgumentException expected) {
28
-    }
29
-
30
-    // Legal
31
-    new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date());
32
-  }
33
-
34
-  public void testSameValueAsEqualsHashCode() throws Exception {
35
-    CarrierMovement cm1 = new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date());
36
-    CarrierMovement cm2 = new CarrierMovement(STOCKHOLM, HAMBURG, new Date(), new Date());
37
-    CarrierMovement cm3 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
38
-    CarrierMovement cm4 = new CarrierMovement(HAMBURG, STOCKHOLM, new Date(), new Date());
39
-
40
-    assertTrue(cm1.sameValueAs(cm2));
41
-    assertFalse(cm2.sameValueAs(cm3));
42
-    assertTrue(cm3.sameValueAs(cm4));
43
-
44
-    assertTrue(cm1.equals(cm2));
45
-    assertFalse(cm2.equals(cm3));
46
-    assertTrue(cm3.equals(cm4));
47
-
48
-    assertTrue(cm1.hashCode() == cm2.hashCode());
49
-    assertFalse(cm2.hashCode() == cm3.hashCode());
50
-    assertTrue(cm3.hashCode() == cm4.hashCode());
51
-  }
52
-
53
-}

+ 0
- 28
dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/ScheduleTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class ScheduleTest extends TestCase {
6
-
7
-  public void testCarrierMovements() throws Exception {
8
-    //TODO: Test goes here...
9
-  }
10
-
11
-  public void testSameValueAs() throws Exception {
12
-    //TODO: Test goes here...
13
-  }
14
-
15
-  public void testCopy() throws Exception {
16
-    //TODO: Test goes here...
17
-  }
18
-
19
-  public void testEquals() throws Exception {
20
-    //TODO: Test goes here...
21
-  }
22
-
23
-  public void testHashCode() throws Exception {
24
-    //TODO: Test goes here...
25
-  }
26
-
27
-
28
-}

+ 0
- 28
dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/VoyageNumberTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class VoyageNumberTest extends TestCase {
6
-
7
-  public void testEquals() throws Exception {
8
-    //TODO: Test goes here...
9
-  }
10
-
11
-  public void testHashCode() throws Exception {
12
-    //TODO: Test goes here...
13
-  }
14
-
15
-  public void testSameValueAs() throws Exception {
16
-    //TODO: Test goes here...
17
-  }
18
-
19
-  public void testCopy() throws Exception {
20
-    //TODO: Test goes here...
21
-  }
22
-
23
-  public void testToString() throws Exception {
24
-    //TODO: Test goes here...
25
-  }
26
-
27
-
28
-}

+ 0
- 19
dddsample/src/test/java/se/citerus/dddsample/domain/model/voyage/VoyageTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import junit.framework.TestCase;
4
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
5
-
6
-import java.util.Date;
7
-
8
-public class VoyageTest extends TestCase {
9
-
10
-
11
-  public void testSchedule() {
12
-    Voyage transcontinental = new Voyage.Builder(new VoyageNumber("4567"),
13
-      LONGBEACH).
14
-      addMovement(CHICAGO, new Date(), new Date()).
15
-      addMovement(NEWYORK, new Date(), new Date()).
16
-      build();
17
-  }
18
-
19
-}

+ 0
- 7
dddsample/src/test/java/se/citerus/dddsample/domain/shared/AlwaysFalseSpec.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared;
2
-
3
-public class AlwaysFalseSpec extends AbstractSpecification<Object> {
4
-  public boolean isSatisfiedBy(Object o) {
5
-    return false;
6
-  }
7
-}

+ 0
- 7
dddsample/src/test/java/se/citerus/dddsample/domain/shared/AlwaysTrueSpec.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared;
2
-
3
-public class AlwaysTrueSpec extends AbstractSpecification<Object> {
4
-  public boolean isSatisfiedBy(Object o) {
5
-    return true;
6
-  }
7
-}

+ 0
- 24
dddsample/src/test/java/se/citerus/dddsample/domain/shared/AndSpecificationTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class AndSpecificationTest extends TestCase {
6
-
7
-  public void testAndIsSatisifedBy() throws Exception {
8
-    AlwaysTrueSpec trueSpec = new AlwaysTrueSpec();
9
-    AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
10
-
11
-    AndSpecification<Object> andSpecification = new AndSpecification<Object>(trueSpec, trueSpec);
12
-    assertTrue(andSpecification.isSatisfiedBy(new Object()));
13
-
14
-    andSpecification = new AndSpecification<Object>(falseSpec, trueSpec);
15
-    assertFalse(andSpecification.isSatisfiedBy(new Object()));
16
-
17
-    andSpecification = new AndSpecification<Object>(trueSpec, falseSpec);
18
-    assertFalse(andSpecification.isSatisfiedBy(new Object()));
19
-
20
-    andSpecification = new AndSpecification<Object>(falseSpec, falseSpec);
21
-    assertFalse(andSpecification.isSatisfiedBy(new Object()));
22
-
23
-  }
24
-}

+ 0
- 18
dddsample/src/test/java/se/citerus/dddsample/domain/shared/NotSpecificationTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class NotSpecificationTest extends TestCase {
6
-
7
-  public void testAndIsSatisifedBy() throws Exception {
8
-    AlwaysTrueSpec trueSpec = new AlwaysTrueSpec();
9
-    AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
10
-
11
-    NotSpecification<Object> notSpecification = new NotSpecification<Object>(trueSpec);
12
-    assertFalse(notSpecification.isSatisfiedBy(new Object()));
13
-
14
-    notSpecification = new NotSpecification<Object>(falseSpec);
15
-    assertTrue(notSpecification.isSatisfiedBy(new Object()));
16
-
17
-  }
18
-}

+ 0
- 24
dddsample/src/test/java/se/citerus/dddsample/domain/shared/OrSpecificationTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class OrSpecificationTest extends TestCase {
6
-
7
-  public void testAndIsSatisifedBy() throws Exception {
8
-    AlwaysTrueSpec trueSpec = new AlwaysTrueSpec();
9
-    AlwaysFalseSpec falseSpec = new AlwaysFalseSpec();
10
-
11
-    OrSpecification<Object> orSpecification = new OrSpecification<Object>(trueSpec, trueSpec);
12
-    assertTrue(orSpecification.isSatisfiedBy(new Object()));
13
-
14
-    orSpecification = new OrSpecification<Object>(falseSpec, trueSpec);
15
-    assertTrue(orSpecification.isSatisfiedBy(new Object()));
16
-
17
-    orSpecification = new OrSpecification<Object>(trueSpec, falseSpec);
18
-    assertTrue(orSpecification.isSatisfiedBy(new Object()));
19
-
20
-    orSpecification = new OrSpecification<Object>(falseSpec, falseSpec);
21
-    assertFalse(orSpecification.isSatisfiedBy(new Object()));
22
-
23
-  }
24
-}

+ 0
- 40
dddsample/src/test/java/se/citerus/dddsample/domain/shared/experimental/EntitySupportTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-import junit.framework.TestCase;
4
-
5
-public class EntitySupportTest extends TestCase {
6
-
7
-  public void testOneAnnotationSuccess() {
8
-    OneAnnotationEntity entity = new OneAnnotationEntity("id");
9
-    assertEquals("id", entity.identity());
10
-  }
11
-
12
-  public void testSameIdentityEqualsHashcode() {
13
-    OneAnnotationEntity entity1 = new OneAnnotationEntity("A");
14
-    OneAnnotationEntity entity2 = new OneAnnotationEntity("A");
15
-    OneAnnotationEntity entity3 = new OneAnnotationEntity("B");
16
-
17
-    assertTrue(entity1.sameAs(entity2));
18
-    assertFalse(entity2.sameAs(entity3));
19
-
20
-    assertTrue(entity1.equals(entity2));
21
-    assertFalse(entity2.equals(entity3));
22
-
23
-    assertTrue(entity1.hashCode() == entity2.hashCode());
24
-    assertFalse(entity2.hashCode() == entity3.hashCode());
25
-  }
26
-
27
-  class OneAnnotationEntity extends EntitySupport<OneAnnotationEntity, String> {
28
-    private final String id;
29
-
30
-    OneAnnotationEntity(String id) {
31
-      this.id = id;
32
-    }
33
-
34
-    @Override
35
-    public String identity() {
36
-      return id;
37
-    }
38
-  }
39
-
40
-}

+ 0
- 43
dddsample/src/test/java/se/citerus/dddsample/domain/shared/experimental/ValueObjectSupportTest.java Просмотреть файл

1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-import junit.framework.TestCase;
4
-
5
-
6
-public class ValueObjectSupportTest extends TestCase {
7
-
8
-  public void testEquals() {
9
-    final AValueObject vo1 = new AValueObject("A");
10
-    final AValueObject vo2 = new AValueObject("A");
11
-    final BValueObject vo3 = new BValueObject("A", 1);
12
-
13
-    assertEquals(vo1, vo2);
14
-    assertEquals(vo2, vo1);
15
-    assertFalse(vo2.equals(vo3));
16
-    assertFalse(vo3.equals(vo2));
17
-
18
-    assertTrue(vo1.sameValueAs(vo2));
19
-    assertFalse(vo2.sameValueAs(vo3));
20
-  }
21
-
22
-  class AValueObject extends ValueObjectSupport<AValueObject> {
23
-    String s;
24
-
25
-    AValueObject(String s) {
26
-      this.s = s;
27
-    }
28
-
29
-    AValueObject() {
30
-    }
31
-  }
32
-
33
-  class BValueObject extends AValueObject {
34
-    int x;
35
-
36
-    BValueObject(String s, int x) {
37
-      super(s);
38
-      this.x = x;
39
-    }
40
-
41
-  }
42
-
43
-}

+ 0
- 22
dddsample/src/test/java/se/citerus/dddsample/infrastructure/TrackingIdGeneratorTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure;
2
-
3
-import junit.framework.Assert;
4
-import junit.framework.TestCase;
5
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
6
-import se.citerus.dddsample.domain.model.cargo.TrackingIdGenerator;
7
-import se.citerus.dddsample.infrastructure.persistence.TrackingIdGeneratorInMem;
8
-
9
-public class TrackingIdGeneratorTest extends TestCase {
10
-
11
-  TrackingIdGenerator trackingIdGenerator = new TrackingIdGeneratorInMem();
12
-
13
-  public void testNextTrackingId() {
14
-    TrackingId trackingId = trackingIdGenerator.nextTrackingId();
15
-    Assert.assertNotNull(trackingId);
16
-
17
-    TrackingId trackingId2 = trackingIdGenerator.nextTrackingId();
18
-    Assert.assertNotNull(trackingId2);
19
-    Assert.assertFalse(trackingId.equals(trackingId2));
20
-  }
21
-
22
-}

+ 0
- 78
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/AbstractRepositoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
-
3
-import org.hibernate.SessionFactory;
4
-import org.hibernate.classic.Session;
5
-import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
6
-import org.springframework.orm.hibernate3.HibernateTransactionManager;
7
-import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
8
-import org.springframework.transaction.support.TransactionTemplate;
9
-import se.citerus.dddsample.application.util.SampleDataGenerator;
10
-import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
11
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
12
-
13
-import java.lang.reflect.Field;
14
-
15
-public abstract class AbstractRepositoryTest extends AbstractTransactionalDataSourceSpringContextTests {
16
-
17
-  SessionFactory sessionFactory;
18
-  SimpleJdbcTemplate sjt;
19
-  HandlingEventFactory handlingEventFactory;
20
-  HandlingEventRepository handlingEventRepository;
21
-
22
-  public void setHandlingEventFactory(HandlingEventFactory handlingEventFactory) {
23
-    this.handlingEventFactory = handlingEventFactory;
24
-  }
25
-
26
-  public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
27
-    this.handlingEventRepository = handlingEventRepository;
28
-  }
29
-
30
-  protected AbstractRepositoryTest() {
31
-    setAutowireMode(AUTOWIRE_BY_NAME);
32
-    setDependencyCheck(false);
33
-  }
34
-
35
-  public void setSessionFactory(SessionFactory sessionFactory) {
36
-    this.sessionFactory = sessionFactory;
37
-    transactionManager = new HibernateTransactionManager(sessionFactory);
38
-  }
39
-
40
-  public SessionFactory getSessionFactory() {
41
-    return sessionFactory;
42
-  }
43
-
44
-  protected void flush() {
45
-    sessionFactory.getCurrentSession().flush();
46
-  }
47
-
48
-  @Override
49
-  protected String[] getConfigLocations() {
50
-    return new String[]{"/context-infrastructure-persistence.xml", "context-domain.xml"};
51
-  }
52
-
53
-  @Override
54
-  protected void onSetUpInTransaction() throws Exception {
55
-    // TODO store Sample* and object instances here instead of handwritten SQL
56
-    SampleDataGenerator.loadSampleData(jdbcTemplate, new TransactionTemplate(transactionManager));
57
-    sjt = new SimpleJdbcTemplate(jdbcTemplate);
58
-  }
59
-
60
-  protected Session getSession() {
61
-    return sessionFactory.getCurrentSession();
62
-  }
63
-
64
-  // Instead of exposing a getId() on persistent classes
65
-  protected Long getLongId(Object o) {
66
-    if (getSession().contains(o)) {
67
-      return (Long) getSession().getIdentifier(o);
68
-    } else {
69
-      try {
70
-        Field id = o.getClass().getDeclaredField("id");
71
-        id.setAccessible(true);
72
-        return (Long) id.get(o);
73
-      } catch (Exception e) {
74
-        throw new RuntimeException(e);
75
-      }
76
-    }
77
-  }
78
-}

+ 0
- 180
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
-
3
-import se.citerus.dddsample.application.util.SampleDataGenerator;
4
-import se.citerus.dddsample.domain.model.cargo.*;
5
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
6
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.LOAD;
7
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.RECEIVE;
8
-import se.citerus.dddsample.domain.model.location.Location;
9
-import se.citerus.dddsample.domain.model.location.LocationRepository;
10
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
11
-import se.citerus.dddsample.domain.model.location.UnLocode;
12
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM004;
13
-import se.citerus.dddsample.domain.model.voyage.Voyage;
14
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
15
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
16
-
17
-import java.util.Arrays;
18
-import java.util.Date;
19
-import java.util.List;
20
-import java.util.Map;
21
-
22
-public class CargoRepositoryTest extends AbstractRepositoryTest {
23
-
24
-  CargoRepository cargoRepository;
25
-  LocationRepository locationRepository;
26
-  VoyageRepository voyageRepository;
27
-
28
-  public void setCargoRepository(CargoRepository cargoRepository) {
29
-    this.cargoRepository = cargoRepository;
30
-  }
31
-
32
-  public void setLocationRepository(LocationRepository locationRepository) {
33
-    this.locationRepository = locationRepository;
34
-  }
35
-
36
-  public void setVoyageRepository(VoyageRepository voyageRepository) {
37
-    this.voyageRepository = voyageRepository;
38
-  }
39
-
40
-  public void testFindByCargoId() {
41
-    final TrackingId trackingId = new TrackingId("FGH");
42
-    final Cargo cargo = cargoRepository.find(trackingId);
43
-//	TODO: Remove the database column where the cargo origin used to be stored. Only the spec has origin now.
44
-//			And then remove the following line from the test.    
45
-//  assertEquals(STOCKHOLM, cargo.origin());
46
-    assertEquals(HONGKONG, cargo.routeSpecification().origin());
47
-    assertEquals(HELSINKI, cargo.routeSpecification().destination());
48
-
49
-    final List<HandlingEvent> events = handlingEventRepository.lookupHandlingHistoryOfCargo(cargo).distinctEventsByCompletionTime();
50
-    assertEquals(2, events.size());
51
-
52
-    HandlingEvent firstEvent = events.get(0);
53
-    assertHandlingEvent(cargo, firstEvent, RECEIVE, HONGKONG, 100, 160, Voyage.NONE);
54
-
55
-    HandlingEvent secondEvent = events.get(1);
56
-
57
-    Voyage hongkongMelbourneTokyoAndBack = new Voyage.Builder(
58
-      new VoyageNumber("0303"), HONGKONG).
59
-      addMovement(MELBOURNE, new Date(), new Date()).
60
-      addMovement(TOKYO, new Date(), new Date()).
61
-      addMovement(HONGKONG, new Date(), new Date()).
62
-      build();
63
-
64
-    assertHandlingEvent(cargo, secondEvent, LOAD, HONGKONG, 150, 110, hongkongMelbourneTokyoAndBack);
65
-
66
-    List<Leg> legs = cargo.itinerary().legs();
67
-    assertEquals(3, legs.size());
68
-
69
-    Leg firstLeg = legs.get(0);
70
-    assertLeg(firstLeg, "0101", HONGKONG, MELBOURNE);
71
-
72
-    Leg secondLeg = legs.get(1);
73
-    assertLeg(secondLeg, "0101", MELBOURNE, STOCKHOLM);
74
-
75
-    Leg thirdLeg = legs.get(2);
76
-    assertLeg(thirdLeg, "0101", STOCKHOLM, HELSINKI);
77
-  }
78
-
79
-  private void assertHandlingEvent(Cargo cargo, HandlingEvent event, HandlingEvent.Type expectedEventType, Location expectedLocation, int completionTimeMs, int registrationTimeMs, Voyage voyage) {
80
-    assertEquals(expectedEventType, event.type());
81
-    assertEquals(expectedLocation, event.location());
82
-
83
-    Date expectedCompletionTime = SampleDataGenerator.offset(completionTimeMs);
84
-    assertEquals(expectedCompletionTime, event.completionTime());
85
-
86
-    Date expectedRegistrationTime = SampleDataGenerator.offset(registrationTimeMs);
87
-    assertEquals(expectedRegistrationTime, event.registrationTime());
88
-
89
-    assertEquals(voyage, event.voyage());
90
-    assertEquals(cargo, event.cargo());
91
-  }
92
-
93
-  public void testFindByCargoIdUnknownId() {
94
-    assertNull(cargoRepository.find(new TrackingId("UNKNOWN")));
95
-  }
96
-
97
-  private void assertLeg(Leg firstLeg, String vn, Location expectedFrom, Location expectedTo) {
98
-    assertEquals(new VoyageNumber(vn), firstLeg.voyage().voyageNumber());
99
-    assertEquals(expectedFrom, firstLeg.loadLocation());
100
-    assertEquals(expectedTo, firstLeg.unloadLocation());
101
-  }
102
-
103
-  public void testSave() {
104
-    TrackingId trackingId = new TrackingId("AAA");
105
-    Location origin = locationRepository.find(STOCKHOLM.unLocode());
106
-    Location destination = locationRepository.find(MELBOURNE.unLocode());
107
-
108
-    Cargo cargo = new Cargo(trackingId, new RouteSpecification(origin, destination, new Date()));
109
-    cargoRepository.store(cargo);
110
-
111
-    cargo.assignToRoute(new Itinerary(Arrays.asList(
112
-      new Leg(
113
-        voyageRepository.find(new VoyageNumber("0101")),
114
-        locationRepository.find(STOCKHOLM.unLocode()),
115
-        locationRepository.find(MELBOURNE.unLocode()),
116
-        new Date(), new Date())
117
-    )));
118
-
119
-    flush();
120
-
121
-    Map<String, Object> map = sjt.queryForMap(
122
-      "select * from Cargo where tracking_id = ?", trackingId.stringValue());
123
-
124
-    assertEquals("AAA", map.get("TRACKING_ID"));
125
-
126
-    Long originId = getLongId(origin);
127
-    assertEquals(originId, map.get("SPEC_ORIGIN_ID"));
128
-
129
-    Long destinationId = getLongId(destination);
130
-    assertEquals(destinationId, map.get("SPEC_DESTINATION_ID"));
131
-
132
-    getSession().clear();
133
-
134
-    final Cargo loadedCargo = cargoRepository.find(trackingId);
135
-    assertEquals(1, loadedCargo.itinerary().legs().size());
136
-  }
137
-
138
-  public void testReplaceItinerary() {
139
-    Cargo cargo = cargoRepository.find(new TrackingId("FGH"));
140
-    Long cargoId = getLongId(cargo);
141
-    assertEquals(3, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));
142
-
143
-    Location legFrom = locationRepository.find(new UnLocode("FIHEL"));
144
-    Location legTo = locationRepository.find(new UnLocode("DEHAM"));
145
-    Itinerary newItinerary = new Itinerary(Arrays.asList(new Leg(CM004, legFrom, legTo, new Date(), new Date())));
146
-
147
-    cargo.assignToRoute(newItinerary);
148
-
149
-    cargoRepository.store(cargo);
150
-    flush();
151
-
152
-    assertEquals(1, sjt.queryForInt("select count(*) from Leg where cargo_id = ?", cargoId));
153
-  }
154
-
155
-
156
-  public void testFindAll() {
157
-    List<Cargo> all = cargoRepository.findAll();
158
-    assertNotNull(all);
159
-    assertEquals(6, all.size());
160
-  }
161
-
162
-  public void testFindCargosOnVoyage() {
163
-    Voyage voyage = voyageRepository.find(new VoyageNumber("0101"));
164
-    List<Cargo> cargos = cargoRepository.findCargosOnVoyage(voyage);
165
-    assertEquals(3, cargos.size());
166
-    for (Cargo cargo : cargos) {
167
-      boolean found = false;
168
-      for (Leg leg : cargo.itinerary().legs()) {
169
-        if (leg.voyage().sameAs(voyage)) {
170
-          found = true;
171
-        }
172
-      }
173
-      assertTrue("Cargo " + cargo + " has no leg on voyage " + voyage, found);
174
-    }
175
-    
176
-    Voyage voyage2 = voyageRepository.find(new VoyageNumber("0100S"));
177
-    assertTrue(cargoRepository.findCargosOnVoyage(voyage2).isEmpty());
178
-  }
179
-
180
-}

+ 0
- 71
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
-
3
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
4
-import se.citerus.dddsample.domain.model.cargo.Cargo;
5
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
6
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
8
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
9
-import se.citerus.dddsample.domain.model.location.Location;
10
-import se.citerus.dddsample.domain.model.location.LocationRepository;
11
-import static se.citerus.dddsample.domain.model.location.SampleLocations.MELBOURNE;
12
-import se.citerus.dddsample.domain.model.location.UnLocode;
13
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
14
-
15
-import java.util.Date;
16
-import java.util.List;
17
-import java.util.Map;
18
-
19
-public class HandlingEventRepositoryTest extends AbstractRepositoryTest {
20
-
21
-  HandlingEventRepository handlingEventRepository;
22
-  CargoRepository cargoRepository;
23
-  LocationRepository locationRepository;
24
-
25
-  public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
26
-    this.handlingEventRepository = handlingEventRepository;
27
-  }
28
-
29
-  public void setCargoRepository(CargoRepository cargoRepository) {
30
-    this.cargoRepository = cargoRepository;
31
-  }
32
-
33
-  public void setLocationRepository(LocationRepository locationRepository) {
34
-    this.locationRepository = locationRepository;
35
-  }
36
-
37
-  public void testSave() {
38
-    Location location = locationRepository.find(new UnLocode("SESTO"));
39
-
40
-    Cargo cargo = cargoRepository.find(new TrackingId("XYZ"));
41
-    Date completionTime = new Date(10);
42
-    Date registrationTime = new Date(20);
43
-    HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, HandlingEvent.Type.CLAIM, location);
44
-
45
-    handlingEventRepository.store(event);
46
-
47
-    flush();
48
-
49
-    Map<String, Object> result = sjt.queryForMap("select * from HandlingEvent where id = ?", getLongId(event));
50
-    assertEquals(1L, result.get("CARGO_ID"));
51
-    assertEquals(new Date(10), result.get("COMPLETIONTIME"));
52
-    assertEquals(new Date(20), result.get("REGISTRATIONTIME"));
53
-    assertEquals("CLAIM", result.get("TYPE"));
54
-    // TODO: the rest of the columns
55
-  }
56
-
57
-  public void testFindEventsForCargo() throws Exception {
58
-    Cargo cargo = cargoRepository.find(new TrackingId("XYZ"));
59
-    List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(cargo).distinctEventsByCompletionTime();
60
-    assertEquals(12, handlingEvents.size());
61
-  }
62
-
63
-  public void testMostRecentHandling() {
64
-    Cargo cargo = cargoRepository.find(new TrackingId("XYZ"));
65
-    HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(cargo);
66
-    assertEquals(cargo, handlingEvent.cargo());
67
-    assertEquals(toDate("2007-09-27", "05:00"), handlingEvent.completionTime());
68
-    assertEquals(new HandlingActivity(HandlingEvent.Type.CLAIM, MELBOURNE), handlingEvent.activity());
69
-  }
70
-
71
-}

+ 0
- 31
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/LocationRepositoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
-
3
-import se.citerus.dddsample.domain.model.location.Location;
4
-import se.citerus.dddsample.domain.model.location.LocationRepository;
5
-import se.citerus.dddsample.domain.model.location.UnLocode;
6
-
7
-import java.util.List;
8
-
9
-public class LocationRepositoryTest extends AbstractRepositoryTest {
10
-  private LocationRepository locationRepository;
11
-
12
-  public void testFind() throws Exception {
13
-    final UnLocode melbourne = new UnLocode("AUMEL");
14
-    Location location = locationRepository.find(melbourne);
15
-    assertNotNull(location);
16
-    assertEquals(melbourne, location.unLocode());
17
-
18
-    assertNull(locationRepository.find(new UnLocode("NOLOC")));
19
-  }
20
-
21
-  public void testFindAll() throws Exception {
22
-    List<Location> allLocations = locationRepository.findAll();
23
-
24
-    assertNotNull(allLocations);
25
-    assertEquals(7, allLocations.size());
26
-  }
27
-
28
-  public void setLocationRepository(LocationRepository locationRepository) {
29
-    this.locationRepository = locationRepository;
30
-  }
31
-}

+ 0
- 27
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/VoyageRepositoryTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
-
3
-import se.citerus.dddsample.domain.model.voyage.Voyage;
4
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
5
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
6
-
7
-public class VoyageRepositoryTest extends AbstractRepositoryTest {
8
-
9
-  VoyageRepository voyageRepository;
10
-
11
-  public void setVoyageRepository(VoyageRepository voyageRepository) {
12
-    this.voyageRepository = voyageRepository;
13
-  }
14
-
15
-  public void testFind() throws Exception {
16
-    Voyage voyage = voyageRepository.find(new VoyageNumber("0101"));
17
-    assertNotNull(voyage);
18
-    assertEquals("0101", voyage.voyageNumber().stringValue());
19
-    /* TODO adapt
20
-    assertEquals(STOCKHOLM, carrierMovement.departureLocation());
21
-    assertEquals(HELSINKI, carrierMovement.arrivalLocation());
22
-    assertEquals(DateTestUtil.toDate("2007-09-23", "02:00"), carrierMovement.departureTime());
23
-    assertEquals(DateTestUtil.toDate("2007-09-23", "03:00"), carrierMovement.arrivalTime());
24
-    */
25
-  }
26
-
27
-}

+ 0
- 84
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/CargoRepositoryInMem.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.inmemory;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Cargo;
4
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
5
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
6
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
-import se.citerus.dddsample.domain.model.location.Location;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9
-import se.citerus.dddsample.domain.model.voyage.Voyage;
10
-
11
-import java.util.*;
12
-
13
-/**
14
- * CargoRepositoryInMem implement the CargoRepository interface but is a test
15
- * class not intended for usage in real application.
16
- * <p/>
17
- * It setup a simple local hash with a number of Cargo's with TrackingId as key
18
- * defined at compile time.
19
- * <p/>
20
- */
21
-public class CargoRepositoryInMem implements CargoRepository {
22
-
23
-  private Map<String, Cargo> cargoDb;
24
-
25
-  /**
26
-   * Constructor.
27
-   */
28
-  public CargoRepositoryInMem() {
29
-    cargoDb = new HashMap<String, Cargo>();
30
-  }
31
-
32
-  public Cargo find(final TrackingId trackingId) {
33
-    return cargoDb.get(trackingId.stringValue());
34
-  }
35
-
36
-  @Override
37
-  public List<Cargo> findCargosOnVoyage(Voyage voyage) {
38
-    List<Cargo> onVoyage = new ArrayList<Cargo>();
39
-    for (Cargo cargo : cargoDb.values()) {
40
-      if (voyage.sameAs(cargo.currentVoyage())) {
41
-        onVoyage.add(cargo);
42
-      }
43
-    }
44
-    return onVoyage;
45
-  }
46
-
47
-  @Override
48
-  public void store(Cargo cargo) {
49
-    cargoDb.put(cargo.trackingId().stringValue(), cargo);
50
-  }
51
-
52
-  @Override
53
-  public List<Cargo> findAll() {
54
-    return new ArrayList<Cargo>(cargoDb.values());
55
-  }
56
-
57
-  public void init() throws Exception {
58
-    final TrackingId xyz = new TrackingId("XYZ");
59
-    final Cargo cargoXYZ = createCargoWithDeliveryHistory(xyz, STOCKHOLM, MELBOURNE);
60
-    cargoDb.put(xyz.stringValue(), cargoXYZ);
61
-
62
-    final TrackingId zyx = new TrackingId("ZYX");
63
-    final Cargo cargoZYX = createCargoWithDeliveryHistory(zyx, MELBOURNE, STOCKHOLM);
64
-    cargoDb.put(zyx.stringValue(), cargoZYX);
65
-
66
-    final TrackingId abc = new TrackingId("ABC");
67
-    final Cargo cargoABC = createCargoWithDeliveryHistory(abc, STOCKHOLM, HELSINKI);
68
-    cargoDb.put(abc.stringValue(), cargoABC);
69
-
70
-    final TrackingId cba = new TrackingId("CBA");
71
-    final Cargo cargoCBA = createCargoWithDeliveryHistory(cba, HELSINKI, STOCKHOLM);
72
-    cargoDb.put(cba.stringValue(), cargoCBA);
73
-  }
74
-
75
-  public static Cargo createCargoWithDeliveryHistory(TrackingId trackingId,
76
-                                                     Location origin,
77
-                                                     Location destination) {
78
-
79
-    final RouteSpecification routeSpecification = new RouteSpecification(origin, destination, new Date());
80
-    final Cargo cargo = new Cargo(trackingId, routeSpecification);
81
-
82
-    return cargo;
83
-  }
84
-}

+ 0
- 69
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/HandlingEventRepositoryInMem.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.inmemory;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Cargo;
4
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
5
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
6
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
7
-import se.citerus.dddsample.domain.model.handling.HandlingHistory;
8
-import se.citerus.dddsample.domain.model.shared.EventSequenceNumber;
9
-
10
-import java.util.*;
11
-
12
-public class HandlingEventRepositoryInMem implements HandlingEventRepository {
13
-
14
-  private Map<TrackingId, List<HandlingEvent>> eventMap = new HashMap<TrackingId, List<HandlingEvent>>();
15
-  private static final Comparator<HandlingEvent> BY_COMPLETION_TIME_DESC = new Comparator<HandlingEvent>() {
16
-    @Override
17
-    public int compare(HandlingEvent o1, HandlingEvent o2) {
18
-      // Newest first
19
-      return o2.completionTime().compareTo(o1.completionTime());
20
-    }
21
-  };
22
-
23
-  @Override
24
-  public HandlingEvent find(EventSequenceNumber eventSequenceNumber) {
25
-    for (List<HandlingEvent> handlingEvents : eventMap.values()) {
26
-      for (HandlingEvent handlingEvent : handlingEvents) {
27
-        if (handlingEvent.sequenceNumber().sameValueAs(eventSequenceNumber)) {
28
-          return handlingEvent;
29
-        }
30
-      }
31
-    }
32
-
33
-    return null;
34
-  }
35
-
36
-  @Override
37
-  public void store(HandlingEvent event) {
38
-    final TrackingId trackingId = event.cargo().trackingId();
39
-    List<HandlingEvent> list = eventMap.get(trackingId);
40
-    if (list == null) {
41
-      list = new ArrayList<HandlingEvent>();
42
-      eventMap.put(trackingId, list);
43
-    }
44
-    list.add(event);
45
-  }
46
-
47
-  @Override
48
-  public HandlingHistory lookupHandlingHistoryOfCargo(Cargo cargo) {
49
-    List<HandlingEvent> events = eventMap.get(cargo.trackingId());
50
-
51
-    if (events == null) {
52
-      return HandlingHistory.emptyForCargo(cargo);
53
-    } else {
54
-      return HandlingHistory.fromEvents(events);
55
-    }
56
-  }
57
-
58
-  @Override
59
-  public HandlingEvent mostRecentHandling(Cargo cargo) {
60
-    List<HandlingEvent> handlingEvents = eventMap.get(cargo.trackingId());
61
-    if (handlingEvents == null) {
62
-      return null;
63
-    }
64
-
65
-    Collections.sort(handlingEvents, BY_COMPLETION_TIME_DESC);
66
-    return handlingEvents.get(0);
67
-  }
68
-
69
-}

+ 0
- 25
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/LocationRepositoryInMem.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.inmemory;
2
-
3
-import se.citerus.dddsample.domain.model.location.Location;
4
-import se.citerus.dddsample.domain.model.location.LocationRepository;
5
-import se.citerus.dddsample.domain.model.location.SampleLocations;
6
-import se.citerus.dddsample.domain.model.location.UnLocode;
7
-
8
-import java.util.List;
9
-
10
-public class LocationRepositoryInMem implements LocationRepository {
11
-
12
-  public Location find(UnLocode unLocode) {
13
-    for (Location location : SampleLocations.getAll()) {
14
-      if (location.unLocode().equals(unLocode)) {
15
-        return location;
16
-      }
17
-    }
18
-    return null;
19
-  }
20
-
21
-  public List<Location> findAll() {
22
-    return SampleLocations.getAll();
23
-  }
24
-
25
-}

+ 0
- 14
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/inmemory/VoyageRepositoryInMem.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.persistence.inmemory;
2
-
3
-import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
4
-import se.citerus.dddsample.domain.model.voyage.Voyage;
5
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
6
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
7
-
8
-public final class VoyageRepositoryInMem implements VoyageRepository {
9
-
10
-  public Voyage find(VoyageNumber voyageNumber) {
11
-    return SampleVoyages.lookup(voyageNumber);
12
-  }
13
-
14
-}

+ 0
- 80
dddsample/src/test/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingServiceTest.java Просмотреть файл

1
-package se.citerus.dddsample.infrastructure.routing;
2
-
3
-import com.pathfinder.api.GraphTraversalService;
4
-import com.pathfinder.internal.GraphDAO;
5
-import com.pathfinder.internal.GraphTraversalServiceImpl;
6
-import junit.framework.TestCase;
7
-import static org.easymock.EasyMock.*;
8
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
9
-import se.citerus.dddsample.domain.model.cargo.*;
10
-import se.citerus.dddsample.domain.model.location.Location;
11
-import se.citerus.dddsample.domain.model.location.LocationRepository;
12
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
13
-import se.citerus.dddsample.domain.model.voyage.SampleVoyages;
14
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
15
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
16
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
17
-
18
-import java.util.Arrays;
19
-import java.util.List;
20
-
21
-public class ExternalRoutingServiceTest extends TestCase {
22
-
23
-  private ExternalRoutingService externalRoutingService;
24
-  private VoyageRepository voyageRepository;
25
-
26
-  protected void setUp() throws Exception {
27
-    externalRoutingService = new ExternalRoutingService();
28
-    LocationRepository locationRepository = new LocationRepositoryInMem();
29
-    externalRoutingService.setLocationRepository(locationRepository);
30
-
31
-    voyageRepository = createMock(VoyageRepository.class);
32
-    externalRoutingService.setVoyageRepository(voyageRepository);
33
-
34
-    GraphTraversalService graphTraversalService = new GraphTraversalServiceImpl(new GraphDAO() {
35
-      public List<String> listLocations() {
36
-        return Arrays.asList(TOKYO.unLocode().stringValue(), STOCKHOLM.unLocode().stringValue(), GOTHENBURG.unLocode().stringValue());
37
-      }
38
-
39
-      public void storeCarrierMovementId(String cmId, String from, String to) {
40
-      }
41
-    });
42
-    externalRoutingService.setGraphTraversalService(graphTraversalService);
43
-  }
44
-
45
-  // TODO this test belongs in com.pathfinder
46
-
47
-  public void testCalculatePossibleRoutes() {
48
-    TrackingId trackingId = new TrackingId("ABC");
49
-    RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, toDate("2009-04-01"));
50
-    Cargo cargo = new Cargo(trackingId, routeSpecification);
51
-
52
-    expect(voyageRepository.find(isA(VoyageNumber.class))).andStubReturn(SampleVoyages.CM002);
53
-
54
-    replay(voyageRepository);
55
-
56
-    List<Itinerary> candidates = externalRoutingService.fetchRoutesForSpecification(routeSpecification);
57
-    assertNotNull(candidates);
58
-
59
-    for (Itinerary itinerary : candidates) {
60
-      List<Leg> legs = itinerary.legs();
61
-      assertNotNull(legs);
62
-      assertFalse(legs.isEmpty());
63
-
64
-      // Cargo origin and start of first leg should match
65
-      assertEquals(cargo.routeSpecification().origin(), legs.get(0).loadLocation());
66
-
67
-      // Cargo final destination and last leg stop should match
68
-      Location lastLegStop = legs.get(legs.size() - 1).unloadLocation();
69
-      assertEquals(cargo.routeSpecification().destination(), lastLegStop);
70
-
71
-      for (int i = 0; i < legs.size() - 1; i++) {
72
-        // Assert that all legs are connected
73
-        assertEquals(legs.get(i).unloadLocation(), legs.get(i + 1).loadLocation());
74
-      }
75
-    }
76
-
77
-    verify(voyageRepository);
78
-  }
79
-
80
-}

+ 0
- 58
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/CargoRoutingDTOAssemblerTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.booking.facade.internal.assembler;
2
-
3
-import junit.framework.TestCase;
4
-import se.citerus.dddsample.domain.model.cargo.*;
5
-import se.citerus.dddsample.domain.model.location.Location;
6
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
7
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
8
-import se.citerus.dddsample.interfaces.booking.facade.dto.CargoRoutingDTO;
9
-import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
10
-
11
-import java.util.Arrays;
12
-import java.util.Date;
13
-
14
-public class CargoRoutingDTOAssemblerTest extends TestCase {
15
-
16
-  public void testToDTO() throws Exception {
17
-    final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
18
-
19
-    final Location origin = STOCKHOLM;
20
-    final Location destination = MELBOURNE;
21
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(origin, destination, new Date()));
22
-
23
-    final Itinerary itinerary = new Itinerary(
24
-      Arrays.asList(
25
-        new Leg(CM001, origin, SHANGHAI, new Date(), new Date()),
26
-        new Leg(CM001, ROTTERDAM, destination, new Date(), new Date())
27
-      )
28
-    );
29
-
30
-    cargo.assignToRoute(itinerary);
31
-
32
-    final CargoRoutingDTO dto = assembler.toDTO(cargo);
33
-
34
-    assertEquals(2, dto.getLegs().size());
35
-
36
-    LegDTO legDTO = dto.getLegs().get(0);
37
-    assertEquals("CM001", legDTO.getVoyageNumber());
38
-    assertEquals("SESTO", legDTO.getFrom());
39
-    assertEquals("CNSHA", legDTO.getTo());
40
-
41
-    legDTO = dto.getLegs().get(1);
42
-    assertEquals("CM001", legDTO.getVoyageNumber());
43
-    assertEquals("NLRTM", legDTO.getFrom());
44
-    assertEquals("AUMEL", legDTO.getTo());
45
-  }
46
-
47
-  public void testToDTO_NoItinerary() throws Exception {
48
-    final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
49
-
50
-    final Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(STOCKHOLM, MELBOURNE, new Date()));
51
-    final CargoRoutingDTO dto = assembler.toDTO(cargo);
52
-
53
-    assertEquals("XYZ", dto.getTrackingId());
54
-    assertEquals("SESTO", dto.getOrigin());
55
-    assertEquals("AUMEL", dto.getFinalDestination());
56
-    assertTrue(dto.getLegs().isEmpty());
57
-  }
58
-}

+ 0
- 86
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/ItineraryCandidateDTOAssemblerTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.booking.facade.internal.assembler;
2
-
3
-import junit.framework.TestCase;
4
-import static org.easymock.EasyMock.*;
5
-import se.citerus.dddsample.domain.model.cargo.Itinerary;
6
-import se.citerus.dddsample.domain.model.cargo.Leg;
7
-import se.citerus.dddsample.domain.model.location.Location;
8
-import se.citerus.dddsample.domain.model.location.LocationRepository;
9
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
10
-import se.citerus.dddsample.domain.model.location.UnLocode;
11
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
12
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
13
-import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
14
-import se.citerus.dddsample.interfaces.booking.facade.dto.LegDTO;
15
-import se.citerus.dddsample.interfaces.booking.facade.dto.RouteCandidateDTO;
16
-
17
-import java.util.ArrayList;
18
-import java.util.Arrays;
19
-import java.util.Date;
20
-import java.util.List;
21
-
22
-public class ItineraryCandidateDTOAssemblerTest extends TestCase {
23
-
24
-  public void testToDTO() throws Exception {
25
-    final ItineraryCandidateDTOAssembler assembler = new ItineraryCandidateDTOAssembler();
26
-
27
-    final Location origin = STOCKHOLM;
28
-    final Location destination = MELBOURNE;
29
-
30
-    final Itinerary itinerary = new Itinerary(
31
-      Arrays.asList(
32
-        new Leg(CM001, origin, SHANGHAI, new Date(), new Date()),
33
-        new Leg(CM001, ROTTERDAM, destination, new Date(), new Date())
34
-      )
35
-    );
36
-
37
-    final RouteCandidateDTO dto = assembler.toDTO(itinerary);
38
-
39
-    assertEquals(2, dto.getLegs().size());
40
-    LegDTO legDTO = dto.getLegs().get(0);
41
-    assertEquals("CM001", legDTO.getVoyageNumber());
42
-    assertEquals("SESTO", legDTO.getFrom());
43
-    assertEquals("CNSHA", legDTO.getTo());
44
-
45
-    legDTO = dto.getLegs().get(1);
46
-    assertEquals("CM001", legDTO.getVoyageNumber());
47
-    assertEquals("NLRTM", legDTO.getFrom());
48
-    assertEquals("AUMEL", legDTO.getTo());
49
-  }
50
-
51
-  public void testFromDTO() throws Exception {
52
-    final ItineraryCandidateDTOAssembler assembler = new ItineraryCandidateDTOAssembler();
53
-
54
-    final List<LegDTO> legs = new ArrayList<LegDTO>();
55
-    legs.add(new LegDTO("CM001", "AAAAA", "BBBBB", new Date(), new Date()));
56
-    legs.add(new LegDTO("CM001", "BBBBB", "CCCCC", new Date(), new Date()));
57
-
58
-    final LocationRepository locationRepository = createMock(LocationRepository.class);
59
-    expect(locationRepository.find(new UnLocode("AAAAA"))).andReturn(HONGKONG);
60
-    expect(locationRepository.find(new UnLocode("BBBBB"))).andReturn(TOKYO).times(2);
61
-    expect(locationRepository.find(new UnLocode("CCCCC"))).andReturn(CHICAGO);
62
-
63
-    final VoyageRepository voyageRepository = new VoyageRepositoryInMem();
64
-
65
-    replay(locationRepository);
66
-
67
-
68
-    // Tested call
69
-    final Itinerary itinerary = assembler.fromDTO(new RouteCandidateDTO(legs), voyageRepository, locationRepository);
70
-
71
-
72
-    assertNotNull(itinerary);
73
-    assertNotNull(itinerary.legs());
74
-    assertEquals(2, itinerary.legs().size());
75
-
76
-    final Leg leg1 = itinerary.legs().get(0);
77
-    assertNotNull(leg1);
78
-    assertEquals(HONGKONG, leg1.loadLocation());
79
-    assertEquals(TOKYO, leg1.unloadLocation());
80
-
81
-    final Leg leg2 = itinerary.legs().get(1);
82
-    assertNotNull(leg2);
83
-    assertEquals(TOKYO, leg2.loadLocation());
84
-    assertEquals(CHICAGO, leg2.unloadLocation());
85
-  }
86
-}

+ 0
- 31
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/facade/internal/assembler/LocationDTOAssemblerTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.booking.facade.internal.assembler;
2
-
3
-import junit.framework.TestCase;
4
-import se.citerus.dddsample.domain.model.location.Location;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HAMBURG;
6
-import static se.citerus.dddsample.domain.model.location.SampleLocations.STOCKHOLM;
7
-import se.citerus.dddsample.interfaces.booking.facade.dto.LocationDTO;
8
-
9
-import java.util.Arrays;
10
-import java.util.List;
11
-
12
-public class LocationDTOAssemblerTest extends TestCase {
13
-
14
-  public void testToDTOList() {
15
-    final LocationDTOAssembler assembler = new LocationDTOAssembler();
16
-    final List<Location> locationList = Arrays.asList(STOCKHOLM, HAMBURG);
17
-
18
-    final List<LocationDTO> dtos = assembler.toDTOList(locationList);
19
-
20
-    assertEquals(2, dtos.size());
21
-
22
-    LocationDTO dto = dtos.get(0);
23
-    assertEquals("SESTO", dto.getUnLocode());
24
-    assertEquals("Stockholm", dto.getName());
25
-
26
-    dto = dtos.get(1);
27
-    assertEquals("DEHAM", dto.getUnLocode());
28
-    assertEquals("Hamburg", dto.getName());
29
-  }
30
-
31
-}

+ 0
- 29
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminControllerTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.booking.web;
2
-
3
-import junit.framework.TestCase;
4
-import org.easymock.EasyMock;
5
-import org.springframework.mock.web.MockHttpServletRequest;
6
-import org.springframework.mock.web.MockHttpServletResponse;
7
-import se.citerus.dddsample.interfaces.booking.facade.BookingServiceFacade;
8
-
9
-public class CargoAdminControllerTest extends TestCase {
10
-
11
-  CargoAdminController controller;
12
-  BookingServiceFacade bookingServiceFacade;
13
-  MockHttpServletRequest request;
14
-  MockHttpServletResponse response;
15
-
16
-  public CargoAdminControllerTest() {
17
-    controller = new CargoAdminController();
18
-    bookingServiceFacade = EasyMock.createMock(BookingServiceFacade.class);
19
-    controller.setBookingServiceFacade(bookingServiceFacade);
20
-  }
21
-
22
-  public void testAssignItinerary() throws Exception {
23
-    request = new MockHttpServletRequest("GET", "assignItinerary.html");
24
-    response = new MockHttpServletResponse();
25
-
26
-    controller.handleRequest(request, response);
27
-  }
28
-
29
-}

+ 0
- 48
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.booking.web;
2
-
3
-import junit.framework.TestCase;
4
-import org.springframework.mock.web.MockHttpServletRequest;
5
-import org.springframework.web.bind.ServletRequestDataBinder;
6
-
7
-import java.util.List;
8
-
9
-public class ItinerarySelectionCommandTest extends TestCase {
10
-
11
-  RouteAssignmentCommand command;
12
-  MockHttpServletRequest request;
13
-
14
-  public void testBind() {
15
-    command = new RouteAssignmentCommand();
16
-    request = new MockHttpServletRequest();
17
-
18
-    request.addParameter("legs[0].voyageNumber", "CM01");
19
-    request.addParameter("legs[0].fromUnLocode", "AAAAA");
20
-    request.addParameter("legs[0].toUnLocode", "BBBBB");
21
-
22
-    request.addParameter("legs[1].voyageNumber", "CM02");
23
-    request.addParameter("legs[1].fromUnLocode", "CCCCC");
24
-    request.addParameter("legs[1].toUnLocode", "DDDDD");
25
-
26
-    request.addParameter("trackingId", "XYZ");
27
-
28
-    ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
29
-    binder.bind(request);
30
-
31
-    List<RouteAssignmentCommand.LegCommand> legs = command.getLegs();
32
-    assertEquals(2, legs.size());
33
-
34
-    RouteAssignmentCommand.LegCommand leg = legs.get(0);
35
-    assertEquals("CM01", leg.getVoyageNumber());
36
-    assertEquals("AAAAA", leg.getFromUnLocode());
37
-    assertEquals("BBBBB", leg.getToUnLocode());
38
-
39
-    leg = legs.get(1);
40
-    assertEquals("CM02", leg.getVoyageNumber());
41
-    assertEquals("CCCCC", leg.getFromUnLocode());
42
-    assertEquals("DDDDD", leg.getToUnLocode());
43
-
44
-    assertEquals("XYZ", command.getTrackingId());
45
-  }
46
-
47
-
48
-}

+ 0
- 96
dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingControllerTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.tracking;
2
-
3
-import junit.framework.TestCase;
4
-import org.easymock.EasyMock;
5
-import org.springframework.context.support.StaticApplicationContext;
6
-import org.springframework.mock.web.MockHttpServletRequest;
7
-import org.springframework.mock.web.MockHttpServletResponse;
8
-import org.springframework.mock.web.MockHttpSession;
9
-import org.springframework.mock.web.MockServletContext;
10
-import org.springframework.validation.BindingResult;
11
-import org.springframework.validation.Errors;
12
-import org.springframework.validation.FieldError;
13
-import org.springframework.web.servlet.ModelAndView;
14
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
15
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
16
-import se.citerus.dddsample.infrastructure.persistence.inmemory.CargoRepositoryInMem;
17
-import se.citerus.dddsample.infrastructure.persistence.inmemory.HandlingEventRepositoryInMem;
18
-
19
-public class CargoTrackingControllerTest extends TestCase {
20
-  CargoTrackingController controller;
21
-  MockHttpServletRequest request;
22
-  MockHttpServletResponse response;
23
-  MockHttpSession session;
24
-  MockServletContext servletContext;
25
-  CargoRepositoryInMem cargoRepository;
26
-  HandlingEventRepository handlingEventRepository;
27
-
28
-  protected void setUp() throws Exception {
29
-    servletContext = new MockServletContext("test");
30
-    request = new MockHttpServletRequest(servletContext);
31
-    response = new MockHttpServletResponse();
32
-    session = new MockHttpSession(servletContext);
33
-    request.setSession(session);
34
-
35
-    controller = new CargoTrackingController();
36
-    StaticApplicationContext applicationContext = new StaticApplicationContext();
37
-    controller.setApplicationContext(applicationContext);
38
-    controller.setFormView("test-form");
39
-    controller.setSuccessView("test-success");
40
-    controller.setCommandName("test-command-name");
41
-    cargoRepository = new CargoRepositoryInMem();
42
-    cargoRepository.init();
43
-
44
-    handlingEventRepository = new HandlingEventRepositoryInMem();
45
-    controller.setHandlingEventRepository(handlingEventRepository);
46
-  }
47
-
48
-  public void testHandleGet() throws Exception {
49
-    controller.setCargoRepository(new CargoRepositoryInMem());
50
-    request.setMethod("GET");
51
-
52
-    ModelAndView mav = controller.handleRequest(request, response);
53
-
54
-    assertEquals("test-form", mav.getViewName());
55
-    assertEquals(2, mav.getModel().size());
56
-    assertTrue(mav.getModel().get("test-command-name") instanceof TrackCommand);
57
-  }
58
-
59
-  public void testHandlePost() throws Exception {
60
-    controller.setCargoRepository(cargoRepository);
61
-    request.addParameter("trackingId", "ABC");
62
-    request.setMethod("POST");
63
-
64
-    ModelAndView mav = controller.handleRequest(request, response);
65
-
66
-    assertEquals("test-form", mav.getViewName());
67
-    // Errors, command are two standard map attributes, the third should be the cargo object
68
-    assertEquals(3, mav.getModel().size());
69
-    CargoTrackingViewAdapter cargo = (CargoTrackingViewAdapter) mav.getModel().get("cargo");
70
-    assertEquals("ABC", cargo.getTrackingId());
71
-  }
72
-
73
-  public void testUnknownCargo() throws Exception {
74
-    CargoRepository cargoRepository = EasyMock.createNiceMock(CargoRepository.class);
75
-    EasyMock.replay(cargoRepository);
76
-    controller.setCargoRepository(cargoRepository);
77
-
78
-    request.setMethod("POST");
79
-    request.setParameter("trackingId", "unknown-id");
80
-
81
-    ModelAndView mav = controller.handleRequest(request, response);
82
-
83
-    assertEquals("test-form", mav.getViewName());
84
-    assertEquals(2, mav.getModel().size());
85
-
86
-    TrackCommand command = (TrackCommand) mav.getModel().get(controller.getCommandName());
87
-    assertEquals("unknown-id", command.getTrackingId());
88
-
89
-    Errors errors = (Errors) mav.getModel().get(BindingResult.MODEL_KEY_PREFIX + controller.getCommandName());
90
-    FieldError fe = errors.getFieldError("trackingId");
91
-    assertEquals("cargo.unknown_id", fe.getCode());
92
-    assertEquals(1, fe.getArguments().length);
93
-    assertEquals(command.getTrackingId(), fe.getArguments()[0]);
94
-  }
95
-
96
-}

+ 0
- 70
dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/CargoTrackingViewAdapterTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.tracking;
2
-
3
-import junit.framework.TestCase;
4
-import org.springframework.context.support.StaticApplicationContext;
5
-import se.citerus.dddsample.domain.model.cargo.Cargo;
6
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
7
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
9
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HANGZOU;
10
-import static se.citerus.dddsample.domain.model.location.SampleLocations.HELSINKI;
11
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
12
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.CM001;
13
-
14
-import java.util.*;
15
-
16
-public class CargoTrackingViewAdapterTest extends TestCase {
17
-
18
-  public void testCreate() {
19
-    // Disable test for now, CargoTrackingViewAdapter is being reconsidered 
20
-    if (true) return;
21
-
22
-    Cargo cargo = new Cargo(new TrackingId("XYZ"), new RouteSpecification(HANGZOU, HELSINKI, new Date()));
23
-//	TODO: Need to put an itinerary on the Cargo in order to test the
24
-//	isExpected(). Those assertions are commented out because they only
25
-//	worked as a side-effect of the incorrect (now corrected) behavior of 
26
-//  Itinerary, which previously said than an empty itinerary considered all
27
-//  events as "expected", whereas an empty itinerary should actually consider
28
-//  any event unexpected. (ie empty itinerary means nothing happens.)
29
-
30
-    cargo.handled(new HandlingActivity(HandlingEvent.Type.RECEIVE, HANGZOU));
31
-    cargo.handled(new HandlingActivity(HandlingEvent.Type.LOAD, HANGZOU, CM001));
32
-    cargo.handled(new HandlingActivity(HandlingEvent.Type.UNLOAD, HELSINKI, CM001));
33
-
34
-    StaticApplicationContext applicationContext = new StaticApplicationContext();
35
-    applicationContext.addMessage("cargo.status.IN_PORT", Locale.GERMAN, "In port {0}");
36
-    applicationContext.refresh();
37
-
38
-    List<HandlingEvent> events = new ArrayList<HandlingEvent>();
39
-    CargoTrackingViewAdapter adapter = new CargoTrackingViewAdapter(cargo, applicationContext, Locale.GERMAN, events);
40
-
41
-    assertEquals("XYZ", adapter.getTrackingId());
42
-    assertEquals("Hangzhou", adapter.getOrigin());
43
-    assertEquals("Helsinki", adapter.getDestination());
44
-    assertEquals("In port Helsinki", adapter.getStatusText());
45
-
46
-    Iterator<CargoTrackingViewAdapter.HandlingEventViewAdapter> it = adapter.getEvents().iterator();
47
-
48
-    CargoTrackingViewAdapter.HandlingEventViewAdapter event = it.next();
49
-    assertEquals("RECEIVE", event.getType());
50
-    assertEquals("Hangzhou", event.getLocation());
51
-    assertEquals("1970-01-01 08:00 CST", event.getTime());
52
-    assertEquals("", event.getVoyageNumber());
53
-//    assertTrue(event.isExpected());
54
-
55
-    event = it.next();
56
-    assertEquals("LOAD", event.getType());
57
-    assertEquals("Hangzhou", event.getLocation());
58
-    assertEquals("1970-01-01 08:00 CST", event.getTime());
59
-    assertEquals("CM001", event.getVoyageNumber());
60
-//    assertTrue(event.isExpected());
61
-
62
-    event = it.next();
63
-    assertEquals("UNLOAD", event.getType());
64
-    assertEquals("Helsinki", event.getLocation());
65
-    assertEquals("1970-01-01 01:00 CET", event.getTime());
66
-    assertEquals("CM001", event.getVoyageNumber());
67
-//    assertTrue(event.isExpected());
68
-  }
69
-
70
-}

+ 0
- 37
dddsample/src/test/java/se/citerus/dddsample/interfaces/tracking/TrackCommandValidatorTest.java Просмотреть файл

1
-package se.citerus.dddsample.interfaces.tracking;
2
-
3
-import junit.framework.TestCase;
4
-import org.springframework.validation.BeanPropertyBindingResult;
5
-import org.springframework.validation.BindingResult;
6
-import org.springframework.validation.FieldError;
7
-
8
-public class TrackCommandValidatorTest extends TestCase {
9
-
10
-  TrackCommandValidator validator;
11
-  TrackCommand command;
12
-  BindingResult errors;
13
-
14
-  protected void setUp() throws Exception {
15
-    validator = new TrackCommandValidator();
16
-    command = new TrackCommand();
17
-    errors = new BeanPropertyBindingResult(command, "command");
18
-  }
19
-
20
-  public void testValidateIllegalId() throws Exception {
21
-    validator.validate(command, errors);
22
-
23
-    assertEquals(1, errors.getErrorCount());
24
-    FieldError error = errors.getFieldError("trackingId");
25
-    assertNotNull(error);
26
-    assertNull(error.getRejectedValue());
27
-    assertEquals("error.required", error.getCode());
28
-  }
29
-
30
-  public void testValidateSuccess() throws Exception {
31
-    command.setTrackingId("non-empty");
32
-    validator.validate(command, errors);
33
-
34
-    assertFalse(errors.hasErrors());
35
-  }
36
-
37
-}

+ 0
- 426
dddsample/src/test/java/se/citerus/dddsample/scenario/CargoLifecycleScenarioTest.java Просмотреть файл

1
-package se.citerus.dddsample.scenario;
2
-
3
-import static org.hamcrest.MatcherAssert.assertThat;
4
-import static org.hamcrest.Matchers.is;
5
-import static org.junit.Assert.*;
6
-import org.junit.Test;
7
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
8
-import se.citerus.dddsample.domain.model.cargo.*;
9
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
10
-import static se.citerus.dddsample.domain.model.cargo.TransportStatus.*;
11
-import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
12
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
13
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
14
-import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
15
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
16
-import se.citerus.dddsample.domain.model.location.Location;
17
-import se.citerus.dddsample.domain.model.location.LocationRepository;
18
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
19
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
20
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
21
-import se.citerus.dddsample.domain.model.voyage.Voyage;
22
-import static se.citerus.dddsample.domain.model.voyage.Voyage.NONE;
23
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
24
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
25
-import se.citerus.dddsample.domain.service.RoutingService;
26
-import se.citerus.dddsample.infrastructure.persistence.TrackingIdGeneratorInMem;
27
-import se.citerus.dddsample.infrastructure.persistence.inmemory.CargoRepositoryInMem;
28
-import se.citerus.dddsample.infrastructure.persistence.inmemory.HandlingEventRepositoryInMem;
29
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
30
-import se.citerus.dddsample.infrastructure.persistence.inmemory.VoyageRepositoryInMem;
31
-
32
-import java.util.Arrays;
33
-import java.util.Date;
34
-import java.util.List;
35
-
36
-public class CargoLifecycleScenarioTest {
37
-
38
-  /**
39
-   * Repository implementations are part of the infrastructure layer,
40
-   * which in this test is stubbed out by in-memory replacements.
41
-   */
42
-  HandlingEventRepository handlingEventRepository = new HandlingEventRepositoryInMem();
43
-  CargoRepository cargoRepository = new CargoRepositoryInMem();
44
-  LocationRepository locationRepository = new LocationRepositoryInMem();
45
-  VoyageRepository voyageRepository = new VoyageRepositoryInMem();
46
-
47
-  HandlingEventFactory handlingEventFactory = new HandlingEventFactory(cargoRepository, voyageRepository, locationRepository);
48
-  CargoFactory cargoFactory = new CargoFactory(locationRepository, new TrackingIdGeneratorInMem());
49
-
50
-  /**
51
-   * This is a domain service interface, whose implementation
52
-   * is part of the infrastructure layer (re mote call to external system).
53
-   * <p/>
54
-   * It is stubbed in this test.
55
-   */
56
-  RoutingService routingService = new ScenarioStubRoutingService();
57
-
58
-  TrackingId trackingId;
59
-
60
-  @Test
61
-  public void cargoIsCorrectlyDelivered() throws Exception {
62
-    bookCargoFromHongkongToStockholm();
63
-    checkDeliveryAfterBooking();
64
-
65
-    // Route: Hongkong - Long Beach - New York - Stockholm
66
-    routeCargoFromHongkongToStockholm();
67
-    checkDeliveryAfterRouting();
68
-
69
-
70
-    receiveInHongkong();
71
-    checkDeliveryAfterReceiveInHongkong();
72
-
73
-    loadInHongkong();
74
-    checkDeliveryAfterLoadInHongKong();
75
-
76
-    unloadInLongBeach();
77
-    checkDeliveryAfterUnloadInLongBeach();
78
-
79
-    loadInLongBeach();
80
-    checkDeliveryAfterLoadInLongBeach();
81
-
82
-    unloadInNewYork();
83
-    checkDeliveryAfterUnloadInNewYork();
84
-
85
-    loadInNewYork();
86
-    checkDeliveryAfterLoadInNewYork();
87
-
88
-    unloadInStockholmOffOf(v200);
89
-    checkDeliveryAfterUnloadInStockholm();
90
-
91
-    claimInStockholm();
92
-    checkDeliveryAfterClaimInStockholm();
93
-  }
94
-
95
-  private void unloadInLongBeach() throws CannotCreateHandlingEventException {
96
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-06"), v100, LONGBEACH, UNLOAD);
97
-  }
98
-
99
-  private void checkDeliveryAfterUnloadInLongBeach() {
100
-    Cargo cargo = cargoRepository.find(trackingId);
101
-
102
-    assertThat(cargo.currentVoyage(), is(NONE));
103
-    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
104
-    assertThat(cargo.transportStatus(), is(IN_PORT));
105
-    assertFalse(cargo.isMisdirected());
106
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, LONGBEACH, v250)));
107
-  }
108
-
109
-  private void loadInLongBeach() throws CannotCreateHandlingEventException {
110
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-07"), v250, LONGBEACH, LOAD);
111
-  }
112
-
113
-  private void checkDeliveryAfterLoadInLongBeach() {
114
-    Cargo cargo = cargoRepository.find(trackingId);
115
-
116
-    assertThat(cargo.currentVoyage(), is(v250));
117
-    assertThat(cargo.lastKnownLocation(), is(LONGBEACH));
118
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
119
-    assertFalse(cargo.isMisdirected());
120
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, NEWYORK, v250)));
121
-  }
122
-
123
-  private void unloadInNewYork() throws CannotCreateHandlingEventException {
124
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), v250, NEWYORK, UNLOAD);
125
-  }
126
-
127
-  private void checkDeliveryAfterUnloadInNewYork() {
128
-    Cargo cargo = cargoRepository.find(trackingId);
129
-
130
-    assertThat(cargo.currentVoyage(), is(NONE));
131
-    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
132
-    assertThat(cargo.transportStatus(), is(IN_PORT));
133
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, NEWYORK, v200)));
134
-    assertFalse(cargo.isMisdirected());
135
-  }
136
-
137
-  private void loadInNewYork() throws CannotCreateHandlingEventException {
138
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-10"), v200, NEWYORK, LOAD);
139
-  }
140
-
141
-  private void checkDeliveryAfterLoadInNewYork() {
142
-    Cargo cargo = cargoRepository.find(trackingId);
143
-
144
-    assertThat(cargo.currentVoyage(), is(v200));
145
-    assertThat(cargo.lastKnownLocation(), is(NEWYORK));
146
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
147
-    assertFalse(cargo.isMisdirected());
148
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, v200)));
149
-  }
150
-
151
-  @Test
152
-  public void cargoIsMisdirectedAndRerouted() throws Exception {
153
-    bookCargoFromHongkongToStockholm();
154
-    checkDeliveryAfterBooking();
155
-
156
-
157
-    // Initial route: Hongkong - Long Beach - New York - Stockholm
158
-    routeCargoFromHongkongToStockholm();
159
-    checkDeliveryAfterRouting();
160
-
161
-
162
-    receiveInHongkong();
163
-    checkDeliveryAfterReceiveInHongkong();
164
-
165
-    loadInHongkong();
166
-    checkDeliveryAfterLoadInHongKong();
167
-
168
-    unloadInTokyo();
169
-    checkDeliveryAfterUnloadInTokyo();
170
-
171
-
172
-    // Reroute: Tokyo - Hamburg - Stockholm
173
-    specifyNewRouteFromTokyoToStockholm();
174
-    checkDeliveryAfterNewRouteSpecified();
175
-
176
-    assignToNewRouteFromTokyoToStockholm();
177
-    checkDeliveryAfterAssignedToNewRoute();
178
-
179
-
180
-    loadInTokyo();
181
-    checkDeliveryAfterLoadInTokyo();
182
-
183
-    unloadInHamburg();
184
-    checkDeliveryAfterUnloadInHamburg();
185
-
186
-    loadInHamburg();
187
-    checkDeliveryAfterLoadInHamburg();
188
-
189
-    unloadInStockholmOffOf(v400);
190
-    checkDeliveryAfterUnloadInStockholm();
191
-
192
-    claimInStockholm();
193
-    checkDeliveryAfterClaimInStockholm();
194
-  }
195
-
196
-  private void bookCargoFromHongkongToStockholm() {
197
-    Date arrivalDeadline = toDate("2009-03-18");
198
-    Cargo cargo = cargoFactory.newCargo(HONGKONG.unLocode(), STOCKHOLM.unLocode(), arrivalDeadline);
199
-    cargoRepository.store(cargo);
200
-
201
-    trackingId = cargo.trackingId();
202
-  }
203
-
204
-  private void routeCargoFromHongkongToStockholm() {
205
-    Cargo cargo = cargoRepository.find(trackingId);
206
-    List<Itinerary> itineraries = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
207
-    Itinerary itinerary = itineraries.get(0);
208
-    cargo.assignToRoute(itinerary);
209
-    cargoRepository.store(cargo);
210
-  }
211
-
212
-  public void checkDeliveryAfterBooking() throws Exception {
213
-    Cargo cargo = cargoRepository.find(trackingId);
214
-
215
-    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
216
-    assertThat(cargo.routingStatus(), is(NOT_ROUTED));
217
-    assertFalse(cargo.isMisdirected());
218
-    assertNull(cargo.estimatedTimeOfArrival());
219
-    assertNull(cargo.nextExpectedActivity());
220
-  }
221
-
222
-  public void checkDeliveryAfterRouting() throws Exception {
223
-    Cargo cargo = cargoRepository.find(trackingId);
224
-
225
-    assertThat(cargo.transportStatus(), is(NOT_RECEIVED));
226
-    assertThat(cargo.routingStatus(), is(ROUTED));
227
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(RECEIVE, HONGKONG)));
228
-    assertNotNull(cargo.estimatedTimeOfArrival());
229
-  }
230
-
231
-  public void receiveInHongkong() throws CannotCreateHandlingEventException {
232
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-01"), null, HONGKONG, RECEIVE);
233
-  }
234
-
235
-  private void checkDeliveryAfterReceiveInHongkong() {
236
-    Cargo cargo = cargoRepository.find(trackingId);
237
-    assertThat(cargo.transportStatus(), is(IN_PORT));
238
-    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
239
-  }
240
-
241
-  public void loadInHongkong() throws CannotCreateHandlingEventException {
242
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-03"), v100, HONGKONG, LOAD);
243
-  }
244
-
245
-  private void checkDeliveryAfterLoadInHongKong() {
246
-    // Check current state - should be ok
247
-    Cargo cargo = cargoRepository.find(trackingId);
248
-
249
-    assertThat(cargo.currentVoyage(), is(v100));
250
-    assertThat(cargo.lastKnownLocation(), is(HONGKONG));
251
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
252
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, LONGBEACH, v100)));
253
-    assertFalse(cargo.isMisdirected());
254
-  }
255
-
256
-  public void unloadInTokyo() throws CannotCreateHandlingEventException {
257
-    // Cargo is now (incorrectly) unloaded in Tokyo
258
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-05"), v100, TOKYO, UNLOAD);
259
-  }
260
-
261
-  private void checkDeliveryAfterUnloadInTokyo() {
262
-    Cargo cargo = cargoRepository.find(trackingId);
263
-    // Check current state - cargo is misdirected!
264
-    assertThat(cargo.currentVoyage(), is(NONE));
265
-    assertThat(cargo.lastKnownLocation(), is(TOKYO));
266
-    assertThat(cargo.transportStatus(), is(IN_PORT));
267
-    assertTrue(cargo.isMisdirected());
268
-    assertNull(cargo.nextExpectedActivity());
269
-  }
270
-
271
-  public void specifyNewRouteFromTokyoToStockholm() {
272
-    // TODO cleaner reroute from "earliest location from where the new route originates"
273
-    Cargo cargo = cargoRepository.find(trackingId);
274
-
275
-    // Specify a new route, this time from Tokyo (where it was incorrectly unloaded) to Stockholm
276
-    RouteSpecification fromTokyo = cargo.routeSpecification().withOrigin(TOKYO);
277
-    cargo.specifyNewRoute(fromTokyo);
278
-    cargoRepository.store(cargo);
279
-  }
280
-
281
-  public void checkDeliveryAfterNewRouteSpecified() {
282
-    Cargo cargo = cargoRepository.find(trackingId);
283
-
284
-    // The old itinerary does not satisfy the new specification
285
-    assertThat(cargo.routingStatus(), is(MISROUTED));
286
-    assertNull(cargo.nextExpectedActivity());
287
-  }
288
-
289
-  public void assignToNewRouteFromTokyoToStockholm() {
290
-    Cargo cargo = cargoRepository.find(trackingId);
291
-
292
-    // Repeat procedure of selecting one out of a number of possible routes satisfying the route spec
293
-    List<Itinerary> newItineraries = routingService.fetchRoutesForSpecification(cargo.routeSpecification());
294
-    Itinerary newItinerary = newItineraries.get(0);
295
-
296
-    cargo.assignToRoute(newItinerary);
297
-    cargoRepository.store(cargo);
298
-  }
299
-
300
-  public void checkDeliveryAfterAssignedToNewRoute() {
301
-    Cargo cargo = cargoRepository.find(trackingId);
302
-
303
-    // New itinerary should satisfy new route
304
-    assertThat(cargo.routingStatus(), is(ROUTED));
305
-    // TODO is it really misdirected at this point?
306
-    assertTrue(cargo.isMisdirected());
307
-    //assertEquals(new HandlingActivity(LOAD, TOKYO, v300), cargo.nextExpectedActivity());
308
-    assertNull(cargo.nextExpectedActivity());
309
-  }
310
-
311
-  public void loadInTokyo() throws CannotCreateHandlingEventException {
312
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-08"), v300, TOKYO, LOAD);
313
-  }
314
-
315
-  private void checkDeliveryAfterLoadInTokyo() {
316
-    Cargo cargo = cargoRepository.find(trackingId);
317
-    // Check current state - should be ok
318
-    assertThat(cargo.currentVoyage(), is(v300));
319
-    assertThat(cargo.lastKnownLocation(), is(TOKYO));
320
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
321
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, HAMBURG, v300)));
322
-    assertFalse(cargo.isMisdirected());
323
-  }
324
-
325
-  public void unloadInHamburg() throws CannotCreateHandlingEventException {
326
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-12"), v300, HAMBURG, UNLOAD);
327
-  }
328
-
329
-  private void checkDeliveryAfterUnloadInHamburg() {
330
-    Cargo cargo = cargoRepository.find(trackingId);
331
-    // Check current state - should be ok
332
-
333
-    assertThat(cargo.currentVoyage(), is(NONE));
334
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
335
-    assertThat(cargo.transportStatus(), is(IN_PORT));
336
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(LOAD, HAMBURG, v400)));
337
-    assertFalse(cargo.isMisdirected());
338
-  }
339
-
340
-  public void loadInHamburg() throws CannotCreateHandlingEventException {
341
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-14"), v400, HAMBURG, LOAD);
342
-  }
343
-
344
-  private void checkDeliveryAfterLoadInHamburg() {
345
-    Cargo cargo = cargoRepository.find(trackingId);
346
-    // Check current state - should be ok
347
-
348
-    assertThat(cargo.currentVoyage(), is(v400));
349
-    assertThat(cargo.lastKnownLocation(), is(HAMBURG));
350
-    assertThat(cargo.transportStatus(), is(ONBOARD_CARRIER));
351
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(UNLOAD, STOCKHOLM, v400)));
352
-    assertFalse(cargo.isMisdirected());
353
-  }
354
-
355
-  public void unloadInStockholmOffOf(Voyage voyage) throws CannotCreateHandlingEventException {
356
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-15"), voyage, STOCKHOLM, UNLOAD);
357
-  }
358
-
359
-  private void checkDeliveryAfterUnloadInStockholm() {
360
-    Cargo cargo = cargoRepository.find(trackingId);
361
-    // Check current state - should be ok
362
-    assertThat(cargo.currentVoyage(), is(NONE));
363
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
364
-    assertThat(cargo.transportStatus(), is(IN_PORT));
365
-    assertThat(cargo.nextExpectedActivity(), is(new HandlingActivity(CLAIM, STOCKHOLM)));
366
-    assertFalse(cargo.isMisdirected());
367
-  }
368
-
369
-  private void claimInStockholm() throws CannotCreateHandlingEventException {
370
-    createHandlingEventAndUpdateAggregates(toDate("2009-03-16"), null, STOCKHOLM, CLAIM);
371
-  }
372
-
373
-  private void checkDeliveryAfterClaimInStockholm() {
374
-    Cargo cargo = cargoRepository.find(trackingId);
375
-    // Check current state - should be ok
376
-    assertThat(cargo.currentVoyage(), is(NONE));
377
-    assertThat(cargo.lastKnownLocation(), is(STOCKHOLM));
378
-    assertThat(cargo.transportStatus(), is(CLAIMED));
379
-    assertFalse(cargo.isMisdirected());
380
-    assertNull(cargo.nextExpectedActivity());
381
-  }
382
-
383
-  private void createHandlingEventAndUpdateAggregates(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
384
-    updateHandlingEventAggregate(completionTime, voyage, location, type);
385
-    updateCargoAggregate();
386
-  }
387
-
388
-  private void updateHandlingEventAggregate(Date completionTime, Voyage voyage, Location location, HandlingEvent.Type type) throws CannotCreateHandlingEventException {
389
-    VoyageNumber voyageNumber = voyage != null ? voyage.voyageNumber() : null;
390
-    HandlingEvent handlingEvent = handlingEventFactory.createHandlingEvent(new Date(), completionTime, trackingId, voyageNumber, location.unLocode(), type);
391
-    handlingEventRepository.store(handlingEvent);
392
-  }
393
-
394
-  private void updateCargoAggregate() {
395
-    Cargo cargo = cargoRepository.find(trackingId);
396
-    HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(cargo);
397
-    cargo.handled(handlingEvent.activity());
398
-    cargoRepository.store(cargo);
399
-  }
400
-
401
-  private static class ScenarioStubRoutingService implements RoutingService {
402
-
403
-    public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
404
-      if (routeSpecification.origin().equals(HONGKONG)) {
405
-        // Hongkong - NYC - Chicago - Stockholm, initial routing
406
-        return Arrays.asList(
407
-          new Itinerary(Arrays.asList(
408
-            new Leg(v100, HONGKONG, LONGBEACH, toDate("2009-03-03"), toDate("2009-03-09")),
409
-            new Leg(v250, LONGBEACH, NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")),
410
-            new Leg(v200, NEWYORK, STOCKHOLM, toDate("2009-03-07"), toDate("2009-03-11"))
411
-          ))
412
-        );
413
-      } else {
414
-        // Tokyo - Hamburg - Stockholm, rerouting misdirected cargo from Tokyo
415
-        return Arrays.asList(
416
-          new Itinerary(Arrays.asList(
417
-            new Leg(v300, TOKYO, HAMBURG, toDate("2009-03-08"), toDate("2009-03-12")),
418
-            new Leg(v400, HAMBURG, STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15"))
419
-          ))
420
-        );
421
-      }
422
-    }
423
-
424
-  }
425
-
426
-}

+ 0
- 107
dddsample/src/test/java/se/citerus/dddsample/scenario/VoyageRescheduledScenarioTest.java Просмотреть файл

1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-aug-05
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.scenario;
8
-
9
-import static org.hamcrest.MatcherAssert.assertThat;
10
-import static org.hamcrest.Matchers.is;
11
-import org.junit.Before;
12
-import org.junit.Test;
13
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
14
-import se.citerus.dddsample.domain.model.cargo.Cargo;
15
-import se.citerus.dddsample.domain.model.cargo.CargoFactory;
16
-import se.citerus.dddsample.domain.model.cargo.Itinerary;
17
-import se.citerus.dddsample.domain.model.cargo.Leg;
18
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.MISROUTED;
19
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.ROUTED;
20
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
21
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
22
-import se.citerus.dddsample.domain.model.voyage.Voyage;
23
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
24
-import se.citerus.dddsample.infrastructure.persistence.TrackingIdGeneratorInMem;
25
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
26
-
27
-import java.util.Date;
28
-
29
-public class VoyageRescheduledScenarioTest {
30
-
31
-  Cargo cargo;
32
-  Voyage voyage1;
33
-  Voyage voyage2;
34
-  Voyage voyage3;
35
-
36
-  @Before
37
-  public void setupCargo() {
38
-    // Creating new voyages to avoid rescheduling shared ones, breaking other tests
39
-    voyage1 = new Voyage(new VoyageNumber("V1"), HONGKONG_TO_NEW_YORK.schedule());
40
-    voyage2 = new Voyage(new VoyageNumber("V2"), NEW_YORK_TO_DALLAS.schedule());
41
-    voyage3 = new Voyage(new VoyageNumber("V3"), DALLAS_TO_HELSINKI.schedule());
42
-    CargoFactory cargoFactory = new CargoFactory(new LocationRepositoryInMem(), new TrackingIdGeneratorInMem());
43
-    cargo = cargoFactory.newCargo(HANGZOU.unLocode(), STOCKHOLM.unLocode(), toDate("2008-12-23"));
44
-    Itinerary itinerary = new Itinerary(
45
-      Leg.deriveLeg(voyage1, HANGZOU, NEWYORK),
46
-      Leg.deriveLeg(voyage2, NEWYORK, DALLAS),
47
-      Leg.deriveLeg(voyage3, DALLAS, STOCKHOLM)
48
-    );
49
-    cargo.assignToRoute(itinerary);
50
-  }
51
-
52
-  @Test
53
-  public void voyageIsRescheduledWithMaintainableRoute() {
54
-    assertThat(cargo.routingStatus(), is(ROUTED));
55
-
56
-    Date oldDepartureTime = toDate("2008-10-24", "07:00");
57
-
58
-    assertThat(voyage2.schedule().departureTimeAt(NEWYORK), is(oldDepartureTime));
59
-    assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(oldDepartureTime));
60
-
61
-    // Now voyage2 is rescheduled, the departure from NYC is delayed a few hours.
62
-    Date newDepartureTime = toDate("2008-10-24", "18:00");
63
-    voyage2.departureRescheduled(NEWYORK, newDepartureTime);
64
-
65
-    // The schedule of voyage2 is updated
66
-    assertThat(voyage2.schedule().departureTimeAt(NEWYORK), is(newDepartureTime));
67
-    // ...but the cargo itinerary still has the old departure time
68
-    assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(oldDepartureTime));
69
-
70
-    // Generate a new itinerary from the old one and assign the cargo to this route
71
-    Itinerary newItinerary = cargo.itinerary().withRescheduledVoyage(voyage2);
72
-    cargo.assignToRoute(newItinerary);
73
-
74
-    // Now the cargo aggregate is updated to reflect the scheduling change!
75
-    assertThat(cargo.itinerary().loadTimeAt(NEWYORK), is(newDepartureTime));
76
-    assertThat(cargo.routingStatus(), is(ROUTED));
77
-  }
78
-
79
-  @Test
80
-  public void voyageIsRescheduledWithUnmaintainableRoute() {
81
-    assertThat(cargo.routingStatus(), is(ROUTED));
82
-
83
-    // Voyage1 arrives in NYC at 2008-10-23 23:10
84
-    // Now rescheduling the departure of voyage2 to BEFORE
85
-    // voyage1 arrives in NYC. This makes it impossible to
86
-    // keep the latter part of the old itinerary, and the new itinerary
87
-    // is therefore truncated after unload in NYC.
88
-
89
-    // TODO delay the arrival instead of advancing the departure
90
-
91
-    Date newDepartureTime = toDate("2008-10-23", "18:30");
92
-    voyage2.departureRescheduled(NEWYORK, newDepartureTime);
93
-
94
-    // Only the part of the itinerary up to and including NYC is maintainable, the rest is truncated
95
-    Itinerary truncatedItinerary = cargo.itinerary().withRescheduledVoyage(voyage2);
96
-    assertThat(truncatedItinerary.lastLeg().unloadLocation(), is(NEWYORK));
97
-
98
-    //Or... The Itinerary is created with an 'Illegal Connection' based on a coomparison of
99
-    //each transfer with a Location.minimumAllowedConnectionTime(). Since Loation is an entity
100
-    //we don't allow Itinerary to dynamically use the property directly because it is not immutable.
101
-    
102
-    // The cargo enters MISROUTED state
103
-    cargo.assignToRoute(truncatedItinerary);
104
-    assertThat(cargo.routingStatus(), is(MISROUTED));
105
-  }
106
-
107
-}