+++ /dev/null
-/*
- * 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);
- }
-
-}
--- /dev/null
+/*
+ * 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);
+ }
+
+}
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.
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 {
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);
}
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);
}
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);
+ }
+
}
group.setHtmlContentAllowed(true);
group.setItemCaptionGenerator(item -> generateCaption(item, items));
- testRead(design, group);
+ testRead(design, group, true);
testWrite(design, group, true);
}
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;
/**
* @author Vaadin Ltd
*/
public class DateFieldDeclarativeTest
- extends AbstarctDateFieldDeclarativeTest<DateField> {
+ extends AbstractDateFieldDeclarativeTest<DateField> {
@Test
public void remainingAttributes()
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;
* @author Vaadin Ltd
*/
public class InlineDateFieldDeclarativeTest
- extends AbstarctDateFieldDeclarativeTest<InlineDateField> {
+ extends AbstractDateFieldDeclarativeTest<InlineDateField> {
@Test
public void testInlineDateFieldToFromDesign() throws Exception {
group.setHtmlContentAllowed(true);
group.setItemCaptionGenerator(item -> generateCaption(item, items));
- testRead(design, group);
+ testRead(design, group, true);
testWrite(design, group, true);
}