Przeglądaj źródła

HandlingEventService now has a single, strongly typed method for registering events.

A JAX-WS-based remote interface for registering events has been introduced, which works as an anti-corruption layer as well. 

CarrierMovementRepository uses Hibernate implementation, test class created.

Reverted to Spring 2.0.8 in order to get JAX-WS integration going, but that's only until the next release gets out.
peter_backlund 18 lat temu
rodzic
commit
d1628e710a
18 zmienionych plików z 356 dodań i 119 usunięć
  1. 63
    7
      dddsample/pom.xml
  2. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryHibernate.java
  3. 0
    2
      dddsample/src/main/java/se/citerus/dddsample/repository/HibernateRepository.java
  4. 12
    40
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventService.java
  5. 23
    47
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java
  6. 21
    0
      dddsample/src/main/java/se/citerus/dddsample/service/InvalidEventTypeException.java
  7. 20
    0
      dddsample/src/main/java/se/citerus/dddsample/service/UnknownCarrierMovementIdException.java
  8. 20
    0
      dddsample/src/main/java/se/citerus/dddsample/service/UnknownTrackingIdException.java
  9. 14
    0
      dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpoint.java
  10. 69
    0
      dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpointImpl.java
  11. 2
    1
      dddsample/src/main/resources/context-persistence.xml
  12. 45
    0
      dddsample/src/main/resources/context-remote.xml
  13. 2
    2
      dddsample/src/main/resources/log4j.properties
  14. 10
    0
      dddsample/src/main/webapp/WEB-INF/web.xml
  15. 1
    0
      dddsample/src/test/java/se/citerus/dddsample/repository/AbstractRepositoryTest.java
  16. 30
    0
      dddsample/src/test/java/se/citerus/dddsample/repository/CarrierMovementRepositoryTest.java
  17. 5
    0
      dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java
  18. 18
    19
      dddsample/src/test/java/se/citerus/dddsample/service/HandlingEventServiceTest.java

+ 63
- 7
dddsample/pom.xml Wyświetl plik

@@ -24,8 +24,22 @@
24 24
       <id>maven2-repository.dev.java.net</id>
25 25
       <name>Java.net Repository for Maven</name>
26 26
       <url>http://download.java.net/maven/2/</url>
27
+      <layout>default</layout>
28
+    </repository>
29
+    <repository>
30
+      <id>maven-repository.dev.java.net</id>
31
+      <name>Java.net Repository for Maven 1</name>
32
+      <url>http://download.java.net/maven/1/</url>
33
+      <layout>legacy</layout>
27 34
     </repository>
28 35
   </repositories>
36
+  <pluginRepositories>
37
+    <pluginRepository>
38
+      <id>maven2-repository.dev.java.net</id>
39
+      <name>Java.net Repository for Maven</name>
40
+      <url>http://download.java.net/maven/2/</url>
41
+    </pluginRepository>
42
+  </pluginRepositories>
29 43
   <developers>
30 44
     <developer>
31 45
       <id>peba</id>
@@ -91,6 +105,24 @@
91 105
           <!--scanIntervalSeconds>10</scanIntervalSeconds-->
92 106
         </configuration>
93 107
       </plugin>
108
+
109
+      <!-- JAX-WS generation plugin -->
110
+      <plugin>
111
+        <groupId>org.codehaus.mojo</groupId>
112
+        <artifactId>jaxws-maven-plugin</artifactId>
113
+        <executions>
114
+          <execution>
115
+            <goals>
116
+              <goal>wsgen</goal>
117
+            </goals>
118
+          </execution>
119
+        </executions>
120
+        <configuration>
121
+          <sei>se.citerus.dddsample.ws.HandlingEventServiceEndpointImpl</sei>
122
+          <verbose>true</verbose>
123
+        </configuration>
124
+      </plugin>
125
+
94 126
     </plugins>
95 127
   </build>
96 128
   <dependencies>
@@ -103,27 +135,29 @@
103 135
     <dependency>
104 136
       <groupId>org.springframework</groupId>
105 137
       <artifactId>spring-webmvc</artifactId>
106
-      <version>2.5</version>
138
+      <version>2.0.8</version>
107 139
     </dependency>
108 140
     <dependency>
109 141
       <groupId>org.springframework</groupId>
110
-      <artifactId>spring-orm</artifactId>
111
-      <version>2.5</version>
142
+      <artifactId>spring-hibernate3</artifactId>
143
+      <!-- -orm in 2.5.x -->
144
+      <version>2.0.8</version>
112 145
     </dependency>
113 146
     <dependency>
114 147
       <groupId>org.springframework</groupId>
115 148
       <artifactId>spring-jdbc</artifactId>
116
-      <version>2.5</version>
149
+      <version>2.0.8</version>
117 150
     </dependency>
118 151
     <dependency>
119 152
       <groupId>org.springframework</groupId>
120 153
       <artifactId>spring-aop</artifactId>
121
-      <version>2.5</version>
154
+      <version>2.0.8</version>
122 155
     </dependency>
123 156
     <dependency>
124 157
       <groupId>org.springframework</groupId>
125
-      <artifactId>spring-test</artifactId>
126
-      <version>2.5</version>
158
+      <artifactId>spring-mock</artifactId>
159
+      <!-- -test in 2.5.x -->
160
+      <version>2.0.8</version>
127 161
       <scope>test</scope>
128 162
     </dependency>
129 163
     <dependency>
@@ -189,5 +223,27 @@
189 223
       <version>2.3</version>
190 224
       <scope>test</scope>
191 225
     </dependency>
226
+    <dependency>
227
+      <groupId>org.jvnet.jax-ws-commons.spring</groupId>
228
+      <artifactId>jaxws-spring</artifactId>
229
+      <version>1.8</version>
230
+      <exclusions>
231
+        <exclusion>
232
+          <groupId>org.springframework</groupId>
233
+          <artifactId>spring</artifactId>
234
+        </exclusion>
235
+      </exclusions>
236
+    </dependency>
237
+    <dependency>
238
+      <groupId>com.sun.xml.ws</groupId>
239
+      <artifactId>jaxws-rt</artifactId>
240
+      <version>2.1.3</version>
241
+    </dependency>
242
+    <dependency>
243
+      <groupId>com.sun.istack</groupId>
244
+      <artifactId>istack-commons-runtime</artifactId>
245
+      <version>1.0</version>
246
+      <scope>runtime</scope>
247
+    </dependency>
192 248
   </dependencies>
193 249
 </project>

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryHibernate.java Wyświetl plik

@@ -14,7 +14,7 @@ public class CarrierMovementRepositoryHibernate extends HibernateRepository impl
14 14
   public CarrierMovement find(CarrierMovementId carrierMovementId) {
15 15
     return (CarrierMovement) getSession().
16 16
             createQuery("from CarrierMovement where carrierMovementId = ?").
17
-            setParameter(1, carrierMovementId).
17
+            setParameter(0, carrierMovementId).
18 18
             uniqueResult();
19 19
   }
20 20
 

+ 0
- 2
dddsample/src/main/java/se/citerus/dddsample/repository/HibernateRepository.java Wyświetl plik

@@ -2,7 +2,6 @@ package se.citerus.dddsample.repository;
2 2
 
3 3
 import org.hibernate.Session;
4 4
 import org.hibernate.SessionFactory;
5
-import org.springframework.beans.factory.annotation.Autowired;
6 5
 import org.springframework.beans.factory.annotation.Required;
7 6
 
8 7
 /**
@@ -13,7 +12,6 @@ public abstract class HibernateRepository {
13 12
 
14 13
   SessionFactory sessionFactory;
15 14
 
16
-  @Autowired
17 15
   @Required
18 16
   public void setSessionFactory(SessionFactory sessionFactory) {
19 17
     this.sessionFactory = sessionFactory;

+ 12
- 40
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventService.java Wyświetl plik

@@ -1,5 +1,9 @@
1 1
 package se.citerus.dddsample.service;
2 2
 
3
+import se.citerus.dddsample.domain.TrackingId;
4
+import se.citerus.dddsample.domain.CarrierMovementId;
5
+import se.citerus.dddsample.domain.HandlingEvent;
6
+
3 7
 import java.util.Date;
4 8
 
5 9
 
@@ -10,47 +14,15 @@ import java.util.Date;
10 14
 public interface HandlingEventService {
11 15
 
12 16
   /**
13
-   * Register that a cargo has been loaded.
14
-   *
15
-   * @param completionTime when the event was completed, for example finished loading
16
-   * @param carrierMovementId carrier movement id
17
-   * @param trackingIds tracking ids of cargos to register this event for
18
-   */
19
-  void registerLoad(Date completionTime, String carrierMovementId, String[] trackingIds);
20
-
21
-  /**
22
-   * Register that a cargo has been unloaded.
23
-   *
24
-   * @param completionTime when the event was completed, for example finished loading
25
-   * @param carrierMovementId carrier movement id
26
-   * @param trackingIds tracking ids of cargos to register this event for
27
-   */
28
-  void registerUnload(Date completionTime, String carrierMovementId, String[] trackingIds);
29
-
30
-  /**
31
-   * Register that a cargo has been claimed.
32
-   *
33
-   * @param completionTime when the event was completed, for example finished loading
34
-   * @param unlocode United Nations Location Code, for example "SESTO" for SwEden/STOckholm
35
-   * @param trackingIds tracking ids of cargos to register this event for
36
-   */
37
-  void registerClaim(Date completionTime, String unlocode, String[] trackingIds);
38
-
39
-  /**
40
-   * Register that a cargo has been recieved.
41
-   *
42 17
    * @param completionTime when the event was completed, for example finished loading
43
-   * @param unlocode United Nations Location Code, for example "SESTO" for SwEden/STOckholm
44
-   * @param trackingIds tracking ids of cargos to register this event for
18
+   * @param trackingId tracking id
19
+   * @param carrierMovementId carrier movement
20
+   * @param unlocode United Nations Location Code for the location of the event
21
+   * @param type type of event
22
+   * @throws UnknownCarrierMovementIdException if there's not carrier movement with this id
23
+   * @throws se.citerus.dddsample.service.UnknownTrackingIdException if there's no cargo with this tracking id
45 24
    */
46
-  void registerRecieve(Date completionTime, String unlocode, String[] trackingIds);
25
+  void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, String unlocode, HandlingEvent.Type type)
26
+  throws UnknownCarrierMovementIdException, UnknownTrackingIdException;
47 27
 
48
-  /**
49
-   * Register that a cargo has been cleared by customs.
50
-   *
51
-   * @param completionTime when the event was completed, for example finished loading
52
-   * @param unlocode United Nations Location Code, for example "SESTO" for SwEden/STOckholm
53
-   * @param trackingIds tracking ids of cargos to register this event for
54
-   */
55
-  void registerCustomsCleared(Date completionTime, String unlocode, String[] trackingIds);
56 28
 }

+ 23
- 47
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java Wyświetl plik

@@ -15,62 +15,38 @@ public class HandlingEventServiceImpl implements HandlingEventService {
15 15
   private HandlingEventRepository handlingEventRepository;
16 16
 
17 17
   @Transactional(readOnly = false)
18
-  public void registerLoad(Date completionTime, String carrierMovementId, String[] trackingIds) {
19
-    doRegisterWithCarrierMovement(completionTime, findCarrierMovement(carrierMovementId), HandlingEvent.Type.LOAD, trackingIds);
20
-  }
21
-
22
-  @Transactional(readOnly = false)
23
-  public void registerUnload(Date completionTime, String carrierMovementId, String[] trackingIds) {
24
-    doRegisterWithCarrierMovement(completionTime, findCarrierMovement(carrierMovementId), HandlingEvent.Type.UNLOAD, trackingIds);
25
-  }
26
-
27
-  @Transactional(readOnly = false)
28
-  public void registerClaim(Date completionTime, String unlocode, String[] trackingIds) {
29
-    doRegisterWithLocation(completionTime, findLocation(unlocode), HandlingEvent.Type.CLAIM, trackingIds);
30
-  }
31
-
32
-  @Transactional(readOnly = false)
33
-  public void registerRecieve(Date completionTime, String unlocode, String[] trackingIds) {
34
-    doRegisterWithLocation(completionTime, findLocation(unlocode), HandlingEvent.Type.RECEIVE, trackingIds);
35
-  }
36
-
37
-  @Transactional(readOnly = false)
38
-  public void registerCustomsCleared(Date completionTime, String unlocode, String[] trackingIds) {
39
-    doRegisterWithLocation(completionTime, findLocation(unlocode), HandlingEvent.Type.CUSTOMS, trackingIds);
40
-  }
41
-
42
-  private void doRegisterWithLocation(Date completionTime, Location location, HandlingEvent.Type type, String[] trackingIds) {
43
-    for (String tid: trackingIds) {
44
-      Cargo cargo = findCargo(tid);
45
-      Date registrationTime = new Date();
46
-      HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, type, location);
47
-      handlingEventRepository.save(event);
18
+  public void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, String unlocode, HandlingEvent.Type type) throws UnknownCarrierMovementIdException, UnknownTrackingIdException {
19
+    Cargo cargo = findCargo(trackingId);
20
+    CarrierMovement carrierMovement = findCarrierMovement(carrierMovementId);
21
+    Location location = findLocation(unlocode);
22
+    Date registrationTime = new Date();
23
+    HandlingEvent event;
24
+    if (carrierMovement != null) {
25
+      event = new HandlingEvent(cargo, completionTime, registrationTime, type, carrierMovement);
26
+    } else {
27
+      event = new HandlingEvent(cargo, completionTime, registrationTime, type, location);
48 28
     }
29
+    handlingEventRepository.save(event);
49 30
   }
50 31
 
51
-  private void doRegisterWithCarrierMovement(Date completionTime, CarrierMovement carrierMovement, HandlingEvent.Type type, String[] trackingIds) {
52
-    for (String tid: trackingIds) {
53
-      Cargo cargo = findCargo(tid);
54
-      Date registrationTime = new Date();
55
-      HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, type, carrierMovement);
56
-      handlingEventRepository.save(event);
57
-    }
58
-  }
59
-
60
-  private Cargo findCargo(String trackingId) {
32
+  private Cargo findCargo(TrackingId trackingId) throws UnknownTrackingIdException {
61 33
     Validate.notNull(trackingId, "Tracking ID is required");
62
-    Cargo cargo = cargoRepository.find(new TrackingId(trackingId));
63
-    Validate.notNull(cargo, "Cargo is not found. Tracking ID=" + trackingId);
34
+    Cargo cargo = cargoRepository.find(trackingId);
35
+    if (cargo == null) {
36
+      throw new UnknownTrackingIdException(trackingId);
37
+    }
64 38
 
65 39
     return cargo;
66 40
   }
67 41
 
68
-  private CarrierMovement findCarrierMovement(String carrierId) {
69
-    Validate.notNull(carrierId, "Carrier ID is required");
70
-    CarrierMovement carrier = carrierMovementRepository.find(new CarrierMovementId(carrierId));
71
-    Validate.notNull(carrier, "Carrier is not found: Carrier ID=" + carrierId);
42
+  private CarrierMovement findCarrierMovement(CarrierMovementId carrierMovementId) throws UnknownCarrierMovementIdException {
43
+    Validate.notNull(carrierMovementId, "Carrier ID is required");
44
+    CarrierMovement carrierMovement = carrierMovementRepository.find(carrierMovementId);
45
+    if (carrierMovement == null) {
46
+      throw new UnknownCarrierMovementIdException(carrierMovementId);
47
+    }
72 48
 
73
-    return carrier;
49
+    return carrierMovement;
74 50
   }
75 51
 
76 52
   private Location findLocation(String unlocode) {

+ 21
- 0
dddsample/src/main/java/se/citerus/dddsample/service/InvalidEventTypeException.java Wyświetl plik

@@ -0,0 +1,21 @@
1
+package se.citerus.dddsample.service;
2
+
3
+import se.citerus.dddsample.domain.HandlingEvent;
4
+
5
+import java.util.Arrays;
6
+
7
+/**
8
+ * Thrown when trying to register an event with an invalid type.
9
+ *
10
+ */
11
+public class InvalidEventTypeException extends Throwable {
12
+  private String eventType;
13
+
14
+  public InvalidEventTypeException(String eventType) {
15
+    this.eventType = eventType;
16
+  }
17
+
18
+  public String getMessage() {
19
+    return "Invalid event type: " + eventType + ". Valid types are: " + Arrays.deepToString(HandlingEvent.Type.values());
20
+  }
21
+}

+ 20
- 0
dddsample/src/main/java/se/citerus/dddsample/service/UnknownCarrierMovementIdException.java Wyświetl plik

@@ -0,0 +1,20 @@
1
+package se.citerus.dddsample.service;
2
+
3
+import se.citerus.dddsample.domain.CarrierMovementId;
4
+
5
+/**
6
+ * Thrown when trying to register an event with an unknown carrier movement id.
7
+ *
8
+ */
9
+public class UnknownCarrierMovementIdException extends Exception {
10
+  private CarrierMovementId carrierMovementId;
11
+
12
+  public UnknownCarrierMovementIdException(CarrierMovementId carrierMovementId) {
13
+    this.carrierMovementId = carrierMovementId;
14
+  }
15
+
16
+  @Override
17
+  public String getMessage() {
18
+    return "No carrier movement with id " + carrierMovementId.idString() + " exists in the system";
19
+  }
20
+}

+ 20
- 0
dddsample/src/main/java/se/citerus/dddsample/service/UnknownTrackingIdException.java Wyświetl plik

@@ -0,0 +1,20 @@
1
+package se.citerus.dddsample.service;
2
+
3
+import se.citerus.dddsample.domain.TrackingId;
4
+
5
+/**
6
+ * Thrown when trying to register an event with an unknown tracking id.
7
+ *
8
+ */
9
+public class UnknownTrackingIdException extends Exception {
10
+  private TrackingId trackingId;
11
+
12
+  public UnknownTrackingIdException(TrackingId trackingId) {
13
+    this.trackingId = trackingId;
14
+  }
15
+
16
+  @Override
17
+  public String getMessage() {
18
+    return "No cargo with tracking id " + trackingId.idString() + " exists in the system";
19
+  }
20
+}

+ 14
- 0
dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpoint.java Wyświetl plik

@@ -0,0 +1,14 @@
1
+package se.citerus.dddsample.ws;
2
+
3
+import javax.jws.WebService;
4
+
5
+/**
6
+ * Web service endpoint for handling event registration.
7
+ *
8
+ */
9
+@WebService
10
+public interface HandlingEventServiceEndpoint {
11
+
12
+  void register(String completionTime, String trackingId, String carrierMovementId, String unlocode, String eventType);
13
+
14
+}

+ 69
- 0
dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpointImpl.java Wyświetl plik

@@ -0,0 +1,69 @@
1
+package se.citerus.dddsample.ws;
2
+
3
+import org.apache.commons.logging.Log;
4
+import org.apache.commons.logging.LogFactory;
5
+import se.citerus.dddsample.domain.CarrierMovementId;
6
+import se.citerus.dddsample.domain.HandlingEvent;
7
+import se.citerus.dddsample.domain.TrackingId;
8
+import se.citerus.dddsample.service.HandlingEventService;
9
+import se.citerus.dddsample.service.UnknownCarrierMovementIdException;
10
+import se.citerus.dddsample.service.UnknownTrackingIdException;
11
+import se.citerus.dddsample.service.InvalidEventTypeException;
12
+
13
+import javax.jws.WebService;
14
+import java.text.ParseException;
15
+import java.text.SimpleDateFormat;
16
+import java.util.Date;
17
+
18
+@WebService(endpointInterface = "se.citerus.dddsample.ws.HandlingEventServiceEndpoint")
19
+public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEndpoint {
20
+
21
+  private HandlingEventService handlingEventService;
22
+  private static final Log logger = LogFactory.getLog(HandlingEventServiceEndpointImpl.class);
23
+  private static final String ISO_8601_FORMAT = "yyyy-mm-dd HH:MM:SS.SSS";
24
+
25
+  public void register(String completionTime, String trackingId, String carrierMovementId,
26
+                       String unlocode, String eventType) {
27
+    try {
28
+      Date date = parseIso8601Date(completionTime);
29
+      TrackingId tid = new TrackingId(trackingId);
30
+      CarrierMovementId cid = new CarrierMovementId(carrierMovementId);
31
+      HandlingEvent.Type type = parseEventType(eventType);
32
+
33
+      handlingEventService.register(date, tid, cid, unlocode, type);
34
+      
35
+    } catch (ParseException pe) {
36
+      logger.error("Invalid date format: " + completionTime);
37
+    } catch (UnknownTrackingIdException utid) {
38
+      handleRetry(utid);
39
+    } catch (UnknownCarrierMovementIdException ucmi) {
40
+      handleRetry(ucmi);
41
+    } catch (InvalidEventTypeException iete) {
42
+      logger.error(iete, iete);
43
+    } catch (Exception e) {
44
+      logger.error(e, e);
45
+    }
46
+    // TODO: possibly handle "Duplicate event" exceptions due to unique constraint violations
47
+  }
48
+
49
+  private HandlingEvent.Type parseEventType(String eventType) throws InvalidEventTypeException {
50
+    try {
51
+      return HandlingEvent.Type.valueOf(eventType);
52
+    } catch(IllegalArgumentException e) {
53
+      throw new InvalidEventTypeException(eventType);
54
+    }
55
+  }
56
+
57
+  private void handleRetry(Exception e) {
58
+    logger.info("Placing event in retry queue due to: " + e.getMessage());
59
+    // TODO: actually place in a retry queue
60
+  }
61
+
62
+  private Date parseIso8601Date(String completionTime) throws ParseException {
63
+    return new SimpleDateFormat(ISO_8601_FORMAT).parse(completionTime);
64
+  }
65
+
66
+  public void setHandlingEventService(HandlingEventService handlingEventService) {
67
+    this.handlingEventService = handlingEventService;
68
+  }
69
+}

+ 2
- 1
dddsample/src/main/resources/context-persistence.xml Wyświetl plik

@@ -44,7 +44,8 @@
44 44
     <property name="sessionFactory" ref="sessionFactory"/>
45 45
   </bean>
46 46
 
47
-  <bean id="carrierMovementRepository" class="se.citerus.dddsample.repository.CarrierMovementRepositoryInMem">
47
+  <bean id="carrierMovementRepository" class="se.citerus.dddsample.repository.CarrierMovementRepositoryHibernate">
48
+    <property name="sessionFactory" ref="sessionFactory"/>
48 49
   </bean>
49 50
 
50 51
 </beans>

+ 45
- 0
dddsample/src/main/resources/context-remote.xml Wyświetl plik

@@ -0,0 +1,45 @@
1
+<?xml version="1.0"?>
2
+
3
+<beans xmlns="http://www.springframework.org/schema/beans"
4
+       xmlns:ws="http://jax-ws.dev.java.net/spring/core"
5
+       xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
6
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
+       xsi:schemaLocation="
8
+        http://jax-ws.dev.java.net/spring/core https://jax-ws.dev.java.net/spring/core.xsd
9
+        http://jax-ws.dev.java.net/spring/servlet https://jax-ws.dev.java.net/spring/servlet.xsd
10
+        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
11
+
12
+
13
+  <wss:bindings id="jax-ws.http">
14
+    <wss:bindings>
15
+      <wss:binding url="/ws/RegisterEvent">
16
+        <wss:service>
17
+          <ws:service bean="#handlingEventServiceEndpoint"/>
18
+        </wss:service>
19
+      </wss:binding>
20
+    </wss:bindings>
21
+  </wss:bindings>
22
+
23
+
24
+  <bean id="handlingEventServiceEndpoint" class="se.citerus.dddsample.ws.HandlingEventServiceEndpointImpl">
25
+    <property name="handlingEventService" ref="handlingEventService"/>
26
+  </bean>
27
+  <!--
28
+  -->
29
+
30
+  <!-- jax-ws-spring does not work with spring 2.5 yet
31
+  <beans xmlns="http://www.springframework.org/schema/beans"
32
+         xmlns:ws="http://jax-ws.dev.java.net/spring/core"
33
+         xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
34
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
35
+         xsi:schemaLocation="
36
+          http://jax-ws.dev.java.net/spring/core https://jax-ws.dev.java.net/spring/core.xsd
37
+          http://jax-ws.dev.java.net/spring/servlet https://jax-ws.dev.java.net/spring/servlet.xsd
38
+          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
39
+
40
+  <ws:service id="handlingEventServiceWS" bean="handlingEventServiceEndpoint"/>
41
+
42
+  <wss:binding url="/registerEvent" service="#handlingEventServiceWS"/>
43
+  -->
44
+
45
+</beans>

+ 2
- 2
dddsample/src/main/resources/log4j.properties Wyświetl plik

@@ -19,5 +19,5 @@ log4j.logger.se.citerus.dddsample=debug
19 19
 log4j.logger.net.sf.ehcache.config.ConfigurationFactory=error
20 20
 log4j.logger.org.hibernate.tool.hbm2ddl.SchemaExport=debug
21 21
 
22
-log4j.logger.org.springframework.orm=debug
23
-log4j.logger.org.springframework.transaction=debug
22
+#log4j.logger.org.springframework.orm=debug
23
+#log4j.logger.org.springframework.transaction=debug

+ 10
- 0
dddsample/src/main/webapp/WEB-INF/web.xml Wyświetl plik

@@ -30,6 +30,16 @@
30 30
     <url-pattern>*.html</url-pattern>
31 31
   </servlet-mapping>
32 32
 
33
+  <servlet>
34
+    <servlet-name>jaxws-servlet</servlet-name>
35
+    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
36
+  </servlet>
37
+
38
+  <servlet-mapping>
39
+    <servlet-name>jaxws-servlet</servlet-name>
40
+    <url-pattern>/ws/*</url-pattern>
41
+  </servlet-mapping>
42
+
33 43
   <filter>
34 44
     <filter-name>sitemesh</filter-name>
35 45
     <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>

+ 1
- 0
dddsample/src/test/java/se/citerus/dddsample/repository/AbstractRepositoryTest.java Wyświetl plik

@@ -13,6 +13,7 @@ public abstract class AbstractRepositoryTest extends AbstractTransactionalDataSo
13 13
   SimpleJdbcTemplate sjt;
14 14
 
15 15
   protected AbstractRepositoryTest() {
16
+    setAutowireMode(AUTOWIRE_BY_NAME);
16 17
     setDependencyCheck(false);
17 18
   }
18 19
 

+ 30
- 0
dddsample/src/test/java/se/citerus/dddsample/repository/CarrierMovementRepositoryTest.java Wyświetl plik

@@ -0,0 +1,30 @@
1
+package se.citerus.dddsample.repository;
2
+
3
+import se.citerus.dddsample.domain.CarrierMovementId;
4
+import se.citerus.dddsample.domain.CarrierMovement;
5
+import se.citerus.dddsample.domain.Location;
6
+
7
+/**
8
+ * Created by IntelliJ IDEA.
9
+ * User: Peter Backlund
10
+ * Date: 2008-jan-19
11
+ * Time: 18:41:50
12
+ * To change this template use File | Settings | File Templates.
13
+ */
14
+public class CarrierMovementRepositoryTest extends AbstractRepositoryTest {
15
+
16
+  CarrierMovementRepository carrierMovementRepository;
17
+
18
+  public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
19
+    this.carrierMovementRepository = carrierMovementRepository;
20
+  }
21
+
22
+  public void testFind() throws Exception {
23
+    CarrierMovement carrierMovement = carrierMovementRepository.find(new CarrierMovementId("CAR_001"));
24
+    assertNotNull(carrierMovement);
25
+    assertEquals("CAR_001", carrierMovement.carrierId().idString());
26
+    assertEquals(new Location("SESTO"), carrierMovement.from());
27
+    assertEquals(new Location("FIHEL"), carrierMovement.to());
28
+  }
29
+
30
+}

+ 5
- 0
dddsample/src/test/java/se/citerus/dddsample/service/CargoServiceTest.java Wyświetl plik

@@ -27,6 +27,11 @@ public class CargoServiceTest extends AbstractDependencyInjectionSpringContextTe
27 27
   HandlingEventRepository handlingEventRepository;
28 28
   SessionFactory sessionFactory;
29 29
 
30
+  public CargoServiceTest() {
31
+    setAutowireMode(AUTOWIRE_BY_NAME);
32
+    setDependencyCheck(false);    
33
+  }
34
+
30 35
   public void setCargoService(CargoService cargoService) {
31 36
     this.cargoService = cargoService;
32 37
   }

+ 18
- 19
dddsample/src/test/java/se/citerus/dddsample/service/HandlingEventServiceTest.java Wyświetl plik

@@ -36,51 +36,50 @@ public class HandlingEventServiceTest extends TestCase {
36 36
   }
37 37
 
38 38
   public void testRegisterEvent() throws Exception {
39
-    final String carrierMovementId = "AAA_BBB";
40
-    final String[] trackingIds = { "ABC", "XYZ" };
41 39
     final Date date = new Date();
42 40
 
43
-    expect(cargoRepository.find(new TrackingId("ABC"))).andReturn(cargoABC);
44
-    expect(cargoRepository.find(new TrackingId("XYZ"))).andReturn(cargoXYZ);
45
-    expect(carrierMovementRepository.find(new CarrierMovementId("AAA_BBB"))).andReturn(cmAAA_BBB);
41
+    final TrackingId trackingId = new TrackingId("ABC");
42
+    expect(cargoRepository.find(trackingId)).andReturn(cargoABC);
43
+
44
+    final CarrierMovementId carrierMovementId = new CarrierMovementId("AAA_BBB");
45
+    expect(carrierMovementRepository.find(carrierMovementId)).andReturn(cmAAA_BBB);
46 46
 
47 47
     // TODO: does not inspect the handling event instance in a sufficient way
48 48
     handlingEventRepository.save(isA(HandlingEvent.class));
49
-    expectLastCall().times(2);  // Two tracking ids
50 49
 
51 50
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
52 51
     
53
-    service.registerUnload(date, carrierMovementId, trackingIds);
52
+    service.register(date, trackingId, carrierMovementId, "SESTO", HandlingEvent.Type.LOAD);
54 53
   }
55 54
   
56 55
   public void testRegisterEventInvalidCarrier() throws Exception {
57
-    final String[] trackingIds = { "ABC", "XYZ" };
58 56
     final Date date = new Date();
59 57
 
60
-    expect(carrierMovementRepository.find(new CarrierMovementId("AAA_BBB"))).andReturn(null);
61
-    
58
+    final CarrierMovementId carrierMovementId = new CarrierMovementId("AAA_BBB");
59
+    expect(carrierMovementRepository.find(carrierMovementId)).andReturn(null);
60
+
61
+    final TrackingId trackingId = new TrackingId("XYZ");
62
+    expect(cargoRepository.find(trackingId)).andReturn(new Cargo(trackingId, new Location("FROM"), new Location("TO")));
63
+
62 64
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
63 65
     
64 66
     try {
65
-      service.registerUnload(date, "AAA_BBB", trackingIds);
67
+      service.register(date, trackingId, carrierMovementId, "AUMEL", HandlingEvent.Type.UNLOAD);
66 68
       fail("Should not be able to register an event with non-existing carrier movement");
67
-    } catch (IllegalArgumentException expected) {}
69
+    } catch (UnknownCarrierMovementIdException expected) {}
68 70
   }
69 71
   
70 72
   public void testRegisterEventInvalidCargo() throws Exception {
71
-    final String[] trackIds = { "ABC", "XYZ" };
72 73
     final Date date = new Date();
73 74
 
74
-    expect(cargoRepository.find(new TrackingId("ABC"))).andReturn(cargoABC);
75
-    expect(cargoRepository.find(new TrackingId("XYZ"))).andReturn(null);
76
-    expect(carrierMovementRepository.find(new CarrierMovementId("AAA_BBB"))).andReturn(cmAAA_BBB);
77
-    handlingEventRepository.save(isA(HandlingEvent.class));
75
+    final TrackingId trackingId = new TrackingId("XYZ");
76
+    expect(cargoRepository.find(trackingId)).andReturn(null);
78 77
 
79 78
     replay(cargoRepository, carrierMovementRepository, handlingEventRepository);
80 79
     
81 80
     try {
82
-      service.registerUnload(date, "AAA_BBB", trackIds);
81
+      service.register(date, trackingId, null, "CNHKG", HandlingEvent.Type.CLAIM);
83 82
       fail("Should not be able to register an event with non-existing cargo");
84
-    } catch (IllegalArgumentException expected) {}
83
+    } catch (UnknownTrackingIdException expected) {}
85 84
   }
86 85
 }