aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-08-18 23:07:28 +0300
committerArtur Signell <artur@vaadin.com>2016-08-20 11:00:13 +0300
commitdd5870249c4eeb12a6ae2865c36ac9b687220206 (patch)
treee8037d4fc8003b75dcacede3e9971b1ce9b827ed /compatibility-server/src/test
parentcfe379885275aae74b88c22ec4dd1bd3a8a094bd (diff)
downloadvaadin-framework-dd5870249c4eeb12a6ae2865c36ac9b687220206.tar.gz
vaadin-framework-dd5870249c4eeb12a6ae2865c36ac9b687220206.zip
Move DateField and old validators to compatibility package
Change-Id: I800db8383171280c01eb427e121467a37acbca66
Diffstat (limited to 'compatibility-server/src/test')
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigDecimalRangeValidatorTest.java60
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigIntegerRangeValidatorTest.java60
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/ByteRangeValidatorTest.java59
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/CompositeValidatorTest.java124
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/DateRangeValidatorTest.java106
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/DoubleRangeValidatorTest.java52
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/EmailValidatorTest.java31
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/FloatRangeValidatorTest.java54
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/IntegerRangeValidatorTest.java52
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/LongRangeValidatorTest.java52
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/NullValidatorTest.java47
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/RegexpValidatorTest.java53
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/ShortRangeValidatorTest.java60
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/data/validator/StringLengthValidatorTest.java77
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldConverterTest.java79
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java124
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java73
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithConverterAndValidatorTest.java49
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatterTest.java111
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithValidatorTest.java179
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/validation/RangeValidatorTest.java63
-rw-r--r--compatibility-server/src/test/java/com/vaadin/tests/server/validation/ReadOnlyValidationTest.java17
22 files changed, 1582 insertions, 0 deletions
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigDecimalRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigDecimalRangeValidatorTest.java
new file mode 100644
index 0000000000..3fe6d1f6ff
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigDecimalRangeValidatorTest.java
@@ -0,0 +1,60 @@
+package com.vaadin.tests.data.validator;
+
+import java.math.BigDecimal;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyBigDecimalRangeValidator;
+
+public class BigDecimalRangeValidatorTest {
+
+ private LegacyBigDecimalRangeValidator cleanValidator = new LegacyBigDecimalRangeValidator(
+ "no values", null, null);
+ private LegacyBigDecimalRangeValidator minValidator = new LegacyBigDecimalRangeValidator(
+ "no values", new BigDecimal(10.1), null);
+ private LegacyBigDecimalRangeValidator maxValidator = new LegacyBigDecimalRangeValidator(
+ "no values", null, new BigDecimal(100.1));
+ private LegacyBigDecimalRangeValidator minMaxValidator = new LegacyBigDecimalRangeValidator(
+ "no values", new BigDecimal(10.5), new BigDecimal(100.5));
+
+ @Test
+ public void testNullValue() {
+ Assert.assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", maxValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ Assert.assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(new BigDecimal(-15.0)));
+ Assert.assertTrue("Didn't accept valid value",
+ minValidator.isValid(new BigDecimal(10.1)));
+ Assert.assertFalse("Accepted too small value",
+ minValidator.isValid(new BigDecimal(10.0)));
+ }
+
+ @Test
+ public void testMaxValue() {
+ Assert.assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(new BigDecimal(1120.0)));
+ Assert.assertTrue("Didn't accept valid value",
+ maxValidator.isValid(new BigDecimal(15.0)));
+ Assert.assertFalse("Accepted too large value",
+ maxValidator.isValid(new BigDecimal(100.6)));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ Assert.assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(new BigDecimal(10.5)));
+ Assert.assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(new BigDecimal(100.5)));
+ Assert.assertFalse("Accepted too small value",
+ minMaxValidator.isValid(new BigDecimal(10.4)));
+ Assert.assertFalse("Accepted too large value",
+ minMaxValidator.isValid(new BigDecimal(100.6)));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigIntegerRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigIntegerRangeValidatorTest.java
new file mode 100644
index 0000000000..c54e868e64
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/BigIntegerRangeValidatorTest.java
@@ -0,0 +1,60 @@
+package com.vaadin.tests.data.validator;
+
+import java.math.BigInteger;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyBigIntegerRangeValidator;
+
+public class BigIntegerRangeValidatorTest {
+
+ private LegacyBigIntegerRangeValidator cleanValidator = new LegacyBigIntegerRangeValidator(
+ "no values", null, null);
+ private LegacyBigIntegerRangeValidator minValidator = new LegacyBigIntegerRangeValidator(
+ "no values", BigInteger.valueOf(10), null);
+ private LegacyBigIntegerRangeValidator maxValidator = new LegacyBigIntegerRangeValidator(
+ "no values", null, BigInteger.valueOf(100));
+ private LegacyBigIntegerRangeValidator minMaxValidator = new LegacyBigIntegerRangeValidator(
+ "no values", BigInteger.valueOf(10), BigInteger.valueOf(100));
+
+ @Test
+ public void testNullValue() {
+ Assert.assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", maxValidator.isValid(null));
+ Assert.assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ Assert.assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(BigInteger.valueOf(-15)));
+ Assert.assertTrue("Didn't accept valid value",
+ minValidator.isValid(BigInteger.valueOf(15)));
+ Assert.assertFalse("Accepted too small value",
+ minValidator.isValid(BigInteger.valueOf(9)));
+ }
+
+ @Test
+ public void testMaxValue() {
+ Assert.assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(BigInteger.valueOf(1120)));
+ Assert.assertTrue("Didn't accept valid value",
+ maxValidator.isValid(BigInteger.valueOf(15)));
+ Assert.assertFalse("Accepted too large value",
+ maxValidator.isValid(BigInteger.valueOf(120)));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ Assert.assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(BigInteger.valueOf(15)));
+ Assert.assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(BigInteger.valueOf(99)));
+ Assert.assertFalse("Accepted too small value",
+ minMaxValidator.isValid(BigInteger.valueOf(9)));
+ Assert.assertFalse("Accepted too large value",
+ minMaxValidator.isValid(BigInteger.valueOf(110)));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/ByteRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/ByteRangeValidatorTest.java
new file mode 100644
index 0000000000..fa6dd8f098
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/ByteRangeValidatorTest.java
@@ -0,0 +1,59 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyByteRangeValidator;
+
+public class ByteRangeValidatorTest {
+
+ private LegacyByteRangeValidator cleanValidator = new LegacyByteRangeValidator(
+ "no values", null, null);
+ private LegacyByteRangeValidator minValidator = new LegacyByteRangeValidator(
+ "no values", (byte) 10, null);
+ private LegacyByteRangeValidator maxValidator = new LegacyByteRangeValidator(
+ "no values", null, (byte) 100);
+ private LegacyByteRangeValidator minMaxValidator = new LegacyByteRangeValidator(
+ "no values", (byte) 10, (byte) 100);
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((byte) -15));
+ assertTrue("Didn't accept valid value",
+ minValidator.isValid((byte) 15));
+ assertFalse("Accepted too small value", minValidator.isValid((byte) 9));
+ }
+
+ @Test
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((byte) 112));
+ assertTrue("Didn't accept valid value",
+ maxValidator.isValid((byte) 15));
+ assertFalse("Accepted too large value",
+ maxValidator.isValid((byte) 120));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((byte) 15));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((byte) 99));
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid((byte) 9));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid((byte) 110));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/CompositeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/CompositeValidatorTest.java
new file mode 100644
index 0000000000..2975331e8a
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/CompositeValidatorTest.java
@@ -0,0 +1,124 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.v7.data.Validator;
+import com.vaadin.v7.data.validator.LegacyCompositeValidator;
+import com.vaadin.v7.data.validator.LegacyCompositeValidator.CombinationMode;
+import com.vaadin.v7.data.validator.LegacyEmailValidator;
+import com.vaadin.v7.data.validator.LegacyRegexpValidator;
+
+public class CompositeValidatorTest {
+
+ LegacyCompositeValidator and = new LegacyCompositeValidator(
+ CombinationMode.AND, "One validator not valid");
+ LegacyCompositeValidator or = new LegacyCompositeValidator(
+ CombinationMode.OR, "No validators are valid");
+ LegacyEmailValidator email = new LegacyEmailValidator("Faulty email");
+ LegacyRegexpValidator regex = new LegacyRegexpValidator("@mail.com", false,
+ "Partial match validator error");
+
+ @Before
+ public void setUp() {
+ and.addValidator(email);
+ and.addValidator(regex);
+
+ or.addValidator(email);
+ or.addValidator(regex);
+ }
+
+ @Test
+ public void testCorrectValue() {
+ String testString = "user@mail.com";
+ assertTrue(email.isValid(testString));
+ assertTrue(regex.isValid(testString));
+ try {
+ // notNull.validate(null);
+ // fail("expected null to fail with an exception");
+ and.validate(testString);
+ } catch (Validator.InvalidValueException ex) {
+ // assertEquals("Null not accepted", ex.getMessage());
+ fail("And validator should be valid");
+ }
+ try {
+ or.validate(testString);
+ } catch (Validator.InvalidValueException ex) {
+ // assertEquals("Null not accepted", ex.getMessage());
+ fail("And validator should be valid");
+ }
+ }
+
+ @Test
+ public void testCorrectRegex() {
+
+ String testString = "@mail.com";
+ assertFalse(testString + " should not validate",
+ email.isValid(testString));
+ assertTrue(testString + "should validate", regex.isValid(testString));
+ try {
+ // notNull.validate(null);
+ and.validate(testString);
+ fail("expected and to fail with an exception");
+ } catch (Validator.InvalidValueException ex) {
+ assertEquals("Faulty email", ex.getMessage());
+ // fail("And validator should be valid");
+ }
+ try {
+ or.validate(testString);
+ } catch (Validator.InvalidValueException ex) {
+ // assertEquals("Null not accepted", ex.getMessage());
+ fail("Or validator should be valid");
+ }
+ }
+
+ @Test
+ public void testCorrectEmail() {
+
+ String testString = "user@gmail.com";
+
+ assertTrue(testString + " should validate", email.isValid(testString));
+ assertFalse(testString + " should not validate",
+ regex.isValid(testString));
+ try {
+ and.validate(testString);
+ fail("expected and to fail with an exception");
+ } catch (Validator.InvalidValueException ex) {
+ assertEquals("Partial match validator error", ex.getMessage());
+ }
+ try {
+ or.validate(testString);
+ } catch (Validator.InvalidValueException ex) {
+ fail("Or validator should be valid");
+ }
+ }
+
+ @Test
+ public void testBothFaulty() {
+
+ String testString = "gmail.com";
+
+ assertFalse(testString + " should not validate",
+ email.isValid(testString));
+ assertFalse(testString + " should not validate",
+ regex.isValid(testString));
+ try {
+ and.validate(testString);
+ fail("expected and to fail with an exception");
+ } catch (Validator.InvalidValueException ex) {
+ assertEquals("Faulty email", ex.getMessage());
+ }
+ try {
+ or.validate(testString);
+ fail("expected or to fail with an exception");
+ } catch (Validator.InvalidValueException ex) {
+ assertEquals("No validators are valid", ex.getMessage());
+ }
+ }
+
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/DateRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/DateRangeValidatorTest.java
new file mode 100644
index 0000000000..a0afc9c617
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/DateRangeValidatorTest.java
@@ -0,0 +1,106 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.v7.data.validator.LegacyDateRangeValidator;
+
+public class DateRangeValidatorTest {
+ Calendar startDate = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
+ Locale.ENGLISH);
+ Calendar endDate = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
+ Locale.ENGLISH);
+
+ private LegacyDateRangeValidator cleanValidator;
+ private LegacyDateRangeValidator minValidator;
+ private LegacyDateRangeValidator maxValidator;
+ private LegacyDateRangeValidator minMaxValidator;
+
+ @Before
+ public void setUp() {
+ startDate.set(2000, Calendar.JANUARY, 1, 12, 0, 0);
+ endDate.set(2000, Calendar.FEBRUARY, 20, 12, 0, 0);
+
+ cleanValidator = new LegacyDateRangeValidator(
+ "Given date outside range", null, null, Resolution.DAY);
+ minValidator = new LegacyDateRangeValidator(
+ "Given date before startDate", startDate.getTime(), null,
+ Resolution.DAY);
+ maxValidator = new LegacyDateRangeValidator("Given date after endDate",
+ null, endDate.getTime(), Resolution.DAY);
+ minMaxValidator = new LegacyDateRangeValidator(
+ "Given date outside range", startDate.getTime(),
+ endDate.getTime(), Resolution.DAY);
+ }
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
+ Locale.ENGLISH);
+ cal.setTime(startDate.getTime());
+ cal.add(Calendar.SECOND, 1);
+
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(cal.getTime()));
+ assertTrue("Didn't accept valid value",
+ minValidator.isValid(cal.getTime()));
+
+ cal.add(Calendar.SECOND, -3);
+
+ assertFalse("Accepted too small value",
+ minValidator.isValid(cal.getTime()));
+ }
+
+ @Test
+ public void testMaxValue() {
+ Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
+ Locale.ENGLISH);
+ cal.setTime(endDate.getTime());
+ cal.add(Calendar.SECOND, -1);
+
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(cal.getTime()));
+ assertTrue("Didn't accept valid value",
+ maxValidator.isValid(cal.getTime()));
+
+ cal.add(Calendar.SECOND, 2);
+ assertFalse("Accepted too large value",
+ maxValidator.isValid(cal.getTime()));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT"),
+ Locale.ENGLISH);
+ cal.setTime(endDate.getTime());
+
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(cal.getTime()));
+ cal.add(Calendar.SECOND, 1);
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid(cal.getTime()));
+ cal.setTime(startDate.getTime());
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(cal.getTime()));
+ cal.add(Calendar.SECOND, -1);
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid(cal.getTime()));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/DoubleRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/DoubleRangeValidatorTest.java
new file mode 100644
index 0000000000..ec3a34bfa6
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/DoubleRangeValidatorTest.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyDoubleRangeValidator;
+
+public class DoubleRangeValidatorTest {
+
+ private LegacyDoubleRangeValidator cleanValidator = new LegacyDoubleRangeValidator(
+ "no values", null, null);
+ private LegacyDoubleRangeValidator minValidator = new LegacyDoubleRangeValidator(
+ "no values", 10.1, null);
+ private LegacyDoubleRangeValidator maxValidator = new LegacyDoubleRangeValidator(
+ "no values", null, 100.1);
+ private LegacyDoubleRangeValidator minMaxValidator = new LegacyDoubleRangeValidator(
+ "no values", 10.5, 100.5);
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(-15.0));
+ assertTrue("Didn't accept valid value", minValidator.isValid(10.1));
+ assertFalse("Accepted too small value", minValidator.isValid(10.0));
+ }
+
+ @Test
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(1120.0));
+ assertTrue("Didn't accept valid value", maxValidator.isValid(15.0));
+ assertFalse("Accepted too large value", maxValidator.isValid(100.6));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(10.5));
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(100.5));
+ assertFalse("Accepted too small value", minMaxValidator.isValid(10.4));
+ assertFalse("Accepted too large value", minMaxValidator.isValid(100.6));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/EmailValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/EmailValidatorTest.java
new file mode 100644
index 0000000000..92eef3d4b8
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/EmailValidatorTest.java
@@ -0,0 +1,31 @@
+package com.vaadin.tests.data.validator;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyEmailValidator;
+
+public class EmailValidatorTest {
+
+ private LegacyEmailValidator validator = new LegacyEmailValidator("Error");
+
+ @Test
+ public void testEmailValidatorWithNull() {
+ Assert.assertTrue(validator.isValid(null));
+ }
+
+ @Test
+ public void testEmailValidatorWithEmptyString() {
+ Assert.assertTrue(validator.isValid(""));
+ }
+
+ @Test
+ public void testEmailValidatorWithFaultyString() {
+ Assert.assertFalse(validator.isValid("not.an.email"));
+ }
+
+ @Test
+ public void testEmailValidatorWithOkEmail() {
+ Assert.assertTrue(validator.isValid("my.name@email.com"));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/FloatRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/FloatRangeValidatorTest.java
new file mode 100644
index 0000000000..36bd41864c
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/FloatRangeValidatorTest.java
@@ -0,0 +1,54 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyFloatRangeValidator;
+
+public class FloatRangeValidatorTest {
+
+ private LegacyFloatRangeValidator cleanValidator = new LegacyFloatRangeValidator(
+ "no values", null, null);
+ private LegacyFloatRangeValidator minValidator = new LegacyFloatRangeValidator(
+ "no values", 10.1f, null);
+ private LegacyFloatRangeValidator maxValidator = new LegacyFloatRangeValidator(
+ "no values", null, 100.1f);
+ private LegacyFloatRangeValidator minMaxValidator = new LegacyFloatRangeValidator(
+ "no values", 10.5f, 100.5f);
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(-15.0f));
+ assertTrue("Didn't accept valid value", minValidator.isValid(10.1f));
+ assertFalse("Accepted too small value", minValidator.isValid(10.0f));
+ }
+
+ @Test
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(1120.0f));
+ assertTrue("Didn't accept valid value", maxValidator.isValid(15.0f));
+ assertFalse("Accepted too large value", maxValidator.isValid(100.6f));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(10.5f));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid(100.5f));
+ assertFalse("Accepted too small value", minMaxValidator.isValid(10.4f));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid(100.6f));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/IntegerRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/IntegerRangeValidatorTest.java
new file mode 100644
index 0000000000..595d5f4ab8
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/IntegerRangeValidatorTest.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyIntegerRangeValidator;
+
+public class IntegerRangeValidatorTest {
+
+ private LegacyIntegerRangeValidator cleanValidator = new LegacyIntegerRangeValidator(
+ "no values", null, null);
+ private LegacyIntegerRangeValidator minValidator = new LegacyIntegerRangeValidator(
+ "no values", 10, null);
+ private LegacyIntegerRangeValidator maxValidator = new LegacyIntegerRangeValidator(
+ "no values", null, 100);
+ private LegacyIntegerRangeValidator minMaxValidator = new LegacyIntegerRangeValidator(
+ "no values", 10, 100);
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(-15));
+ assertTrue("Didn't accept valid value", minValidator.isValid(15));
+ assertFalse("Accepted too small value", minValidator.isValid(9));
+ }
+
+ @Test
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(1120));
+ assertTrue("Didn't accept valid value", maxValidator.isValid(15));
+ assertFalse("Accepted too large value", maxValidator.isValid(120));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(15));
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(99));
+ assertFalse("Accepted too small value", minMaxValidator.isValid(9));
+ assertFalse("Accepted too large value", minMaxValidator.isValid(110));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/LongRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/LongRangeValidatorTest.java
new file mode 100644
index 0000000000..6ecd21984c
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/LongRangeValidatorTest.java
@@ -0,0 +1,52 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyLongRangeValidator;
+
+public class LongRangeValidatorTest {
+
+ private LegacyLongRangeValidator cleanValidator = new LegacyLongRangeValidator(
+ "no values", null, null);
+ private LegacyLongRangeValidator minValidator = new LegacyLongRangeValidator(
+ "no values", 10l, null);
+ private LegacyLongRangeValidator maxValidator = new LegacyLongRangeValidator(
+ "no values", null, 100l);
+ private LegacyLongRangeValidator minMaxValidator = new LegacyLongRangeValidator(
+ "no values", 10l, 100l);
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(-15l));
+ assertTrue("Didn't accept valid value", minValidator.isValid(15l));
+ assertFalse("Accepted too small value", minValidator.isValid(9l));
+ }
+
+ @Test
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid(1120l));
+ assertTrue("Didn't accept valid value", maxValidator.isValid(15l));
+ assertFalse("Accepted too large value", maxValidator.isValid(120l));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(15l));
+ assertTrue("Didn't accept valid value", minMaxValidator.isValid(99l));
+ assertFalse("Accepted too small value", minMaxValidator.isValid(9l));
+ assertFalse("Accepted too large value", minMaxValidator.isValid(110l));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/NullValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/NullValidatorTest.java
new file mode 100644
index 0000000000..6e43b30cdf
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/NullValidatorTest.java
@@ -0,0 +1,47 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.Validator;
+import com.vaadin.v7.data.validator.LegacyNullValidator;
+
+public class NullValidatorTest {
+
+ LegacyNullValidator notNull = new LegacyNullValidator("Null not accepted",
+ false);
+ LegacyNullValidator onlyNull = new LegacyNullValidator("Only null accepted",
+ true);
+
+ @Test
+ public void testNullValue() {
+ try {
+ notNull.validate(null);
+ fail("expected null to fail with an exception");
+ } catch (Validator.InvalidValueException ex) {
+ assertEquals("Null not accepted", ex.getMessage());
+ }
+ try {
+ onlyNull.validate(null);
+ } catch (Validator.InvalidValueException ex) {
+ fail("onlyNull should not throw exception for null");
+ }
+ }
+
+ @Test
+ public void testNonNullValue() {
+ try {
+ onlyNull.validate("Not a null value");
+ fail("expected onlyNull validator to fail with an exception");
+ } catch (Validator.InvalidValueException ex) {
+ assertEquals("Only null accepted", ex.getMessage());
+ }
+ try {
+ notNull.validate("Not a null value");
+ } catch (Validator.InvalidValueException ex) {
+ fail("notNull should not throw exception for \"Not a null value\"");
+ }
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/RegexpValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/RegexpValidatorTest.java
new file mode 100644
index 0000000000..1768999969
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/RegexpValidatorTest.java
@@ -0,0 +1,53 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyRegexpValidator;
+
+public class RegexpValidatorTest {
+
+ private LegacyRegexpValidator completeValidator = new LegacyRegexpValidator(
+ "pattern", true, "Complete match validator error");
+ private LegacyRegexpValidator partialValidator = new LegacyRegexpValidator(
+ "pattern", false, "Partial match validator error");
+
+ @Test
+ public void testRegexpValidatorWithNull() {
+ assertTrue(completeValidator.isValid(null));
+ assertTrue(partialValidator.isValid(null));
+ }
+
+ @Test
+ public void testRegexpValidatorWithEmptyString() {
+ assertTrue(completeValidator.isValid(""));
+ assertTrue(partialValidator.isValid(""));
+ }
+
+ @Test
+ public void testCompleteRegexpValidatorWithFaultyString() {
+ assertFalse(completeValidator.isValid("mismatch"));
+ assertFalse(completeValidator.isValid("pattern2"));
+ assertFalse(completeValidator.isValid("1pattern"));
+ }
+
+ @Test
+ public void testCompleteRegexpValidatorWithOkString() {
+ assertTrue(completeValidator.isValid("pattern"));
+ }
+
+ @Test
+ public void testPartialRegexpValidatorWithFaultyString() {
+ assertFalse(partialValidator.isValid("mismatch"));
+ }
+
+ @Test
+ public void testPartialRegexpValidatorWithOkString() {
+ assertTrue(partialValidator.isValid("pattern"));
+ assertTrue(partialValidator.isValid("1pattern"));
+ assertTrue(partialValidator.isValid("pattern2"));
+ assertTrue(partialValidator.isValid("1pattern2"));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/ShortRangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/ShortRangeValidatorTest.java
new file mode 100644
index 0000000000..41c3e67942
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/ShortRangeValidatorTest.java
@@ -0,0 +1,60 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyShortRangeValidator;
+
+public class ShortRangeValidatorTest {
+
+ private LegacyShortRangeValidator cleanValidator = new LegacyShortRangeValidator(
+ "no values", null, null);
+ private LegacyShortRangeValidator minValidator = new LegacyShortRangeValidator(
+ "no values", (short) 10, null);
+ private LegacyShortRangeValidator maxValidator = new LegacyShortRangeValidator(
+ "no values", null, (short) 100);
+ private LegacyShortRangeValidator minMaxValidator = new LegacyShortRangeValidator(
+ "no values", (short) 10, (short) 100);
+
+ @Test
+ public void testNullValue() {
+ assertTrue("Didn't accept null", cleanValidator.isValid(null));
+ assertTrue("Didn't accept null", minValidator.isValid(null));
+ assertTrue("Didn't accept null", maxValidator.isValid(null));
+ assertTrue("Didn't accept null", minMaxValidator.isValid(null));
+ }
+
+ @Test
+ public void testMinValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((short) -15));
+ assertTrue("Didn't accept valid value",
+ minValidator.isValid((short) 15));
+ assertFalse("Accepted too small value",
+ minValidator.isValid((short) 9));
+ }
+
+ @Test
+ public void testMaxValue() {
+ assertTrue("Validator without ranges didn't accept value",
+ cleanValidator.isValid((short) 1120));
+ assertTrue("Didn't accept valid value",
+ maxValidator.isValid((short) 15));
+ assertFalse("Accepted too large value",
+ maxValidator.isValid((short) 120));
+ }
+
+ @Test
+ public void testMinMaxValue() {
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((short) 15));
+ assertTrue("Didn't accept valid value",
+ minMaxValidator.isValid((short) 99));
+ assertFalse("Accepted too small value",
+ minMaxValidator.isValid((short) 9));
+ assertFalse("Accepted too large value",
+ minMaxValidator.isValid((short) 110));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/data/validator/StringLengthValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/StringLengthValidatorTest.java
new file mode 100644
index 0000000000..e24e8fcd5d
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/data/validator/StringLengthValidatorTest.java
@@ -0,0 +1,77 @@
+package com.vaadin.tests.data.validator;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyStringLengthValidator;
+
+public class StringLengthValidatorTest {
+
+ private LegacyStringLengthValidator validator = new LegacyStringLengthValidator(
+ "Error");
+ private LegacyStringLengthValidator validatorNoNull = new LegacyStringLengthValidator(
+ "Error", 1, 5, false);
+ private LegacyStringLengthValidator validatorMinValue = new LegacyStringLengthValidator(
+ "Error", 5, null, true);
+ private LegacyStringLengthValidator validatorMaxValue = new LegacyStringLengthValidator(
+ "Error", null, 15, true);
+
+ @Test
+ public void testValidatorWithNull() {
+ assertTrue("Didn't accept null", validator.isValid(null));
+ assertTrue("Didn't accept null", validatorMinValue.isValid(null));
+ }
+
+ @Test
+ public void testValidatorNotAcceptingNull() {
+ assertFalse("Accepted null", validatorNoNull.isValid(null));
+ }
+
+ @Test
+ public void testEmptyString() {
+ assertTrue("Didn't accept empty String", validator.isValid(""));
+ assertTrue("Didn't accept empty String", validatorMaxValue.isValid(""));
+ assertFalse("Accepted empty string even though has lower bound of 1",
+ validatorNoNull.isValid(""));
+ assertFalse("Accepted empty string even though has lower bound of 5",
+ validatorMinValue.isValid(""));
+ }
+
+ @Test
+ public void testTooLongString() {
+ assertFalse("Too long string was accepted",
+ validatorNoNull.isValid("This string is too long"));
+ assertFalse("Too long string was accepted",
+ validatorMaxValue.isValid("This string is too long"));
+ }
+
+ @Test
+ public void testNoUpperBound() {
+ assertTrue("String not accepted even though no upper bound",
+ validatorMinValue.isValid(
+ "This is a really long string to test that no upper bound exists"));
+ }
+
+ @Test
+ public void testNoLowerBound() {
+ assertTrue("Didn't accept short string", validatorMaxValue.isValid(""));
+ assertTrue("Didn't accept short string",
+ validatorMaxValue.isValid("1"));
+ }
+
+ @Test
+ public void testStringLengthValidatorWithOkStringLength() {
+ assertTrue("Didn't accept string of correct length",
+ validatorNoNull.isValid("OK!"));
+ assertTrue("Didn't accept string of correct length",
+ validatorMaxValue.isValid("OK!"));
+ }
+
+ @Test
+ public void testTooShortStringLength() {
+ assertFalse("Accepted a string that was too short.",
+ validatorMinValue.isValid("shot"));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldConverterTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldConverterTest.java
new file mode 100644
index 0000000000..5b4e8c7352
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldConverterTest.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.tests.server.component.datefield;
+
+import java.util.Date;
+import java.util.Locale;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.v7.data.util.converter.LegacyConverter;
+import com.vaadin.v7.ui.LegacyDateField;
+
+public class DateFieldConverterTest {
+
+ private Property<Long> date;
+ private LegacyDateField datefield;
+
+ @Before
+ public void setUp() {
+ date = new ObjectProperty<Long>(0L);
+ datefield = new LegacyDateField();
+ datefield.setBuffered(false);
+ datefield.setConverter(new LegacyConverter<Date, Long>() {
+
+ @Override
+ public Long convertToModel(Date value,
+ Class<? extends Long> targetType, Locale locale)
+ throws ConversionException {
+ return value.getTime();
+ }
+
+ @Override
+ public Date convertToPresentation(Long value,
+ Class<? extends Date> targetType, Locale locale)
+ throws ConversionException {
+ return new Date(value);
+ }
+
+ @Override
+ public Class<Long> getModelType() {
+ return Long.class;
+ }
+
+ @Override
+ public Class<Date> getPresentationType() {
+ return Date.class;
+ }
+ });
+ datefield.setPropertyDataSource(date);
+ }
+
+ /*
+ * See #12193.
+ */
+ @Test
+ public void testResolution() {
+ datefield.setValue(new Date(110, 0, 1));
+ datefield.setResolution(Resolution.MINUTE);
+ datefield.validate();
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java
new file mode 100644
index 0000000000..97e944a0a7
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.datefield;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.v7.ui.LegacyDateField;
+
+/**
+ * Tests the declarative support for implementations of {@link LegacyDateField}.
+ *
+ * @author Vaadin Ltd
+ * @since 7.4
+ */
+public class LegacyDateFieldDeclarativeTest
+ extends DeclarativeTestBase<LegacyDateField> {
+
+ private static final String TAG_NAME = "com_vaadin_v7_ui-legacy-date-field";
+
+ private String getYearResolutionDesign() {
+ return "<" + TAG_NAME + " resolution='year' value='2020'/>";
+ }
+
+ private LegacyDateField getYearResolutionExpected() {
+ LegacyDateField df = new LegacyDateField();
+ df.setResolution(Resolution.YEAR);
+ df.setValue(new Date(2020 - 1900, 1 - 1, 1));
+ return df;
+ }
+
+ private String getTimezoneDesign() {
+ String timeZone = new SimpleDateFormat("Z").format(new Date());
+ return String.format(
+ "<" + TAG_NAME
+ + " range-start=\"2014-05-05 00:00:00%1$s\" range-end=\"2014-06-05 00:00:00%1$s\" date-out-of-range-message=\"Please select a sensible date\" date-format=\"yyyy-MM-dd\" lenient show-iso-week-numbers parse-error-message=\"You are doing it wrong\" time-zone=\"GMT+05:00\" value=\"2014-05-15 00:00:00%1$s\"/>",
+ timeZone);
+ }
+
+ private LegacyDateField getTimezoneExpected() {
+ LegacyDateField df = new LegacyDateField();
+
+ df.setRangeStart(new Date(2014 - 1900, 5 - 1, 5));
+ df.setRangeEnd(new Date(2014 - 1900, 6 - 1, 5));
+ df.setDateOutOfRangeMessage("Please select a sensible date");
+ df.setResolution(Resolution.DAY);
+ df.setDateFormat("yyyy-MM-dd");
+ df.setLenient(true);
+ df.setShowISOWeekNumbers(true);
+ df.setParseErrorMessage("You are doing it wrong");
+ df.setTimeZone(TimeZone.getTimeZone("GMT+5"));
+ df.setValue(new Date(2014 - 1900, 5 - 1, 15));
+
+ return df;
+ }
+
+ @Test
+ public void readTimezone() {
+ testRead(getTimezoneDesign(), getTimezoneExpected());
+ }
+
+ @Test
+ public void writeTimezone() {
+ testWrite(getTimezoneDesign(), getTimezoneExpected());
+ }
+
+ @Test
+ public void readYearResolution() {
+ testRead(getYearResolutionDesign(), getYearResolutionExpected());
+ }
+
+ @Test
+ public void writeYearResolution() {
+ // Writing is always done in full resolution..
+ String timeZone = new SimpleDateFormat("Z")
+ .format(new Date(2020 - 1900, 1 - 1, 1));
+ testWrite(
+ getYearResolutionDesign().replace("2020",
+ "2020-01-01 00:00:00" + timeZone),
+ getYearResolutionExpected());
+ }
+
+ @Test
+ public void testReadOnlyValue() {
+ Date date = new Date(2020 - 1900, 1 - 1, 1);
+ String timeZone = new SimpleDateFormat("Z").format(date);
+ String design = "<" + TAG_NAME
+ + " readonly resolution='year' value='2020-01-01 00:00:00"
+ + timeZone + "'/>";
+ LegacyDateField df = new LegacyDateField();
+ df.setResolution(Resolution.YEAR);
+ df.setValue(date);
+ df.setReadOnly(true);
+
+ testRead(design, df);
+ testWrite(design, df);
+ }
+
+ @Override
+ public LegacyDateField testRead(String design, LegacyDateField expected) {
+ return super.testRead(
+ "<html><head><meta charset='UTF-8' name='package-mapping' content='com_vaadin_v7_ui:com.vaadin.v7.ui'></head> "
+ + design + "</html>",
+ expected);
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java
new file mode 100644
index 0000000000..0777a0c782
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.server.component.datefield;
+
+import java.util.Date;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.v7.ui.LegacyPopupDateField;
+
+/**
+ * Tests the declarative support for implementations of
+ * {@link LegacyPopupDateField}.
+ *
+ * @since 7.4
+ * @author Vaadin Ltd
+ */
+public class LegacyPopupDateFieldDeclarativeTest
+ extends DeclarativeTestBase<LegacyPopupDateField> {
+
+ private static final String TAG_NAME = "com_vaadin_v7_ui-legacy-popup-date-field";
+
+ private String getBasicDesign() {
+ return "<" + TAG_NAME
+ + " assistive-text='at' text-field-enabled='false' show-iso-week-numbers resolution=\"MINUTE\" range-end=\"2019-01-15\" input-prompt=\"Pick a day\" value=\"2003-02-27 07:15\"></vaadin-popup-date-field>";
+ }
+
+ private LegacyPopupDateField getBasicExpected() {
+ LegacyPopupDateField pdf = new LegacyPopupDateField();
+ pdf.setShowISOWeekNumbers(true);
+ pdf.setResolution(Resolution.MINUTE);
+ pdf.setRangeEnd(new Date(2019 - 1900, 1 - 1, 15));
+ pdf.setInputPrompt("Pick a day");
+ pdf.setValue(new Date(2003 - 1900, 2 - 1, 27, 7, 15));
+ pdf.setTextFieldEnabled(false);
+ pdf.setAssistiveText("at");
+ return pdf;
+ }
+
+ @Test
+ public void readBasic() throws Exception {
+ testRead(getBasicDesign(), getBasicExpected());
+ }
+
+ @Test
+ public void writeBasic() throws Exception {
+ testRead(getBasicDesign(), getBasicExpected());
+ }
+
+ @Override
+ public LegacyPopupDateField testRead(String design,
+ LegacyPopupDateField expected) {
+ return super.testRead(
+ "<html><head><meta charset='UTF-8' name='package-mapping' content='com_vaadin_v7_ui:com.vaadin.v7.ui'></head> "
+ + design + "</html>",
+ expected);
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithConverterAndValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithConverterAndValidatorTest.java
new file mode 100644
index 0000000000..caea12d024
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithConverterAndValidatorTest.java
@@ -0,0 +1,49 @@
+package com.vaadin.tests.server.component.textfield;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.tests.data.converter.ConverterFactoryTest.ConvertTo42;
+import com.vaadin.v7.data.validator.LegacyRangeValidator;
+import com.vaadin.v7.ui.LegacyTextField;
+
+public class TextFieldWithConverterAndValidatorTest {
+
+ private LegacyTextField field;
+ private ObjectProperty<Integer> property;
+
+ @Before
+ public void setUp() {
+ field = new LegacyTextField();
+ field.setInvalidAllowed(false);
+ }
+
+ @Test
+ public void testConvert42AndValidator() {
+ property = new ObjectProperty<Integer>(123);
+ field.setConverter(new ConvertTo42());
+ field.setPropertyDataSource(property);
+
+ field.addValidator(new LegacyRangeValidator<Integer>("Incorrect value",
+ Integer.class, 42, 42));
+
+ // succeeds
+ field.setValue("a");
+ // succeeds
+ field.setValue("42");
+ // succeeds - no validation
+ property.setValue(42);
+
+ // nulls
+
+ // succeeds - validate() converts field value back to property type
+ // before validation
+ property.setValue(null);
+ field.validate();
+ // succeeds
+ field.setValue(null);
+ }
+
+ // TODO test converter changing value to null with validator
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatterTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatterTest.java
new file mode 100644
index 0000000000..633269a0ab
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatterTest.java
@@ -0,0 +1,111 @@
+package com.vaadin.tests.server.component.textfield;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.Property;
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.data.util.PropertyFormatter;
+import com.vaadin.v7.ui.LegacyTextField;
+
+public class TextFieldWithPropertyFormatterTest {
+
+ private static final String INPUT_VALUE = "foo";
+ private static final String PARSED_VALUE = "BAR";
+ private static final String FORMATTED_VALUE = "FOOBAR";
+ private static final String ORIGINAL_VALUE = "Original";
+ private LegacyTextField field;
+ private PropertyFormatter<String> formatter;
+ private ObjectProperty<String> property;
+ private ValueChangeListener listener;
+ private int listenerCalled;
+ private int repainted;
+
+ @Before
+ public void setUp() {
+
+ field = new LegacyTextField() {
+ @Override
+ public void markAsDirty() {
+ repainted++;
+ super.markAsDirty();
+ }
+ };
+
+ formatter = new PropertyFormatter<String>() {
+
+ @Override
+ public String parse(String formattedValue) throws Exception {
+ assertEquals(INPUT_VALUE, formattedValue);
+ return PARSED_VALUE;
+ }
+
+ @Override
+ public String format(String value) {
+ return FORMATTED_VALUE;
+ }
+ };
+
+ property = new ObjectProperty<String>(ORIGINAL_VALUE);
+
+ formatter.setPropertyDataSource(property);
+ field.setPropertyDataSource(formatter);
+
+ listener = new Property.ValueChangeListener() {
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ listenerCalled++;
+ assertEquals(1, listenerCalled);
+ assertEquals(FORMATTED_VALUE, event.getProperty().getValue());
+ }
+ };
+
+ field.addListener(listener);
+ listenerCalled = 0;
+ repainted = 0;
+ }
+
+ @Test
+ public void testWithServerApi() {
+ checkInitialState();
+
+ field.setValue(INPUT_VALUE);
+
+ checkEndState();
+
+ }
+
+ private void checkEndState() {
+ assertEquals(1, listenerCalled);
+ assertTrue(repainted >= 1);
+ assertEquals(FORMATTED_VALUE, field.getValue());
+ assertEquals(FORMATTED_VALUE, formatter.getValue());
+ assertEquals(PARSED_VALUE, property.getValue());
+ }
+
+ private void checkInitialState() {
+ assertEquals(ORIGINAL_VALUE, property.getValue());
+ assertEquals(FORMATTED_VALUE, formatter.getValue());
+ assertEquals(FORMATTED_VALUE, field.getValue());
+ }
+
+ @Test
+ public void testWithSimulatedClientSideChange() {
+ checkInitialState();
+
+ field.changeVariables(null,
+ Collections.singletonMap("text", (Object) INPUT_VALUE));
+
+ checkEndState();
+
+ }
+
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithValidatorTest.java
new file mode 100644
index 0000000000..6fc2108b63
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldWithValidatorTest.java
@@ -0,0 +1,179 @@
+package com.vaadin.tests.server.component.textfield;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.vaadin.data.util.ObjectProperty;
+import com.vaadin.v7.data.Validator;
+import com.vaadin.v7.data.Validator.InvalidValueException;
+import com.vaadin.v7.data.validator.LegacyEmailValidator;
+import com.vaadin.v7.data.validator.LegacyRegexpValidator;
+import com.vaadin.v7.data.validator.LegacyStringLengthValidator;
+import com.vaadin.v7.ui.LegacyTextField;
+
+public class TextFieldWithValidatorTest {
+
+ private LegacyTextField field;
+ private ObjectProperty<String> property;
+
+ @Before
+ public void setUp() {
+
+ field = new LegacyTextField();
+ field.setInvalidAllowed(false);
+ property = new ObjectProperty<String>("original");
+ field.setPropertyDataSource(property);
+ }
+
+ @Test
+ public void testMultipleValidators() {
+ field.addValidator(new LegacyStringLengthValidator(
+ "Length not between 1 and 3", 1, 3, false));
+ field.addValidator(new LegacyStringLengthValidator(
+ "Length not between 2 and 4", 2, 4, false));
+
+ // fails
+ try {
+ field.setValue("a");
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ // succeeds
+ field.setValue("ab");
+ // fails
+ try {
+ field.setValue("abcd");
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ }
+
+ @Test
+ public void testRemoveValidator() {
+ Validator validator1 = new LegacyStringLengthValidator(
+ "Length not between 1 and 3", 1, 3, false);
+ Validator validator2 = new LegacyStringLengthValidator(
+ "Length not between 2 and 4", 2, 4, false);
+
+ field.addValidator(validator1);
+ field.addValidator(validator2);
+ field.removeValidator(validator1);
+
+ // fails
+ try {
+ field.setValue("a");
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ // succeeds
+ field.setValue("ab");
+ // succeeds
+ field.setValue("abcd");
+ }
+
+ @Test
+ public void testRemoveAllValidators() {
+ Validator validator1 = new LegacyStringLengthValidator(
+ "Length not between 1 and 3", 1, 3, false);
+ Validator validator2 = new LegacyStringLengthValidator(
+ "Length not between 2 and 4", 2, 4, false);
+
+ field.addValidator(validator1);
+ field.addValidator(validator2);
+ field.removeAllValidators();
+
+ // all should succeed now
+ field.setValue("a");
+ field.setValue("ab");
+ field.setValue("abcd");
+ }
+
+ @Test
+ public void testEmailValidator() {
+ field.addValidator(new LegacyEmailValidator("Invalid e-mail address"));
+
+ // not required
+
+ field.setRequired(false);
+ // succeeds
+ field.setValue("");
+ // needed as required flag not checked by setValue()
+ field.validate();
+ // succeeds
+ field.setValue(null);
+ // needed as required flag not checked by setValue()
+ field.validate();
+ // succeeds
+ field.setValue("test@example.com");
+ // fails
+ try {
+ field.setValue("invalid e-mail");
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+
+ // required
+
+ field.setRequired(true);
+ // fails
+ try {
+ field.setValue("");
+ // needed as required flag not checked by setValue()
+ field.validate();
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ // fails
+ try {
+ field.setValue(null);
+ // needed as required flag not checked by setValue()
+ field.validate();
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ // succeeds
+ field.setValue("test@example.com");
+ // fails
+ try {
+ field.setValue("invalid e-mail");
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ }
+
+ @Test
+ public void testRegexpValidator() {
+ field.addValidator(new LegacyRegexpValidator("pattern", true,
+ "Validation failed"));
+ field.setRequired(false);
+
+ // succeeds
+ field.setValue("");
+ // needed as required flag not checked by setValue()
+ field.validate();
+ // succeeds
+ field.setValue(null);
+ // needed as required flag not checked by setValue()
+ field.validate();
+ // succeeds
+ field.setValue("pattern");
+
+ // fails
+ try {
+ field.setValue("mismatch");
+ fail();
+ } catch (InvalidValueException e) {
+ // should fail
+ }
+ }
+
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/validation/RangeValidatorTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/validation/RangeValidatorTest.java
new file mode 100644
index 0000000000..1d5032e956
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/validation/RangeValidatorTest.java
@@ -0,0 +1,63 @@
+package com.vaadin.tests.server.validation;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyIntegerRangeValidator;
+
+public class RangeValidatorTest {
+
+ // This test uses IntegerRangeValidator for simplicity.
+ // IntegerRangeValidator contains no code so we really are testing
+ // RangeValidator
+ @Test
+ public void testMinValueNonInclusive() {
+ LegacyIntegerRangeValidator iv = new LegacyIntegerRangeValidator(
+ "Failed", 0, 10);
+ iv.setMinValueIncluded(false);
+ assertFalse(iv.isValid(0));
+ assertTrue(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+
+ @Test
+ public void testMinMaxValuesInclusive() {
+ LegacyIntegerRangeValidator iv = new LegacyIntegerRangeValidator(
+ "Failed", 0, 10);
+ assertTrue(iv.isValid(0));
+ assertTrue(iv.isValid(1));
+ assertTrue(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+
+ @Test
+ public void testMaxValueNonInclusive() {
+ LegacyIntegerRangeValidator iv = new LegacyIntegerRangeValidator(
+ "Failed", 0, 10);
+ iv.setMaxValueIncluded(false);
+ assertTrue(iv.isValid(0));
+ assertTrue(iv.isValid(9));
+ assertFalse(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+
+ @Test
+ public void testMinMaxValuesNonInclusive() {
+ LegacyIntegerRangeValidator iv = new LegacyIntegerRangeValidator(
+ "Failed", 0, 10);
+ iv.setMinValueIncluded(false);
+ iv.setMaxValueIncluded(false);
+
+ assertFalse(iv.isValid(0));
+ assertTrue(iv.isValid(1));
+ assertTrue(iv.isValid(9));
+ assertFalse(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+}
diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/validation/ReadOnlyValidationTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/validation/ReadOnlyValidationTest.java
new file mode 100644
index 0000000000..503ba455fd
--- /dev/null
+++ b/compatibility-server/src/test/java/com/vaadin/tests/server/validation/ReadOnlyValidationTest.java
@@ -0,0 +1,17 @@
+package com.vaadin.tests.server.validation;
+
+import org.junit.Test;
+
+import com.vaadin.v7.data.validator.LegacyIntegerValidator;
+import com.vaadin.v7.ui.LegacyTextField;
+
+public class ReadOnlyValidationTest {
+
+ @Test
+ public void testIntegerValidation() {
+ LegacyTextField field = new LegacyTextField();
+ field.addValidator(new LegacyIntegerValidator("Enter a Valid Number"));
+ field.setValue(String.valueOf(10));
+ field.validate();
+ }
+}