diff options
Diffstat (limited to 'server/src/test/java')
7 files changed, 229 insertions, 58 deletions
diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java index 4950ef5bef..ca8c4d9849 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java @@ -21,25 +21,24 @@ import java.util.TimeZone; import org.junit.Test; -import com.vaadin.legacy.ui.LegacyDateField; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.DateField; /** - * Tests the declarative support for implementations of {@link LegacyDateField}. + * Tests the declarative support for implementations of {@link DateField}. * * @author Vaadin Ltd * @since 7.4 */ -public class DateFieldDeclarativeTest - extends DeclarativeTestBase<LegacyDateField> { +public class DateFieldDeclarativeTest extends DeclarativeTestBase<DateField> { private String getYearResolutionDesign() { - return "<com_vaadin_legacy_ui-legacy-date-field resolution='year' value='2020'/>"; + return "<vaadin-date-field resolution='year' value='2020'/>"; } - private LegacyDateField getYearResolutionExpected() { - LegacyDateField df = new LegacyDateField(); + private DateField getYearResolutionExpected() { + DateField df = new DateField(); df.setResolution(Resolution.YEAR); df.setValue(new Date(2020 - 1900, 1 - 1, 1)); return df; @@ -48,12 +47,12 @@ public class DateFieldDeclarativeTest private String getTimezoneDesign() { String timeZone = new SimpleDateFormat("Z").format(new Date()); return String.format( - "<com_vaadin_legacy_ui-legacy-date-field 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\"/>", + "<vaadin-date-field 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(); + private DateField getTimezoneExpected() { + DateField df = new DateField(); df.setRangeStart(new Date(2014 - 1900, 5 - 1, 5)); df.setRangeEnd(new Date(2014 - 1900, 6 - 1, 5)); @@ -99,9 +98,9 @@ public class DateFieldDeclarativeTest public void testReadOnlyValue() { Date date = new Date(2020 - 1900, 1 - 1, 1); String timeZone = new SimpleDateFormat("Z").format(date); - String design = "<com_vaadin_legacy_ui-legacy-date-field readonly resolution='year' value='2020-01-01 00:00:00" + String design = "<vaadin-date-field readonly resolution='year' value='2020-01-01 00:00:00" + timeZone + "'/>"; - LegacyDateField df = new LegacyDateField(); + DateField df = new DateField(); df.setResolution(Resolution.YEAR); df.setValue(date); df.setReadOnly(true); @@ -109,12 +108,4 @@ public class DateFieldDeclarativeTest 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_legacy_ui:com.vaadin.legacy.ui'></head> " - + design + "</html>", - expected); - } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java index bd0af5361e..8885573bd8 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldListenersTest.java @@ -6,20 +6,20 @@ import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.FocusEvent; import com.vaadin.event.FieldEvents.FocusListener; -import com.vaadin.legacy.ui.LegacyDateField; import com.vaadin.tests.server.component.AbstractListenerMethodsTestBase; +import com.vaadin.ui.DateField; public class DateFieldListenersTest extends AbstractListenerMethodsTestBase { @Test public void testFocusListenerAddGetRemove() throws Exception { - testListenerAddGetRemove(LegacyDateField.class, FocusEvent.class, + testListenerAddGetRemove(DateField.class, FocusEvent.class, FocusListener.class); } @Test public void testBlurListenerAddGetRemove() throws Exception { - testListenerAddGetRemove(LegacyDateField.class, BlurEvent.class, + testListenerAddGetRemove(DateField.class, BlurEvent.class, BlurListener.class); } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java index 77c5a23c73..1ea1dc8f4a 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java @@ -21,36 +21,36 @@ import java.text.SimpleDateFormat; import org.junit.Test; -import com.vaadin.legacy.ui.LegacyDateField; -import com.vaadin.legacy.ui.LegacyInlineDateField; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.DateField; +import com.vaadin.ui.InlineDateField; import com.vaadin.ui.declarative.Design; /** - * Tests the declarative support for implementations of {@link LegacyDateField}. + * Tests the declarative support for implementations of {@link DateField}. * * @since 7.4 * @author Vaadin Ltd */ -public class InlineDateFieldDeclarativeTest extends - DeclarativeTestBase<LegacyInlineDateField> { +public class InlineDateFieldDeclarativeTest + extends DeclarativeTestBase<InlineDateField> { @Test public void testInlineDateFieldToFromDesign() throws Exception { - LegacyInlineDateField field = new LegacyInlineDateField("Day is", + InlineDateField field = new InlineDateField("Day is", new SimpleDateFormat("yyyy-MM-dd").parse("2003-02-27")); field.setResolution(Resolution.DAY); field.setShowISOWeekNumbers(true); - field.setRangeStart(new SimpleDateFormat("yyyy-MM-dd") - .parse("2001-02-27")); - field.setRangeEnd(new SimpleDateFormat("yyyy-MM-dd") - .parse("2011-02-27")); + field.setRangeStart( + new SimpleDateFormat("yyyy-MM-dd").parse("2001-02-27")); + field.setRangeEnd( + new SimpleDateFormat("yyyy-MM-dd").parse("2011-02-27")); ByteArrayOutputStream bos = new ByteArrayOutputStream(); Design.write(field, bos); - LegacyInlineDateField result = (LegacyInlineDateField) Design + InlineDateField result = (InlineDateField) Design .read(new ByteArrayInputStream(bos.toByteArray())); assertEquals(field.getResolution(), result.getResolution()); assertEquals(field.getCaption(), result.getCaption()); diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java new file mode 100644 index 0000000000..c3cc896fd8 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyDateFieldDeclarativeTest.java @@ -0,0 +1,120 @@ +/* + * Copyright 2000-2014 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.legacy.ui.LegacyDateField; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.tests.design.DeclarativeTestBase; + +/** + * Tests the declarative support for implementations of {@link LegacyDateField}. + * + * @author Vaadin Ltd + * @since 7.4 + */ +public class LegacyDateFieldDeclarativeTest + extends DeclarativeTestBase<LegacyDateField> { + + private String getYearResolutionDesign() { + return "<com_vaadin_legacy_ui-legacy-date-field 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( + "<com_vaadin_legacy_ui-legacy-date-field 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 = "<com_vaadin_legacy_ui-legacy-date-field 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_legacy_ui:com.vaadin.legacy.ui'></head> " + + design + "</html>", + expected); + } +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java new file mode 100644 index 0000000000..a4ef67e100 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/LegacyPopupDateFieldDeclarativeTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2000-2014 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.legacy.ui.LegacyPopupDateField; +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.tests.design.DeclarativeTestBase; + +/** + * Tests the declarative support for implementations of + * {@link LegacyPopupDateField}. + * + * @since 7.4 + * @author Vaadin Ltd + */ +public class LegacyPopupDateFieldDeclarativeTest + extends DeclarativeTestBase<LegacyPopupDateField> { + + private String getBasicDesign() { + return "<com_vaadin_legacy_ui-legacy-popup-date-field 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_legacy_ui:com.vaadin.legacy.ui'></head> " + + design + "</html>", + expected); + } +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java index f22583e1ae..c2595eaf98 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java @@ -19,26 +19,26 @@ import java.util.Date; import org.junit.Test; -import com.vaadin.legacy.ui.LegacyDateField; -import com.vaadin.legacy.ui.LegacyPopupDateField; import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.DateField; +import com.vaadin.ui.PopupDateField; /** - * Tests the declarative support for implementations of {@link LegacyDateField}. + * Tests the declarative support for implementations of {@link DateField}. * * @since 7.4 * @author Vaadin Ltd */ public class PopupDateFieldDeclarativeTest - extends DeclarativeTestBase<LegacyPopupDateField> { + extends DeclarativeTestBase<PopupDateField> { private String getBasicDesign() { - return "<com_vaadin_legacy_ui-legacy-popup-date-field 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>"; + return "<vaadin-popup-date-field 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(); + private PopupDateField getBasicExpected() { + PopupDateField pdf = new PopupDateField(); pdf.setShowISOWeekNumbers(true); pdf.setResolution(Resolution.MINUTE); pdf.setRangeEnd(new Date(2019 - 1900, 1 - 1, 15)); @@ -59,12 +59,4 @@ public class PopupDateFieldDeclarativeTest 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_legacy_ui:com.vaadin.legacy.ui'></head> " - + design + "</html>", - expected); - } } diff --git a/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java b/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java index d8c75fb795..43bfefc681 100644 --- a/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java +++ b/server/src/test/java/com/vaadin/ui/DateFieldTestCase.java @@ -1,24 +1,22 @@ package com.vaadin.ui; -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.legacy.ui.LegacyDateField; - -import java.util.Date; - import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNull.nullValue; +import java.util.Date; + +import org.junit.Before; +import org.junit.Test; + public class DateFieldTestCase { - private LegacyDateField dateField; + private DateField dateField; private Date date; @Before public void setup() { - dateField = new LegacyDateField(); + dateField = new DateField(); date = new Date(); } |