]> source.dussan.org Git - vaadin-framework.git/commitdiff
Provide declarative tests for all V7 field components.
authorDenis Anisimov <denis@vaadin.com>
Mon, 17 Oct 2016 13:43:43 +0000 (16:43 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 21 Oct 2016 08:44:19 +0000 (08:44 +0000)
Change-Id: I6bd65efe355730f358fdbc38b9cc592e27077de2

15 files changed:
compatibility-server/src/test/java/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/abstractcomponent/AbstractComponentDeclarativeTestBase.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/abstractfield/AbstractFieldDeclarativeTest.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/abstracttextfield/AbstractTextFieldDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/checkbox/CheckboxDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/colorpicker/AbstractColorPickerDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerAreaDeclarativeTest.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/colorpicker/ColorPickerDeclarativeTest.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/passwordfield/PasswordFieldDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/reachtextarea/RichTextAreaDeclarativeTest.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/textarea/TextAreaDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/textfield/TextFieldDeclarativeTest.java

index dcfb41581027eb4ee2d6bf9832f6f0824b7f3786..0f75ea8099f734a1b8b135a2a6de08d63f37be28 100644 (file)
@@ -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<Slider> {
+public class SliderDeclarativeTest
+        extends AbstractFieldDeclarativeTest<Slider, Double> {
 
+    @Override
     @Test
-    public void testDefault() {
-        String design = "<vaadin-slider>";
+    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 = "<vaadin-slider min=10 max=20 resolution=1 value=12.3>";
+    public void testVertical() {
+        String design = "<vaadin-slider vertical>";
 
         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 = "<vaadin-slider vertical>";
+    @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 = "<vaadin-slider readonly min=10 max=20 resolution=1 value=12.3>";
+    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<Slider> 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 (file)
index 0000000..2722dae
--- /dev/null
@@ -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.
+ * <p>
+ * 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<T extends AbstractComponent>
+        extends DeclarativeTestBase<T> {
+
+    /**
+     * 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<? extends T> 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 = "<div>testError</div>";
+        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 (file)
index 0000000..530019f
--- /dev/null
@@ -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.
+ * <p>
+ * 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<T extends AbstractDateField>
+        extends AbstractFieldDeclarativeTest<T, LocalDate> {
+
+    @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 (file)
index 0000000..df7b64b
--- /dev/null
@@ -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.
+ * <p>
+ * 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<T extends AbstractField<V>, V>
+        extends AbstractComponentDeclarativeTestBase<T> {
+
+    @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;
+}
index d7fd06dbe8b62e5a12458773885e0b35567bfc02..7ba3e6aaca9efb261473d70135e4bed273b0e119 100644 (file)
  */
 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<AbstractTextField> {
+public abstract class AbstractTextFieldDeclarativeTest<T extends AbstractTextField>
+        extends AbstractFieldDeclarativeTest<T, String> {
 
     @Test
-    public void testAttributes() {
-        String design = "<vaadin-text-field "
-                // + "null-representation=this-is-null "
-                // + "null-setting-allowed "
-                + "maxlength=5 " + "placeholder=input value-change-mode=eager "
-                + "value-change-timeout=100 />";
-        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);
     }
 
 }
index 2ef0ffd89136bd7af36c61252cd1de63e9326a3e..0b45579d5d9cb55cb62eea2c6bd2b142e9b9049f 100644 (file)
@@ -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<CheckBox> {
-
-    @Test
-    public void testChecked() {
-        String design = "<vaadin-check-box />";
-        CheckBox checkBox = new CheckBox();
-        testRead(design, checkBox);
-        testWrite(design, checkBox);
-    }
+public class CheckboxDeclarativeTest
+        extends AbstractFieldDeclarativeTest<CheckBox, Boolean> {
 
-    @Test
-    public void testUnchecked() {
+    @Override
+    public void valueDeserialization()
+            throws InstantiationException, IllegalAccessException {
         String design = "<vaadin-check-box checked />";
         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 = "<vaadin-check-box readonly checked />";
+
         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<CheckBox> getComponentClass() {
+        return CheckBox.class;
+    }
+
 }
index 8018d6603e9419b6d6d3126a2cbb33da0eded5f5..2c646e47a0789e0bdb3a666a3ff4dfcdace45483 100644 (file)
@@ -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<AbstractColorPicker> {
+/**
+ * Abstract test class which contains tests for declarative format for
+ * properties that are common for AbstractColorPicker.
+ * <p>
+ * 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<T extends AbstractColorPicker>
+        extends AbstractFieldDeclarativeTest<T, Color> {
 
     @Test
-    public void testAllAbstractColorPickerFeatures() {
-        String design = "<vaadin-color-picker color='#fafafa' default-caption-enabled position='100,100'"
-                + " popup-style='simple' rgb-visibility='false' hsv-visibility='false'"
-                + " history-visibility=false textfield-visibility=false />";
-        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 = "<vaadin-color-picker />";
-        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 = "<vaadin-color-picker-area color='#fafafa' default-caption-enabled position='100,100'"
-                + " popup-style='simple' rgb-visibility='false' hsv-visibility='false'"
-                + " history-visibility=false textfield-visibility=false />";
-        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 = "<vaadin-color-picker-area />";
-        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 (file)
index 0000000..715acfd
--- /dev/null
@@ -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<ColorPickerArea> {
+
+    @Override
+    protected String getComponentTag() {
+        return "vaadin-color-picker-area";
+    }
+
+    @Override
+    protected Class<ColorPickerArea> 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 (file)
index 0000000..41d730e
--- /dev/null
@@ -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<ColorPicker> {
+
+    @Override
+    protected String getComponentTag() {
+        return "vaadin-color-picker";
+    }
+
+    @Override
+    protected Class<ColorPicker> getComponentClass() {
+        return ColorPicker.class;
+    }
+
+}
index ef6ec554c22f9fcd9aeeb3b377acf6bc4df1c55f..58fdd3912be43c824eece17b2ba0548092ccbc78 100644 (file)
  */
 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<DateField> {
-
-    private String getBasicDesign() {
-        return "<vaadin-date-field assistive-text='at' text-field-enabled='false' show-iso-week-numbers range-end=\"2019-01-15\" placeholder=\"Pick a day\" value=\"2003-02-27\"></vaadin-date-field>";
-    }
+public class DateFieldDeclarativeTest
+        extends AbstarctDateFieldDeclarativeTest<DateField> {
 
-    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<? extends DateField> getComponentClass() {
+        return DateField.class;
     }
 
 }
index c9476419861280547444d05d733cb733893ce683..c6b97a1ec24bd2d4aaed5dba40f902cced3e84de 100644 (file)
@@ -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<InlineDateField> {
+        extends AbstarctDateFieldDeclarativeTest<InlineDateField> {
 
     @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<? extends InlineDateField> getComponentClass() {
+        return InlineDateField.class;
+    }
+
 }
index a2ccc78300ce831bfce95858765f37f494c8a2a6..c7908fd6b05fcd8a8ca866c2099476bb51ce02c4 100644 (file)
  */
 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<PasswordField> {
+public class PasswordFieldDeclarativeTest extends TextFieldDeclarativeTest {
+
+    @Override
+    protected Class<? extends TextField> getComponentClass() {
+        return PasswordField.class;
+    }
 
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<vaadin-password-field readonly value=\"test value\"/>";
-        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 (file)
index 0000000..43da30b
--- /dev/null
@@ -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<RichTextArea, String> {
+
+    public void valueDeserialization()
+            throws InstantiationException, IllegalAccessException {
+        String value = "<b>Header</b> \n<br>Some text";
+        String design = String.format("<%s>\n      %s\n      </%s>",
+                getComponentTag(), value, getComponentTag());
+
+        RichTextArea component = new RichTextArea();
+        component.setValue(value);
+
+        testRead(design, component);
+        testWrite(design, component);
+    }
+
+    public void readOnlyValue()
+            throws InstantiationException, IllegalAccessException {
+        String value = "<b>Header</b> \n<br>Some text";
+        String design = String.format("<%s readonly>\n      %s\n      </%s>",
+                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<RichTextArea> getComponentClass() {
+        return RichTextArea.class;
+    }
+
+}
index 1b6df09c191fdd0ab882df2a5845c260e7e52ce3..ad8d88e9c5d30aba835cb841669a7258882b520e 100644 (file)
@@ -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<TextArea> {
+public class TextAreaDeclarativeTest
+        extends AbstractTextFieldDeclarativeTest<TextArea> {
 
-    @Test
-    public void testTextArea() {
-        String design = "<vaadin-text-area rows=6 word-wrap=false>Hello World!</vaadin-text-area>";
-        TextArea ta = new TextArea();
-        ta.setRows(6);
-        ta.setWordWrap(false);
-        ta.setValue("Hello World!");
-        testRead(design, ta);
-        testWrite(design, ta);
+    @Override
+    public void valueDeserialization()
+            throws InstantiationException, IllegalAccessException {
+        String value = "Hello World!";
+        String design = String.format("<%s>%s</%s>", getComponentTag(), value,
+                getComponentTag());
+
+        TextArea component = new TextArea();
+        component.setValue(value);
+
+        testRead(design, component);
+        testWrite(design, component);
+    }
+
+    @Override
+    public void readOnlyValue()
+            throws InstantiationException, IllegalAccessException {
+        String value = "Hello World!";
+        String design = String.format("<%s readonly>%s</%s>", getComponentTag(),
+                value, getComponentTag());
+
+        TextArea component = new TextArea();
+        component.setValue(value);
+        component.setReadOnly(true);
+
+        testRead(design, component);
+        testWrite(design, component);
     }
 
     @Test
@@ -61,14 +80,28 @@ public class TextAreaDeclarativeTest extends DeclarativeTestBase<TextArea> {
     }
 
     @Test
-    public void testReadOnlyValue() {
-        String design = "<vaadin-text-area readonly rows=6 word-wrap=false>Hello World!</vaadin-text-area>";
-        TextArea ta = new TextArea();
-        ta.setRows(6);
-        ta.setWordWrap(false);
-        ta.setValue("Hello World!");
-        ta.setReadOnly(true);
-        testRead(design, ta);
-        testWrite(design, ta);
+    public void remainingAttriburesDeserialization() {
+        int rows = 11;
+        boolean wrap = false;
+        String design = String.format("<%s rows='%s' word-wrap='%s'/>",
+                getComponentTag(), rows, wrap);
+
+        TextArea component = new TextArea();
+        component.setRows(rows);
+        component.setWordWrap(wrap);
+
+        testRead(design, component);
+        testWrite(design, component);
+    }
+
+    @Override
+    protected String getComponentTag() {
+        return "vaadin-text-area";
     }
+
+    @Override
+    protected Class<TextArea> getComponentClass() {
+        return TextArea.class;
+    }
+
 }
index b0050dfbe88a8342238707e6a74205258cb2710c..aa39cc3625ff08e4f9b93b084ebb7a9ce11bb2f4 100644 (file)
@@ -17,7 +17,7 @@ package com.vaadin.tests.server.component.textfield;
 
 import org.junit.Test;
 
-import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.tests.server.component.abstracttextfield.AbstractTextFieldDeclarativeTest;
 import com.vaadin.ui.TextField;
 
 /**
@@ -26,32 +26,47 @@ import com.vaadin.ui.TextField;
  * @since 7.4
  * @author Vaadin Ltd
  */
-public class TextFieldDeclarativeTest extends DeclarativeTestBase<TextField> {
+public class TextFieldDeclarativeTest
+        extends AbstractTextFieldDeclarativeTest<TextField> {
 
+    @Override
     @Test
-    public void testEmpty() {
-        String design = "<vaadin-text-field/>";
-        TextField tf = new TextField();
-        testRead(design, tf);
-        testWrite(design, tf);
+    public void valueDeserialization()
+            throws InstantiationException, IllegalAccessException {
+        String value = "foo";
+        String design = String.format("<%s value='%s'/>", getComponentTag(),
+                value);
+
+        TextField component = getComponentClass().newInstance();
+        component.setValue(value);
+        testRead(design, component);
+        testWrite(design, component);
     }
 
+    @Override
     @Test
-    public void testValue() {
-        String design = "<vaadin-text-field value=\"test value\"/>";
-        TextField tf = new TextField();
-        tf.setValue("test value");
-        testRead(design, tf);
-        testWrite(design, tf);
+    public void readOnlyValue()
+            throws InstantiationException, IllegalAccessException {
+        String value = "foo";
+        String design = String.format("<%s readonly value='%s'/>",
+                getComponentTag(), value);
+
+        TextField component = getComponentClass().newInstance();
+        component.setValue(value);
+
+        component.setReadOnly(true);
+        testRead(design, component);
+        testWrite(design, component);
     }
 
-    @Test
-    public void testReadOnlyValue() {
-        String design = "<vaadin-text-field readonly value=\"test value\"/>";
-        TextField tf = new TextField();
-        tf.setValue("test value");
-        tf.setReadOnly(true);
-        testRead(design, tf);
-        testWrite(design, tf);
+    @Override
+    protected String getComponentTag() {
+        return "vaadin-text-field";
     }
+
+    @Override
+    protected Class<? extends TextField> getComponentClass() {
+        return TextField.class;
+    }
+
 }