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