|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+package se.citerus.dddsample.web.command;
|
|
|
2
|
+
|
|
|
3
|
+import junit.framework.TestCase;
|
|
|
4
|
+import org.springframework.validation.BindingResult;
|
|
|
5
|
+import org.springframework.validation.BeanPropertyBindingResult;
|
|
|
6
|
+import org.springframework.validation.FieldError;
|
|
|
7
|
+
|
|
|
8
|
+public class TrackCommandValidatorTest extends TestCase {
|
|
|
9
|
+
|
|
|
10
|
+ TrackCommandValidator validator;
|
|
|
11
|
+ TrackCommand command;
|
|
|
12
|
+ BindingResult errors;
|
|
|
13
|
+
|
|
|
14
|
+ protected void setUp() throws Exception {
|
|
|
15
|
+ validator = new TrackCommandValidator();
|
|
|
16
|
+ command = new TrackCommand();
|
|
|
17
|
+ errors = new BeanPropertyBindingResult(command, "command");
|
|
|
18
|
+ }
|
|
|
19
|
+
|
|
|
20
|
+ public void testValidateIllegalId() throws Exception {
|
|
|
21
|
+ validator.validate(command, errors);
|
|
|
22
|
+
|
|
|
23
|
+ assertEquals(1, errors.getErrorCount());
|
|
|
24
|
+ FieldError error = errors.getFieldError("trackingId");
|
|
|
25
|
+ assertNotNull(error);
|
|
|
26
|
+ assertNull(error.getRejectedValue());
|
|
|
27
|
+ assertEquals("track.illegal-id", error.getCode());
|
|
|
28
|
+ }
|
|
|
29
|
+
|
|
|
30
|
+ public void testValidateSuccess() throws Exception {
|
|
|
31
|
+ command.setTrackingId("non-empty");
|
|
|
32
|
+ validator.validate(command, errors);
|
|
|
33
|
+
|
|
|
34
|
+ assertFalse(errors.hasErrors());
|
|
|
35
|
+ }
|
|
|
36
|
+
|
|
|
37
|
+}
|