|
|
@@ -1,80 +0,0 @@
|
|
1
|
|
-package se.citerus.dddsample.application;
|
|
2
|
|
-
|
|
3
|
|
-import com.partner.pathfinder.api.GraphTraversalService;
|
|
4
|
|
-import com.partner.pathfinder.internal.GraphDAO;
|
|
5
|
|
-import com.partner.pathfinder.internal.GraphTraversalServiceImpl;
|
|
6
|
|
-import junit.framework.TestCase;
|
|
7
|
|
-import static org.easymock.EasyMock.*;
|
|
8
|
|
-import se.citerus.dddsample.domain.model.cargo.*;
|
|
9
|
|
-import se.citerus.dddsample.domain.model.carrier.SampleVoyages;
|
|
10
|
|
-import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
|
|
11
|
|
-import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
|
|
12
|
|
-import se.citerus.dddsample.domain.model.location.Location;
|
|
13
|
|
-import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
14
|
|
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
|
|
15
|
|
-import se.citerus.dddsample.infrastructure.persistence.inmemory.LocationRepositoryInMem;
|
|
16
|
|
-import se.citerus.dddsample.infrastructure.routing.ExternalRoutingService;
|
|
17
|
|
-
|
|
18
|
|
-import javax.sql.DataSource;
|
|
19
|
|
-import java.util.Arrays;
|
|
20
|
|
-import java.util.Date;
|
|
21
|
|
-import java.util.List;
|
|
22
|
|
-
|
|
23
|
|
-public class RoutingServiceTest extends TestCase {
|
|
24
|
|
-
|
|
25
|
|
- private ExternalRoutingService externalRoutingService;
|
|
26
|
|
- private VoyageRepository voyageRepository;
|
|
27
|
|
-
|
|
28
|
|
- protected void setUp() throws Exception {
|
|
29
|
|
- externalRoutingService = new ExternalRoutingService();
|
|
30
|
|
- LocationRepository locationRepository = new LocationRepositoryInMem();
|
|
31
|
|
- externalRoutingService.setLocationRepository(locationRepository);
|
|
32
|
|
-
|
|
33
|
|
- voyageRepository = createMock(VoyageRepository.class);
|
|
34
|
|
- externalRoutingService.setVoyageRepository(voyageRepository);
|
|
35
|
|
-
|
|
36
|
|
- GraphTraversalService graphTraversalService = new GraphTraversalServiceImpl(new GraphDAO(createMock(DataSource.class)) {
|
|
37
|
|
- public List<String> listLocations() {
|
|
38
|
|
- return Arrays.asList(TOKYO.unLocode().idString(), STOCKHOLM.unLocode().idString(), GOTHENBURG.unLocode().idString());
|
|
39
|
|
- }
|
|
40
|
|
-
|
|
41
|
|
- public void storeCarrierMovementId(String cmId, String from, String to) {
|
|
42
|
|
- }
|
|
43
|
|
- });
|
|
44
|
|
- externalRoutingService.setGraphTraversalService(graphTraversalService);
|
|
45
|
|
- }
|
|
46
|
|
-
|
|
47
|
|
- public void testCalculatePossibleRoutes() {
|
|
48
|
|
- TrackingId trackingId = new TrackingId("ABC");
|
|
49
|
|
- RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, new Date());
|
|
50
|
|
- Cargo cargo = new Cargo(trackingId, HONGKONG, 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.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 conencted
|
|
73
|
|
- assertEquals(legs.get(i).unloadLocation(), legs.get(i + 1).loadLocation());
|
|
74
|
|
- }
|
|
75
|
|
- }
|
|
76
|
|
-
|
|
77
|
|
- verify(voyageRepository);
|
|
78
|
|
- }
|
|
79
|
|
-
|
|
80
|
|
-}
|