1 package org.nuiton.validator.xwork2.field;
2
3 /*
4 * #%L
5 * Nuiton Validator
6 * %%
7 * Copyright (C) 2013 - 2014 Code Lutin, Tony Chemit
8 * %%
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * #L%
23 */
24
25 import org.junit.Test;
26 import org.nuiton.validator.model.Company;
27
28 /**
29 * @author Sylvain Bavencoff - bavencoff@codelutin.com
30 */
31 public class FrenchSirenFieldValidatorTest extends AbstractFieldValidatorTest<Company> {
32
33 public FrenchSirenFieldValidatorTest() {
34 super(Company.class);
35 }
36
37 @Test
38 @Override
39 public void testValidator() throws Exception {
40
41 assertNull(bean.getSiren());
42
43 // Valid siren
44 bean.setSiren("751700782");
45 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
46 false);
47
48 // Valid siren
49 bean.setSiren("263903007");
50 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
51 false);
52
53 // Not Valid siren, because bad checksum
54 bean.setSiren("263903000");
55 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
56 true);
57
58 // Not valid siren
59 bean.setSiren("44211670");
60 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
61 true);
62
63 // Not valid siren
64 bean.setSiren("442116703000389");
65 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
66 true);
67
68 // Not valid siren
69 bean.setSiren("4421bf167");
70 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
71 true);
72
73 // Use requiredString for empty siren
74 bean.setSiren("");
75 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
76 false);
77
78 // Use required for null siren
79 bean.setSiren(null);
80 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
81 false);
82
83 // Valid siren with spaces
84 bean.setSiren("535 198 188 ");
85 assertFieldInError(Company.PROPERTY_SIREN, "company.siren.format",
86 false);
87
88 }
89 }