|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+package se.citerus.dddsample.service.dto.assembler;
|
|
|
2
|
+
|
|
|
3
|
+import junit.framework.TestCase;
|
|
|
4
|
+import se.citerus.dddsample.domain.*;
|
|
|
5
|
+import static se.citerus.dddsample.domain.SampleLocations.*;
|
|
|
6
|
+import se.citerus.dddsample.service.dto.CargoRoutingDTO;
|
|
|
7
|
+import se.citerus.dddsample.service.dto.LegDTO;
|
|
|
8
|
+import se.citerus.dddsample.service.dto.assembler.CargoRoutingDTOAssembler;
|
|
|
9
|
+
|
|
|
10
|
+public class CargoRoutingDTOAssemblerTest extends TestCase {
|
|
|
11
|
+
|
|
|
12
|
+ public void testToDTO() throws Exception {
|
|
|
13
|
+ final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
|
|
|
14
|
+
|
|
|
15
|
+ final Location origin = STOCKHOLM;
|
|
|
16
|
+ final Location destination = MELBOURNE;
|
|
|
17
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), origin, destination);
|
|
|
18
|
+
|
|
|
19
|
+ final CarrierMovement cm = new CarrierMovement(
|
|
|
20
|
+ new CarrierMovementId("ABC"), origin, destination);
|
|
|
21
|
+
|
|
|
22
|
+ final Itinerary itinerary = new Itinerary(
|
|
|
23
|
+ new Leg(cm, origin, SHANGHAI),
|
|
|
24
|
+ new Leg(cm, ROTTERDAM, destination)
|
|
|
25
|
+ );
|
|
|
26
|
+
|
|
|
27
|
+ cargo.setItinerary(itinerary);
|
|
|
28
|
+
|
|
|
29
|
+ final CargoRoutingDTO dto = assembler.toDTO(cargo);
|
|
|
30
|
+
|
|
|
31
|
+ assertEquals(2, dto.getLegs().size());
|
|
|
32
|
+
|
|
|
33
|
+ LegDTO legDTO = dto.getLegs().get(0);
|
|
|
34
|
+ assertEquals("ABC", legDTO.getCarrierMovementId());
|
|
|
35
|
+ assertEquals("SESTO (Stockholm)", legDTO.getFrom());
|
|
|
36
|
+ assertEquals("CNSHA (Shanghai)", legDTO.getTo());
|
|
|
37
|
+
|
|
|
38
|
+ legDTO = dto.getLegs().get(1);
|
|
|
39
|
+ assertEquals("ABC", legDTO.getCarrierMovementId());
|
|
|
40
|
+ assertEquals("NLRTM (Rotterdam)", legDTO.getFrom());
|
|
|
41
|
+ assertEquals("AUMEL (Melbourne)", legDTO.getTo());
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
|
44
|
+ public void testToDTO_NoItinerary() throws Exception {
|
|
|
45
|
+ final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
|
|
|
46
|
+
|
|
|
47
|
+ final Cargo cargo = new Cargo(new TrackingId("XYZ"), STOCKHOLM, MELBOURNE);
|
|
|
48
|
+ final CargoRoutingDTO dto = assembler.toDTO(cargo);
|
|
|
49
|
+
|
|
|
50
|
+ assertEquals("XYZ", dto.getTrackingId());
|
|
|
51
|
+ assertEquals("SESTO (Stockholm)", dto.getOrigin());
|
|
|
52
|
+ assertEquals("AUMEL (Melbourne)", dto.getFinalDestination());
|
|
|
53
|
+ assertTrue(dto.getLegs().isEmpty());
|
|
|
54
|
+ }
|
|
|
55
|
+}
|