]> source.dussan.org Git - vaadin-framework.git/commitdiff
Declarative tests improvements
authorDenis <denis@vaadin.com>
Tue, 20 Dec 2016 08:46:17 +0000 (10:46 +0200)
committerIlia Motornyi <elmot@vaadin.com>
Tue, 20 Dec 2016 08:46:17 +0000 (10:46 +0200)
server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java [deleted file]
server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstractDateFieldDeclarativeTest.java [new file with mode: 0644]
server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java
server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java
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/radiobuttongroup/RadioButtonGroupDeclarativeTest.java

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
deleted file mode 100644 (file)
index 530019f..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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/abstractdatefield/AbstractDateFieldDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstractDateFieldDeclarativeTest.java
new file mode 100644 (file)
index 0000000..880a6a4
--- /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 AbstractDateFieldDeclarativeTest<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);
+    }
+
+}
index 590d7ec8eab43cd97cd867b96ad383651f92d689..4da4a49cc1ccbe2ae3500b4132ce05f47a64c7c6 100644 (file)
@@ -20,20 +20,25 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.List;
+import java.util.function.Consumer;
 
+import org.junit.Assert;
 import org.junit.Test;
 
 import com.vaadin.data.Listing;
+import com.vaadin.data.provider.Query;
 import com.vaadin.server.ExternalResource;
 import com.vaadin.server.FileResource;
 import com.vaadin.server.Resource;
 import com.vaadin.server.SerializablePredicate;
 import com.vaadin.server.ThemeResource;
+import com.vaadin.tests.design.DeclarativeTestBaseBase;
 import com.vaadin.tests.server.component.abstractcomponent.AbstractComponentDeclarativeTestBase;
 import com.vaadin.ui.AbstractComponent;
 import com.vaadin.ui.AbstractListing;
 import com.vaadin.ui.IconGenerator;
 import com.vaadin.ui.ItemCaptionGenerator;
+import com.vaadin.ui.declarative.DesignContext;
 
 /**
  * {@link AbstractListing} component declarative test.
@@ -144,6 +149,33 @@ public abstract class AbstractListingDeclarativeTest<T extends AbstractListing &
         return super.acceptProperty(clazz, readMethod, writeMethod);
     }
 
+    public DesignContext readComponentAndCompare(String design, T expected,
+            Consumer<DesignContext> configureContext) {
+        DesignContext context = super.readComponentAndCompare(design, expected);
+        configureContext.accept(context);
+        T read = (T) context.getRootComponent();
+        testReadData(design, expected, read, context);
+        return context;
+    }
+
+    public T testRead(String design, T expected, boolean testWrite) {
+        T read = testRead(design, expected);
+        if (testWrite) {
+            DesignContext context = new DesignContext();
+            context.setShouldWriteDataDelegate(
+                    DeclarativeTestBaseBase.ALWAYS_WRITE_DATA);
+            testReadData(design, expected, read, context);
+        }
+        return read;
+    }
+
+    private void testReadData(String design, T expected, T read,
+            DesignContext context) {
+        Assert.assertEquals(read.getDataProvider().size(new Query<>()),
+                expected.getDataProvider().size(new Query<>()));
+        testWrite(read, design, context);
+    }
+
     private Method getIconGeneratorMethod(T component)
             throws IllegalAccessException, InvocationTargetException {
         try {
index 5a13d51aaa35b59bae7667679741b9d1d8aeb140..e96bb4bb55a6d52a069756f0764cf66c61f6e340 100644 (file)
@@ -67,14 +67,13 @@ public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMulti
         component.select("foobar");
         component.setItemCaptionGenerator(item -> item + "1");
 
-        DesignContext context = readComponentAndCompare(design, component);
+        DesignContext context = readComponentAndCompare(design, component,
+                ctxt -> configureContext(type, attribute, component, ctxt));
         Assert.assertEquals(type,
                 context.getCustomAttributes(context.getRootComponent())
                         .get(attribute));
         context = new DesignContext();
-        context.setCustomAttribute(component, attribute, type);
-        context.setShouldWriteDataDelegate(
-                DeclarativeTestBaseBase.ALWAYS_WRITE_DATA);
+        configureContext(type, attribute, component, context);
         testWrite(component, design, context);
     }
 
@@ -97,14 +96,13 @@ public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMulti
         component.setValue(new HashSet<>(Arrays.asList("foo", "foobar")));
         component.setItemCaptionGenerator(item -> item + "1");
 
-        DesignContext context = readComponentAndCompare(design, component);
+        DesignContext context = readComponentAndCompare(design, component,
+                ctxt -> configureContext(type, attribute, component, ctxt));
         Assert.assertEquals(type,
                 context.getCustomAttributes(context.getRootComponent())
                         .get(attribute));
         context = new DesignContext();
-        context.setCustomAttribute(component, attribute, type);
-        context.setShouldWriteDataDelegate(
-                DeclarativeTestBaseBase.ALWAYS_WRITE_DATA);
+        configureContext(type, attribute, component, context);
         testWrite(component, design, context);
     }
 
@@ -125,8 +123,15 @@ public abstract class AbstractMultiSelectDeclarativeTest<T extends AbstractMulti
         component.setItems(items);
         component.setReadOnly(true);
 
-        testRead(design, component);
+        testRead(design, component, true);
         testWrite(design, component, true);
     }
 
+    private void configureContext(String type, String attribute, T component,
+            DesignContext context) {
+        context.setCustomAttribute(component, attribute, type);
+        context.setShouldWriteDataDelegate(
+                DeclarativeTestBaseBase.ALWAYS_WRITE_DATA);
+    }
+
 }
index f94938b765194492bb92c310cc1920ae122dc3df..5699de96de7fdd6e041da85b783447934be99c17 100644 (file)
@@ -63,7 +63,7 @@ public class CheckBoxGroupDeclarativeTest
         group.setHtmlContentAllowed(true);
         group.setItemCaptionGenerator(item -> generateCaption(item, items));
 
-        testRead(design, group);
+        testRead(design, group, true);
         testWrite(design, group, true);
     }
 
index 58fdd3912be43c824eece17b2ba0548092ccbc78..ea7971b84eb2b46caa03f969791e9cd1ba592bac 100644 (file)
@@ -17,7 +17,7 @@ package com.vaadin.tests.server.component.datefield;
 
 import org.junit.Test;
 
-import com.vaadin.tests.server.component.abstractdatefield.AbstarctDateFieldDeclarativeTest;
+import com.vaadin.tests.server.component.abstractdatefield.AbstractDateFieldDeclarativeTest;
 import com.vaadin.ui.DateField;
 
 /**
@@ -27,7 +27,7 @@ import com.vaadin.ui.DateField;
  * @author Vaadin Ltd
  */
 public class DateFieldDeclarativeTest
-        extends AbstarctDateFieldDeclarativeTest<DateField> {
+        extends AbstractDateFieldDeclarativeTest<DateField> {
 
     @Test
     public void remainingAttributes()
index c6b97a1ec24bd2d4aaed5dba40f902cced3e84de..4e056d3c639ea365bab8b3219615f0eab19fe17b 100644 (file)
@@ -21,7 +21,7 @@ import java.time.LocalDate;
 
 import org.junit.Test;
 
-import com.vaadin.tests.server.component.abstractdatefield.AbstarctDateFieldDeclarativeTest;
+import com.vaadin.tests.server.component.abstractdatefield.AbstractDateFieldDeclarativeTest;
 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 AbstarctDateFieldDeclarativeTest<InlineDateField> {
+        extends AbstractDateFieldDeclarativeTest<InlineDateField> {
 
     @Test
     public void testInlineDateFieldToFromDesign() throws Exception {
index 620fb170b6889a0cf60e6b9a4c806ce3b3349f66..d25c12a4d7088d4780bc71ae3f6c6f5442859758 100644 (file)
@@ -63,7 +63,7 @@ public class RadioButtonGroupDeclarativeTest
         group.setHtmlContentAllowed(true);
         group.setItemCaptionGenerator(item -> generateCaption(item, items));
 
-        testRead(design, group);
+        testRead(design, group, true);
         testWrite(design, group, true);
     }