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;
23
24 import com.google.common.collect.Sets;
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.nuiton.validator.NuitonValidator;
28 import org.nuiton.validator.NuitonValidatorModel;
29 import org.nuiton.validator.NuitonValidatorResult;
30 import org.nuiton.validator.ValidatorTestHelper;
31 import org.nuiton.validator.model.Family;
32 import org.nuiton.validator.model.Person;
33
34
35
36
37
38
39
40 public class XWork2NuitonValidatorTest {
41
42 @Test
43 public void testNewValidator() throws Exception {
44
45 XWork2NuitonValidatorProvider provider =
46 new XWork2NuitonValidatorProvider();
47
48
49 NuitonValidatorModel<Person> model =
50 provider.getModel(Person.class, null);
51
52 NuitonValidator<Person> validator = provider.newValidator(model);
53
54 Assert.assertNotNull(validator);
55
56 ValidatorTestHelper.testPerson(validator);
57
58 }
59
60 @Test
61 public void testNewValidator2() throws Exception {
62
63 XWork2NuitonValidatorProvider provider =
64 new XWork2NuitonValidatorProvider();
65
66 NuitonValidatorModel<Family> model =
67 provider.getModel(Family.class, null);
68
69 NuitonValidator<Family> validator = provider.newValidator(model);
70
71 Assert.assertNotNull(validator);
72
73 Family f = new Family();
74 Person father = new Person();
75 Person mother = new Person();
76 f.setMember(Sets.newHashSet(father, mother));
77
78 NuitonValidatorResult validate = validator.validate(f);
79
80 Assert.assertFalse(validate.isValid());
81
82 father.setFirstname("john");
83 father.setName("smith");
84 mother.setFirstname("jim");
85 mother.setName("smith");
86
87 validate = validator.validate(f);
88
89 Assert.assertTrue(validate.isValid());
90 }
91 }