2 * Copyright 2000-2016 Vaadin Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
16 package com.vaadin.v7.tests.server.component.datefield;
18 import java.text.SimpleDateFormat;
19 import java.util.Date;
20 import java.util.TimeZone;
22 import org.junit.Test;
24 import com.vaadin.tests.design.DeclarativeTestBase;
25 import com.vaadin.v7.shared.ui.datefield.Resolution;
26 import com.vaadin.v7.ui.DateField;
29 * Tests the declarative support for implementations of {@link DateField}.
34 public class LegacyDateFieldDeclarativeTest
35 extends DeclarativeTestBase<DateField> {
37 private String getYearResolutionDesign() {
38 return "<vaadin7-date-field resolution='year' value='2020'/>";
41 private DateField getYearResolutionExpected() {
42 DateField df = new DateField();
43 df.setResolution(Resolution.YEAR);
44 df.setValue(new Date(2020 - 1900, 1 - 1, 1));
48 private String getTimezoneDesign() {
49 String timeZone = new SimpleDateFormat("Z").format(new Date());
51 "<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\"/>",
55 private DateField getTimezoneExpected() {
56 DateField df = new DateField();
58 df.setRangeStart(new Date(2014 - 1900, 5 - 1, 5));
59 df.setRangeEnd(new Date(2014 - 1900, 6 - 1, 5));
60 df.setDateOutOfRangeMessage("Please select a sensible date");
61 df.setResolution(Resolution.DAY);
62 df.setDateFormat("yyyy-MM-dd");
64 df.setShowISOWeekNumbers(true);
65 df.setParseErrorMessage("You are doing it wrong");
66 df.setTimeZone(TimeZone.getTimeZone("GMT+5"));
67 df.setValue(new Date(2014 - 1900, 5 - 1, 15));
73 public void readTimezone() {
74 testRead(getTimezoneDesign(), getTimezoneExpected());
78 public void writeTimezone() {
79 testWrite(getTimezoneDesign(), getTimezoneExpected());
83 public void readYearResolution() {
84 testRead(getYearResolutionDesign(), getYearResolutionExpected());
88 public void writeYearResolution() {
89 // Writing is always done in full resolution..
90 String timeZone = new SimpleDateFormat("Z")
91 .format(new Date(2020 - 1900, 1 - 1, 1));
93 getYearResolutionDesign().replace("2020",
94 "2020-01-01 00:00:00" + timeZone),
95 getYearResolutionExpected());
99 public void testReadOnlyValue() {
100 Date date = new Date(2020 - 1900, 1 - 1, 1);
101 String timeZone = new SimpleDateFormat("Z").format(date);
102 String design = "<vaadin7-date-field readonly resolution='year' value='2020-01-01 00:00:00"
104 DateField df = new DateField();
105 df.setResolution(Resolution.YEAR);
107 df.setReadOnly(true);
109 testRead(design, df);
110 testWrite(design, df);