diff options
author | Denis <denis@vaadin.com> | 2016-12-20 10:46:17 +0200 |
---|---|---|
committer | Ilia Motornyi <elmot@vaadin.com> | 2016-12-20 10:46:17 +0200 |
commit | 912c86800baa0b4260c472fd06dc9360fb5c6666 (patch) | |
tree | ce43fb1ebd2c6be190fa1c47a01eee0847877274 /server/src | |
parent | c76f217ff0fc09b8bd4ab4645b416ed3e55d93f8 (diff) | |
download | vaadin-framework-912c86800baa0b4260c472fd06dc9360fb5c6666.tar.gz vaadin-framework-912c86800baa0b4260c472fd06dc9360fb5c6666.zip |
Declarative tests improvements
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstractDateFieldDeclarativeTest.java (renamed from server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java) | 2 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java | 32 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java | 23 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java | 2 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/datefield/DateFieldDeclarativeTest.java | 4 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/datefield/InlineDateFieldDeclarativeTest.java | 4 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/tests/server/component/radiobuttongroup/RadioButtonGroupDeclarativeTest.java | 2 |
7 files changed, 53 insertions, 16 deletions
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/AbstractDateFieldDeclarativeTest.java index 530019fa92..880a6a47f7 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstarctDateFieldDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractdatefield/AbstractDateFieldDeclarativeTest.java @@ -36,7 +36,7 @@ import com.vaadin.ui.AbstractDateField; * @author Vaadin Ltd * */ -public abstract class AbstarctDateFieldDeclarativeTest<T extends AbstractDateField> +public abstract class AbstractDateFieldDeclarativeTest<T extends AbstractDateField> extends AbstractFieldDeclarativeTest<T, LocalDate> { @Override diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java index 590d7ec8ea..4da4a49cc1 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractlisting/AbstractListingDeclarativeTest.java @@ -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 { diff --git a/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java index 5a13d51aaa..e96bb4bb55 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/abstractmultiselect/AbstractMultiSelectDeclarativeTest.java @@ -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); + } + } diff --git a/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java index f94938b765..5699de96de 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/checkboxgroup/CheckBoxGroupDeclarativeTest.java @@ -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); } 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 58fdd3912b..ea7971b84e 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 @@ -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() 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 c6b97a1ec2..4e056d3c63 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.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 { diff --git a/server/src/test/java/com/vaadin/tests/server/component/radiobuttongroup/RadioButtonGroupDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/radiobuttongroup/RadioButtonGroupDeclarativeTest.java index 620fb170b6..d25c12a4d7 100644 --- a/server/src/test/java/com/vaadin/tests/server/component/radiobuttongroup/RadioButtonGroupDeclarativeTest.java +++ b/server/src/test/java/com/vaadin/tests/server/component/radiobuttongroup/RadioButtonGroupDeclarativeTest.java @@ -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); } |