1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.nuiton.validator.xwork2.field;
23
24 import org.junit.Test;
25 import org.nuiton.validator.xwork2.field.ValidatorBean.ValidatorBeanEntry;
26
27 import java.util.Arrays;
28
29
30
31
32 public class CollectionUniqueKeyValidatorTest extends AbstractValidatorBeanFieldValidatorTest {
33
34 static protected ValidatorBeanEntry beanEntry = new ValidatorBeanEntry(0, "stringValue");
35
36 static protected ValidatorBeanEntry beanEntry2 = new ValidatorBeanEntry(0, "fake");
37
38 static protected ValidatorBeanEntry beanEntry3 = new ValidatorBeanEntry(0, "stringValue", "stringValue2");
39
40 @Test
41 @Override
42 public void testValidator() throws Exception {
43 assertNull(bean.getEntries());
44
45
46 assertFieldInError("entries", "collectionUniqueKey.one.failed", false);
47 assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
48 assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
49 assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
50 assertFieldInError("entries", "collectionUniqueKey.five.failed", false);
51
52
53 bean.setEntries(Arrays.asList(beanEntry));
54
55 assertFieldInError("entries", "collectionUniqueKey.one.failed", false);
56 assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
57 assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
58 assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
59 assertFieldInError("entries", "collectionUniqueKey.five.failed", false);
60
61
62 bean.setEntry(beanEntry3);
63 assertFieldInError("entries", "collectionUniqueKey.one.failed", false);
64 assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
65 assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
66 assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
67 assertFieldInError("entries", "collectionUniqueKey.five.failed", true);
68
69
70
71 bean.setEntries(Arrays.asList(beanEntry, beanEntry));
72
73 assertFieldInError("entries", "collectionUniqueKey.one.failed", true);
74 assertFieldInError("entries", "collectionUniqueKey.two.failed", true);
75 assertFieldInError("entries", "collectionUniqueKey.three.failed", true);
76 assertFieldInError("entries", "collectionUniqueKey.four.failed", true);
77
78
79 bean.setEntries(Arrays.asList(beanEntry2));
80
81 assertFieldInError("entries", "collectionUniqueKey.one.failed", false);
82 assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
83 assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
84 assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
85
86
87 bean.setEntries(Arrays.asList(beanEntry2, beanEntry));
88
89 assertFieldInError("entries", "collectionUniqueKey.one.failed", true);
90 assertFieldInError("entries", "collectionUniqueKey.two.failed", false);
91 assertFieldInError("entries", "collectionUniqueKey.three.failed", false);
92 assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
93
94
95
96 bean.setEntries(Arrays.asList(beanEntry, beanEntry3));
97 assertFieldInError("entries", "collectionUniqueKey.one.failed", true);
98 assertFieldInError("entries", "collectionUniqueKey.two.failed", true);
99 assertFieldInError("entries", "collectionUniqueKey.three.failed", true);
100 assertFieldInError("entries", "collectionUniqueKey.four.failed", false);
101
102 beanEntry.setStringValue2("stringValue2");
103
104 bean.setEntries(Arrays.asList(beanEntry, beanEntry3));
105 assertFieldInError("entries", "collectionUniqueKey.one.failed", true);
106 assertFieldInError("entries", "collectionUniqueKey.two.failed", true);
107 assertFieldInError("entries", "collectionUniqueKey.three.failed", true);
108 assertFieldInError("entries", "collectionUniqueKey.four.failed", true);
109
110
111 }
112 }