From 203baea2fbc3dead5831ffba7f32cf66094f8ae8 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Mon, 17 Oct 2016 16:43:43 +0300 Subject: [PATCH] Provide declarative tests for all V7 field components. Change-Id: I6bd65efe355730f358fdbc38b9cc592e27077de2 --- .../slider/SliderDeclarativeTest.java | 83 +++--- .../AbstractComponentDeclarativeTestBase.java | 239 ++++++++++++++++++ .../AbstarctDateFieldDeclarativeTest.java | 105 ++++++++ .../AbstractFieldDeclarativeTest.java | 69 +++++ .../AbstractTextFieldDeclarativeTest.java | 46 ++-- .../checkbox/CheckboxDeclarativeTest.java | 41 +-- .../AbstractColorPickerDeclarativeTest.java | 113 +++++---- .../ColorPickerAreaDeclarativeTest.java | 40 +++ .../ColorPickerDeclarativeTest.java | 40 +++ .../datefield/DateFieldDeclarativeTest.java | 55 ++-- .../InlineDateFieldDeclarativeTest.java | 14 +- .../PasswordFieldDeclarativeTest.java | 30 +-- .../RichTextAreaDeclarativeTest.java | 83 ++++++ .../textarea/TextAreaDeclarativeTest.java | 73 ++++-- .../textfield/TextFieldDeclarativeTest.java | 57 +++-- 15 files changed, 891 insertions(+), 197 deletions(-) create mode 100644 server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java create mode 100644 server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java create mode 100644 server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java create mode 100644 server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerAreaDeclarativeTest.java create mode 100644 server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerDeclarativeTest.java create mode 100644 server/src/test/java/com/vaadin/tests/server/component/reachtextarea/RichTextAreaDeclarativeTest.java diff --git a/compatibility-server/src/test/java/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java b/compatibility-server/src/test/java/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java index dcfb415810..0f75ea8099 100644 --- a/compatibility-server/src/test/java/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java +++ b/compatibility-server/src/test/java/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java @@ -18,7 +18,7 @@ package com.vaadin.tests.server.component.slider; import org.junit.Test; import com.vaadin.shared.ui.slider.SliderOrientation; -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest; import com.vaadin.ui.Slider; /** @@ -27,55 +27,78 @@ import com.vaadin.ui.Slider; * @since * @author Vaadin Ltd */ -public class SliderDeclarativeTest extends DeclarativeTestBase { +public class SliderDeclarativeTest + extends AbstractFieldDeclarativeTest { + @Override @Test - public void testDefault() { - String design = ""; + public void valueDeserialization() + throws InstantiationException, IllegalAccessException { + Double value = 12.3; + int resolution = 1; + String design = String.format("<%s resolution=%d value='%s'/>", + getComponentTag(), resolution, value); - Slider expected = new Slider(); + Slider component = new Slider(); + component.setResolution(resolution); + component.setValue(value); - testRead(design, expected); - testWrite(design, expected); + testRead(design, component); + testWrite(design, component); } @Test - public void testHorizontal() { - String design = ""; + public void testVertical() { + String design = ""; Slider expected = new Slider(); - expected.setMin(10.0); - expected.setMax(20.0); - expected.setResolution(1); - expected.setValue(12.3); + expected.setOrientation(SliderOrientation.VERTICAL); testRead(design, expected); testWrite(design, expected); } - @Test - public void testVertical() { - String design = ""; + @Override + public void readOnlyValue() + throws InstantiationException, IllegalAccessException { + Double value = 12.3; + int resolution = 1; + String design = String.format("<%s resolution=%d readonly value='%s'/>", + getComponentTag(), resolution, value); - Slider expected = new Slider(); - expected.setOrientation(SliderOrientation.VERTICAL); + Slider component = new Slider(); + component.setResolution(resolution); + component.setValue(value); - testRead(design, expected); - testWrite(design, expected); + component.setReadOnly(true); + testRead(design, component); + testWrite(design, component); } @Test - public void testReadOnlyValue() { - String design = ""; + public void remainingAttributeDeserialization() { + int min = 3; + int max = 47; + String design = String.format("<%s min=%d value=%d max='%d'/>", + getComponentTag(), min, min, max); - Slider expected = new Slider(); - expected.setMin(10.0); - expected.setMax(20.0); - expected.setResolution(1); - expected.setValue(12.3); - expected.setReadOnly(true); + Slider component = new Slider(); + component.setMin(min); + component.setMax(max); + component.setOrientation(SliderOrientation.HORIZONTAL); - testRead(design, expected); - testWrite(design, expected); + testRead(design, component); + testWrite(design, component); } + + @Override + protected String getComponentTag() { + return "vaadin-slider"; + } + + @Override + protected Class getComponentClass() { + return Slider.class; + } + } diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java new file mode 100644 index 0000000000..2722dae51a --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java @@ -0,0 +1,239 @@ +/* + * Copyright 2000-2016 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.abstractcomponent; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.Locale; + +import org.junit.Test; + +import com.vaadin.server.ErrorMessage.ErrorLevel; +import com.vaadin.server.ExternalResource; +import com.vaadin.server.FileResource; +import com.vaadin.server.ThemeResource; +import com.vaadin.server.UserError; +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.AbstractComponent; +import com.vaadin.ui.declarative.DesignContext; + +/** + * Abstract test class which contains tests for declarative format for + * properties that are common for AbstractComponent. + *

+ * It's an abstract so it's not supposed to be run as is. Instead each + * declarative test for a real component should extend it and implement abstract + * methods to be able to test the common properties. Components specific + * properties should be tested additionally in the subclasses implementations. + * + * @author Vaadin Ltd + * + */ +public abstract class AbstractComponentDeclarativeTestBase + extends DeclarativeTestBase { + + /** + * Returns expected element tag for the tested component. + * + * @return expected element tag + */ + protected abstract String getComponentTag(); + + /** + * Returns component class which is a subject to test + * + * @return the component class + */ + protected abstract Class getComponentClass(); + + @Test + public void emptyAbstractComponentDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s/> ", getComponentTag()); + T component = getComponentClass().newInstance(); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void abstractComponentAttributesDeserialization() + throws InstantiationException, IllegalAccessException { + String id = "testId"; + String caption = "testCaption"; + boolean captionAsHtml = true; + String description = "testDescription"; + boolean enabled = false; + String error = "

testError
"; + String height = "47%"; + String width = "83px"; + String icon = "img/example.gif"; + Locale locale = new Locale("fi", "FI"); + String primaryStyle = "testPrimaryStyle"; + boolean readOnly = true; + boolean responsive = true; + String styleName = "testStyleName"; + boolean visible = false; + + String design = String.format( + "<%s id='%s' caption='%s' caption-as-html description='%s' " + + "error='%s' enabled='false' width='%s' height='%s' " + + "icon='%s' locale='%s' primary-style-name='%s' " + + "readonly responsive style-name='%s' visible='false'/>", + getComponentTag(), id, caption, description, error, width, + height, icon, locale.toString(), primaryStyle, styleName); + + T component = getComponentClass().newInstance(); + component.setId(id); + component.setCaption(caption); + component.setCaptionAsHtml(captionAsHtml); + component.setDescription(description); + component.setEnabled(enabled); + component.setComponentError(new UserError(error, + com.vaadin.server.AbstractErrorMessage.ContentMode.HTML, + ErrorLevel.ERROR)); + component.setHeight(height); + component.setWidth(width); + component.setIcon(new FileResource(new File(icon))); + component.setLocale(locale); + component.setPrimaryStyleName(primaryStyle); + component.setReadOnly(readOnly); + component.setResponsive(responsive); + component.setStyleName(styleName); + component.setVisible(visible); + + testRead(design, component); + testWrite(design, component); + } + + @Test + public void externalIcon() + throws InstantiationException, IllegalAccessException { + String url = "http://example.com/example.gif"; + + String design = String.format("<%s icon='%s'/>", getComponentTag(), + url); + + T component = getComponentClass().newInstance(); + + component.setIcon(new ExternalResource(url)); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void themeIcon() + throws InstantiationException, IllegalAccessException { + String path = "example.gif"; + + String design = String.format("<%s icon='theme://%s'/>", + getComponentTag(), path); + + T component = getComponentClass().newInstance(); + + component.setIcon(new ThemeResource(path)); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void sizeFullDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s size-full/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + + component.setSizeFull(); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void widthFullDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s width-full/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + + component.setWidth("100%"); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void heightFullDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s height-full/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + + component.setHeight("100%"); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void sizeUnderfinedDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + + component.setSizeUndefined(); + testRead(design, component); + testWrite(design, component); + + } + + @Test + public void heightUnderfinedDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + + component.setHeightUndefined(); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void widthUnderfinedDeserialization() + throws InstantiationException, IllegalAccessException { + String design = String.format("<%s/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + + component.setWidthUndefined(); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void testUnknownAttribute() { + String value = "bar"; + String design = String.format("<%s foo='%s'/>", getComponentTag(), + value); + + DesignContext context = readAndReturnContext(design); + T label = getComponentClass().cast(context.getRootComponent()); + assertTrue("Custom attribute was preserved in custom attributes", + context.getCustomAttributes(label).containsKey("foo")); + + testWrite(label, design, context); + } + +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java new file mode 100644 index 0000000000..530019fa92 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java @@ -0,0 +1,105 @@ +/* + * Copyright 2000-2016 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.abstractdatefield; + +import java.time.LocalDate; +import java.util.Locale; + +import org.junit.Test; + +import com.vaadin.shared.ui.datefield.Resolution; +import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest; +import com.vaadin.ui.AbstractDateField; + +/** + * Abstract test class which contains tests for declarative format for + * properties that are common for AbstractDateField. + *

+ * It's an abstract so it's not supposed to be run as is. Instead each + * declarative test for a real component should extend it and implement abstract + * methods to be able to test the common properties. Components specific + * properties should be tested additionally in the subclasses implementations. + * + * @author Vaadin Ltd + * + */ +public abstract class AbstarctDateFieldDeclarativeTest + extends AbstractFieldDeclarativeTest { + + @Override + public void valueDeserialization() + throws InstantiationException, IllegalAccessException { + LocalDate value = LocalDate.of(2003, 02, 27); + String design = String.format("<%s value='%s'/>", getComponentTag(), + value); + + T component = getComponentClass().newInstance(); + component.setValue(value); + + testRead(design, component); + testWrite(design, component); + } + + @Test + public void abstractDateFieldAttributesDeserialization() + throws InstantiationException, IllegalAccessException { + boolean showIsoWeeks = true; + LocalDate end = LocalDate.of(2019, 01, 15); + LocalDate start = LocalDate.of(2001, 02, 11); + String dateOutOfRange = "test date out of range"; + Resolution resolution = Resolution.MONTH; + String dateFormat = "test format"; + boolean lenient = true; + String parseErrorMsg = "test parse error"; + String design = String.format( + "<%s show-iso-week-numbers range-end='%s' range-start='%s' " + + "date-out-of-range-message='%s' resolution='%s' " + + "date-format='%s' lenient parse-error-message='%s'/>", + getComponentTag(), end, start, dateOutOfRange, + resolution.name().toLowerCase(Locale.ENGLISH), dateFormat, + parseErrorMsg); + + T component = getComponentClass().newInstance(); + + component.setShowISOWeekNumbers(showIsoWeeks); + component.setRangeEnd(end); + component.setRangeStart(start); + component.setDateOutOfRangeMessage(dateOutOfRange); + component.setResolution(resolution); + component.setDateFormat(dateFormat); + component.setLenient(lenient); + component.setParseErrorMessage(parseErrorMsg); + + testRead(design, component); + testWrite(design, component); + } + + @Override + public void readOnlyValue() + throws InstantiationException, IllegalAccessException { + LocalDate value = LocalDate.of(2003, 02, 27); + String design = String.format("<%s value='%s' readonly/>", + getComponentTag(), value); + + T component = getComponentClass().newInstance(); + component.setValue(value); + component.setReadOnly(true); + + testRead(design, component); + testWrite(design, component); + } + +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java new file mode 100644 index 0000000000..df7b64b671 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2000-2016 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.abstractfield; + +import org.junit.Test; + +import com.vaadin.tests.server.component.abstractcomponent.AbstractComponentDeclarativeTestBase; +import com.vaadin.ui.AbstractField; + +/** + * Abstract test class which contains tests for declarative format for + * properties that are common for AbstractField. + *

+ * It's an abstract so it's not supposed to be run as is. Instead each + * declarative test for a real component should extend it and implement abstract + * methods to be able to test the common properties. Components specific + * properties should be tested additionally in the subclasses implementations. + * + * @author Vaadin Ltd + * + */ +public abstract class AbstractFieldDeclarativeTest, V> + extends AbstractComponentDeclarativeTestBase { + + @Test + public void requiredDeserialization() + throws InstantiationException, IllegalAccessException { + boolean isRequired = true; + String design = String.format("<%s required/>", getComponentTag()); + + T component = getComponentClass().newInstance(); + component.setRequired(isRequired); + testRead(design, component); + testWrite(design, component); + } + + @Test + public void tabIndexDeserialization() + throws InstantiationException, IllegalAccessException { + int tabIndex = 13; + String design = String.format("<%s tabindex='%s'/>", getComponentTag(), + tabIndex); + + T component = getComponentClass().newInstance(); + component.setTabIndex(tabIndex); + + testRead(design, component); + testWrite(design, component); + } + + public abstract void valueDeserialization() + throws InstantiationException, IllegalAccessException; + + public abstract void readOnlyValue() + throws InstantiationException, IllegalAccessException; +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java index d7fd06dbe8..7ba3e6aaca 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java @@ -15,12 +15,13 @@ */ package com.vaadin.tests.server.component.abstracttextfield; +import java.util.Locale; + import org.junit.Test; import com.vaadin.shared.ui.ValueChangeMode; -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest; import com.vaadin.ui.AbstractTextField; -import com.vaadin.ui.TextField; /** * Tests declarative support for AbstractTextField. @@ -28,26 +29,31 @@ import com.vaadin.ui.TextField; * @since * @author Vaadin Ltd */ -public class AbstractTextFieldDeclarativeTest - extends DeclarativeTestBase { +public abstract class AbstractTextFieldDeclarativeTest + extends AbstractFieldDeclarativeTest { @Test - public void testAttributes() { - String design = ""; - AbstractTextField tf = new TextField(); - // FIXME - // tf.setNullRepresentation("this-is-null"); - // tf.setNullSettingAllowed(true); - tf.setMaxLength(5); - tf.setPlaceholder("input"); - tf.setValueChangeMode(ValueChangeMode.EAGER); - tf.setValueChangeTimeout(100); - testRead(design, tf); - testWrite(design, tf); + public void abstractTextFieldAttributes() + throws InstantiationException, IllegalAccessException { + int maxLength = 5; + String placeholder = "foo"; + ValueChangeMode mode = ValueChangeMode.EAGER; + int timeout = 100; + String design = String.format( + "<%s maxlength='%d' placeholder='%s' " + + "value-change-mode='%s' value-change-timeout='%d'/>", + getComponentTag(), maxLength, placeholder, + mode.name().toLowerCase(Locale.ENGLISH), timeout); + + T component = getComponentClass().newInstance(); + + component.setMaxLength(maxLength); + component.setPlaceholder(placeholder); + component.setValueChangeMode(mode); + component.setValueChangeTimeout(timeout); + + testRead(design, component); + testWrite(design, component); } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java index 2ef0ffd891..0b45579d5d 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java @@ -15,9 +15,7 @@ */ package com.vaadin.tests.server.component.checkbox; -import org.junit.Test; - -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest; import com.vaadin.ui.CheckBox; /** @@ -26,32 +24,43 @@ import com.vaadin.ui.CheckBox; * @since 7.4 * @author Vaadin Ltd */ -public class CheckboxDeclarativeTest extends DeclarativeTestBase { - - @Test - public void testChecked() { - String design = ""; - CheckBox checkBox = new CheckBox(); - testRead(design, checkBox); - testWrite(design, checkBox); - } +public class CheckboxDeclarativeTest + extends AbstractFieldDeclarativeTest { - @Test - public void testUnchecked() { + @Override + public void valueDeserialization() + throws InstantiationException, IllegalAccessException { String design = ""; CheckBox checkBox = new CheckBox(); + checkBox.setValue(true); + testRead(design, checkBox); testWrite(design, checkBox); } - @Test - public void testReadOnlyValue() { + @Override + public void readOnlyValue() + throws InstantiationException, IllegalAccessException { String design = ""; + CheckBox checkBox = new CheckBox(); + checkBox.setValue(true); checkBox.setReadOnly(true); + testRead(design, checkBox); testWrite(design, checkBox); } + + @Override + protected String getComponentTag() { + return "vaadin-check-box"; + } + + @Override + protected Class getComponentClass() { + return CheckBox.class; + } + } diff --git a/server/src/test/java/com/vaadin/tests/server/component/colorpicker/AbstractColorPickerDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/colorpicker/AbstractColorPickerDeclarativeTest.java index 8018d6603e..2c646e47a0 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/colorpicker/AbstractColorPickerDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/colorpicker/AbstractColorPickerDeclarativeTest.java @@ -18,70 +18,89 @@ package com.vaadin.tests.server.component.colorpicker; import org.junit.Test; import com.vaadin.shared.ui.colorpicker.Color; -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest; import com.vaadin.ui.AbstractColorPicker; import com.vaadin.ui.AbstractColorPicker.PopupStyle; -import com.vaadin.ui.ColorPicker; -import com.vaadin.ui.ColorPickerArea; -public class AbstractColorPickerDeclarativeTest - extends DeclarativeTestBase { +/** + * Abstract test class which contains tests for declarative format for + * properties that are common for AbstractColorPicker. + *

+ * It's an abstract so it's not supposed to be run as is. Instead each + * declarative test for a real component should extend it and implement abstract + * methods to be able to test the common properties. Components specific + * properties should be tested additionally in the subclasses implementations. + * + * @author Vaadin Ltd + * + */ +public abstract class AbstractColorPickerDeclarativeTest + extends AbstractFieldDeclarativeTest { @Test - public void testAllAbstractColorPickerFeatures() { - String design = ""; - ColorPicker colorPicker = new ColorPicker(); - int colorInt = Integer.parseInt("fafafa", 16); - colorPicker.setValue(new Color(colorInt)); - colorPicker.setDefaultCaptionEnabled(true); - colorPicker.setPosition(100, 100); - colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE); - colorPicker.setRGBVisibility(false); - colorPicker.setHSVVisibility(false); - colorPicker.setSwatchesVisibility(true); - colorPicker.setHistoryVisibility(false); - colorPicker.setTextfieldVisibility(false); + public void testAllAbstractColorPickerFeatures() + throws InstantiationException, IllegalAccessException { + boolean defaultCaption = true; + PopupStyle popupStyle = PopupStyle.POPUP_SIMPLE; + int x = 79; + int y = 91; + boolean rgbVisibility = false; + boolean hsvVisibility = false; + boolean swatchesVisibility = true; + boolean historyVisibility = false; + boolean textFieldVisibility = false; + String design = String.format( + "<%s default-caption-enabled position='%s,%s'" + + " popup-style='%s' rgb-visibility='%s' hsv-visibility='%s' " + + "history-visibility='%s' textfield-visibility='%s'/>", + getComponentTag(), x, y, popupStyle.toString(), rgbVisibility, + hsvVisibility, historyVisibility, textFieldVisibility); + + T colorPicker = getComponentClass().newInstance(); + + colorPicker.setDefaultCaptionEnabled(defaultCaption); + colorPicker.setPosition(x, y); + colorPicker.setPopupStyle(popupStyle); + colorPicker.setRGBVisibility(rgbVisibility); + colorPicker.setHSVVisibility(hsvVisibility); + colorPicker.setSwatchesVisibility(swatchesVisibility); + colorPicker.setHistoryVisibility(historyVisibility); + colorPicker.setTextfieldVisibility(textFieldVisibility); testWrite(design, colorPicker); testRead(design, colorPicker); } - @Test - public void testEmptyColorPicker() { - String design = ""; - ColorPicker colorPicker = new ColorPicker(); - testRead(design, colorPicker); - testWrite(design, colorPicker); - } + @Override + public void valueDeserialization() + throws InstantiationException, IllegalAccessException { + String rgb = "fafafa"; + String design = String.format("<%s color='#%s'/>", getComponentTag()); + + T colorPicker = getComponentClass().newInstance(); + int colorInt = Integer.parseInt(rgb, 16); - @Test - public void testAllAbstractColorPickerAreaFeatures() { - String design = ""; - AbstractColorPicker colorPicker = new ColorPickerArea(); - int colorInt = Integer.parseInt("fafafa", 16); colorPicker.setValue(new Color(colorInt)); - colorPicker.setDefaultCaptionEnabled(true); - colorPicker.setPosition(100, 100); - colorPicker.setPopupStyle(PopupStyle.POPUP_SIMPLE); - colorPicker.setRGBVisibility(false); - colorPicker.setHSVVisibility(false); - colorPicker.setSwatchesVisibility(true); - colorPicker.setHistoryVisibility(false); - colorPicker.setTextfieldVisibility(false); testWrite(design, colorPicker); testRead(design, colorPicker); } - @Test - public void testEmptyColorPickerArea() { - String design = ""; - AbstractColorPicker colorPicker = new ColorPickerArea(); - testRead(design, colorPicker); + @Override + public void readOnlyValue() + throws InstantiationException, IllegalAccessException { + String rgb = "fafafa"; + String design = String.format("<%s color='#%s' readonly/>", + getComponentTag()); + + T colorPicker = getComponentClass().newInstance(); + int colorInt = Integer.parseInt(rgb, 16); + + colorPicker.setValue(new Color(colorInt)); + colorPicker.setReadOnly(true); + testWrite(design, colorPicker); + testRead(design, colorPicker); } + } diff --git a/server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerAreaDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerAreaDeclarativeTest.java new file mode 100644 index 0000000000..715acfd050 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerAreaDeclarativeTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2016 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.colorpicker; + +import com.vaadin.ui.ColorPickerArea; + +/** + * Declarative test for ColorPickerArea. Provides only information about + * ColorPickerArea class. All tests are in the superclass. + * + * @author Vaadin Ltd + * + */ +public class ColorPickerAreaDeclarativeTest + extends AbstractColorPickerDeclarativeTest { + + @Override + protected String getComponentTag() { + return "vaadin-color-picker-area"; + } + + @Override + protected Class getComponentClass() { + return ColorPickerArea.class; + } + +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerDeclarativeTest.java new file mode 100644 index 0000000000..41d730eb18 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerDeclarativeTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2000-2016 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.colorpicker; + +import com.vaadin.ui.ColorPicker; + +/** + * Declarative test for ColorPicker. Provides only information about + * ColorPickerArea class. All tests are in the superclass. + * + * @author Vaadin Ltd + * + */ +public class ColorPickerDeclarativeTest + extends AbstractColorPickerDeclarativeTest { + + @Override + protected String getComponentTag() { + return "vaadin-color-picker"; + } + + @Override + protected Class getComponentClass() { + return ColorPicker.class; + } + +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java index ef6ec554c2..58fdd3912b 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java @@ -15,46 +15,49 @@ */ package com.vaadin.tests.server.component.datefield; -import java.time.LocalDate; - import org.junit.Test; -import com.vaadin.tests.design.DeclarativeTestBase; -import com.vaadin.ui.AbstractDateField; +import com.vaadin.tests.server.component.abstractdatefield.AbstarctDateFieldDeclarativeTest; import com.vaadin.ui.DateField; /** - * Tests the declarative support for implementations of - * {@link AbstractDateField}. + * Tests the declarative support for implementations of {@link DateField}. * * @since 7.4 * @author Vaadin Ltd */ -public class DateFieldDeclarativeTest extends DeclarativeTestBase { - - private String getBasicDesign() { - return ""; - } +public class DateFieldDeclarativeTest + extends AbstarctDateFieldDeclarativeTest { - private DateField getBasicExpected() { - DateField pdf = new DateField(); - pdf.setShowISOWeekNumbers(true); - pdf.setRangeEnd(LocalDate.of(2019, 01, 15)); - pdf.setPlaceholder("Pick a day"); - pdf.setValue(LocalDate.of(2003, 2, 27)); - pdf.setTextFieldEnabled(false); - pdf.setAssistiveText("at"); - return pdf; + @Test + public void remainingAttributes() + throws InstantiationException, IllegalAccessException { + String placeholder = "foo"; + String assistiveText = "at"; + boolean textFieldEnabled = false; + String design = String.format( + "<%s placeholder='%s' " + + "assistive-text='%s' text-field-enabled='%s'/>", + getComponentTag(), placeholder, assistiveText, + textFieldEnabled); + + DateField component = getComponentClass().newInstance(); + component.setPlaceholder(placeholder); + component.setTextFieldEnabled(textFieldEnabled); + component.setAssistiveText(assistiveText); + + testRead(design, component); + testWrite(design, component); } - @Test - public void readBasic() throws Exception { - testRead(getBasicDesign(), getBasicExpected()); + @Override + protected String getComponentTag() { + return "vaadin-date-field"; } - @Test - public void writeBasic() throws Exception { - testRead(getBasicDesign(), getBasicExpected()); + @Override + protected Class getComponentClass() { + return DateField.class; } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java index c947641986..c6b97a1ec2 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java @@ -21,7 +21,7 @@ import java.time.LocalDate; import org.junit.Test; -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.abstractdatefield.AbstarctDateFieldDeclarativeTest; import com.vaadin.ui.AbstractDateField; import com.vaadin.ui.InlineDateField; import com.vaadin.ui.declarative.Design; @@ -34,7 +34,7 @@ import com.vaadin.ui.declarative.Design; * @author Vaadin Ltd */ public class InlineDateFieldDeclarativeTest - extends DeclarativeTestBase { + extends AbstarctDateFieldDeclarativeTest { @Test public void testInlineDateFieldToFromDesign() throws Exception { @@ -56,4 +56,14 @@ public class InlineDateFieldDeclarativeTest assertEquals(field.getRangeEnd(), result.getRangeEnd()); } + @Override + protected String getComponentTag() { + return "vaadin-inline-date-field"; + } + + @Override + protected Class getComponentClass() { + return InlineDateField.class; + } + } diff --git a/server/src/test/java/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java index a2ccc78300..c7908fd6b0 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java @@ -15,26 +15,26 @@ */ package com.vaadin.tests.server.component.passwordfield; -import org.junit.Test; - -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.textfield.TextFieldDeclarativeTest; import com.vaadin.ui.PasswordField; +import com.vaadin.ui.TextField; /** - * - * @since + * Declarative test for PasswordField. Provides only information about + * ColorPickerArea class. All tests are in the superclass. + * * @author Vaadin Ltd + * */ -public class PasswordFieldDeclarativeTest - extends DeclarativeTestBase { +public class PasswordFieldDeclarativeTest extends TextFieldDeclarativeTest { + + @Override + protected Class getComponentClass() { + return PasswordField.class; + } - @Test - public void testReadOnlyValue() { - String design = ""; - PasswordField tf = new PasswordField(); - tf.setValue("test value"); - tf.setReadOnly(true); - testRead(design, tf); - testWrite(design, tf); + @Override + protected String getComponentTag() { + return "vaadin-password-field"; } } diff --git a/server/src/test/java/com/vaadin/tests/server/component/reachtextarea/RichTextAreaDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/reachtextarea/RichTextAreaDeclarativeTest.java new file mode 100644 index 0000000000..43da30bb64 --- /dev/null +++ b/server/src/test/java/com/vaadin/tests/server/component/reachtextarea/RichTextAreaDeclarativeTest.java @@ -0,0 +1,83 @@ +/* + * Copyright 2000-2016 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.reachtextarea; + +import java.util.Locale; + +import org.junit.Test; + +import com.vaadin.shared.ui.ValueChangeMode; +import com.vaadin.tests.server.component.abstractfield.AbstractFieldDeclarativeTest; +import com.vaadin.ui.RichTextArea; + +public class RichTextAreaDeclarativeTest + extends AbstractFieldDeclarativeTest { + + public void valueDeserialization() + throws InstantiationException, IllegalAccessException { + String value = "Header \n
Some text"; + String design = String.format("<%s>\n %s\n ", + getComponentTag(), value, getComponentTag()); + + RichTextArea component = new RichTextArea(); + component.setValue(value); + + testRead(design, component); + testWrite(design, component); + } + + public void readOnlyValue() + throws InstantiationException, IllegalAccessException { + String value = "Header \n
Some text"; + String design = String.format("<%s readonly>\n %s\n ", + getComponentTag(), value, getComponentTag()); + + RichTextArea component = new RichTextArea(); + component.setValue(value); + component.setReadOnly(true); + + testRead(design, component); + testWrite(design, component); + } + + @Test + public void remainingAttributeDeserialization() { + ValueChangeMode mode = ValueChangeMode.TIMEOUT; + int timeout = 67; + String design = String.format( + "<%s value-change-mode='%s' value-change-timeout='%d'/>", + getComponentTag(), mode.name().toLowerCase(Locale.ENGLISH), + timeout); + + RichTextArea component = new RichTextArea(); + component.setValueChangeMode(mode); + component.setValueChangeTimeout(timeout); + + testRead(design, component); + testWrite(design, component); + } + + @Override + protected String getComponentTag() { + return "vaadin-rich-text-area"; + } + + @Override + protected Class getComponentClass() { + return RichTextArea.class; + } + +} diff --git a/server/src/test/java/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java index 1b6df09c19..ad8d88e9c5 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java @@ -22,7 +22,7 @@ import org.jsoup.parser.Tag; import org.junit.Assert; import org.junit.Test; -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.abstracttextfield.AbstractTextFieldDeclarativeTest; import com.vaadin.ui.TextArea; import com.vaadin.ui.declarative.DesignContext; @@ -32,17 +32,36 @@ import com.vaadin.ui.declarative.DesignContext; * @since 7.4 * @author Vaadin Ltd */ -public class TextAreaDeclarativeTest extends DeclarativeTestBase