]> source.dussan.org Git - vaadin-framework.git/blob
e9b7ac79598ca91ed0bf6553fa6cd1da923d4b96
[vaadin-framework.git] /
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.v7.tests.server.component.datefield;
17
18 import java.text.SimpleDateFormat;
19 import java.util.Date;
20 import java.util.TimeZone;
21
22 import org.junit.Test;
23
24 import com.vaadin.tests.design.DeclarativeTestBase;
25 import com.vaadin.v7.shared.ui.datefield.Resolution;
26 import com.vaadin.v7.ui.DateField;
27
28 /**
29  * Tests the declarative support for implementations of {@link DateField}.
30  *
31  * @author Vaadin Ltd
32  * @since 7.4
33  */
34 public class LegacyDateFieldDeclarativeTest
35         extends DeclarativeTestBase<DateField> {
36
37     private String getYearResolutionDesign() {
38         return "<vaadin7-date-field resolution='year' value='2020'/>";
39     }
40
41     private DateField getYearResolutionExpected() {
42         DateField df = new DateField();
43         df.setResolution(Resolution.YEAR);
44         df.setValue(new Date(2020 - 1900, 1 - 1, 1));
45         return df;
46     }
47
48     private String getTimezoneDesign() {
49         String timeZone = new SimpleDateFormat("Z").format(new Date());
50         return String.format(
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\"/>",
52                 timeZone);
53     }
54
55     private DateField getTimezoneExpected() {
56         DateField df = new DateField();
57
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");
63         df.setLenient(true);
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));
68
69         return df;
70     }
71
72     @Test
73     public void readTimezone() {
74         testRead(getTimezoneDesign(), getTimezoneExpected());
75     }
76
77     @Test
78     public void writeTimezone() {
79         testWrite(getTimezoneDesign(), getTimezoneExpected());
80     }
81
82     @Test
83     public void readYearResolution() {
84         testRead(getYearResolutionDesign(), getYearResolutionExpected());
85     }
86
87     @Test
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));
92         testWrite(
93                 getYearResolutionDesign().replace("2020",
94                         "2020-01-01 00:00:00" + timeZone),
95                 getYearResolutionExpected());
96     }
97
98     @Test
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"
103                 + timeZone + "'/>";
104         DateField df = new DateField();
105         df.setResolution(Resolution.YEAR);
106         df.setValue(date);
107         df.setReadOnly(true);
108
109         testRead(design, df);
110         testWrite(design, df);
111     }
112
113 }