|
|
@@ -1,11 +1,17 @@
|
|
1
|
1
|
package se.citerus.dddsample.service.dto.assembler;
|
|
2
|
2
|
|
|
3
|
3
|
import junit.framework.TestCase;
|
|
|
4
|
+import static org.easymock.EasyMock.*;
|
|
4
|
5
|
import se.citerus.dddsample.domain.*;
|
|
5
|
6
|
import static se.citerus.dddsample.domain.SampleLocations.*;
|
|
|
7
|
+import se.citerus.dddsample.repository.CarrierMovementRepository;
|
|
|
8
|
+import se.citerus.dddsample.repository.LocationRepository;
|
|
6
|
9
|
import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
|
|
7
|
10
|
import se.citerus.dddsample.service.dto.LegDTO;
|
|
8
|
11
|
|
|
|
12
|
+import java.util.ArrayList;
|
|
|
13
|
+import java.util.List;
|
|
|
14
|
+
|
|
9
|
15
|
public class ItineraryCandidateDTOAssemblerTest extends TestCase {
|
|
10
|
16
|
|
|
11
|
17
|
public void testToDTO() throws Exception {
|
|
|
@@ -35,4 +41,49 @@ public class ItineraryCandidateDTOAssemblerTest extends TestCase {
|
|
35
|
41
|
assertEquals("NLRTM", legDTO.getFrom());
|
|
36
|
42
|
assertEquals("AUMEL", legDTO.getTo());
|
|
37
|
43
|
}
|
|
|
44
|
+
|
|
|
45
|
+ public void testFromDTO() throws Exception {
|
|
|
46
|
+ final ItineraryCandidateDTOAssembler assembler = new ItineraryCandidateDTOAssembler();
|
|
|
47
|
+
|
|
|
48
|
+ final List<LegDTO> legs = new ArrayList<LegDTO>();
|
|
|
49
|
+ legs.add(new LegDTO("CM1", "AAAAA", "BBBBB"));
|
|
|
50
|
+ legs.add(new LegDTO("CM2", "BBBBB", "CCCCC"));
|
|
|
51
|
+
|
|
|
52
|
+ final LocationRepository locationRepository = createMock(LocationRepository.class);
|
|
|
53
|
+ expect(locationRepository.find(new UnLocode("AAAAA"))).andReturn(HONGKONG);
|
|
|
54
|
+ expect(locationRepository.find(new UnLocode("BBBBB"))).andReturn(TOKYO).times(2);
|
|
|
55
|
+ expect(locationRepository.find(new UnLocode("CCCCC"))).andReturn(CHICAGO);
|
|
|
56
|
+
|
|
|
57
|
+ final CarrierMovementRepository carrierMovementRepository = createMock(CarrierMovementRepository.class);
|
|
|
58
|
+ final CarrierMovementId cmId1 = new CarrierMovementId("CM1");
|
|
|
59
|
+ final CarrierMovementId cmId2 = new CarrierMovementId("CM2");
|
|
|
60
|
+ final CarrierMovement cm1 = new CarrierMovement(cmId1, HONGKONG, TOKYO);
|
|
|
61
|
+ final CarrierMovement cm2 = new CarrierMovement(cmId2, TOKYO, CHICAGO);
|
|
|
62
|
+
|
|
|
63
|
+ expect(carrierMovementRepository.find(cmId1)).andReturn(cm1);
|
|
|
64
|
+ expect(carrierMovementRepository.find(cmId2)).andReturn(cm2);
|
|
|
65
|
+
|
|
|
66
|
+ replay(locationRepository, carrierMovementRepository);
|
|
|
67
|
+
|
|
|
68
|
+
|
|
|
69
|
+ // Tested call
|
|
|
70
|
+ final Itinerary itinerary = assembler.fromDTO(new ItineraryCandidateDTO(legs), carrierMovementRepository, locationRepository);
|
|
|
71
|
+
|
|
|
72
|
+
|
|
|
73
|
+ assertNotNull(itinerary);
|
|
|
74
|
+ assertNotNull(itinerary.legs());
|
|
|
75
|
+ assertEquals(2, itinerary.legs().size());
|
|
|
76
|
+
|
|
|
77
|
+ final Leg leg1 = itinerary.legs().get(0);
|
|
|
78
|
+ assertNotNull(leg1);
|
|
|
79
|
+ assertEquals(HONGKONG, leg1.from());
|
|
|
80
|
+ assertEquals(TOKYO, leg1.to());
|
|
|
81
|
+ assertEquals(cm1, leg1.carrierMovement());
|
|
|
82
|
+
|
|
|
83
|
+ final Leg leg2 = itinerary.legs().get(1);
|
|
|
84
|
+ assertNotNull(leg2);
|
|
|
85
|
+ assertEquals(TOKYO, leg2.from());
|
|
|
86
|
+ assertEquals(CHICAGO, leg2.to());
|
|
|
87
|
+ assertEquals(cm2, leg2.carrierMovement());
|
|
|
88
|
+ }
|
|
38
|
89
|
}
|