소스 검색

Failing scenario test for a routing service, with a few added skeleton interfaces, domain classes and methods.

peter_backlund 18 년 전
부모
커밋
7613908c1e

+ 20
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java 파일 보기

29
   @Embedded
29
   @Embedded
30
   private DeliveryHistory deliveryHistory;
30
   private DeliveryHistory deliveryHistory;
31
 
31
 
32
+  @OneToOne
33
+  private Itinerary itinerary;
34
+
32
   public Cargo(TrackingId trackingId, Location origin, Location finalDestination) {
35
   public Cargo(TrackingId trackingId, Location origin, Location finalDestination) {
33
     this.trackingId = trackingId;
36
     this.trackingId = trackingId;
34
     this.origin = origin;
37
     this.origin = origin;
83
     return finalDestination.equals(lastKnownLocation());
86
     return finalDestination.equals(lastKnownLocation());
84
   }
87
   }
85
 
88
 
89
+  /**
90
+   * Assigns an itinerary to this cargo.
91
+   * @param itinerary an itinerary
92
+   */
93
+  public void assignItinerary(Itinerary itinerary) {
94
+    this.itinerary = itinerary;
95
+  }
96
+
97
+  /**
98
+   * @return True if the cargo has been misdirected,
99
+   * that is if the cargo is in a location that's not in the itinerary.
100
+   */
101
+  public boolean isMisdirected() {
102
+    // TODO: implement
103
+    return false;
104
+  }
105
+
86
   @Override
106
   @Override
87
   public String toString() {
107
   public String toString() {
88
     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
108
     return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java 파일 보기

12
  * HandlingEvent's are sent from different Incident Logging Applications some time after the event occured and contain information about the
12
  * HandlingEvent's are sent from different Incident Logging Applications some time after the event occured and contain information about the
13
  * {@link TrackingId}, {@link Location}, timestamp of the completion of the event, and possibly, if applicable a {@link CarrierMovement}.
13
  * {@link TrackingId}, {@link Location}, timestamp of the completion of the event, and possibly, if applicable a {@link CarrierMovement}.
14
  * <br><br>
14
  * <br><br>
15
- * HandlingEvent's could contain information about a {@link CarrierMovement} and if so, the event type must be either {@link Type.LOAD} or
16
- * {@link Type.UNLOAD}. All other events must be of {@link Type.RECEIVE}, {@link Type.CLAIM} or {@link Type.CUSTOMS}.
15
+ * HandlingEvent's could contain information about a {@link CarrierMovement} and if so, the event type must be either {@link Type#LOAD} or
16
+ * {@link Type#UNLOAD}. All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
17
  */
17
  */
18
 @Entity
18
 @Entity
19
 public class HandlingEvent {
19
 public class HandlingEvent {

+ 17
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Itinerary.java 파일 보기

1
+package se.citerus.dddsample.domain;
2
+
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.Id;
6
+
7
+/**
8
+ *
9
+ */
10
+@Entity
11
+public class Itinerary {
12
+
13
+  @Id
14
+  @GeneratedValue
15
+  private Long id;
16
+
17
+}

+ 3
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Location.java 파일 보기

82
     return unLocode.hashCode();
82
     return unLocode.hashCode();
83
   }
83
   }
84
 
84
 
85
+  /**
86
+   * @return Unlocode and name, on the format "SESTO (Stockholm)"
87
+   */
85
   @Override
88
   @Override
86
   public String toString() {
89
   public String toString() {
87
     return unLocode.idString() + " (" + name + ")";
90
     return unLocode.idString() + " (" + name + ")";

+ 7
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/Specification.java 파일 보기

1
+package se.citerus.dddsample.domain;
2
+
3
+/**
4
+ * 
5
+ */
6
+public interface Specification {
7
+}

+ 16
- 0
dddsample/src/main/java/se/citerus/dddsample/service/RoutingService.java 파일 보기

1
+package se.citerus.dddsample.service;
2
+
3
+import se.citerus.dddsample.domain.Cargo;
4
+import se.citerus.dddsample.domain.Itinerary;
5
+import se.citerus.dddsample.domain.Specification;
6
+
7
+import java.util.Set;
8
+
9
+/**
10
+ *  
11
+ */
12
+public interface RoutingService {
13
+
14
+  Set<Itinerary> calculatePossibleRoutes(Cargo cargo, Specification specification);
15
+
16
+}

+ 6
- 0
dddsample/src/main/resources/hibernate.cfg.xml 파일 보기

7
 <hibernate-configuration>
7
 <hibernate-configuration>
8
 
8
 
9
   <session-factory>
9
   <session-factory>
10
+    <!-- Properties defined here are shared between test and production -->
10
     <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
11
     <property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
11
     <mapping class="se.citerus.dddsample.domain.Cargo"/>
12
     <mapping class="se.citerus.dddsample.domain.Cargo"/>
12
     <mapping class="se.citerus.dddsample.domain.Location"/>
13
     <mapping class="se.citerus.dddsample.domain.Location"/>
13
     <mapping class="se.citerus.dddsample.domain.HandlingEvent"/>
14
     <mapping class="se.citerus.dddsample.domain.HandlingEvent"/>
14
     <mapping class="se.citerus.dddsample.domain.CarrierMovement"/>
15
     <mapping class="se.citerus.dddsample.domain.CarrierMovement"/>
16
+    <mapping class="se.citerus.dddsample.domain.Itinerary"/>
17
+    <mapping class="se.citerus.dddsample.domain.TrackingId"/>
18
+    <mapping class="se.citerus.dddsample.domain.DeliveryHistory"/>
19
+    <mapping class="se.citerus.dddsample.domain.CarrierMovementId"/>
20
+    <mapping class="se.citerus.dddsample.domain.UnLocode"/>
15
   </session-factory>
21
   </session-factory>
16
 
22
 
17
 </hibernate-configuration>
23
 </hibernate-configuration>

+ 65
- 0
dddsample/src/test/java/se/citerus/dddsample/service/RoutingServiceTest.java 파일 보기

1
+package se.citerus.dddsample.service;
2
+
3
+import junit.framework.TestCase;
4
+import se.citerus.dddsample.domain.*;
5
+import se.citerus.dddsample.repository.CargoRepository;
6
+
7
+import java.util.Date;
8
+import java.util.Set;
9
+
10
+public class RoutingServiceTest extends TestCase {
11
+
12
+  RoutingService routingService;
13
+  CargoRepository cargoRepository;
14
+  HandlingEventService handlingEventService;
15
+
16
+  public void testCalculateRoute() throws Exception {
17
+    TrackingId trackingId = new TrackingId("XYZ123");
18
+    Cargo cargo = cargoRepository.find(trackingId);
19
+
20
+    Specification specification = null;
21
+
22
+    /*
23
+      The routing service calculates a number of possible routes that
24
+      satisfy the given specification (must arrive in three days, must not
25
+      cost more than $10,000 etc).
26
+     */
27
+    Set<Itinerary> itineraryCandidates = routingService.calculatePossibleRoutes(cargo, specification);
28
+
29
+    /*
30
+      Someone, or something, selects the most appropriate itinerary and
31
+      assigns that itinerary to the cargo.
32
+     */
33
+    Itinerary itinerary = selectItinerary(itineraryCandidates);
34
+    cargo.assignItinerary(itinerary);
35
+
36
+    /*
37
+      A number of events occur, all of which are according to plan
38
+     */
39
+    handlingEventService.register(new Date(), trackingId, new CarrierMovementId("A001"), new UnLocode("SE","STO"), null);
40
+    handlingEventService.register(new Date(), trackingId, new CarrierMovementId("B002"), null, null);
41
+    handlingEventService.register(new Date(), trackingId, new CarrierMovementId("C003"), null, null);
42
+
43
+    /*
44
+      Cargo should not be misdirected at this point.
45
+     */
46
+    assertFalse(cargo.isMisdirected());
47
+
48
+    /*
49
+      An unexpected event occur.
50
+     */
51
+    handlingEventService.register(null, null, null, null, null);
52
+
53
+    /*
54
+      Now the cargo is misdirected.
55
+     */
56
+    assertTrue(cargo.isMisdirected());
57
+  }
58
+
59
+
60
+  // Stub for the itinerary selection process
61
+  private Itinerary selectItinerary(Set<Itinerary> itineraryCandidates) {
62
+    return itineraryCandidates.iterator().next();
63
+  }
64
+
65
+}

+ 0
- 2
dddsample/src/test/resources/mock-context-persistence.xml 파일 보기

20
     <constructor-arg value="se.citerus.dddsample.repository.CarrierMovementRepository"/>
20
     <constructor-arg value="se.citerus.dddsample.repository.CarrierMovementRepository"/>
21
   </bean>
21
   </bean>
22
 
22
 
23
-
24
-
25
   <bean id="locationRepository" class="se.citerus.dddsample.repository.LocationRepositoryHibernate">
23
   <bean id="locationRepository" class="se.citerus.dddsample.repository.LocationRepositoryHibernate">
26
     <property name="sessionFactory" ref="sessionFactory"/>
24
     <property name="sessionFactory" ref="sessionFactory"/>
27
   </bean>
25
   </bean>