From 4a3cf1c18e3d29d5c9caf422a67cda2928ef718b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 4 Feb 2015 23:14:00 +0200 Subject: [PATCH] Refactored and updated (Popup|Inline|)DateField declarative tests Change-Id: I1dc27ed0a61aea0e9c263a88885e8d20c815bc92 --- .../vaadin/tests/design/DateFieldsTest.java | 99 ------------------- .../datefield/DateFieldDeclarativeTest.java | 90 +++++++++++++++++ .../InlineDateFieldDeclarativeTest.java | 62 ++++++++++++ .../PopupDateFieldDeclarativeTest.java | 62 ++++++++++++ 4 files changed, 214 insertions(+), 99 deletions(-) delete mode 100644 server/tests/src/com/vaadin/tests/design/DateFieldsTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java diff --git a/server/tests/src/com/vaadin/tests/design/DateFieldsTest.java b/server/tests/src/com/vaadin/tests/design/DateFieldsTest.java deleted file mode 100644 index b8aa6ad3c9..0000000000 --- a/server/tests/src/com/vaadin/tests/design/DateFieldsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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.design; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.text.SimpleDateFormat; -import java.util.TimeZone; - -import org.junit.Test; - -import com.vaadin.shared.ui.datefield.Resolution; -import com.vaadin.ui.DateField; -import com.vaadin.ui.InlineDateField; -import com.vaadin.ui.PopupDateField; -import com.vaadin.ui.declarative.Design; - -/** - * Tests the declarative support for implementations of {@link DateField}. - * - * @since 7.4 - * @author Vaadin Ltd - */ -public class DateFieldsTest { - - @Test - public void testInlineDateFieldToFromDesign() throws Exception { - 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")); - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - Design.write(field, bos); - - InlineDateField result = (InlineDateField) Design - .read(new ByteArrayInputStream(bos.toByteArray())); - assertEquals(field.getResolution(), result.getResolution()); - assertEquals(field.getCaption(), result.getCaption()); - assertEquals(field.getValue(), result.getValue()); - assertEquals(field.getRangeStart(), result.getRangeStart()); - assertEquals(field.getRangeEnd(), result.getRangeEnd()); - } - - @Test - public void testPopupDateFieldFromDesign() throws Exception { - ByteArrayInputStream bis = new ByteArrayInputStream( - "" - .getBytes()); - PopupDateField result = (PopupDateField) Design.read(bis); - assertEquals(Resolution.MINUTE, result.getResolution()); - assertEquals("Day is", result.getCaption()); - assertTrue(result.isShowISOWeekNumbers()); - assertEquals("Pick a day", result.getInputPrompt()); - assertEquals( - new SimpleDateFormat("yyyy-MM-dd HH:mm") - .parse("2003-02-27 07:15"), - result.getValue()); - assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("2019-01-15"), - result.getRangeEnd()); - - } - - @Test - public void testPopupDateFieldFromDesignInTicket() throws Exception { - ByteArrayInputStream bis = new ByteArrayInputStream( - "" - .getBytes()); - DateField result = (DateField) Design.read(bis); - assertEquals(Resolution.DAY, result.getResolution()); - assertTrue(result.isShowISOWeekNumbers()); - assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("2014-05-15"), - result.getValue()); - assertEquals(new SimpleDateFormat("yyyy-MM-dd").parse("2014-06-05"), - result.getRangeEnd()); - assertEquals(TimeZone.getTimeZone("GMT+5"), result.getTimeZone()); - } - -} diff --git a/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java new file mode 100644 index 0000000000..5058cf5a5f --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java @@ -0,0 +1,90 @@ +/* + * 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 java.util.TimeZone; + +import org.junit.Test; + +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 DateField}. + * + * @since 7.4 + * @author Vaadin Ltd + */ +public class DateFieldDeclarativeTest extends DeclarativeTestBase { + + private String getYearResolutionDesign() { + return ""; + } + + private DateField getYearResolutionExpected() { + DateField df = new DateField(); + df.setResolution(Resolution.YEAR); + df.setValue(new Date(2020 - 1900, 1 - 1, 1)); + return df; + } + + private String getTimezoneDesign() { + return ""; + } + + 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)); + 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.. + testWrite( + getYearResolutionDesign().replace("2020", + "2020-01-01 00:00:00+0200"), + getYearResolutionExpected()); + } +} diff --git a/server/tests/src/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java new file mode 100644 index 0000000000..04468c658a --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java @@ -0,0 +1,62 @@ +/* + * 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.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.text.SimpleDateFormat; + +import org.junit.Test; + +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 DateField}. + * + * @since 7.4 + * @author Vaadin Ltd + */ +public class InlineDateFieldDeclarativeTest extends + DeclarativeTestBase { + + @Test + public void testInlineDateFieldToFromDesign() throws Exception { + 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")); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + Design.write(field, bos); + + InlineDateField result = (InlineDateField) Design + .read(new ByteArrayInputStream(bos.toByteArray())); + assertEquals(field.getResolution(), result.getResolution()); + assertEquals(field.getCaption(), result.getCaption()); + assertEquals(field.getValue(), result.getValue()); + assertEquals(field.getRangeStart(), result.getRangeStart()); + assertEquals(field.getRangeEnd(), result.getRangeEnd()); + } + +} diff --git a/server/tests/src/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java new file mode 100644 index 0000000000..708c800300 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/datefield/PopupDateFieldDeclarativeTest.java @@ -0,0 +1,62 @@ +/* + * 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.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 DateField}. + * + * @since 7.4 + * @author Vaadin Ltd + */ +public class PopupDateFieldDeclarativeTest extends + DeclarativeTestBase { + + private String getBasicDesign() { + return ""; + } + + private PopupDateField getBasicExpected() { + PopupDateField pdf = new PopupDateField(); + 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()); + } + +} -- 2.39.5