View Javadoc
1   /*
2    * #%L
3    * Nuiton Validator
4    * %%
5    * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
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   * To test {@link XWork2NuitonValidator}.
36   *
37   * @author Tony Chemit - chemit@codelutin.com
38   * @since 2.0
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"); // since 18 mai 2013 possible in France!
85          mother.setName("smith");
86  
87          validate = validator.validate(f);
88  
89          Assert.assertTrue(validate.isValid());
90      }
91  }