You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LegacyDateFieldDeclarativeTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.vaadin.v7.tests.server.component.datefield;
  2. import java.text.SimpleDateFormat;
  3. import java.util.Date;
  4. import java.util.TimeZone;
  5. import org.junit.Test;
  6. import com.vaadin.tests.design.DeclarativeTestBase;
  7. import com.vaadin.v7.shared.ui.datefield.Resolution;
  8. import com.vaadin.v7.ui.DateField;
  9. /**
  10. * Tests the declarative support for implementations of {@link DateField}.
  11. *
  12. * @author Vaadin Ltd
  13. * @since 7.4
  14. */
  15. public class LegacyDateFieldDeclarativeTest
  16. extends DeclarativeTestBase<DateField> {
  17. private String getYearResolutionDesign() {
  18. return "<vaadin7-date-field resolution='year' value='2020'/>";
  19. }
  20. private DateField getYearResolutionExpected() {
  21. DateField df = new DateField();
  22. df.setResolution(Resolution.YEAR);
  23. df.setValue(new Date(2020 - 1900, 1 - 1, 1));
  24. return df;
  25. }
  26. private String getTimezoneDesign() {
  27. String timeZone = new SimpleDateFormat("Z")
  28. .format(new Date(2014 - 1900, 5 - 1, 5));
  29. return String.format(
  30. "<vaadin7-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\"/>",
  31. timeZone);
  32. }
  33. private DateField getTimezoneExpected() {
  34. DateField df = new DateField();
  35. df.setRangeStart(new Date(2014 - 1900, 5 - 1, 5));
  36. df.setRangeEnd(new Date(2014 - 1900, 6 - 1, 5));
  37. df.setDateOutOfRangeMessage("Please select a sensible date");
  38. df.setResolution(Resolution.DAY);
  39. df.setDateFormat("yyyy-MM-dd");
  40. df.setLenient(true);
  41. df.setShowISOWeekNumbers(true);
  42. df.setParseErrorMessage("You are doing it wrong");
  43. df.setTimeZone(TimeZone.getTimeZone("GMT+5"));
  44. df.setValue(new Date(2014 - 1900, 5 - 1, 15));
  45. return df;
  46. }
  47. @Test
  48. public void readTimezone() {
  49. testRead(getTimezoneDesign(), getTimezoneExpected());
  50. }
  51. @Test
  52. public void writeTimezone() {
  53. testWrite(getTimezoneDesign(), getTimezoneExpected());
  54. }
  55. @Test
  56. public void readYearResolution() {
  57. testRead(getYearResolutionDesign(), getYearResolutionExpected());
  58. }
  59. @Test
  60. public void writeYearResolution() {
  61. // Writing is always done in full resolution..
  62. String timeZone = new SimpleDateFormat("Z")
  63. .format(new Date(2020 - 1900, 1 - 1, 1));
  64. testWrite(
  65. getYearResolutionDesign().replace("2020",
  66. "2020-01-01 00:00:00" + timeZone),
  67. getYearResolutionExpected());
  68. }
  69. @Test
  70. public void testReadOnlyValue() {
  71. Date date = new Date(2020 - 1900, 1 - 1, 1);
  72. String timeZone = new SimpleDateFormat("Z").format(date);
  73. String design = "<vaadin7-date-field readonly resolution='year' value='2020-01-01 00:00:00"
  74. + timeZone + "'/>";
  75. DateField df = new DateField();
  76. df.setResolution(Resolution.YEAR);
  77. df.setValue(date);
  78. df.setReadOnly(true);
  79. testRead(design, df);
  80. testWrite(design, df);
  81. }
  82. }