diff options
Diffstat (limited to 'tests/server-side/com')
41 files changed, 1135 insertions, 195 deletions
diff --git a/tests/server-side/com/vaadin/data/util/BeanItemTest.java b/tests/server-side/com/vaadin/data/util/BeanItemTest.java index 044a410803..51e11260f5 100644 --- a/tests/server-side/com/vaadin/data/util/BeanItemTest.java +++ b/tests/server-side/com/vaadin/data/util/BeanItemTest.java @@ -12,11 +12,6 @@ import java.util.Map; import junit.framework.Assert; import junit.framework.TestCase; -import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.MethodProperty; -import com.vaadin.data.util.MethodPropertyDescriptor; -import com.vaadin.data.util.VaadinPropertyDescriptor; - /** * Test BeanItem specific features. * @@ -322,7 +317,7 @@ public class BeanItemTest extends TestCase { MyClass.class.getDeclaredMethod("getName"), MyClass.class.getDeclaredMethod("setName", String.class)); - BeanItem<MyClass> item = new BeanItem(new MyClass("bean1")); + BeanItem<MyClass> item = new BeanItem<MyClass>(new MyClass("bean1")); Assert.assertEquals(6, item.getItemPropertyIds().size()); Assert.assertEquals(null, item.getItemProperty("myname")); diff --git a/tests/server-side/com/vaadin/data/util/NestedMethodPropertyTest.java b/tests/server-side/com/vaadin/data/util/NestedMethodPropertyTest.java index b110ea1c6b..640ede8743 100644 --- a/tests/server-side/com/vaadin/data/util/NestedMethodPropertyTest.java +++ b/tests/server-side/com/vaadin/data/util/NestedMethodPropertyTest.java @@ -10,8 +10,6 @@ import java.io.Serializable; import junit.framework.Assert; import junit.framework.TestCase; -import com.vaadin.data.util.NestedMethodProperty; - public class NestedMethodPropertyTest extends TestCase { public static class Address implements Serializable { @@ -126,34 +124,34 @@ public class NestedMethodPropertyTest extends TestCase { } public void testSingleLevelNestedSimpleProperty() { - NestedMethodProperty nameProperty = new NestedMethodProperty(vaadin, - "name"); + NestedMethodProperty<String> nameProperty = new NestedMethodProperty<String>( + vaadin, "name"); Assert.assertEquals(String.class, nameProperty.getType()); Assert.assertEquals("Vaadin", nameProperty.getValue()); } public void testSingleLevelNestedObjectProperty() { - NestedMethodProperty managerProperty = new NestedMethodProperty(vaadin, - "manager"); + NestedMethodProperty<Person> managerProperty = new NestedMethodProperty<Person>( + vaadin, "manager"); Assert.assertEquals(Person.class, managerProperty.getType()); Assert.assertEquals(joonas, managerProperty.getValue()); } public void testMultiLevelNestedProperty() { - NestedMethodProperty managerNameProperty = new NestedMethodProperty( + NestedMethodProperty<String> managerNameProperty = new NestedMethodProperty<String>( vaadin, "manager.name"); - NestedMethodProperty addressProperty = new NestedMethodProperty(vaadin, - "manager.address"); - NestedMethodProperty streetProperty = new NestedMethodProperty(vaadin, - "manager.address.street"); - NestedMethodProperty postalCodePrimitiveProperty = new NestedMethodProperty( + NestedMethodProperty<Address> addressProperty = new NestedMethodProperty<Address>( + vaadin, "manager.address"); + NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>( + vaadin, "manager.address.street"); + NestedMethodProperty<Integer> postalCodePrimitiveProperty = new NestedMethodProperty<Integer>( vaadin, "manager.address.postalCodePrimitive"); - NestedMethodProperty postalCodeObjectProperty = new NestedMethodProperty( + NestedMethodProperty<Integer> postalCodeObjectProperty = new NestedMethodProperty<Integer>( vaadin, "manager.address.postalCodeObject"); - NestedMethodProperty booleanProperty = new NestedMethodProperty(vaadin, - "manager.address.boolean"); + NestedMethodProperty<Boolean> booleanProperty = new NestedMethodProperty<Boolean>( + vaadin, "manager.address.boolean"); Assert.assertEquals(String.class, managerNameProperty.getType()); Assert.assertEquals("Joonas", managerNameProperty.getValue()); @@ -166,25 +164,27 @@ public class NestedMethodPropertyTest extends TestCase { Assert.assertEquals(Integer.class, postalCodePrimitiveProperty.getType()); - Assert.assertEquals(20540, postalCodePrimitiveProperty.getValue()); + Assert.assertEquals(Integer.valueOf(20540), + postalCodePrimitiveProperty.getValue()); Assert.assertEquals(Integer.class, postalCodeObjectProperty.getType()); - Assert.assertEquals(20540, postalCodeObjectProperty.getValue()); + Assert.assertEquals(Integer.valueOf(20540), + postalCodeObjectProperty.getValue()); Assert.assertEquals(Boolean.class, booleanProperty.getType()); - Assert.assertEquals(true, booleanProperty.getValue()); + Assert.assertEquals(Boolean.TRUE, booleanProperty.getValue()); } public void testEmptyPropertyName() { try { - new NestedMethodProperty(vaadin, ""); + new NestedMethodProperty<Object>(vaadin, ""); fail(); } catch (IllegalArgumentException e) { // should get exception } try { - new NestedMethodProperty(vaadin, " "); + new NestedMethodProperty<Object>(vaadin, " "); fail(); } catch (IllegalArgumentException e) { // should get exception @@ -193,25 +193,25 @@ public class NestedMethodPropertyTest extends TestCase { public void testInvalidPropertyName() { try { - new NestedMethodProperty(vaadin, "."); + new NestedMethodProperty<Object>(vaadin, "."); fail(); } catch (IllegalArgumentException e) { // should get exception } try { - new NestedMethodProperty(vaadin, ".manager"); + new NestedMethodProperty<Object>(vaadin, ".manager"); fail(); } catch (IllegalArgumentException e) { // should get exception } try { - new NestedMethodProperty(vaadin, "manager."); + new NestedMethodProperty<Object>(vaadin, "manager."); fail(); } catch (IllegalArgumentException e) { // should get exception } try { - new NestedMethodProperty(vaadin, "manager..name"); + new NestedMethodProperty<Object>(vaadin, "manager..name"); fail(); } catch (IllegalArgumentException e) { // should get exception @@ -220,21 +220,21 @@ public class NestedMethodPropertyTest extends TestCase { public void testInvalidNestedPropertyName() { try { - new NestedMethodProperty(vaadin, "member"); + new NestedMethodProperty<Object>(vaadin, "member"); fail(); } catch (IllegalArgumentException e) { // should get exception } try { - new NestedMethodProperty(vaadin, "manager.pet"); + new NestedMethodProperty<Object>(vaadin, "manager.pet"); fail(); } catch (IllegalArgumentException e) { // should get exception } try { - new NestedMethodProperty(vaadin, "manager.address.city"); + new NestedMethodProperty<Object>(vaadin, "manager.address.city"); fail(); } catch (IllegalArgumentException e) { // should get exception @@ -242,10 +242,10 @@ public class NestedMethodPropertyTest extends TestCase { } public void testNullNestedProperty() { - NestedMethodProperty managerNameProperty = new NestedMethodProperty( + NestedMethodProperty<String> managerNameProperty = new NestedMethodProperty<String>( vaadin, "manager.name"); - NestedMethodProperty streetProperty = new NestedMethodProperty(vaadin, - "manager.address.street"); + NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>( + vaadin, "manager.address.street"); joonas.setAddress(null); try { @@ -274,15 +274,15 @@ public class NestedMethodPropertyTest extends TestCase { } public void testMultiLevelNestedPropertySetValue() { - NestedMethodProperty managerNameProperty = new NestedMethodProperty( + NestedMethodProperty<String> managerNameProperty = new NestedMethodProperty<String>( vaadin, "manager.name"); - NestedMethodProperty addressProperty = new NestedMethodProperty(vaadin, - "manager.address"); - NestedMethodProperty streetProperty = new NestedMethodProperty(vaadin, - "manager.address.street"); - NestedMethodProperty postalCodePrimitiveProperty = new NestedMethodProperty( + NestedMethodProperty<Address> addressProperty = new NestedMethodProperty<Address>( + vaadin, "manager.address"); + NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>( + vaadin, "manager.address.street"); + NestedMethodProperty<Integer> postalCodePrimitiveProperty = new NestedMethodProperty<Integer>( vaadin, "manager.address.postalCodePrimitive"); - NestedMethodProperty postalCodeObjectProperty = new NestedMethodProperty( + NestedMethodProperty<Integer> postalCodeObjectProperty = new NestedMethodProperty<Integer>( vaadin, "manager.address.postalCodeObject"); managerNameProperty.setValue("Joonas L"); @@ -303,21 +303,22 @@ public class NestedMethodPropertyTest extends TestCase { } public void testSerialization() throws IOException, ClassNotFoundException { - NestedMethodProperty streetProperty = new NestedMethodProperty(vaadin, - "manager.address.street"); + NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>( + vaadin, "manager.address.street"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(streetProperty); - NestedMethodProperty property2 = (NestedMethodProperty) new ObjectInputStream( + @SuppressWarnings("unchecked") + NestedMethodProperty<String> property2 = (NestedMethodProperty<String>) new ObjectInputStream( new ByteArrayInputStream(baos.toByteArray())).readObject(); Assert.assertEquals("Ruukinkatu 2-4", property2.getValue()); } public void testIsReadOnly() { - NestedMethodProperty streetProperty = new NestedMethodProperty(vaadin, - "manager.address.street"); - NestedMethodProperty booleanProperty = new NestedMethodProperty(vaadin, - "manager.address.boolean"); + NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>( + vaadin, "manager.address.street"); + NestedMethodProperty<Boolean> booleanProperty = new NestedMethodProperty<Boolean>( + vaadin, "manager.address.boolean"); Assert.assertFalse(streetProperty.isReadOnly()); Assert.assertTrue(booleanProperty.isReadOnly()); diff --git a/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java b/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java index a934b40dce..0ed554a1a0 100644 --- a/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java +++ b/tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java @@ -4,8 +4,6 @@ import junit.framework.TestCase; import org.junit.Assert;
-import com.vaadin.data.util.ObjectProperty;
-
public class ObjectPropertyTest extends TestCase {
public static class TestSuperClass {
@@ -70,7 +68,7 @@ public class ObjectPropertyTest extends TestCase { ObjectProperty<TestSuperClass> prop = new ObjectProperty<TestSuperClass>(
super1, TestSuperClass.class);
Assert.assertEquals("super1", prop.getValue().getName());
- prop.setValue("super2");
+ prop.setValue(new TestSuperClass("super2"));
Assert.assertEquals("super1", super1.getName());
Assert.assertEquals("super2", prop.getValue().getName());
}
@@ -79,7 +77,7 @@ public class ObjectPropertyTest extends TestCase { ObjectProperty<TestSubClass> prop = new ObjectProperty<TestSubClass>(
sub1, TestSubClass.class);
Assert.assertEquals("Subclass: sub1", prop.getValue().getName());
- prop.setValue("sub2");
+ prop.setValue(new TestSubClass("sub2"));
Assert.assertEquals("Subclass: sub1", sub1.getName());
Assert.assertEquals("Subclass: sub2", prop.getValue().getName());
}
@@ -92,7 +90,7 @@ public class ObjectPropertyTest extends TestCase { // create correct subclass based on the runtime type of the instance
// given to ObjectProperty constructor, which is a subclass of the type
// parameter
- prop.setValue("sub2");
+ prop.setValue(new TestSubClass("sub2"));
Assert.assertEquals("Subclass: sub2", prop.getValue().getName());
}
diff --git a/tests/server-side/com/vaadin/data/util/PropertyDescriptorTest.java b/tests/server-side/com/vaadin/data/util/PropertyDescriptorTest.java index c3621fa99b..14e70d76d4 100644 --- a/tests/server-side/com/vaadin/data/util/PropertyDescriptorTest.java +++ b/tests/server-side/com/vaadin/data/util/PropertyDescriptorTest.java @@ -11,9 +11,6 @@ import junit.framework.Assert; import junit.framework.TestCase; import com.vaadin.data.Property; -import com.vaadin.data.util.MethodPropertyDescriptor; -import com.vaadin.data.util.NestedPropertyDescriptor; -import com.vaadin.data.util.VaadinPropertyDescriptor; import com.vaadin.data.util.NestedMethodPropertyTest.Person; public class PropertyDescriptorTest extends TestCase { @@ -33,11 +30,12 @@ public class PropertyDescriptorTest extends TestCase { ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(descriptor); + @SuppressWarnings("unchecked") VaadinPropertyDescriptor<Person> descriptor2 = (VaadinPropertyDescriptor<Person>) new ObjectInputStream( new ByteArrayInputStream(baos.toByteArray())).readObject(); - Property property = descriptor2 - .createProperty(new Person("John", null)); + Property<?> property = descriptor2.createProperty(new Person("John", + null)); Assert.assertEquals("John", property.getValue()); } @@ -47,10 +45,11 @@ public class PropertyDescriptorTest extends TestCase { ByteArrayOutputStream baos = new ByteArrayOutputStream(); new ObjectOutputStream(baos).writeObject(pd); + @SuppressWarnings("unchecked") VaadinPropertyDescriptor<Person> pd2 = (VaadinPropertyDescriptor<Person>) new ObjectInputStream( new ByteArrayInputStream(baos.toByteArray())).readObject(); - Property property = pd2.createProperty(new Person("John", null)); + Property<?> property = pd2.createProperty(new Person("John", null)); Assert.assertEquals("John", property.getValue()); } } diff --git a/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java b/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java index 4516e8d109..a3169332ec 100644 --- a/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java +++ b/tests/server-side/com/vaadin/data/util/PropertySetItemTest.java @@ -9,8 +9,6 @@ import org.easymock.EasyMock; import com.vaadin.data.Item.PropertySetChangeEvent; import com.vaadin.data.Item.PropertySetChangeListener; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.data.util.PropertysetItem; public class PropertySetItemTest extends TestCase { @@ -395,13 +393,13 @@ public class PropertySetItemTest extends TestCase { item.addItemProperty(ID1, prop1); - Assert.assertEquals(String.valueOf(prop1), item.toString()); + Assert.assertEquals(String.valueOf(prop1.getValue()), item.toString()); item.addItemProperty(ID2, prop2); Assert.assertEquals( - String.valueOf(prop1) + " " + String.valueOf(prop2), - item.toString()); + String.valueOf(prop1.getValue()) + " " + + String.valueOf(prop2.getValue()), item.toString()); } } diff --git a/tests/server-side/com/vaadin/data/util/TestContainerSorting.java b/tests/server-side/com/vaadin/data/util/TestContainerSorting.java index dbfea7d75d..8f078199f5 100644 --- a/tests/server-side/com/vaadin/data/util/TestContainerSorting.java +++ b/tests/server-side/com/vaadin/data/util/TestContainerSorting.java @@ -8,8 +8,7 @@ import junit.framework.TestCase; import com.vaadin.data.Container;
import com.vaadin.data.Item;
-import com.vaadin.data.util.HierarchicalContainer;
-import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.tests.util.TestUtil;
public class TestContainerSorting extends TestCase {
@@ -93,12 +92,12 @@ public class TestContainerSorting extends TestCase { "Might and Magic", "Natural languages", "PHP",
"Programming languages", "Python", "Red Alert", "Swedish",
"Toyota", "Volvo" });
- assertArrays(
+ TestUtil.assertArrays(
hc.rootItemIds().toArray(),
new Integer[] { nameToId.get("Cars"), nameToId.get("Games"),
nameToId.get("Natural languages"),
nameToId.get("Programming languages") });
- assertArrays(
+ TestUtil.assertArrays(
hc.getChildren(nameToId.get("Games")).toArray(),
new Integer[] { nameToId.get("Call of Duty"),
nameToId.get("Fallout"),
@@ -168,21 +167,7 @@ public class TestContainerSorting extends TestCase { actual[index++] = o;
}
- assertArrays(actual, idOrder);
-
- }
-
- private void assertArrays(Object[] actualObjects, Object[] expectedObjects) {
- assertEquals(
- "Actual contains a different number of values than was expected",
- expectedObjects.length, actualObjects.length);
-
- for (int i = 0; i < actualObjects.length; i++) {
- Object actual = actualObjects[i];
- Object expected = expectedObjects[i];
-
- assertEquals("Item[" + i + "] does not match", expected, actual);
- }
+ TestUtil.assertArrays(actual, idOrder);
}
diff --git a/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java index beaa1c4e8f..efc31f0bd4 100644 --- a/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java @@ -22,18 +22,17 @@ public abstract class AbstractFilterTest<FILTERTYPE extends Filter> extends } } - protected static class NullProperty implements Property { + protected static class NullProperty implements Property<String> { - public Object getValue() { + public String getValue() { return null; } - public void setValue(Object newValue) throws ReadOnlyException, - ConversionException { + public void setValue(Object newValue) throws ReadOnlyException { throw new ReadOnlyException(); } - public Class<?> getType() { + public Class<String> getType() { return String.class; } diff --git a/tests/server-side/com/vaadin/data/util/filter/AndOrFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/AndOrFilterTest.java index bdd852bd41..fdd5b8a645 100644 --- a/tests/server-side/com/vaadin/data/util/filter/AndOrFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/AndOrFilterTest.java @@ -5,10 +5,8 @@ import junit.framework.Assert; import com.vaadin.data.Container.Filter; import com.vaadin.data.Item; import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.filter.And; -import com.vaadin.data.util.filter.Or; -public class AndOrFilterTest extends AbstractFilterTest { +public class AndOrFilterTest extends AbstractFilterTest<AbstractJunctionFilter> { protected Item item1 = new BeanItem<Integer>(1); protected Item item2 = new BeanItem<Integer>(2); diff --git a/tests/server-side/com/vaadin/data/util/filter/CompareFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/CompareFilterTest.java index 4cd683bfde..99e8429a51 100644 --- a/tests/server-side/com/vaadin/data/util/filter/CompareFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/CompareFilterTest.java @@ -14,7 +14,7 @@ import com.vaadin.data.util.filter.Compare.GreaterOrEqual; import com.vaadin.data.util.filter.Compare.Less; import com.vaadin.data.util.filter.Compare.LessOrEqual; -public class CompareFilterTest extends AbstractFilterTest { +public class CompareFilterTest extends AbstractFilterTest<Compare> { protected Item itemNull; protected Item itemEmpty; diff --git a/tests/server-side/com/vaadin/data/util/filter/IsNullFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/IsNullFilterTest.java index 24d5152cf7..6f90273de1 100644 --- a/tests/server-side/com/vaadin/data/util/filter/IsNullFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/IsNullFilterTest.java @@ -6,10 +6,8 @@ import com.vaadin.data.Container.Filter; import com.vaadin.data.Item; import com.vaadin.data.util.ObjectProperty; import com.vaadin.data.util.PropertysetItem; -import com.vaadin.data.util.filter.And; -import com.vaadin.data.util.filter.IsNull; -public class IsNullFilterTest extends AbstractFilterTest { +public class IsNullFilterTest extends AbstractFilterTest<IsNull> { public void testIsNull() { Item item1 = new PropertysetItem(); diff --git a/tests/server-side/com/vaadin/data/util/filter/NotFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/NotFilterTest.java index be6417ccdf..c3b666e6f7 100644 --- a/tests/server-side/com/vaadin/data/util/filter/NotFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/NotFilterTest.java @@ -5,10 +5,8 @@ import junit.framework.Assert; import com.vaadin.data.Container.Filter; import com.vaadin.data.Item; import com.vaadin.data.util.BeanItem; -import com.vaadin.data.util.filter.And; -import com.vaadin.data.util.filter.Not; -public class NotFilterTest extends AbstractFilterTest { +public class NotFilterTest extends AbstractFilterTest<Not> { protected Item item1 = new BeanItem<Integer>(1); protected Item item2 = new BeanItem<Integer>(2); diff --git a/tests/server-side/com/vaadin/data/util/filter/SimpleStringFilterTest.java b/tests/server-side/com/vaadin/data/util/filter/SimpleStringFilterTest.java index c36a764a54..bc63d57752 100644 --- a/tests/server-side/com/vaadin/data/util/filter/SimpleStringFilterTest.java +++ b/tests/server-side/com/vaadin/data/util/filter/SimpleStringFilterTest.java @@ -2,9 +2,8 @@ package com.vaadin.data.util.filter; import junit.framework.Assert; -import com.vaadin.data.util.filter.SimpleStringFilter; - -public class SimpleStringFilterTest extends AbstractFilterTest { +public class SimpleStringFilterTest extends + AbstractFilterTest<SimpleStringFilter> { protected static TestItem<String, String> createTestItem() { return new TestItem<String, String>("abcde", "TeSt"); diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java index 56c9921a0b..c273bbf590 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java @@ -1344,7 +1344,7 @@ public class SQLContainerTest { Statement statement = conn.createStatement(); statement .executeUpdate("DELETE FROM people WHERE \"ID\"=" - + item.getItemProperty("ID")); + + item.getItemProperty("ID").getValue()); statement.close(); return true; } diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/filters/BetweenTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/filters/BetweenTest.java index 5faa859b67..da4cfe4522 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/filters/BetweenTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/filters/BetweenTest.java @@ -12,7 +12,7 @@ import com.vaadin.data.util.filter.Between; public class BetweenTest { private Item itemWithPropertyValue(Object propertyId, Object value) { - Property property = EasyMock.createMock(Property.class); + Property<?> property = EasyMock.createMock(Property.class); property.getValue(); EasyMock.expectLastCall().andReturn(value).anyTimes(); EasyMock.replay(property); diff --git a/tests/server-side/com/vaadin/terminal/gwt/server/TestAbstractApplicationServletStaticFilesLocation.java b/tests/server-side/com/vaadin/terminal/gwt/server/TestAbstractApplicationServletStaticFilesLocation.java index fcd9970717..7e45ea50d7 100644 --- a/tests/server-side/com/vaadin/terminal/gwt/server/TestAbstractApplicationServletStaticFilesLocation.java +++ b/tests/server-side/com/vaadin/terminal/gwt/server/TestAbstractApplicationServletStaticFilesLocation.java @@ -17,9 +17,6 @@ import javax.servlet.http.HttpServletRequest; import junit.framework.TestCase; -import com.vaadin.terminal.gwt.server.AbstractApplicationServlet; -import com.vaadin.terminal.gwt.server.ApplicationServlet; - public class TestAbstractApplicationServletStaticFilesLocation extends TestCase { ApplicationServlet servlet; @@ -147,9 +144,6 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase .andReturn(realContextPath).anyTimes(); expect(request.getAttribute("javax.servlet.include.servlet_path")) .andReturn(realServletPath).anyTimes(); - expect( - request.getAttribute(AbstractApplicationServlet.REQUEST_VAADIN_STATIC_FILE_PATH)) - .andReturn(null).anyTimes(); return request; } @@ -163,9 +157,6 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase .andReturn(null).anyTimes(); expect(request.getAttribute("javax.servlet.include.servlet_path")) .andReturn(null).anyTimes(); - expect( - request.getAttribute(ApplicationServlet.REQUEST_VAADIN_STATIC_FILE_PATH)) - .andReturn(null).anyTimes(); return request; } diff --git a/tests/server-side/com/vaadin/tests/data/bean/Address.java b/tests/server-side/com/vaadin/tests/data/bean/Address.java new file mode 100644 index 0000000000..73e0bd20fb --- /dev/null +++ b/tests/server-side/com/vaadin/tests/data/bean/Address.java @@ -0,0 +1,63 @@ +package com.vaadin.tests.data.bean;
+
+import java.io.Serializable;
+
+@SuppressWarnings("serial")
+public class Address implements Serializable {
+
+ private String streetAddress = "";
+ private Integer postalCode = null;
+ private String city = "";
+ private Country country = null;
+
+ public Address() {
+
+ }
+
+ public Address(String streetAddress, int postalCode, String city,
+ Country country) {
+ setStreetAddress(streetAddress);
+ setPostalCode(postalCode);
+ setCity(city);
+ setCountry(country);
+ }
+
+ @Override
+ public String toString() {
+ return "Address [streetAddress=" + streetAddress + ", postalCode="
+ + postalCode + ", city=" + city + ", country=" + country + "]";
+ }
+
+ public String getStreetAddress() {
+ return streetAddress;
+ }
+
+ public void setStreetAddress(String streetAddress) {
+ this.streetAddress = streetAddress;
+ }
+
+ public Integer getPostalCode() {
+ return postalCode;
+ }
+
+ public void setPostalCode(Integer postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public Country getCountry() {
+ return country;
+ }
+
+ public void setCountry(Country country) {
+ this.country = country;
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/data/bean/BeanToValidate.java b/tests/server-side/com/vaadin/tests/data/bean/BeanToValidate.java new file mode 100644 index 0000000000..be8e40a118 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/data/bean/BeanToValidate.java @@ -0,0 +1,56 @@ +package com.vaadin.tests.data.bean;
+
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+public class BeanToValidate {
+ @NotNull
+ @Size(min = 3, max = 16)
+ private String firstname;
+
+ @NotNull(message = "Last name must not be empty")
+ private String lastname;
+
+ @Min(value = 18, message = "Must be 18 or above")
+ @Max(150)
+ private int age;
+
+ @Digits(integer = 3, fraction = 2)
+ private String decimals;
+
+ public String getFirstname() {
+ return firstname;
+ }
+
+ public void setFirstname(String firstname) {
+ this.firstname = firstname;
+ }
+
+ public String getLastname() {
+ return lastname;
+ }
+
+ public void setLastname(String lastname) {
+ this.lastname = lastname;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getDecimals() {
+ return decimals;
+ }
+
+ public void setDecimals(String decimals) {
+ this.decimals = decimals;
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/data/bean/Country.java b/tests/server-side/com/vaadin/tests/data/bean/Country.java new file mode 100644 index 0000000000..77192e3057 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/data/bean/Country.java @@ -0,0 +1,18 @@ +package com.vaadin.tests.data.bean;
+
+public enum Country {
+
+ FINLAND("Finland"), SWEDEN("Sweden"), USA("USA"), RUSSIA("Russia"), NETHERLANDS(
+ "Netherlands"), SOUTH_AFRICA("South Africa");
+
+ private String name;
+
+ private Country(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/data/bean/Person.java b/tests/server-side/com/vaadin/tests/data/bean/Person.java new file mode 100644 index 0000000000..c9ef8e9d70 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/data/bean/Person.java @@ -0,0 +1,133 @@ +package com.vaadin.tests.data.bean;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+public class Person {
+ private String firstName;
+ private String lastName;
+ private String email;
+ private int age;
+ private Sex sex;
+ private Address address;
+ private boolean deceased;
+ private Date birthDate;
+
+ private Integer salary; // null if unknown
+ private Double salaryDouble; // null if unknown
+
+ private BigDecimal rent;
+
+ public Person() {
+
+ }
+
+ @Override
+ public String toString() {
+ return "Person [firstName=" + firstName + ", lastName=" + lastName
+ + ", email=" + email + ", age=" + age + ", sex=" + sex
+ + ", address=" + address + ", deceased=" + deceased
+ + ", salary=" + salary + ", salaryDouble=" + salaryDouble
+ + ", rent=" + rent + "]";
+ }
+
+ public Person(String firstName, String lastName, String email, int age,
+ Sex sex, Address address) {
+ super();
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.email = email;
+ this.age = age;
+ this.sex = sex;
+ this.address = address;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ public Sex getSex() {
+ return sex;
+ }
+
+ public void setSex(Sex sex) {
+ this.sex = sex;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public boolean getDeceased() {
+ return deceased;
+ }
+
+ public void setDeceased(boolean deceased) {
+ this.deceased = deceased;
+ }
+
+ public Integer getSalary() {
+ return salary;
+ }
+
+ public void setSalary(Integer salary) {
+ this.salary = salary;
+ }
+
+ public BigDecimal getRent() {
+ return rent;
+ }
+
+ public void setRent(BigDecimal rent) {
+ this.rent = rent;
+ }
+
+ public Double getSalaryDouble() {
+ return salaryDouble;
+ }
+
+ public void setSalaryDouble(Double salaryDouble) {
+ this.salaryDouble = salaryDouble;
+ }
+
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java b/tests/server-side/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java new file mode 100644 index 0000000000..4a7d5a5c2e --- /dev/null +++ b/tests/server-side/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java @@ -0,0 +1,156 @@ +package com.vaadin.tests.data.bean;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Past;
+import javax.validation.constraints.Size;
+
+public class PersonWithBeanValidationAnnotations {
+ @NotNull
+ @Size(min = 5, max = 20)
+ private String firstName;
+ @NotNull
+ private String lastName;
+
+ private String email;
+
+ @Min(0)
+ @Max(100)
+ private int age;
+
+ @NotNull
+ private Sex sex;
+
+ private Address address;
+ private boolean deceased;
+
+ @NotNull
+ @Past
+ private Date birthDate;
+
+ @Min(0)
+ private Integer salary; // null if unknown
+
+ @Digits(integer = 6, fraction = 2)
+ private Double salaryDouble; // null if unknown
+
+ private BigDecimal rent;
+
+ public PersonWithBeanValidationAnnotations() {
+
+ }
+
+ @Override
+ public String toString() {
+ return "Person [firstName=" + firstName + ", lastName=" + lastName
+ + ", email=" + email + ", age=" + age + ", sex=" + sex
+ + ", address=" + address + ", deceased=" + deceased
+ + ", salary=" + salary + ", salaryDouble=" + salaryDouble
+ + ", rent=" + rent + "]";
+ }
+
+ public PersonWithBeanValidationAnnotations(String firstName,
+ String lastName, String email, int age, Sex sex, Address address) {
+ super();
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.email = email;
+ this.age = age;
+ this.sex = sex;
+ this.address = address;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ public Sex getSex() {
+ return sex;
+ }
+
+ public void setSex(Sex sex) {
+ this.sex = sex;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public boolean getDeceased() {
+ return deceased;
+ }
+
+ public void setDeceased(boolean deceased) {
+ this.deceased = deceased;
+ }
+
+ public Integer getSalary() {
+ return salary;
+ }
+
+ public void setSalary(Integer salary) {
+ this.salary = salary;
+ }
+
+ public BigDecimal getRent() {
+ return rent;
+ }
+
+ public void setRent(BigDecimal rent) {
+ this.rent = rent;
+ }
+
+ public Double getSalaryDouble() {
+ return salaryDouble;
+ }
+
+ public void setSalaryDouble(Double salaryDouble) {
+ this.salaryDouble = salaryDouble;
+ }
+
+ public Date getBirthDate() {
+ return birthDate;
+ }
+
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/data/bean/Sex.java b/tests/server-side/com/vaadin/tests/data/bean/Sex.java new file mode 100644 index 0000000000..cce0dfad53 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/data/bean/Sex.java @@ -0,0 +1,20 @@ +package com.vaadin.tests.data.bean;
+
+public enum Sex {
+ MALE("Male"), FEMALE("Female"), UNKNOWN("Unknown");
+
+ private String stringRepresentation;
+
+ private Sex(String stringRepresentation) {
+ this.stringRepresentation = stringRepresentation;
+ }
+
+ public String getStringRepresentation() {
+ return stringRepresentation;
+ }
+
+ @Override
+ public String toString() {
+ return getStringRepresentation();
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java b/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java index 6f3a05562b..abde241451 100644 --- a/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java +++ b/tests/server-side/com/vaadin/tests/server/LicenseInJavaFiles.java @@ -36,6 +36,9 @@ public class LicenseInJavaFiles extends TestCase { for (File f : srcDir.listFiles()) { if (f.isDirectory()) { + if (f.getPath().endsWith("com/vaadin/external")) { + continue; + } checkForLicense(f, missing); } else if (f.getName().endsWith(".java")) { checkForLicenseInFile(f, missing); diff --git a/tests/server-side/com/vaadin/tests/server/TestSerialization.java b/tests/server-side/com/vaadin/tests/server/TestSerialization.java index 03a9d3e262..84ff5ad6fa 100644 --- a/tests/server-side/com/vaadin/tests/server/TestSerialization.java +++ b/tests/server-side/com/vaadin/tests/server/TestSerialization.java @@ -10,6 +10,7 @@ import java.io.Serializable; import junit.framework.TestCase; import com.vaadin.data.Item; +import com.vaadin.data.Property; import com.vaadin.data.util.IndexedContainer; import com.vaadin.data.util.MethodProperty; import com.vaadin.data.validator.RegexpValidator; @@ -19,9 +20,9 @@ public class TestSerialization extends TestCase { public void testValidators() throws Exception { RegexpValidator validator = new RegexpValidator(".*", "Error"); - validator.isValid("aaa"); + validator.validate("aaa"); RegexpValidator validator2 = (RegexpValidator) serializeAndDeserialize(validator); - validator2.isValid("aaa"); + validator2.validate("aaa"); } public void testForm() throws Exception { @@ -78,15 +79,25 @@ public class TestSerialization extends TestCase { data)); Serializable s2 = (Serializable) in.readObject(); + // using special toString(Object) method to avoid calling + // Property.toString(), which will be temporarily disabled if (s.equals(s2)) { - System.out.println(s + " equals " + s2); + System.out.println(toString(s) + " equals " + toString(s2)); } else { - System.out.println(s + " does NOT equal " + s2); + System.out.println(toString(s) + " does NOT equal " + toString(s2)); } return s2; } + private static String toString(Object o) { + if (o instanceof Property) { + return String.valueOf(((Property<?>) o).getValue()); + } else { + return String.valueOf(o); + } + } + public static class Data implements Serializable { private String dummyGetter; private String dummyGetterAndSetter; diff --git a/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java b/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java index 3f16bb262b..2eed8c846a 100644 --- a/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java +++ b/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java @@ -71,7 +71,7 @@ public class TransactionListenersConcurrency extends TestCase { try {
app.start(new URL("http://localhost/"),
- new Properties(), context);
+ new Properties(), context, true);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/tests/server-side/com/vaadin/tests/server/component/absolutelayout/ComponentPosition.java b/tests/server-side/com/vaadin/tests/server/component/absolutelayout/ComponentPosition.java index 6fc7fbba0d..ba45448213 100644 --- a/tests/server-side/com/vaadin/tests/server/component/absolutelayout/ComponentPosition.java +++ b/tests/server-side/com/vaadin/tests/server/component/absolutelayout/ComponentPosition.java @@ -3,6 +3,7 @@ package com.vaadin.tests.server.component.absolutelayout; import junit.framework.TestCase;
import com.vaadin.terminal.Sizeable;
+import com.vaadin.terminal.Sizeable.Unit;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Button;
@@ -12,7 +13,7 @@ public class ComponentPosition extends TestCase { private static final String PARTIAL_CSS = "top:7.0px;left:7.0em;";
private static final Float CSS_VALUE = Float.valueOf(7);
- private static final int UNIT_UNSET = Sizeable.UNITS_PIXELS;
+ private static final Unit UNIT_UNSET = Sizeable.Unit.PIXELS;
/**
* Add component w/o giving positions, assert that everything is unset
@@ -51,11 +52,11 @@ public class ComponentPosition extends TestCase { assertEquals(CSS_VALUE, layout.getPosition(b).getLeftValue());
assertEquals(CSS_VALUE, layout.getPosition(b).getRightValue());
- assertEquals(Sizeable.UNITS_PIXELS, layout.getPosition(b).getTopUnits());
- assertEquals(Sizeable.UNITS_PICAS, layout.getPosition(b)
+ assertEquals(Sizeable.Unit.PIXELS, layout.getPosition(b).getTopUnits());
+ assertEquals(Sizeable.Unit.PICAS, layout.getPosition(b)
.getBottomUnits());
- assertEquals(Sizeable.UNITS_EM, layout.getPosition(b).getLeftUnits());
- assertEquals(Sizeable.UNITS_PERCENTAGE, layout.getPosition(b)
+ assertEquals(Sizeable.Unit.EM, layout.getPosition(b).getLeftUnits());
+ assertEquals(Sizeable.Unit.PERCENTAGE, layout.getPosition(b)
.getRightUnits());
assertEquals(7, layout.getPosition(b).getZIndex());
@@ -77,9 +78,9 @@ public class ComponentPosition extends TestCase { assertEquals(CSS_VALUE, layout.getPosition(b).getLeftValue());
assertNull(layout.getPosition(b).getRightValue());
- assertEquals(Sizeable.UNITS_PIXELS, layout.getPosition(b).getTopUnits());
+ assertEquals(Sizeable.Unit.PIXELS, layout.getPosition(b).getTopUnits());
assertEquals(UNIT_UNSET, layout.getPosition(b).getBottomUnits());
- assertEquals(Sizeable.UNITS_EM, layout.getPosition(b).getLeftUnits());
+ assertEquals(Sizeable.Unit.EM, layout.getPosition(b).getLeftUnits());
assertEquals(UNIT_UNSET, layout.getPosition(b).getRightUnits());
assertEquals(-1, layout.getPosition(b).getZIndex());
@@ -104,9 +105,9 @@ public class ComponentPosition extends TestCase { assertEquals(CSS_VALUE, layout.getPosition(b).getLeftValue());
assertNull(layout.getPosition(b).getRightValue());
- assertEquals(Sizeable.UNITS_PIXELS, layout.getPosition(b).getTopUnits());
+ assertEquals(Sizeable.Unit.PIXELS, layout.getPosition(b).getTopUnits());
assertEquals(UNIT_UNSET, layout.getPosition(b).getBottomUnits());
- assertEquals(Sizeable.UNITS_EM, layout.getPosition(b).getLeftUnits());
+ assertEquals(Sizeable.Unit.EM, layout.getPosition(b).getLeftUnits());
assertEquals(UNIT_UNSET, layout.getPosition(b).getRightUnits());
assertEquals(-1, layout.getPosition(b).getZIndex());
@@ -131,21 +132,20 @@ public class ComponentPosition extends TestCase { layout.getPosition(b).setBottomValue(SIZE);
layout.getPosition(b).setLeftValue(SIZE);
- layout.getPosition(b).setTopUnits(Sizeable.UNITS_CM);
- layout.getPosition(b).setRightUnits(Sizeable.UNITS_EX);
- layout.getPosition(b).setBottomUnits(Sizeable.UNITS_INCH);
- layout.getPosition(b).setLeftUnits(Sizeable.UNITS_MM);
+ layout.getPosition(b).setTopUnits(Sizeable.Unit.CM);
+ layout.getPosition(b).setRightUnits(Sizeable.Unit.EX);
+ layout.getPosition(b).setBottomUnits(Sizeable.Unit.INCH);
+ layout.getPosition(b).setLeftUnits(Sizeable.Unit.MM);
assertEquals(SIZE, layout.getPosition(b).getTopValue());
assertEquals(SIZE, layout.getPosition(b).getRightValue());
assertEquals(SIZE, layout.getPosition(b).getBottomValue());
assertEquals(SIZE, layout.getPosition(b).getLeftValue());
- assertEquals(Sizeable.UNITS_CM, layout.getPosition(b).getTopUnits());
- assertEquals(Sizeable.UNITS_EX, layout.getPosition(b).getRightUnits());
- assertEquals(Sizeable.UNITS_INCH, layout.getPosition(b)
- .getBottomUnits());
- assertEquals(Sizeable.UNITS_MM, layout.getPosition(b).getLeftUnits());
+ assertEquals(Sizeable.Unit.CM, layout.getPosition(b).getTopUnits());
+ assertEquals(Sizeable.Unit.EX, layout.getPosition(b).getRightUnits());
+ assertEquals(Sizeable.Unit.INCH, layout.getPosition(b).getBottomUnits());
+ assertEquals(Sizeable.Unit.MM, layout.getPosition(b).getLeftUnits());
}
@@ -159,21 +159,20 @@ public class ComponentPosition extends TestCase { Button b = new Button();
layout.addComponent(b);
- layout.getPosition(b).setTop(SIZE, Sizeable.UNITS_CM);
- layout.getPosition(b).setRight(SIZE, Sizeable.UNITS_EX);
- layout.getPosition(b).setBottom(SIZE, Sizeable.UNITS_INCH);
- layout.getPosition(b).setLeft(SIZE, Sizeable.UNITS_MM);
+ layout.getPosition(b).setTop(SIZE, Sizeable.Unit.CM);
+ layout.getPosition(b).setRight(SIZE, Sizeable.Unit.EX);
+ layout.getPosition(b).setBottom(SIZE, Sizeable.Unit.INCH);
+ layout.getPosition(b).setLeft(SIZE, Sizeable.Unit.MM);
assertEquals(SIZE, layout.getPosition(b).getTopValue());
assertEquals(SIZE, layout.getPosition(b).getRightValue());
assertEquals(SIZE, layout.getPosition(b).getBottomValue());
assertEquals(SIZE, layout.getPosition(b).getLeftValue());
- assertEquals(Sizeable.UNITS_CM, layout.getPosition(b).getTopUnits());
- assertEquals(Sizeable.UNITS_EX, layout.getPosition(b).getRightUnits());
- assertEquals(Sizeable.UNITS_INCH, layout.getPosition(b)
- .getBottomUnits());
- assertEquals(Sizeable.UNITS_MM, layout.getPosition(b).getLeftUnits());
+ assertEquals(Sizeable.Unit.CM, layout.getPosition(b).getTopUnits());
+ assertEquals(Sizeable.Unit.EX, layout.getPosition(b).getRightUnits());
+ assertEquals(Sizeable.Unit.INCH, layout.getPosition(b).getBottomUnits());
+ assertEquals(Sizeable.Unit.MM, layout.getPosition(b).getLeftUnits());
}
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/tests/server-side/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java new file mode 100644 index 0000000000..753afbdd06 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java @@ -0,0 +1,162 @@ +package com.vaadin.tests.server.component.abstractfield;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.tests.data.bean.Address;
+import com.vaadin.tests.data.bean.Country;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.tests.data.bean.Sex;
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.TextField;
+
+public class AbstractFieldValueConversions extends TestCase {
+
+ Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com",
+ 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town",
+ Country.FINLAND));
+
+ public void testWithoutConversion() {
+ TextField tf = new TextField();
+ tf.setPropertyDataSource(new MethodProperty<String>(paulaBean,
+ "firstName"));
+ assertEquals("Paula", tf.getValue());
+ assertEquals("Paula", tf.getPropertyDataSource().getValue());
+ tf.setValue("abc");
+ assertEquals("abc", tf.getValue());
+ assertEquals("abc", tf.getPropertyDataSource().getValue());
+ assertEquals("abc", paulaBean.getFirstName());
+ }
+
+ public void testStringIdentityConversion() {
+ TextField tf = new TextField();
+ tf.setConverter(new Converter<String, String>() {
+
+ public String convertToModel(String value, Locale locale) {
+ return value;
+ }
+
+ public String convertToPresentation(String value, Locale locale) {
+ return value;
+ }
+
+ public Class<String> getModelType() {
+ return String.class;
+ }
+
+ public Class<String> getPresentationType() {
+ return String.class;
+ }
+ });
+ tf.setPropertyDataSource(new MethodProperty<String>(paulaBean,
+ "firstName"));
+ assertEquals("Paula", tf.getValue());
+ assertEquals("Paula", tf.getPropertyDataSource().getValue());
+ tf.setValue("abc");
+ assertEquals("abc", tf.getValue());
+ assertEquals("abc", tf.getPropertyDataSource().getValue());
+ assertEquals("abc", paulaBean.getFirstName());
+ }
+
+ public void testFailingConversion() {
+ TextField tf = new TextField();
+ tf.setConverter(new Converter<String, Integer>() {
+
+ public Integer convertToModel(String value, Locale locale) {
+ throw new ConversionException("Failed");
+ }
+
+ public String convertToPresentation(Integer value, Locale locale) {
+ throw new ConversionException("Failed");
+ }
+
+ public Class<Integer> getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Class<String> getPresentationType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ });
+ try {
+ tf.setValue(1);
+ fail("setValue(Integer) should throw an exception");
+ } catch (Converter.ConversionException e) {
+ // OK, expected
+ }
+ }
+
+ public void testIntegerStringConversion() {
+ TextField tf = new TextField();
+
+ tf.setConverter(new StringToIntegerConverter());
+ tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean, "age"));
+ assertEquals(34, tf.getPropertyDataSource().getValue());
+ assertEquals("34", tf.getValue());
+ tf.setValue("12");
+ assertEquals(12, tf.getPropertyDataSource().getValue());
+ assertEquals("12", tf.getValue());
+ tf.getPropertyDataSource().setValue(42);
+ assertEquals(42, tf.getPropertyDataSource().getValue());
+ assertEquals("42", tf.getValue());
+ }
+
+ public void testBooleanNullConversion() {
+ CheckBox cb = new CheckBox();
+ cb.setConverter(new Converter<Boolean, Boolean>() {
+
+ public Boolean convertToModel(Boolean value, Locale locale) {
+ // value from a CheckBox should never be null as long as it is
+ // not set to null (handled by conversion below).
+ assertNotNull(value);
+ return value;
+ }
+
+ public Boolean convertToPresentation(Boolean value, Locale locale) {
+ // Datamodel -> field
+ if (value == null) {
+ return false;
+ }
+
+ return value;
+ }
+
+ public Class<Boolean> getModelType() {
+ return Boolean.class;
+ }
+
+ public Class<Boolean> getPresentationType() {
+ return Boolean.class;
+ }
+
+ });
+ MethodProperty<Boolean> property = new MethodProperty<Boolean>(
+ paulaBean, "deceased");
+ cb.setPropertyDataSource(property);
+ assertEquals(Boolean.FALSE, property.getValue());
+ assertEquals(Boolean.FALSE, cb.getValue());
+ Boolean newDmValue = cb.getConverter().convertToPresentation(
+ cb.getValue(), new Locale("fi", "FI"));
+ assertEquals(Boolean.FALSE, newDmValue);
+
+ // FIXME: Should be able to set to false here to cause datamodel to be
+ // set to false but the change will not be propagated to the Property
+ // (field value is already false)
+
+ cb.setValue(true);
+ assertEquals(Boolean.TRUE, cb.getValue());
+ assertEquals(Boolean.TRUE, property.getValue());
+
+ cb.setValue(false);
+ assertEquals(Boolean.FALSE, cb.getValue());
+ assertEquals(Boolean.FALSE, property.getValue());
+
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java b/tests/server-side/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java new file mode 100644 index 0000000000..8a6bcf2e01 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java @@ -0,0 +1,48 @@ +package com.vaadin.tests.server.component.abstractfield;
+
+import java.math.BigDecimal;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import com.vaadin.Application;
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.tests.data.bean.Address;
+import com.vaadin.tests.data.bean.Country;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.tests.data.bean.Sex;
+import com.vaadin.ui.TextField;
+
+public class DefaultConverterFactory extends TestCase {
+
+ Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com",
+ 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town",
+ Country.FINLAND));
+ {
+ paulaBean.setSalary(49000);
+ BigDecimal rent = new BigDecimal(57223);
+ rent = rent.scaleByPowerOfTen(-2);
+ paulaBean.setRent(rent);
+ }
+
+ public void testDefaultNumberConversion() {
+ Application app = new Application();
+ Application.setCurrentApplication(app);
+ TextField tf = new TextField();
+ tf.setLocale(new Locale("en", "US"));
+ tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean,
+ "salary"));
+ assertEquals("49,000", tf.getValue());
+
+ tf.setLocale(new Locale("fi", "FI"));
+ // FIXME: The following line should not be necessary and should be
+ // removed
+ tf.setPropertyDataSource(new MethodProperty<Integer>(paulaBean,
+ "salary"));
+ String value = tf.getValue();
+ // Java uses a non-breaking space (ascii 160) instead of space when
+ // formatting
+ String expected = "49" + (char) 160 + "000";
+ assertEquals(expected, value);
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractfield/TestAbstractFieldListeners.java b/tests/server-side/com/vaadin/tests/server/component/abstractfield/TestAbstractFieldListeners.java index 63536baf68..2a5b50f4bb 100644 --- a/tests/server-side/com/vaadin/tests/server/component/abstractfield/TestAbstractFieldListeners.java +++ b/tests/server-side/com/vaadin/tests/server/component/abstractfield/TestAbstractFieldListeners.java @@ -5,16 +5,17 @@ import com.vaadin.data.Property.ReadOnlyStatusChangeListener; import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.tests.server.component.AbstractListenerMethodsTest;
-import com.vaadin.ui.Button;
+import com.vaadin.ui.CheckBox;
public class TestAbstractFieldListeners extends AbstractListenerMethodsTest {
public void testReadOnlyStatusChangeListenerAddGetRemove() throws Exception {
- testListenerAddGetRemove(Button.class, ReadOnlyStatusChangeEvent.class,
+ testListenerAddGetRemove(CheckBox.class,
+ ReadOnlyStatusChangeEvent.class,
ReadOnlyStatusChangeListener.class);
}
public void testValueChangeListenerAddGetRemove() throws Exception {
- testListenerAddGetRemove(Button.class, ValueChangeEvent.class,
+ testListenerAddGetRemove(CheckBox.class, ValueChangeEvent.class,
ValueChangeListener.class);
}
}
diff --git a/tests/server-side/com/vaadin/tests/server/component/slider/SliderTest.java b/tests/server-side/com/vaadin/tests/server/component/slider/SliderTest.java new file mode 100644 index 0000000000..ab527b3d06 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/component/slider/SliderTest.java @@ -0,0 +1,25 @@ +package com.vaadin.tests.server.component.slider;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import com.vaadin.ui.Slider;
+import com.vaadin.ui.Slider.ValueOutOfBoundsException;
+
+public class SliderTest extends TestCase {
+
+ public void testOutOfBounds() {
+ Slider s = new Slider(0, 10);
+ s.setValue(0);
+ Assert.assertEquals(0.0, s.getValue());
+ s.setValue(10);
+ Assert.assertEquals(10.0, s.getValue());
+ try {
+ s.setValue(20);
+ fail("Should throw out of bounds exception");
+ } catch (ValueOutOfBoundsException e) {
+ // TODO: handle exception
+ }
+
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatter.java b/tests/server-side/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatter.java index 5a494b8ccd..d7b38cecfc 100644 --- a/tests/server-side/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatter.java +++ b/tests/server-side/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatter.java @@ -2,6 +2,8 @@ package com.vaadin.tests.server.component.textfield; import java.util.Collections; +import junit.framework.TestCase; + import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.Property.ValueChangeListener; @@ -11,8 +13,6 @@ import com.vaadin.terminal.Paintable; import com.vaadin.terminal.Paintable.RepaintRequestEvent; import com.vaadin.ui.TextField; -import junit.framework.TestCase; - public class TextFieldWithPropertyFormatter extends TestCase { private static final String INPUT_VALUE = "foo"; @@ -20,7 +20,7 @@ public class TextFieldWithPropertyFormatter extends TestCase { private static final String FORMATTED_VALUE = "FOOBAR"; private static final String ORIGINAL_VALUE = "Original"; private TextField field; - private PropertyFormatter formatter; + private PropertyFormatter<String> formatter; private ObjectProperty<String> property; private ValueChangeListener listener; private int listenerCalled; @@ -32,16 +32,16 @@ public class TextFieldWithPropertyFormatter extends TestCase { field = new TextField(); - formatter = new PropertyFormatter() { + formatter = new PropertyFormatter<String>() { @Override - public Object parse(String formattedValue) throws Exception { + public String parse(String formattedValue) throws Exception { assertEquals(INPUT_VALUE, formattedValue); return PARSED_VALUE; } @Override - public String format(Object value) { + public String format(String value) { return FORMATTED_VALUE; } }; @@ -59,7 +59,7 @@ public class TextFieldWithPropertyFormatter extends TestCase { assertEquals(FORMATTED_VALUE, event.getProperty().getValue()); } }; - + field.addListener(listener); field.addListener(new Paintable.RepaintRequestListener() { public void repaintRequested(RepaintRequestEvent event) { diff --git a/tests/server-side/com/vaadin/tests/server/component/urifragmentutility/UriFragmentUtilityListeners.java b/tests/server-side/com/vaadin/tests/server/component/urifragmentutility/UriFragmentUtilityListeners.java deleted file mode 100644 index fe400e55b9..0000000000 --- a/tests/server-side/com/vaadin/tests/server/component/urifragmentutility/UriFragmentUtilityListeners.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.vaadin.tests.server.component.urifragmentutility;
-
-import com.vaadin.tests.server.component.AbstractListenerMethodsTest;
-import com.vaadin.ui.UriFragmentUtility;
-import com.vaadin.ui.UriFragmentUtility.FragmentChangedEvent;
-import com.vaadin.ui.UriFragmentUtility.FragmentChangedListener;
-
-public class UriFragmentUtilityListeners extends AbstractListenerMethodsTest {
- public void testFragmentChangedListenerAddGetRemove() throws Exception {
- testListenerAddGetRemove(UriFragmentUtility.class,
- FragmentChangedEvent.class, FragmentChangedListener.class);
- }
-}
diff --git a/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java b/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java index afc050b981..ed01e07e06 100644 --- a/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java +++ b/tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java @@ -1,22 +1,23 @@ package com.vaadin.tests.server.component.window;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import com.vaadin.Application;
+import com.vaadin.ui.Root;
+import com.vaadin.ui.Root.LegacyWindow;
import com.vaadin.ui.Window;
public class AddRemoveSubWindow {
- public class TestApp extends Application {
+ public class TestApp extends Application.LegacyApplication {
@Override
public void init() {
- Window w = new Window("Main window");
+ LegacyWindow w = new LegacyWindow("Main window");
setMainWindow(w);
}
}
@@ -26,7 +27,7 @@ public class AddRemoveSubWindow { TestApp app = new TestApp();
app.init();
Window subWindow = new Window("Sub window");
- Window mainWindow = app.getMainWindow();
+ Root mainWindow = app.getMainWindow();
mainWindow.addWindow(subWindow);
// Added to main window so the parent of the sub window should be the
@@ -44,7 +45,7 @@ public class AddRemoveSubWindow { // Try to add the same sub window to another window
try {
- Window w = new Window();
+ LegacyWindow w = new LegacyWindow();
w.addWindow(subWindow);
assertTrue("Window.addWindow did not throw the expected exception",
false);
@@ -60,23 +61,18 @@ public class AddRemoveSubWindow { TestApp app = new TestApp();
app.init();
Window subWindow = new Window("Sub window");
- Window mainWindow = app.getMainWindow();
+ Root mainWindow = app.getMainWindow();
mainWindow.addWindow(subWindow);
// Added to main window so the parent of the sub window should be the
// main window
assertEquals(subWindow.getParent(), mainWindow);
- // Remove from the wrong window, should result in an exception
- boolean removed = subWindow.removeWindow(subWindow);
- assertFalse("Window was removed even though it should not have been",
- removed);
-
// Parent should still be set
assertEquals(subWindow.getParent(), mainWindow);
// Remove from the main window and assert it has been removed
- removed = mainWindow.removeWindow(subWindow);
+ boolean removed = mainWindow.removeWindow(subWindow);
assertTrue("Window was not removed correctly", removed);
assertNull(subWindow.getParent());
}
diff --git a/tests/server-side/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java b/tests/server-side/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java index 3aebd5bf9d..bcdce383f8 100644 --- a/tests/server-side/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java +++ b/tests/server-side/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java @@ -22,12 +22,12 @@ import com.vaadin.ui.AbstractField; * override {@link #setValue(AbstractField)} to set the field value via
* <code>changeVariables()</code>.
*/
-public abstract class AbstractTestFieldValueChange extends TestCase {
+public abstract class AbstractTestFieldValueChange<T> extends TestCase {
- private AbstractField field;
+ private AbstractField<T> field;
private ValueChangeListener listener;
- protected void setUp(AbstractField field) throws Exception {
+ protected void setUp(AbstractField<T> field) throws Exception {
this.field = field;
listener = EasyMock.createStrictMock(ValueChangeListener.class);
@@ -155,14 +155,14 @@ public abstract class AbstractTestFieldValueChange extends TestCase { EasyMock.verify(listener);
}
- protected AbstractField getField() {
+ protected AbstractField<T> getField() {
return field;
}
/**
* Override in subclasses to set value with changeVariables().
*/
- protected void setValue(AbstractField field) {
+ protected void setValue(AbstractField<T> field) {
field.setValue("newValue");
}
diff --git a/tests/server-side/com/vaadin/tests/server/components/TestComboBoxValueChange.java b/tests/server-side/com/vaadin/tests/server/components/TestComboBoxValueChange.java index cb73199fb8..75066c8d4a 100644 --- a/tests/server-side/com/vaadin/tests/server/components/TestComboBoxValueChange.java +++ b/tests/server-side/com/vaadin/tests/server/components/TestComboBoxValueChange.java @@ -12,7 +12,8 @@ import com.vaadin.ui.ComboBox; *
* See <a href="http://dev.vaadin.com/ticket/4394">Ticket 4394</a>.
*/
-public class TestComboBoxValueChange extends AbstractTestFieldValueChange {
+public class TestComboBoxValueChange extends
+ AbstractTestFieldValueChange<Object> {
@Override
protected void setUp() throws Exception {
ComboBox combo = new ComboBox();
@@ -21,7 +22,7 @@ public class TestComboBoxValueChange extends AbstractTestFieldValueChange { }
@Override
- protected void setValue(AbstractField field) {
+ protected void setValue(AbstractField<Object> field) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("selected", new String[] { "myvalue" });
field.changeVariables(field, variables);
diff --git a/tests/server-side/com/vaadin/tests/server/components/TestTextFieldValueChange.java b/tests/server-side/com/vaadin/tests/server/components/TestTextFieldValueChange.java index 1144caf805..d5cb02b477 100644 --- a/tests/server-side/com/vaadin/tests/server/components/TestTextFieldValueChange.java +++ b/tests/server-side/com/vaadin/tests/server/components/TestTextFieldValueChange.java @@ -18,7 +18,8 @@ import com.vaadin.ui.TextField; *
* See <a href="http://dev.vaadin.com/ticket/4394">Ticket 4394</a>.
*/
-public class TestTextFieldValueChange extends AbstractTestFieldValueChange {
+public class TestTextFieldValueChange extends
+ AbstractTestFieldValueChange<String> {
@Override
protected void setUp() throws Exception {
@@ -36,7 +37,7 @@ public class TestTextFieldValueChange extends AbstractTestFieldValueChange { }
@Override
- protected void setValue(AbstractField field) {
+ protected void setValue(AbstractField<String> field) {
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("text", "newValue");
field.changeVariables(field, variables);
@@ -54,8 +55,7 @@ public class TestTextFieldValueChange extends AbstractTestFieldValueChange { getField().setPropertyDataSource(property);
// defaults, buffering off
- getField().setWriteThrough(true);
- getField().setReadThrough(true);
+ getField().setBuffered(false);
// Expectations and start test
getListener().valueChange(EasyMock.isA(ValueChangeEvent.class));
@@ -142,8 +142,7 @@ public class TestTextFieldValueChange extends AbstractTestFieldValueChange { initialValue);
// set buffering
- getField().setWriteThrough(false);
- getField().setReadThrough(false);
+ getField().setBuffered(true);
// Value change should only happen once, when setting the property,
// further changes via property should not cause value change listener
diff --git a/tests/server-side/com/vaadin/tests/server/components/TestWindow.java b/tests/server-side/com/vaadin/tests/server/components/TestWindow.java index 05604aba61..11462b8328 100644 --- a/tests/server-side/com/vaadin/tests/server/components/TestWindow.java +++ b/tests/server-side/com/vaadin/tests/server/components/TestWindow.java @@ -7,6 +7,7 @@ import junit.framework.TestCase; import org.easymock.EasyMock;
+import com.vaadin.ui.Root.LegacyWindow;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;
@@ -20,6 +21,7 @@ public class TestWindow extends TestCase { @Override
protected void setUp() throws Exception {
window = new Window();
+ new LegacyWindow().addWindow(window);
}
public void testCloseListener() {
diff --git a/tests/server-side/com/vaadin/tests/server/validation/RangeValidatorTest.java b/tests/server-side/com/vaadin/tests/server/validation/RangeValidatorTest.java new file mode 100644 index 0000000000..2cb2c6a509 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/validation/RangeValidatorTest.java @@ -0,0 +1,52 @@ +package com.vaadin.tests.server.validation;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.validator.IntegerRangeValidator;
+
+public class RangeValidatorTest extends TestCase {
+
+ // This test uses IntegerRangeValidator for simplicity.
+ // IntegerRangeValidator contains no code so we really are testing
+ // RangeValidator
+ public void testMinValueNonInclusive() {
+ IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
+ iv.setMinValueIncluded(false);
+ assertFalse(iv.isValid(0));
+ assertTrue(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+
+ public void testMinMaxValuesInclusive() {
+ IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
+ assertTrue(iv.isValid(0));
+ assertTrue(iv.isValid(1));
+ assertTrue(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+
+ public void testMaxValueNonInclusive() {
+ IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
+ iv.setMaxValueIncluded(false);
+ assertTrue(iv.isValid(0));
+ assertTrue(iv.isValid(9));
+ assertFalse(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+
+ public void testMinMaxValuesNonInclusive() {
+ IntegerRangeValidator iv = new IntegerRangeValidator("Failed", 0, 10);
+ iv.setMinValueIncluded(false);
+ iv.setMaxValueIncluded(false);
+
+ assertFalse(iv.isValid(0));
+ assertTrue(iv.isValid(1));
+ assertTrue(iv.isValid(9));
+ assertFalse(iv.isValid(10));
+ assertFalse(iv.isValid(11));
+ assertFalse(iv.isValid(-1));
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/validation/TestBeanValidation.java b/tests/server-side/com/vaadin/tests/server/validation/TestBeanValidation.java new file mode 100644 index 0000000000..8f6928fc35 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/server/validation/TestBeanValidation.java @@ -0,0 +1,57 @@ +package com.vaadin.tests.server.validation; + +import org.junit.Test; + +import com.vaadin.data.Validator.InvalidValueException; +import com.vaadin.data.validator.BeanValidator; +import com.vaadin.tests.data.bean.BeanToValidate; + +public class TestBeanValidation { + @Test(expected = InvalidValueException.class) + public void testBeanValidationNull() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, + "firstname"); + validator.validate(null); + } + + @Test(expected = InvalidValueException.class) + public void testBeanValidationStringTooShort() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, + "firstname"); + validator.validate("aa"); + } + + @Test + public void testBeanValidationStringOk() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, + "firstname"); + validator.validate("aaa"); + } + + @Test(expected = InvalidValueException.class) + public void testBeanValidationIntegerTooSmall() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, "age"); + validator.validate(17); + } + + @Test + public void testBeanValidationIntegerOk() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, "age"); + validator.validate(18); + } + + @Test(expected = InvalidValueException.class) + public void testBeanValidationTooManyDigits() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, + "decimals"); + validator.validate("1234.567"); + } + + @Test + public void testBeanValidationDigitsOk() { + BeanValidator validator = new BeanValidator(BeanToValidate.class, + "decimals"); + validator.validate("123.45"); + } + +} diff --git a/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java b/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java index 6939ce27d2..fdf1586a44 100644 --- a/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java +++ b/tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java @@ -11,7 +11,7 @@ public class TestReadOnlyValidation { public void testIntegerValidation() {
TextField field = new TextField();
field.addValidator(new IntegerValidator("Enter a Valid Number"));
- field.setValue(Integer.valueOf(10));
+ field.setValue(String.valueOf(10));
field.validate();
}
}
diff --git a/tests/server-side/com/vaadin/tests/util/GraphVizClassHierarchyCreator.java b/tests/server-side/com/vaadin/tests/util/GraphVizClassHierarchyCreator.java new file mode 100644 index 0000000000..2399879ac8 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/util/GraphVizClassHierarchyCreator.java @@ -0,0 +1,149 @@ +package com.vaadin.tests.util;
+
+import java.lang.reflect.Modifier;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.vaadin.tests.VaadinClasses;
+
+public class GraphVizClassHierarchyCreator {
+
+ public static void main(String[] args) {
+ String gv = getGraphVizHierarchy((List) VaadinClasses.getComponents(),
+ "com.vaadin");
+ System.out.println(gv);
+ }
+
+ private static String getGraphVizHierarchy(List<Class> classes,
+ String packageToInclude) {
+ boolean includeInterfaces = false;
+
+ StringBuilder header = new StringBuilder();
+ header.append("digraph finite_state_machine {\n"
+ + " rankdir=BT;\n" + " dpi=\"150\";\n"
+ + " ratio=\"0.25\";\n");
+
+ StringBuilder sb = new StringBuilder();
+
+ Set<Class> classesAndParents = new HashSet<Class>();
+ for (Class<?> cls : classes) {
+ addClassAndParents(classesAndParents, cls, packageToInclude);
+ }
+
+ Set<Class> interfaces = new HashSet<Class>();
+ for (Object cls : classesAndParents.toArray()) {
+ for (Class<?> c : ((Class) cls).getInterfaces()) {
+ addClassAndParentInterfaces(classesAndParents, c,
+ packageToInclude);
+ }
+ }
+
+ for (Class<?> c : classesAndParents) {
+ appendClass(sb, c, c.getSuperclass(), packageToInclude,
+ includeInterfaces);
+ for (Class ci : c.getInterfaces()) {
+ appendClass(sb, c, ci, packageToInclude, includeInterfaces);
+ }
+ }
+
+ header.append(" node [shape = ellipse, style=\"dotted\"] ");
+ for (Class c : classesAndParents) {
+ if (!c.isInterface() && Modifier.isAbstract(c.getModifiers())) {
+ header.append(c.getSimpleName() + " ");
+ }
+ }
+ if (includeInterfaces) {
+ System.out.print(" node [shape = ellipse, style=\"solid\"] ");
+ for (Class c : classesAndParents) {
+ if (c.isInterface()) {
+ header.append(c.getSimpleName() + " ");
+ }
+ }
+ header.append(";\n");
+ }
+ header.append(";\n");
+ header.append(" node [shape = rectangle, style=\"solid\"];\n");
+ return header.toString() + sb.toString() + "}";
+ }
+
+ private static void addClassAndParents(Set<Class> classesAndParents,
+ Class<?> cls, String packageToInclude) {
+
+ if (cls == null) {
+ return;
+ }
+
+ if (classesAndParents.contains(cls)) {
+ return;
+ }
+
+ if (!cls.getPackage().getName().startsWith(packageToInclude)) {
+ return;
+ }
+
+ classesAndParents.add(cls);
+ addClassAndParents(classesAndParents, cls.getSuperclass(),
+ packageToInclude);
+
+ }
+
+ private static void addClassAndParentInterfaces(
+ Set<Class> classesAndParents, Class<?> cls, String packageToInclude) {
+
+ if (cls == null) {
+ return;
+ }
+
+ if (classesAndParents.contains(cls)) {
+ return;
+ }
+
+ if (!cls.getPackage().getName().startsWith(packageToInclude)) {
+ return;
+ }
+
+ classesAndParents.add(cls);
+ for (Class iClass : cls.getInterfaces()) {
+ addClassAndParentInterfaces(classesAndParents, iClass,
+ packageToInclude);
+ }
+
+ }
+
+ private static void appendClass(StringBuilder sb, Class<?> c,
+ Class<?> superClass, String packageToInclude,
+ boolean includeInterfaces) {
+ if (superClass == null) {
+ return;
+ }
+ if (!c.getPackage().getName().startsWith(packageToInclude)) {
+ return;
+ }
+ if (!superClass.getPackage().getName().startsWith(packageToInclude)) {
+ return;
+ }
+ if (!includeInterfaces && (c.isInterface() || superClass.isInterface())) {
+ return;
+ }
+
+ sb.append(c.getSimpleName()).append(" -> ")
+ .append(superClass.getSimpleName()).append("\n");
+
+ }
+
+ private static void addInterfaces(Set<Class> interfaces, Class<?> cls) {
+ if (interfaces.contains(cls)) {
+ return;
+ }
+
+ if (cls.isInterface()) {
+ interfaces.add(cls);
+ }
+
+ for (Class c : cls.getInterfaces()) {
+ addInterfaces(interfaces, c);
+ }
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/util/TestUtil.java b/tests/server-side/com/vaadin/tests/util/TestUtil.java new file mode 100644 index 0000000000..864d0e0822 --- /dev/null +++ b/tests/server-side/com/vaadin/tests/util/TestUtil.java @@ -0,0 +1,43 @@ +package com.vaadin.tests.util;
+
+import java.util.Iterator;
+
+import junit.framework.Assert;
+
+public class TestUtil {
+ public static void assertArrays(Object[] actualObjects,
+ Object[] expectedObjects) {
+ Assert.assertEquals(
+ "Actual contains a different number of values than was expected",
+ expectedObjects.length, actualObjects.length);
+
+ for (int i = 0; i < actualObjects.length; i++) {
+ Object actual = actualObjects[i];
+ Object expected = expectedObjects[i];
+
+ Assert.assertEquals("Item[" + i + "] does not match", expected,
+ actual);
+ }
+
+ }
+
+ public static void assertIterableEquals(Iterable<?> iterable1,
+ Iterable<?> iterable2) {
+ Iterator<?> i1 = iterable1.iterator();
+ Iterator<?> i2 = iterable2.iterator();
+
+ while (i1.hasNext()) {
+ Object o1 = i1.next();
+ if (!i2.hasNext()) {
+ Assert.fail("The second iterable contains fewer items than the first. The object "
+ + o1 + " has no match in the second iterable.");
+ }
+ Object o2 = i2.next();
+ Assert.assertEquals(o1, o2);
+ }
+ if (i2.hasNext()) {
+ Assert.fail("The second iterable contains more items than the first. The object "
+ + i2.next() + " has no match in the first iterable.");
+ }
+ }
+}
|