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.

AbstractLocalDateTimeFieldDeclarativeTest.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests.server.component.abstractdatefield;
  17. import java.time.LocalDateTime;
  18. import java.time.format.DateTimeFormatter;
  19. import java.util.Locale;
  20. import org.junit.Test;
  21. import com.vaadin.shared.ui.datefield.DateTimeResolution;
  22. import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest;
  23. import com.vaadin.ui.AbstractLocalDateTimeField;
  24. /**
  25. * Abstract test class which contains tests for declarative format for
  26. * properties that are common for AbstractDateField.
  27. * <p>
  28. * It's an abstract so it's not supposed to be run as is. Instead each
  29. * declarative test for a real component should extend it and implement abstract
  30. * methods to be able to test the common properties. Components specific
  31. * properties should be tested additionally in the subclasses implementations.
  32. *
  33. * @author Vaadin Ltd
  34. *
  35. */
  36. public abstract class AbstractLocalDateTimeFieldDeclarativeTest<T extends AbstractLocalDateTimeField>
  37. extends AbstractFieldDeclarativeTest<T, LocalDateTime> {
  38. protected DateTimeFormatter DATE_FORMATTER = DateTimeFormatter
  39. .ofPattern("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH);
  40. @Override
  41. public void valueDeserialization()
  42. throws InstantiationException, IllegalAccessException {
  43. LocalDateTime value = LocalDateTime.of(2003, 02, 27, 10, 37, 43);
  44. String design = String.format("<%s value='%s'/>", getComponentTag(),
  45. DATE_FORMATTER.format(value));
  46. T component = getComponentClass().newInstance();
  47. component.setValue(value);
  48. testRead(design, component);
  49. testWrite(design, component);
  50. }
  51. @Test
  52. public void abstractDateFieldAttributesDeserialization()
  53. throws InstantiationException, IllegalAccessException {
  54. boolean showIsoWeeks = true;
  55. LocalDateTime end = LocalDateTime.of(2019, 02, 27, 10, 37, 43);
  56. LocalDateTime start = LocalDateTime.of(2001, 02, 27, 23, 12, 34);
  57. String dateOutOfRange = "test date out of range";
  58. DateTimeResolution resolution = DateTimeResolution.HOUR;
  59. String dateFormat = "test format";
  60. boolean lenient = true;
  61. String parseErrorMsg = "test parse error";
  62. String design = String.format(
  63. "<%s show-iso-week-numbers range-end='%s' range-start='%s' "
  64. + "date-out-of-range-message='%s' resolution='%s' "
  65. + "date-format='%s' lenient parse-error-message='%s'/>",
  66. getComponentTag(), DATE_FORMATTER.format(end),
  67. DATE_FORMATTER.format(start), dateOutOfRange,
  68. resolution.name().toLowerCase(Locale.ENGLISH), dateFormat,
  69. parseErrorMsg);
  70. T component = getComponentClass().newInstance();
  71. component.setShowISOWeekNumbers(showIsoWeeks);
  72. component.setRangeEnd(end);
  73. component.setRangeStart(start);
  74. component.setDateOutOfRangeMessage(dateOutOfRange);
  75. component.setResolution(resolution);
  76. component.setDateFormat(dateFormat);
  77. component.setLenient(lenient);
  78. component.setParseErrorMessage(parseErrorMsg);
  79. testRead(design, component);
  80. testWrite(design, component);
  81. }
  82. @Override
  83. public void readOnlyValue()
  84. throws InstantiationException, IllegalAccessException {
  85. LocalDateTime value = LocalDateTime.of(2003, 02, 27, 23, 12, 34);
  86. String design = String.format("<%s value='%s' readonly/>",
  87. getComponentTag(), DATE_FORMATTER.format(value));
  88. T component = getComponentClass().newInstance();
  89. component.setValue(value);
  90. component.setReadOnly(true);
  91. testRead(design, component);
  92. testWrite(design, component);
  93. }
  94. }