Change-Id: I1dc27ed0a61aea0e9c263a88885e8d20c815bc92tags/7.4.0.rc1
@@ -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( | |||
"<!DOCTYPE html><html><head></head><body><v-popup-date-field show-iso-week-numbers caption=\"Day is\" resolution=\"MINUTE\" range-end=\"2019-01-15\" input-prompt=\"Pick a day\" value=\"2003-02-27 07:15\"></v-popup-date-field></body></html>" | |||
.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( | |||
"<!DOCTYPE html><html><head></head><body><v-date-field range-start=\"2014-05-05\" range-end=\"2014-06-05\" date-out-of-range-message=\"Please select a sensible date\" resolution=\"day\" date-format=\"yyyy-MM-dd\" lenient show-iso-week-numbers parse-error-message=\"You are doing it wrong\" time-zone=\"GMT+5\" value=\"2014-05-15\"></v-date-field></body></html>" | |||
.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()); | |||
} | |||
} |
@@ -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<DateField> { | |||
private String getYearResolutionDesign() { | |||
return "<v-date-field resolution='year' value='2020'/>"; | |||
} | |||
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 "<v-date-field range-start=\"2014-05-05 00:00:00+0300\" range-end=\"2014-06-05 00:00:00+0300\" date-out-of-range-message=\"Please select a sensible date\" date-format=\"yyyy-MM-dd\" lenient='true' show-iso-week-numbers='true' parse-error-message=\"You are doing it wrong\" time-zone=\"GMT+05:00\" value=\"2014-05-15 00:00:00+0300\"/>"; | |||
} | |||
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()); | |||
} | |||
} |
@@ -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<InlineDateField> { | |||
@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()); | |||
} | |||
} |
@@ -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<PopupDateField> { | |||
private String getBasicDesign() { | |||
return "<v-popup-date-field assistive-text='at' text-field-enabled='false' show-iso-week-numbers resolution=\"MINUTE\" range-end=\"2019-01-15\" input-prompt=\"Pick a day\" value=\"2003-02-27 07:15\"></v-popup-date-field>"; | |||
} | |||
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()); | |||
} | |||
} |