summaryrefslogtreecommitdiffstats
path: root/tests/server-side/com/vaadin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/server-side/com/vaadin')
-rw-r--r--tests/server-side/com/vaadin/data/util/AbstractContainerTest.java1
-rw-r--r--tests/server-side/com/vaadin/data/util/BeanContainerTest.java3
-rw-r--r--tests/server-side/com/vaadin/data/util/BeanItemTest.java8
-rw-r--r--tests/server-side/com/vaadin/data/util/NestedMethodPropertyTest.java89
-rw-r--r--tests/server-side/com/vaadin/data/util/ObjectPropertyTest.java8
-rw-r--r--tests/server-side/com/vaadin/data/util/PropertyDescriptorTest.java11
-rw-r--r--tests/server-side/com/vaadin/data/util/PropertySetItemTest.java8
-rw-r--r--tests/server-side/com/vaadin/data/util/TestContainerSorting.java24
-rw-r--r--tests/server-side/com/vaadin/data/util/TestHierarchicalContainer.java2
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java16
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/AndOrFilterTest.java4
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/CompareFilterTest.java2
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/IsNullFilterTest.java4
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/NotFilterTest.java4
-rw-r--r--tests/server-side/com/vaadin/data/util/filter/SimpleStringFilterTest.java5
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/DataGenerator.java11
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/FreeformQueryUtil.java20
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java35
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/TicketTests.java3
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/UtilTest.java7
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/connection/MockInitialContextFactory.java10
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/filters/BetweenTest.java2
-rw-r--r--tests/server-side/com/vaadin/terminal/gwt/server/TestAbstractApplicationServletStaticFilesLocation.java15
-rw-r--r--tests/server-side/com/vaadin/tests/VaadinClasses.java19
-rw-r--r--tests/server-side/com/vaadin/tests/data/bean/Address.java63
-rw-r--r--tests/server-side/com/vaadin/tests/data/bean/BeanToValidate.java56
-rw-r--r--tests/server-side/com/vaadin/tests/data/bean/Country.java18
-rw-r--r--tests/server-side/com/vaadin/tests/data/bean/Person.java143
-rw-r--r--tests/server-side/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java156
-rw-r--r--tests/server-side/com/vaadin/tests/data/bean/Sex.java20
-rw-r--r--tests/server-side/com/vaadin/tests/data/converter/ConverterFactory.java116
-rw-r--r--tests/server-side/com/vaadin/tests/server/SourceFileChecker.java1
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestAbstractBeanContainerListeners.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestAbstractInMemoryContainerListeners.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestClassesSerializable.java15
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestEventRouter.java2
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestKeyMapper.java14
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestPropertyFormatter.java34
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestSerialization.java19
-rw-r--r--tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java32
-rw-r--r--tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java32
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/AbstractListenerMethodsTest.java9
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/absolutelayout/ComponentPosition.java53
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java1
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java216
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractfield/DefaultConverterFactory.java48
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java37
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractfield/TestAbstractFieldListeners.java7
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/TestAbstractOrderedLayoutListeners.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/abstractsplitpanel/TestAbstractSplitPanelListeners.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/button/ButtonClick.java1
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/datefield/ResolutionTest.java61
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/datefield/WeekNumberCalculation.java111
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/label/LabelConverters.java71
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/menubar/MenuBarIds.java1
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java129
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/slider/SliderTest.java25
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java64
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/table/TableListeners.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/table/TableSerialization.java3
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java4
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/textfield/TextFieldWithPropertyFormatter.java34
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/tree/TestListeners.java2
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/urifragmentutility/UriFragmentUtilityListeners.java13
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/window/AddRemoveSubWindow.java37
-rw-r--r--tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java207
-rw-r--r--tests/server-side/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java10
-rw-r--r--tests/server-side/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java2
-rw-r--r--tests/server-side/com/vaadin/tests/server/components/TestComboBoxValueChange.java7
-rw-r--r--tests/server-side/com/vaadin/tests/server/components/TestTextFieldValueChange.java13
-rw-r--r--tests/server-side/com/vaadin/tests/server/components/TestWindow.java2
-rw-r--r--tests/server-side/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java130
-rw-r--r--tests/server-side/com/vaadin/tests/server/navigator/NavigatorTest.java575
-rw-r--r--tests/server-side/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java63
-rw-r--r--tests/server-side/com/vaadin/tests/server/validation/RangeValidatorTest.java52
-rw-r--r--tests/server-side/com/vaadin/tests/server/validation/TestBeanValidation.java57
-rw-r--r--tests/server-side/com/vaadin/tests/server/validation/TestReadOnlyValidation.java2
-rw-r--r--tests/server-side/com/vaadin/tests/util/GraphVizClassHierarchyCreator.java149
-rw-r--r--tests/server-side/com/vaadin/tests/util/TestUtil.java43
-rw-r--r--tests/server-side/com/vaadin/tests/util/UniqueSerializableTest.java14
81 files changed, 2778 insertions, 525 deletions
diff --git a/tests/server-side/com/vaadin/data/util/AbstractContainerTest.java b/tests/server-side/com/vaadin/data/util/AbstractContainerTest.java
index 6cbe675fa1..d703fb0364 100644
--- a/tests/server-side/com/vaadin/data/util/AbstractContainerTest.java
+++ b/tests/server-side/com/vaadin/data/util/AbstractContainerTest.java
@@ -62,6 +62,7 @@ public abstract class AbstractContainerTest extends TestCase {
protected static class ItemSetChangeCounter extends AbstractEventCounter
implements ItemSetChangeListener {
+ @Override
public void containerItemSetChange(ItemSetChangeEvent event) {
increment();
}
diff --git a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java
index d9fa8d896e..9037e303a8 100644
--- a/tests/server-side/com/vaadin/data/util/BeanContainerTest.java
+++ b/tests/server-side/com/vaadin/data/util/BeanContainerTest.java
@@ -18,6 +18,7 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
protected static class PersonNameResolver implements
BeanIdResolver<String, Person> {
+ @Override
public String getIdForBean(Person bean) {
return bean != null ? bean.getName() : null;
}
@@ -27,6 +28,7 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
protected static class NullResolver implements
BeanIdResolver<String, Person> {
+ @Override
public String getIdForBean(Person bean) {
return null;
}
@@ -332,6 +334,7 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
container
.setBeanIdResolver(new BeanIdResolver<String, AbstractBeanContainerTest.Person>() {
+ @Override
public String getIdForBean(Person bean) {
return bean.getName();
}
diff --git a/tests/server-side/com/vaadin/data/util/BeanItemTest.java b/tests/server-side/com/vaadin/data/util/BeanItemTest.java
index 044a410803..e1ad75796c 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.
*
@@ -132,6 +127,7 @@ public class BeanItemTest extends TestCase {
public void setSub(int i);
+ @Override
public int getOverride();
public void setOverride(int i);
@@ -322,7 +318,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 11676099e6..99ca58ba42 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 d9a8e6e51c..497699605a 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);
}
@@ -220,6 +205,7 @@ public class TestContainerSorting extends TestCase {
public class MyObject implements Comparable<MyObject> {
private String data;
+ @Override
public int compareTo(MyObject o) {
if (o == null) {
return 1;
diff --git a/tests/server-side/com/vaadin/data/util/TestHierarchicalContainer.java b/tests/server-side/com/vaadin/data/util/TestHierarchicalContainer.java
index 60894dbe6f..9e0558a122 100644
--- a/tests/server-side/com/vaadin/data/util/TestHierarchicalContainer.java
+++ b/tests/server-side/com/vaadin/data/util/TestHierarchicalContainer.java
@@ -176,11 +176,13 @@ public class TestHierarchicalContainer extends
// Dummy filter that does not remove any items
c.addContainerFilter(new Filter() {
+ @Override
public boolean passesFilter(Object itemId, Item item)
throws UnsupportedOperationException {
return true;
}
+ @Override
public boolean appliesToProperty(Object propertyId) {
return true;
}
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..6f96c3a51a 100644
--- a/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java
+++ b/tests/server-side/com/vaadin/data/util/filter/AbstractFilterTest.java
@@ -22,25 +22,29 @@ public abstract class AbstractFilterTest<FILTERTYPE extends Filter> extends
}
}
- protected static class NullProperty implements Property {
+ protected static class NullProperty implements Property<String> {
- public Object getValue() {
+ @Override
+ public String getValue() {
return null;
}
- public void setValue(Object newValue) throws ReadOnlyException,
- ConversionException {
+ @Override
+ public void setValue(Object newValue) throws ReadOnlyException {
throw new ReadOnlyException();
}
- public Class<?> getType() {
+ @Override
+ public Class<String> getType() {
return String.class;
}
+ @Override
public boolean isReadOnly() {
return true;
}
+ @Override
public void setReadOnly(boolean newStatus) {
// do nothing
}
@@ -61,11 +65,13 @@ public abstract class AbstractFilterTest<FILTERTYPE extends Filter> extends
this.propertyId = propertyId;
}
+ @Override
public boolean passesFilter(Object itemId, Item item)
throws UnsupportedOperationException {
return this.item == item;
}
+ @Override
public boolean appliesToProperty(Object propertyId) {
return this.propertyId != null ? this.propertyId.equals(propertyId)
: true;
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/DataGenerator.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/DataGenerator.java
index 6fa807b007..489f780d61 100644
--- a/tests/server-side/com/vaadin/data/util/sqlcontainer/DataGenerator.java
+++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/DataGenerator.java
@@ -12,11 +12,12 @@ import com.vaadin.data.util.sqlcontainer.AllTests.DB;
import com.vaadin.data.util.sqlcontainer.connection.JDBCConnectionPool;
public class DataGenerator {
-
- @Test
- public void testDummy(){
- // Added dummy test so JUnit will not complain about "No runnable methods".
- }
+
+ @Test
+ public void testDummy() {
+ // Added dummy test so JUnit will not complain about
+ // "No runnable methods".
+ }
public static void addPeopleToDatabase(JDBCConnectionPool connectionPool)
throws SQLException {
diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/FreeformQueryUtil.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/FreeformQueryUtil.java
index 2579a38aa1..b0e2a232ca 100644
--- a/tests/server-side/com/vaadin/data/util/sqlcontainer/FreeformQueryUtil.java
+++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/FreeformQueryUtil.java
@@ -11,11 +11,12 @@ import com.vaadin.data.util.sqlcontainer.query.generator.filter.QueryBuilder;
public class FreeformQueryUtil {
- @Test
- public void testDummy(){
- // Added dummy test so JUnit will not complain about "No runnable methods".
- }
-
+ @Test
+ public void testDummy() {
+ // Added dummy test so JUnit will not complain about
+ // "No runnable methods".
+ }
+
public static StatementHelper getQueryWithFilters(List<Filter> filters,
int offset, int limit) {
StatementHelper sh = new StatementHelper();
@@ -30,8 +31,7 @@ public class FreeformQueryUtil {
query.append(") AS rownum, * FROM \"PEOPLE\"");
if (!filters.isEmpty()) {
- query.append(QueryBuilder.getWhereStringForFilters(
- filters, sh));
+ query.append(QueryBuilder.getWhereStringForFilters(filters, sh));
}
query.append(") AS a WHERE a.rownum BETWEEN ").append(offset)
.append(" AND ").append(Integer.toString(offset + limit));
@@ -46,8 +46,7 @@ public class FreeformQueryUtil {
query.append("SELECT * FROM (SELECT x.*, ROWNUM AS "
+ "\"rownum\" FROM (SELECT * FROM \"PEOPLE\"");
if (!filters.isEmpty()) {
- query.append(QueryBuilder.getWhereStringForFilters(
- filters, sh));
+ query.append(QueryBuilder.getWhereStringForFilters(filters, sh));
}
query.append(") x) WHERE \"rownum\" BETWEEN ? AND ?");
sh.addParameterValue(offset);
@@ -57,8 +56,7 @@ public class FreeformQueryUtil {
} else {
StringBuilder query = new StringBuilder("SELECT * FROM people");
if (!filters.isEmpty()) {
- query.append(QueryBuilder.getWhereStringForFilters(
- filters, sh));
+ query.append(QueryBuilder.getWhereStringForFilters(filters, sh));
}
if (limit != 0 || offset != 0) {
query.append(" LIMIT ? OFFSET ?");
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..6649bc16e8 100644
--- a/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
+++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
@@ -323,6 +323,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1132,6 +1133,7 @@ public class SQLContainerTest {
delegate.storeRow(EasyMock.isA(Connection.class),
EasyMock.isA(RowItem.class)))
.andAnswer(new IAnswer<Integer>() {
+ @Override
public Integer answer() throws Throwable {
Connection conn = (Connection) EasyMock
.getCurrentArguments()[0];
@@ -1163,6 +1165,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1231,6 +1234,7 @@ public class SQLContainerTest {
delegate.storeRow(EasyMock.isA(Connection.class),
EasyMock.isA(RowItem.class)))
.andAnswer(new IAnswer<Integer>() {
+ @Override
public Integer answer() throws Throwable {
Connection conn = (Connection) EasyMock
.getCurrentArguments()[0];
@@ -1262,6 +1266,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1337,6 +1342,7 @@ public class SQLContainerTest {
delegate.removeRow(EasyMock.isA(Connection.class),
EasyMock.isA(RowItem.class)))
.andAnswer(new IAnswer<Boolean>() {
+ @Override
public Boolean answer() throws Throwable {
Connection conn = (Connection) EasyMock
.getCurrentArguments()[0];
@@ -1344,7 +1350,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;
}
@@ -1352,6 +1358,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1414,6 +1421,7 @@ public class SQLContainerTest {
delegate.storeRow(EasyMock.isA(Connection.class),
EasyMock.isA(RowItem.class)))
.andAnswer(new IAnswer<Integer>() {
+ @Override
public Integer answer() throws Throwable {
Connection conn = (Connection) EasyMock
.getCurrentArguments()[0];
@@ -1432,6 +1440,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1644,6 +1653,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setOrderBy(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<OrderBy> orders = (List<OrderBy>) EasyMock
.getCurrentArguments()[0];
@@ -1655,6 +1665,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1756,6 +1767,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setOrderBy(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<OrderBy> orders = (List<OrderBy>) EasyMock
.getCurrentArguments()[0];
@@ -1767,6 +1779,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1861,6 +1874,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -1872,6 +1886,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1882,6 +1897,7 @@ public class SQLContainerTest {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
@SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
@@ -1931,6 +1947,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -1942,6 +1959,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -1952,6 +1970,7 @@ public class SQLContainerTest {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
@SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
@@ -2000,6 +2019,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -2011,6 +2031,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -2021,6 +2042,7 @@ public class SQLContainerTest {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
@@ -2069,6 +2091,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -2080,6 +2103,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -2090,6 +2114,7 @@ public class SQLContainerTest {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
@SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
@@ -2145,6 +2170,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -2156,6 +2182,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -2166,6 +2193,7 @@ public class SQLContainerTest {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
@SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
@@ -2221,6 +2249,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -2232,6 +2261,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -2242,6 +2272,7 @@ public class SQLContainerTest {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
@SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
@@ -2323,6 +2354,7 @@ public class SQLContainerTest {
EasyMock.expectLastCall().anyTimes();
delegate.setOrderBy(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<OrderBy> orders = (List<OrderBy>) EasyMock
.getCurrentArguments()[0];
@@ -2334,6 +2366,7 @@ public class SQLContainerTest {
EasyMock.expect(
delegate.getQueryString(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<String>() {
+ @Override
public String answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/TicketTests.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/TicketTests.java
index 75ab455678..a12786f13a 100644
--- a/tests/server-side/com/vaadin/data/util/sqlcontainer/TicketTests.java
+++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/TicketTests.java
@@ -64,6 +64,7 @@ public class TicketTests {
EasyMock.expectLastCall().anyTimes();
delegate.setFilters(EasyMock.isA(List.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ @Override
public Object answer() throws Throwable {
List<Filter> orders = (List<Filter>) EasyMock
.getCurrentArguments()[0];
@@ -75,6 +76,7 @@ public class TicketTests {
EasyMock.expect(
delegate.getQueryStatement(EasyMock.anyInt(), EasyMock.anyInt()))
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
public StatementHelper answer() throws Throwable {
Object[] args = EasyMock.getCurrentArguments();
int offset = (Integer) (args[0]);
@@ -85,6 +87,7 @@ public class TicketTests {
}).anyTimes();
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
+ @Override
@SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/UtilTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/UtilTest.java
index d6a6a72300..31bdf2b81b 100644
--- a/tests/server-side/com/vaadin/data/util/sqlcontainer/UtilTest.java
+++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/UtilTest.java
@@ -21,7 +21,7 @@ public class UtilTest {
@Test
public void escapeSQL_severalQuotes_returnsEscapedString() {
Assert.assertEquals("asdf''ghjk''qwerty",
- SQLUtil.escapeSQL("asdf'ghjk'qwerty"));
+ SQLUtil.escapeSQL("asdf'ghjk'qwerty"));
}
@Test
@@ -32,12 +32,13 @@ public class UtilTest {
@Test
public void escapeSQL_multipleDoubleQuotes_returnsEscapedString() {
Assert.assertEquals("asdf\\\"foo\\\"bar",
- SQLUtil.escapeSQL("asdf\"foo\"bar"));
+ SQLUtil.escapeSQL("asdf\"foo\"bar"));
}
@Test
public void escapeSQL_backslashes_returnsEscapedString() {
- Assert.assertEquals("foo\\\\nbar\\\\r", SQLUtil.escapeSQL("foo\\nbar\\r"));
+ Assert.assertEquals("foo\\\\nbar\\\\r",
+ SQLUtil.escapeSQL("foo\\nbar\\r"));
}
@Test
diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/connection/MockInitialContextFactory.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/connection/MockInitialContextFactory.java
index 19019eed0b..324899e373 100644
--- a/tests/server-side/com/vaadin/data/util/sqlcontainer/connection/MockInitialContextFactory.java
+++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/connection/MockInitialContextFactory.java
@@ -11,16 +11,18 @@ import org.junit.Test;
*/
public class MockInitialContextFactory implements InitialContextFactory {
private static Context mockCtx = null;
-
+
@Test
- public void testDummy(){
- // Added dummy test so JUnit will not complain about "No runnable methods".
- }
+ public void testDummy() {
+ // Added dummy test so JUnit will not complain about
+ // "No runnable methods".
+ }
public static void setMockContext(Context ctx) {
mockCtx = ctx;
}
+ @Override
public Context getInitialContext(java.util.Hashtable<?, ?> environment)
throws NamingException {
if (mockCtx == null) {
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..38fca09157 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;
@@ -49,29 +46,35 @@ public class TestAbstractApplicationServletStaticFilesLocation extends TestCase
public class DummyServletConfig implements ServletConfig {
// public DummyServletConfig(Map<String,String> initParameters, )
+ @Override
public String getInitParameter(String name) {
// TODO Auto-generated method stub
return null;
}
+ @Override
public Enumeration<Object> getInitParameterNames() {
return new Enumeration<Object>() {
+ @Override
public boolean hasMoreElements() {
return false;
}
+ @Override
public Object nextElement() {
return null;
}
};
}
+ @Override
public ServletContext getServletContext() {
// TODO Auto-generated method stub
return null;
}
+ @Override
public String getServletName() {
// TODO Auto-generated method stub
return null;
@@ -147,9 +150,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 +163,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/VaadinClasses.java b/tests/server-side/com/vaadin/tests/VaadinClasses.java
index 0baec576d9..2f937bf58d 100644
--- a/tests/server-side/com/vaadin/tests/VaadinClasses.java
+++ b/tests/server-side/com/vaadin/tests/VaadinClasses.java
@@ -15,21 +15,22 @@ import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
-import org.junit.Test;
-
import com.vaadin.Application;
import com.vaadin.ui.Component;
import com.vaadin.ui.ComponentContainer;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.DragAndDropWrapper;
+import com.vaadin.ui.Field;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.LoginForm;
import com.vaadin.ui.PopupView;
-import com.vaadin.ui.SplitPanel;
+import com.vaadin.ui.Root;
import com.vaadin.ui.VerticalSplitPanel;
import com.vaadin.ui.Window;
import com.vaadin.ui.themes.BaseTheme;
+import org.junit.Test;
+
@SuppressWarnings("deprecation")
public class VaadinClasses {
@@ -62,6 +63,15 @@ public class VaadinClasses {
}
}
+ public static List<Class<? extends Field>> getFields() {
+ try {
+ return findClasses(Field.class, "com.vaadin.ui");
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
public static List<Class<? extends BaseTheme>> getThemeClasses() {
try {
return findClasses(BaseTheme.class, "com.vaadin.ui.themes");
@@ -97,13 +107,13 @@ public class VaadinClasses {
classes.remove(DragAndDropWrapper.class);
classes.remove(CustomComponent.class);
classes.remove(LoginForm.class);
+ classes.remove(Root.class);
return classes;
}
public static List<Class<? extends ComponentContainer>> getComponentContainersSupportingUnlimitedNumberOfComponents() {
List<Class<? extends ComponentContainer>> classes = getComponentContainersSupportingAddRemoveComponent();
- classes.remove(SplitPanel.class);
classes.remove(VerticalSplitPanel.class);
classes.remove(HorizontalSplitPanel.class);
classes.remove(Window.class);
@@ -154,6 +164,7 @@ public class VaadinClasses {
Collections.sort(classes, new Comparator<Class<? extends T>>() {
+ @Override
public int compare(Class<? extends T> o1, Class<? extends T> o2) {
return o1.getName().compareTo(o2.getName());
}
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..15cdf34ae5
--- /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..416563baba
--- /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..afdf8dcfa1
--- /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..f7bad31d0e
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/data/bean/Person.java
@@ -0,0 +1,143 @@
+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;
+ }
+
+ public static Person createTestPerson1() {
+ return new Person("Foo", "Bar", "yeah@cool.com", 46, Sex.MALE,
+ new Address("Street", 1123, "Turku", Country.FINLAND));
+ }
+
+ public static Person createTestPerson2() {
+ return new Person("Maya", "Dinkelstein", "maya@foo.bar", 18,
+ Sex.FEMALE, new Address("Red street", 12, "Amsterdam",
+ Country.NETHERLANDS));
+ }
+}
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..93b2273263
--- /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..a4e3f20a11
--- /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/data/converter/ConverterFactory.java b/tests/server-side/com/vaadin/tests/data/converter/ConverterFactory.java
new file mode 100644
index 0000000000..6393d61981
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/data/converter/ConverterFactory.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2011 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.data.converter;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import com.vaadin.Application;
+import com.vaadin.data.util.converter.Converter;
+import com.vaadin.data.util.converter.DefaultConverterFactory;
+import com.vaadin.ui.TextField;
+
+public class ConverterFactory extends TestCase {
+
+ public static class ConvertTo42 implements Converter<String, Integer> {
+
+ @Override
+ public Integer convertToModel(String value, Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ return 42;
+ }
+
+ @Override
+ public String convertToPresentation(Integer value, Locale locale)
+ throws com.vaadin.data.util.converter.Converter.ConversionException {
+ return "42";
+ }
+
+ @Override
+ public Class<Integer> getModelType() {
+ return Integer.class;
+ }
+
+ @Override
+ public Class<String> getPresentationType() {
+ return String.class;
+ }
+
+ }
+
+ public static class ConverterFactory42 extends DefaultConverterFactory {
+ @Override
+ public <PRESENTATION, MODEL> Converter<PRESENTATION, MODEL> createConverter(
+ Class<PRESENTATION> presentationType, Class<MODEL> modelType) {
+ if (modelType == Integer.class) {
+ return (Converter<PRESENTATION, MODEL>) new ConvertTo42();
+ }
+
+ return super.createConverter(presentationType, modelType);
+ }
+ }
+
+ public void testApplicationConverterFactoryInBackgroundThread() {
+ Application.setCurrent(null);
+ final Application appWithCustomIntegerConverter = new Application();
+ appWithCustomIntegerConverter
+ .setConverterFactory(new ConverterFactory42());
+
+ TextField tf = new TextField("", "123") {
+ @Override
+ public Application getApplication() {
+ return appWithCustomIntegerConverter;
+ };
+ };
+ tf.setConverter(Integer.class);
+ // The application converter always returns 42. Current application is
+ // null
+ assertEquals(42, tf.getConvertedValue());
+ }
+
+ public void testApplicationConverterFactoryForDetachedComponent() {
+ final Application appWithCustomIntegerConverter = new Application();
+ appWithCustomIntegerConverter
+ .setConverterFactory(new ConverterFactory42());
+ Application.setCurrent(appWithCustomIntegerConverter);
+
+ TextField tf = new TextField("", "123");
+ tf.setConverter(Integer.class);
+ // The application converter always returns 42. Current application is
+ // null
+ assertEquals(42, tf.getConvertedValue());
+ }
+
+ public void testApplicationConverterFactoryForDifferentThanCurrentApplication() {
+ final Application fieldAppWithCustomIntegerConverter = new Application();
+ fieldAppWithCustomIntegerConverter
+ .setConverterFactory(new ConverterFactory42());
+ Application.setCurrent(new Application());
+
+ TextField tf = new TextField("", "123") {
+ @Override
+ public Application getApplication() {
+ return fieldAppWithCustomIntegerConverter;
+ }
+ };
+ tf.setConverter(Integer.class);
+
+ // The application converter always returns 42. Application.getCurrent()
+ // should not be used
+ assertEquals(42, tf.getConvertedValue());
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java b/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java
index 9906990165..f02e5d2932 100644
--- a/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java
+++ b/tests/server-side/com/vaadin/tests/server/SourceFileChecker.java
@@ -148,6 +148,7 @@ public class SourceFileChecker extends TestCase {
}
abstract class FileContentsValidator implements FileValidator {
+ @Override
public void validateFile(File f) throws Exception {
FileInputStream fis = new FileInputStream(f);
String contents = IOUtils.toString(fis);
diff --git a/tests/server-side/com/vaadin/tests/server/TestAbstractBeanContainerListeners.java b/tests/server-side/com/vaadin/tests/server/TestAbstractBeanContainerListeners.java
index d6598a3b62..0d8433d1c6 100644
--- a/tests/server-side/com/vaadin/tests/server/TestAbstractBeanContainerListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/TestAbstractBeanContainerListeners.java
@@ -5,7 +5,8 @@ import com.vaadin.data.Container.PropertySetChangeListener;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.tests.server.component.AbstractListenerMethodsTest;
-public class TestAbstractBeanContainerListeners extends AbstractListenerMethodsTest {
+public class TestAbstractBeanContainerListeners extends
+ AbstractListenerMethodsTest {
public void testPropertySetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(BeanItemContainer.class,
PropertySetChangeEvent.class, PropertySetChangeListener.class,
diff --git a/tests/server-side/com/vaadin/tests/server/TestAbstractInMemoryContainerListeners.java b/tests/server-side/com/vaadin/tests/server/TestAbstractInMemoryContainerListeners.java
index 4be4e35554..a8e2a4aa2a 100644
--- a/tests/server-side/com/vaadin/tests/server/TestAbstractInMemoryContainerListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/TestAbstractInMemoryContainerListeners.java
@@ -5,7 +5,8 @@ import com.vaadin.data.Container.ItemSetChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.server.component.AbstractListenerMethodsTest;
-public class TestAbstractInMemoryContainerListeners extends AbstractListenerMethodsTest {
+public class TestAbstractInMemoryContainerListeners extends
+ AbstractListenerMethodsTest {
public void testItemSetChangeListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(IndexedContainer.class,
ItemSetChangeEvent.class, ItemSetChangeListener.class);
diff --git a/tests/server-side/com/vaadin/tests/server/TestClassesSerializable.java b/tests/server-side/com/vaadin/tests/server/TestClassesSerializable.java
index c047565fcc..44a6a3b66d 100644
--- a/tests/server-side/com/vaadin/tests/server/TestClassesSerializable.java
+++ b/tests/server-side/com/vaadin/tests/server/TestClassesSerializable.java
@@ -47,7 +47,6 @@ public class TestClassesSerializable extends TestCase {
// class level filtering, also affecting nested classes and
// interfaces
"com\\.vaadin\\.terminal\\.gwt\\.server\\.AbstractCommunicationManager.*", //
- "com\\.vaadin\\.terminal\\.gwt\\.server\\.ApplicationRunnerServlet.*", //
"com\\.vaadin\\.terminal\\.gwt\\.server\\.CommunicationManager.*", //
"com\\.vaadin\\.terminal\\.gwt\\.server\\.PortletCommunicationManager.*", //
};
@@ -98,9 +97,19 @@ public class TestClassesSerializable extends TestCase {
if (!nonSerializableClasses.isEmpty()) {
String nonSerializableString = "";
Iterator<Class<?>> it = nonSerializableClasses.iterator();
- nonSerializableString = it.next().getName();
while (it.hasNext()) {
- nonSerializableString += ", " + it.next().getName();
+ Class c = it.next();
+ nonSerializableString += ", " + c.getName();
+ if (c.isAnonymousClass()) {
+ nonSerializableString += "(super: ";
+ nonSerializableString += c.getSuperclass().getName();
+ nonSerializableString += ", interfaces: ";
+ for (Class i : c.getInterfaces()) {
+ nonSerializableString += i.getName();
+ nonSerializableString += ",";
+ }
+ nonSerializableString += ")";
+ }
}
fail("Serializable not implemented by the following classes and interfaces: "
+ nonSerializableString);
diff --git a/tests/server-side/com/vaadin/tests/server/TestEventRouter.java b/tests/server-side/com/vaadin/tests/server/TestEventRouter.java
index dc388a66ac..a8f5039042 100644
--- a/tests/server-side/com/vaadin/tests/server/TestEventRouter.java
+++ b/tests/server-side/com/vaadin/tests/server/TestEventRouter.java
@@ -15,9 +15,11 @@ public class TestEventRouter extends TestCase {
final ValueChangeListener outer = new ValueChangeListener() {
+ @Override
public void valueChange(ValueChangeEvent event) {
ValueChangeListener inner = new ValueChangeListener() {
+ @Override
public void valueChange(ValueChangeEvent event) {
innerListenerCalls++;
System.out.println("The inner listener was called");
diff --git a/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java b/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java
index ca33cf3314..4f5f0b1431 100644
--- a/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java
+++ b/tests/server-side/com/vaadin/tests/server/TestKeyMapper.java
@@ -1,7 +1,7 @@
package com.vaadin.tests.server;
import java.lang.reflect.Field;
-import java.util.Hashtable;
+import java.util.HashMap;
import junit.framework.TestCase;
@@ -10,7 +10,7 @@ import com.vaadin.terminal.KeyMapper;
public class TestKeyMapper extends TestCase {
public void testAdd() {
- KeyMapper mapper = new KeyMapper();
+ KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
@@ -41,7 +41,7 @@ public class TestKeyMapper extends TestCase {
}
public void testRemoveAll() {
- KeyMapper mapper = new KeyMapper();
+ KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
@@ -58,7 +58,7 @@ public class TestKeyMapper extends TestCase {
}
public void testRemove() {
- KeyMapper mapper = new KeyMapper();
+ KeyMapper<Object> mapper = new KeyMapper<Object>();
Object o1 = new Object();
Object o2 = new Object();
Object o3 = new Object();
@@ -82,15 +82,15 @@ public class TestKeyMapper extends TestCase {
}
- private void assertSize(KeyMapper mapper, int i) {
+ private void assertSize(KeyMapper<?> mapper, int i) {
try {
Field f1 = KeyMapper.class.getDeclaredField("objectKeyMap");
Field f2 = KeyMapper.class.getDeclaredField("keyObjectMap");
f1.setAccessible(true);
f2.setAccessible(true);
- Hashtable<?, ?> h1 = (Hashtable<?, ?>) f1.get(mapper);
- Hashtable<?, ?> h2 = (Hashtable<?, ?>) f2.get(mapper);
+ HashMap<?, ?> h1 = (HashMap<?, ?>) f1.get(mapper);
+ HashMap<?, ?> h2 = (HashMap<?, ?>) f2.get(mapper);
assertEquals(i, h1.size());
assertEquals(i, h2.size());
diff --git a/tests/server-side/com/vaadin/tests/server/TestPropertyFormatter.java b/tests/server-side/com/vaadin/tests/server/TestPropertyFormatter.java
index 91e36b5caa..48c60c83c4 100644
--- a/tests/server-side/com/vaadin/tests/server/TestPropertyFormatter.java
+++ b/tests/server-side/com/vaadin/tests/server/TestPropertyFormatter.java
@@ -27,6 +27,7 @@ public class TestPropertyFormatter extends TestCase {
return getExpectedClass().newInstance();
}
};
+
@SuppressWarnings("rawtypes")
private Class expectedClass;
@@ -34,36 +35,41 @@ public class TestPropertyFormatter extends TestCase {
private Class getExpectedClass() {
return expectedClass;
}
-
+
/**
* The object passed to format should be same as property's type.
- * @throws IllegalAccessException
- * @throws InstantiationException
+ *
+ * @throws IllegalAccessException
+ * @throws InstantiationException
*/
@Test
@SuppressWarnings({ "rawtypes" })
- public void testCorrectTypeForFormat() throws InstantiationException, IllegalAccessException {
- Class[] testedTypes = new Class[] {Integer.class, Boolean.class, Double.class, String.class, Date.class};
- Object[] testValues = new Object[] {new Integer(3), Boolean.FALSE, new Double(3.3), "bar", new Date()};
-
+ public void testCorrectTypeForFormat() throws InstantiationException,
+ IllegalAccessException {
+ Class[] testedTypes = new Class[] { Integer.class, Boolean.class,
+ Double.class, String.class, Date.class };
+ Object[] testValues = new Object[] { new Integer(3), Boolean.FALSE,
+ new Double(3.3), "bar", new Date() };
+
int i = 0;
for (Class class1 : testedTypes) {
expectedClass = class1;
-
+
TestFormatter formatter = new TestFormatter();
-
+
// Should just return null, without formatting
Object value = formatter.getValue();
-
+
// test with property which value is null
- formatter.setPropertyDataSource(new ObjectProperty(null, expectedClass));
+ formatter.setPropertyDataSource(new ObjectProperty(null,
+ expectedClass));
formatter.getValue(); // calls format
-
+
// test with a value
- formatter.setPropertyDataSource(new ObjectProperty(testValues[i++], expectedClass));
+ formatter.setPropertyDataSource(new ObjectProperty(testValues[i++],
+ expectedClass));
formatter.getValue(); // calls format
}
-
}
}
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/TestStreamVariableMapping.java b/tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java
index 7e9aefcbd9..ca1bb45330 100644
--- a/tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java
+++ b/tests/server-side/com/vaadin/tests/server/TestStreamVariableMapping.java
@@ -6,7 +6,9 @@ import org.easymock.EasyMock;
import com.vaadin.Application;
import com.vaadin.terminal.StreamVariable;
+import com.vaadin.terminal.WrappedRequest;
import com.vaadin.terminal.gwt.server.CommunicationManager;
+import com.vaadin.ui.Root;
import com.vaadin.ui.Upload;
public class TestStreamVariableMapping extends TestCase {
@@ -19,7 +21,25 @@ public class TestStreamVariableMapping extends TestCase {
@Override
protected void setUp() throws Exception {
- owner = new Upload();
+ final Application application = new Application();
+ final Root root = new Root() {
+ @Override
+ protected void init(WrappedRequest request) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Application getApplication() {
+ return application;
+ }
+ };
+ owner = new Upload() {
+ @Override
+ public Root getRoot() {
+ return root;
+ }
+ };
streamVariable = EasyMock.createMock(StreamVariable.class);
cm = createCommunicationManager();
@@ -29,20 +49,20 @@ public class TestStreamVariableMapping extends TestCase {
public void testAddStreamVariable() {
String targetUrl = cm.getStreamVariableTargetUrl(owner, variableName,
streamVariable);
- assertTrue(targetUrl.startsWith("app://APP/UPLOAD/PID0/myName/"));
+ assertTrue(targetUrl.startsWith("app://APP/UPLOAD/-1/1/myName/"));
StreamVariable streamVariable2 = cm.getStreamVariable(
- cm.getPaintableId(owner), variableName);
+ owner.getConnectorId(), variableName);
assertSame(streamVariable, streamVariable2);
}
public void testRemoverVariable() {
cm.getStreamVariableTargetUrl(owner, variableName, streamVariable);
- assertNotNull(cm.getStreamVariable(cm.getPaintableId(owner),
- variableName));
+ assertNotNull(cm
+ .getStreamVariable(owner.getConnectorId(), variableName));
cm.cleanStreamVariable(owner, variableName);
- assertNull(cm.getStreamVariable(cm.getPaintableId(owner), variableName));
+ assertNull(cm.getStreamVariable(owner.getConnectorId(), variableName));
}
private CommunicationManager createCommunicationManager() {
diff --git a/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java b/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java
index 224c9f5964..f7ac55b6da 100644
--- a/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java
+++ b/tests/server-side/com/vaadin/tests/server/TransactionListenersConcurrency.java
@@ -17,13 +17,15 @@ import javax.servlet.http.HttpSession;
import junit.framework.TestCase;
-import org.easymock.EasyMock;
-
import com.vaadin.Application;
+import com.vaadin.Application.ApplicationStartEvent;
import com.vaadin.service.ApplicationContext.TransactionListener;
+import com.vaadin.terminal.DeploymentConfiguration;
import com.vaadin.terminal.gwt.server.AbstractWebApplicationContext;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
+import org.easymock.EasyMock;
+
public class TransactionListenersConcurrency extends TestCase {
/**
@@ -45,6 +47,7 @@ public class TransactionListenersConcurrency extends TestCase {
for (int i = 0; i < 5; i++) {
Thread t = new Thread(new Runnable() {
+ @Override
public void run() {
Application app = new Application() {
@@ -69,9 +72,15 @@ public class TransactionListenersConcurrency extends TestCase {
// Start the application so the transaction listener is
// called later on.
try {
-
- app.start(new URL("http://localhost/"),
- new Properties(), context);
+ DeploymentConfiguration dc = EasyMock
+ .createMock(DeploymentConfiguration.class);
+ EasyMock.expect(dc.isProductionMode()).andReturn(true);
+ EasyMock.expect(dc.getInitParameters()).andReturn(
+ new Properties());
+ EasyMock.replay(dc);
+
+ app.start(new ApplicationStartEvent(new URL(
+ "http://localhost/"), dc, context));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -96,8 +105,11 @@ public class TransactionListenersConcurrency extends TestCase {
threads.add(t);
t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+ @Override
public void uncaughtException(Thread t, Throwable e) {
- e = e.getCause();
+ if (e.getCause() != null) {
+ e = e.getCause();
+ }
exceptions.add(e);
}
});
@@ -123,8 +135,10 @@ public class TransactionListenersConcurrency extends TestCase {
if (t instanceof InvocationTargetException) {
t = t.getCause();
}
- t.printStackTrace(System.err);
- fail(t.getClass().getName());
+ if (t != null) {
+ t.printStackTrace(System.err);
+ fail(t.getClass().getName());
+ }
}
System.out.println("Done, all ok");
@@ -161,6 +175,7 @@ public class TransactionListenersConcurrency extends TestCase {
this.delay = delay;
}
+ @Override
public void transactionStart(Application application,
Object transactionData) {
try {
@@ -171,6 +186,7 @@ public class TransactionListenersConcurrency extends TestCase {
}
+ @Override
public void transactionEnd(Application application,
Object transactionData) {
try {
diff --git a/tests/server-side/com/vaadin/tests/server/component/AbstractListenerMethodsTest.java b/tests/server-side/com/vaadin/tests/server/component/AbstractListenerMethodsTest.java
index 355f5167d7..e189ffc77d 100644
--- a/tests/server-side/com/vaadin/tests/server/component/AbstractListenerMethodsTest.java
+++ b/tests/server-side/com/vaadin/tests/server/component/AbstractListenerMethodsTest.java
@@ -48,11 +48,14 @@ public abstract class AbstractListenerMethodsTest extends TestCase {
System.out.println("package " + packageName + ";");
System.out.println("import "
- + AbstractListenerMethodsTest.class.getName() + ";");
+ + AbstractListenerMethodsTest.class.getName()
+ + ";");
System.out.println("import " + c.getName() + ";");
- System.out.println("public class " + c.getSimpleName()
+ System.out.println("public class "
+ + c.getSimpleName()
+ "Listeners extends "
- + AbstractListenerMethodsTest.class.getSimpleName() + " {");
+ + AbstractListenerMethodsTest.class
+ .getSimpleName() + " {");
}
String listenerClassName = m.getParameterTypes()[0]
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 ee8ef6bfbc..4458872c79 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/abstractcomponent/TestAbstractComponentStyleNames.java b/tests/server-side/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java
index b1c4a8f4be..1903e66f92 100644
--- a/tests/server-side/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractcomponent/TestAbstractComponentStyleNames.java
@@ -58,5 +58,4 @@ public class TestAbstractComponentStyleNames extends TestCase {
return new AbstractComponent() {
};
}
-
}
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java b/tests/server-side/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java
index 6a8267f296..f9f170eb2a 100644
--- a/tests/server-side/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractcomponentcontainer/TestAbstractComponentContainerListeners.java
@@ -8,7 +8,8 @@ import com.vaadin.ui.ComponentContainer.ComponentDetachListener;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.VerticalLayout;
-public class TestAbstractComponentContainerListeners extends AbstractListenerMethodsTest {
+public class TestAbstractComponentContainerListeners extends
+ AbstractListenerMethodsTest {
public void testComponentDetachListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(HorizontalLayout.class,
ComponentDetachEvent.class, ComponentDetachListener.class);
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..57af748247
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java
@@ -0,0 +1,216 @@
+package com.vaadin.tests.server.component.abstractfield;
+
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import com.vaadin.Application;
+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>() {
+
+ @Override
+ public String convertToModel(String value, Locale locale) {
+ return value;
+ }
+
+ @Override
+ public String convertToPresentation(String value, Locale locale) {
+ return value;
+ }
+
+ @Override
+ public Class<String> getModelType() {
+ return String.class;
+ }
+
+ @Override
+ 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>() {
+
+ @Override
+ public Integer convertToModel(String value, Locale locale) {
+ throw new ConversionException("Failed");
+ }
+
+ @Override
+ public String convertToPresentation(Integer value, Locale locale) {
+ throw new ConversionException("Failed");
+ }
+
+ @Override
+ public Class<Integer> getModelType() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ 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>() {
+
+ @Override
+ 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;
+ }
+
+ @Override
+ public Boolean convertToPresentation(Boolean value, Locale locale) {
+ // Datamodel -> field
+ if (value == null) {
+ return false;
+ }
+
+ return value;
+ }
+
+ @Override
+ public Class<Boolean> getModelType() {
+ return Boolean.class;
+ }
+
+ @Override
+ 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());
+
+ }
+
+ public static class NumberBean {
+ private Number number;
+
+ public Number getNumber() {
+ return number;
+ }
+
+ public void setNumber(Number number) {
+ this.number = number;
+ }
+
+ }
+
+ public void testNumberDoubleConverterChange() {
+ final Application a = new Application();
+ Application.setCurrent(a);
+ TextField tf = new TextField() {
+ @Override
+ public Application getApplication() {
+ return a;
+ }
+ };
+ NumberBean nb = new NumberBean();
+ nb.setNumber(490);
+
+ tf.setPropertyDataSource(new MethodProperty<Number>(nb, "number"));
+ assertEquals(490, tf.getPropertyDataSource().getValue());
+ assertEquals("490", tf.getValue());
+
+ Converter c1 = tf.getConverter();
+
+ tf.setPropertyDataSource(new MethodProperty<Number>(nb, "number"));
+ Converter c2 = tf.getConverter();
+ assertTrue(
+ "StringToNumber converter is ok for integer types and should stay even though property is changed",
+ c1 == c2);
+ assertEquals(490, tf.getPropertyDataSource().getValue());
+ assertEquals("490", tf.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..25430fc9a5
--- /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.setCurrent(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/RemoveListenersOnDetach.java b/tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java
index 32b80e0bcd..f66f523770 100644
--- a/tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractfield/RemoveListenersOnDetach.java
@@ -2,11 +2,15 @@ package com.vaadin.tests.server.component.abstractfield;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
+import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.util.AbstractProperty;
+import com.vaadin.data.util.converter.Converter.ConversionException;
+import com.vaadin.terminal.WrappedRequest;
import com.vaadin.ui.AbstractField;
-
-import org.junit.Test;
+import com.vaadin.ui.Root;
public class RemoveListenersOnDetach {
@@ -14,9 +18,21 @@ public class RemoveListenersOnDetach {
int numReadOnlyChanges = 0;
AbstractField field = new AbstractField() {
+ private Root root = new Root() {
+
+ @Override
+ protected void init(WrappedRequest request) {
+
+ }
+
+ };
+ private Application application = new Application() {
+
+ };
+
@Override
public Class<?> getType() {
- return null;
+ return String.class;
}
@Override
@@ -31,20 +47,33 @@ public class RemoveListenersOnDetach {
super.readOnlyStatusChange(event);
numReadOnlyChanges++;
}
+
+ @Override
+ public com.vaadin.ui.Root getRoot() {
+ return root;
+ };
+
+ @Override
+ public Application getApplication() {
+ return application;
+ };
};
Property property = new AbstractProperty() {
+ @Override
public Object getValue() {
return null;
}
+ @Override
public void setValue(Object newValue) throws ReadOnlyException,
ConversionException {
fireValueChange();
}
+ @Override
public Class<?> getType() {
- return null;
+ return String.class;
}
};
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 7ee70bde13..9937bf92d5 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/abstractorderedlayout/TestAbstractOrderedLayoutListeners.java b/tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/TestAbstractOrderedLayoutListeners.java
index 02143a2796..a0b34aca78 100644
--- a/tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/TestAbstractOrderedLayoutListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractorderedlayout/TestAbstractOrderedLayoutListeners.java
@@ -5,7 +5,8 @@ import com.vaadin.event.LayoutEvents.LayoutClickListener;
import com.vaadin.tests.server.component.AbstractListenerMethodsTest;
import com.vaadin.ui.VerticalLayout;
-public class TestAbstractOrderedLayoutListeners extends AbstractListenerMethodsTest {
+public class TestAbstractOrderedLayoutListeners extends
+ AbstractListenerMethodsTest {
public void testLayoutClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(VerticalLayout.class, LayoutClickEvent.class,
LayoutClickListener.class);
diff --git a/tests/server-side/com/vaadin/tests/server/component/abstractsplitpanel/TestAbstractSplitPanelListeners.java b/tests/server-side/com/vaadin/tests/server/component/abstractsplitpanel/TestAbstractSplitPanelListeners.java
index 5e9556c182..2b6cdaa6cc 100644
--- a/tests/server-side/com/vaadin/tests/server/component/abstractsplitpanel/TestAbstractSplitPanelListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/component/abstractsplitpanel/TestAbstractSplitPanelListeners.java
@@ -5,7 +5,8 @@ import com.vaadin.ui.AbstractSplitPanel.SplitterClickEvent;
import com.vaadin.ui.AbstractSplitPanel.SplitterClickListener;
import com.vaadin.ui.HorizontalSplitPanel;
-public class TestAbstractSplitPanelListeners extends AbstractListenerMethodsTest {
+public class TestAbstractSplitPanelListeners extends
+ AbstractListenerMethodsTest {
public void testSplitterClickListenerAddGetRemove() throws Exception {
testListenerAddGetRemove(HorizontalSplitPanel.class,
SplitterClickEvent.class, SplitterClickListener.class);
diff --git a/tests/server-side/com/vaadin/tests/server/component/button/ButtonClick.java b/tests/server-side/com/vaadin/tests/server/component/button/ButtonClick.java
index 464d131996..4fe499a0a0 100644
--- a/tests/server-side/com/vaadin/tests/server/component/button/ButtonClick.java
+++ b/tests/server-side/com/vaadin/tests/server/component/button/ButtonClick.java
@@ -38,6 +38,7 @@ public class ButtonClick {
private Button getButton() {
Button b = new Button();
b.addListener(new Button.ClickListener() {
+ @Override
public void buttonClick(ClickEvent ev) {
clicked = true;
}
diff --git a/tests/server-side/com/vaadin/tests/server/component/datefield/ResolutionTest.java b/tests/server-side/com/vaadin/tests/server/component/datefield/ResolutionTest.java
new file mode 100644
index 0000000000..00b5c60dad
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/component/datefield/ResolutionTest.java
@@ -0,0 +1,61 @@
+package com.vaadin.tests.server.component.datefield;
+
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import com.vaadin.tests.util.TestUtil;
+import com.vaadin.ui.DateField.Resolution;
+
+public class ResolutionTest extends TestCase {
+
+ public void testResolutionHigherOrEqualToYear() {
+ Iterable<Resolution> higherOrEqual = Resolution
+ .getResolutionsHigherOrEqualTo(Resolution.YEAR);
+ ArrayList<Resolution> expected = new ArrayList<Resolution>();
+ expected.add(Resolution.YEAR);
+ TestUtil.assertIterableEquals(expected, higherOrEqual);
+ }
+
+ public void testResolutionHigherOrEqualToDay() {
+ Iterable<Resolution> higherOrEqual = Resolution
+ .getResolutionsHigherOrEqualTo(Resolution.DAY);
+ ArrayList<Resolution> expected = new ArrayList<Resolution>();
+ expected.add(Resolution.DAY);
+ expected.add(Resolution.MONTH);
+ expected.add(Resolution.YEAR);
+ TestUtil.assertIterableEquals(expected, higherOrEqual);
+
+ }
+
+ public void testResolutionLowerThanDay() {
+ Iterable<Resolution> higherOrEqual = Resolution
+ .getResolutionsLowerThan(Resolution.DAY);
+ ArrayList<Resolution> expected = new ArrayList<Resolution>();
+ expected.add(Resolution.HOUR);
+ expected.add(Resolution.MINUTE);
+ expected.add(Resolution.SECOND);
+ TestUtil.assertIterableEquals(expected, higherOrEqual);
+
+ }
+
+ public void testResolutionLowerThanSecond() {
+ Iterable<Resolution> higherOrEqual = Resolution
+ .getResolutionsLowerThan(Resolution.SECOND);
+ ArrayList<Resolution> expected = new ArrayList<Resolution>();
+ TestUtil.assertIterableEquals(expected, higherOrEqual);
+ }
+
+ public void testResolutionLowerThanYear() {
+ Iterable<Resolution> higherOrEqual = Resolution
+ .getResolutionsLowerThan(Resolution.YEAR);
+ ArrayList<Resolution> expected = new ArrayList<Resolution>();
+ expected.add(Resolution.MONTH);
+ expected.add(Resolution.DAY);
+ expected.add(Resolution.HOUR);
+ expected.add(Resolution.MINUTE);
+ expected.add(Resolution.SECOND);
+ TestUtil.assertIterableEquals(expected, higherOrEqual);
+
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/component/datefield/WeekNumberCalculation.java b/tests/server-side/com/vaadin/tests/server/component/datefield/WeekNumberCalculation.java
deleted file mode 100644
index ae8bc9beae..0000000000
--- a/tests/server-side/com/vaadin/tests/server/component/datefield/WeekNumberCalculation.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package com.vaadin.tests.server.component.datefield;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import com.vaadin.terminal.gwt.client.DateTimeService;
-
-public class WeekNumberCalculation extends TestCase {
-
- final long MILLISECONDS_PER_DAY = 24 * 3600 * 1000;
-
- static Map<Date, Integer> isoWeekNumbers = new HashMap<Date, Integer>();
- static {
- isoWeekNumbers.put(getDate(2005, 02, 02), 5);
-
- isoWeekNumbers.put(getDate(2005, 1, 1), 53);
- isoWeekNumbers.put(getDate(2005, 1, 2), 53);
- isoWeekNumbers.put(getDate(2005, 1, 3), 1);
- isoWeekNumbers.put(getDate(2005, 1, 4), 1);
- isoWeekNumbers.put(getDate(2005, 1, 5), 1);
- isoWeekNumbers.put(getDate(2005, 1, 6), 1);
- isoWeekNumbers.put(getDate(2005, 1, 7), 1);
- isoWeekNumbers.put(getDate(2005, 1, 8), 1);
- isoWeekNumbers.put(getDate(2005, 1, 9), 1);
- isoWeekNumbers.put(getDate(2005, 1, 10), 2);
- isoWeekNumbers.put(getDate(2005, 12, 31), 52);
- isoWeekNumbers.put(getDate(2005, 12, 30), 52);
- isoWeekNumbers.put(getDate(2005, 12, 29), 52);
- isoWeekNumbers.put(getDate(2005, 12, 28), 52);
- isoWeekNumbers.put(getDate(2005, 12, 27), 52);
- isoWeekNumbers.put(getDate(2005, 12, 26), 52);
- isoWeekNumbers.put(getDate(2005, 12, 25), 51);
- isoWeekNumbers.put(getDate(2007, 1, 1), 1);
- isoWeekNumbers.put(getDate(2007, 12, 30), 52);
- isoWeekNumbers.put(getDate(2007, 12, 31), 1);
- isoWeekNumbers.put(getDate(2008, 1, 1), 1);
- isoWeekNumbers.put(getDate(2008, 12, 28), 52);
- isoWeekNumbers.put(getDate(2008, 12, 29), 1);
- isoWeekNumbers.put(getDate(2008, 12, 30), 1);
- isoWeekNumbers.put(getDate(2008, 12, 31), 1);
- isoWeekNumbers.put(getDate(2009, 1, 1), 1);
- isoWeekNumbers.put(getDate(2009, 12, 31), 53);
- isoWeekNumbers.put(getDate(2010, 1, 1), 53);
- isoWeekNumbers.put(getDate(2010, 1, 2), 53);
- isoWeekNumbers.put(getDate(2010, 1, 3), 53);
- isoWeekNumbers.put(getDate(2010, 1, 4), 1);
- isoWeekNumbers.put(getDate(2010, 1, 5), 1);
- isoWeekNumbers.put(getDate(2010, 10, 10), 40);
-
- }
-
- /**
- * Test all dates from 1990-1992 + some more and see that {@link Calendar}
- * calculates the ISO week number like we do.
- *
- */
- public void testISOWeekNumbers() {
- Calendar c = Calendar.getInstance();
- c.set(1990, 1, 1);
- long start = c.getTimeInMillis();
-
- for (int i = 0; i < 1000; i++) {
- Date d = new Date(start + i * MILLISECONDS_PER_DAY);
- int expected = getCalendarISOWeekNr(d);
- int calculated = DateTimeService.getISOWeekNumber(d);
- assertEquals(d + " should be week " + expected, expected,
- calculated);
-
- }
- }
-
- /**
- * Verify that special cases are handled correctly by us (and
- * {@link Calendar}).
- *
- */
- public void testSampleISOWeekNumbers() {
- for (Date d : isoWeekNumbers.keySet()) {
- // System.out.println("Sample: " + d);
- int expected = isoWeekNumbers.get(d);
- int calculated = DateTimeService.getISOWeekNumber(d);
- assertEquals(d + " should be week " + expected
- + " (Java Calendar is wrong?)", expected,
- getCalendarISOWeekNr(d));
- assertEquals(d + " should be week " + expected, expected,
- calculated);
-
- }
- }
-
- private int getCalendarISOWeekNr(Date d) {
- Calendar c = Calendar.getInstance();
- c.setFirstDayOfWeek(Calendar.MONDAY);
- c.setMinimalDaysInFirstWeek(4);
- c.setTime(d);
-
- return c.get(Calendar.WEEK_OF_YEAR);
- }
-
- private static Date getDate(int year, int month, int date) {
- Calendar c = Calendar.getInstance();
- c.clear();
- c.set(year, month - 1, date);
- return c.getTime();
- }
-
-}
diff --git a/tests/server-side/com/vaadin/tests/server/component/label/LabelConverters.java b/tests/server-side/com/vaadin/tests/server/component/label/LabelConverters.java
new file mode 100644
index 0000000000..48279c7c88
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/component/label/LabelConverters.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2011 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.label;
+
+import junit.framework.TestCase;
+
+import com.vaadin.Application;
+import com.vaadin.data.Property;
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.ui.Label;
+
+public class LabelConverters extends TestCase {
+
+ public void testLabelSetDataSourceLaterOn() {
+ Person p = Person.createTestPerson1();
+ Label l = new Label("My label");
+ assertEquals("My label", l.getValue());
+ assertNull(l.getConverter());
+ l.setPropertyDataSource(new MethodProperty<String>(p, "firstName"));
+ assertEquals(p.getFirstName(), l.getValue());
+ p.setFirstName("123");
+ assertEquals("123", l.getValue());
+ }
+
+ public void testIntegerDataSource() {
+ Application.setCurrent(new Application());
+ Label l = new Label("Foo");
+ Property ds = new MethodProperty<Integer>(Person.createTestPerson1(),
+ "age");
+ l.setPropertyDataSource(ds);
+ assertEquals(String.valueOf(Person.createTestPerson1().getAge()),
+ l.getValue());
+ }
+
+ public void testSetValueWithDataSource() {
+ try {
+ MethodProperty<String> property = new MethodProperty<String>(
+ Person.createTestPerson1(), "firstName");
+ Label l = new Label(property);
+ l.setValue("Foo");
+ fail("setValue should throw an exception when a data source is set");
+ } catch (Exception e) {
+ }
+
+ }
+
+ public void testLabelWithoutDataSource() {
+ Label l = new Label("My label");
+ assertEquals("My label", l.getValue());
+ assertNull(l.getConverter());
+ assertNull(l.getPropertyDataSource());
+ l.setValue("New value");
+ assertEquals("New value", l.getValue());
+ assertNull(l.getConverter());
+ assertNull(l.getPropertyDataSource());
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/component/menubar/MenuBarIds.java b/tests/server-side/com/vaadin/tests/server/component/menubar/MenuBarIds.java
index a0dadf8cc6..f304315ebc 100644
--- a/tests/server-side/com/vaadin/tests/server/component/menubar/MenuBarIds.java
+++ b/tests/server-side/com/vaadin/tests/server/component/menubar/MenuBarIds.java
@@ -87,6 +87,7 @@ public class MenuBarIds extends TestCase implements Command {
}
}
+ @Override
public void menuSelected(MenuItem selectedItem) {
assertNull("lastSelectedItem was not cleared before selecting an item",
lastSelectedItem);
diff --git a/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java
new file mode 100644
index 0000000000..fa730515a2
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/component/root/CustomRootClassLoader.java
@@ -0,0 +1,129 @@
+package com.vaadin.tests.server.component.root;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import com.vaadin.Application;
+import com.vaadin.Application.ApplicationStartEvent;
+import com.vaadin.RootRequiresMoreInformationException;
+import com.vaadin.terminal.DeploymentConfiguration;
+import com.vaadin.terminal.WrappedRequest;
+import com.vaadin.ui.Root;
+
+import org.easymock.EasyMock;
+
+public class CustomRootClassLoader extends TestCase {
+
+ /**
+ * Stub root
+ */
+ public static class MyRoot extends Root {
+ @Override
+ protected void init(WrappedRequest request) {
+ // Nothing to see here
+ }
+ }
+
+ /**
+ * Dummy ClassLoader that just saves the name of the requested class before
+ * delegating to the default implementation.
+ */
+ public class LoggingClassLoader extends ClassLoader {
+
+ private List<String> requestedClasses = new ArrayList<String>();
+
+ @Override
+ protected synchronized Class<?> loadClass(String name, boolean resolve)
+ throws ClassNotFoundException {
+ requestedClasses.add(name);
+ return super.loadClass(name, resolve);
+ }
+ }
+
+ /**
+ * Tests that a Root class can be loaded even if no classloader has been
+ * provided.
+ *
+ * @throws Exception
+ * if thrown
+ */
+ public void testWithNullClassLoader() throws Exception {
+ Application application = createStubApplication();
+ application.start(new ApplicationStartEvent(null,
+ createConfigurationMock(), null));
+
+ Root root = application.getRootForRequest(createRequestMock(null));
+ assertTrue(root instanceof MyRoot);
+ }
+
+ private static DeploymentConfiguration createConfigurationMock() {
+ DeploymentConfiguration configurationMock = EasyMock
+ .createMock(DeploymentConfiguration.class);
+ EasyMock.expect(configurationMock.isProductionMode()).andReturn(false);
+ EasyMock.expect(configurationMock.getInitParameters()).andReturn(
+ new Properties());
+
+ EasyMock.replay(configurationMock);
+ return configurationMock;
+ }
+
+ private static WrappedRequest createRequestMock(ClassLoader classloader) {
+ // Mock a DeploymentConfiguration to give the passed classloader
+ DeploymentConfiguration configurationMock = EasyMock
+ .createMock(DeploymentConfiguration.class);
+ EasyMock.expect(configurationMock.getClassLoader()).andReturn(
+ classloader);
+
+ // Mock a WrappedRequest to give the mocked deployment configuration
+ WrappedRequest requestMock = EasyMock.createMock(WrappedRequest.class);
+ EasyMock.expect(requestMock.getDeploymentConfiguration()).andReturn(
+ configurationMock);
+
+ EasyMock.replay(configurationMock, requestMock);
+ return requestMock;
+ }
+
+ /**
+ * Tests that the ClassLoader passed in the ApplicationStartEvent is used to
+ * load Root classes.
+ *
+ * @throws Exception
+ * if thrown
+ */
+ public void testWithClassLoader() throws Exception {
+ LoggingClassLoader loggingClassLoader = new LoggingClassLoader();
+
+ Application application = createStubApplication();
+ application.start(new ApplicationStartEvent(null,
+ createConfigurationMock(), null));
+
+ Root root = application
+ .getRootForRequest(createRequestMock(loggingClassLoader));
+ assertTrue(root instanceof MyRoot);
+ assertEquals(1, loggingClassLoader.requestedClasses.size());
+ assertEquals(MyRoot.class.getName(),
+ loggingClassLoader.requestedClasses.get(0));
+
+ }
+
+ private Application createStubApplication() {
+ return new Application() {
+ @Override
+ protected String getRootClassName(WrappedRequest request) {
+ // Always use the same root class
+ return MyRoot.class.getName();
+ }
+
+ @Override
+ public Root getRootForRequest(WrappedRequest request)
+ throws RootRequiresMoreInformationException {
+ // Always create a new root for testing (can't directly use
+ // getRoot as it's protected)
+ return getRoot(request);
+ }
+ };
+ }
+}
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..b969bf5e53
--- /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/table/TableColumnAlignments.java b/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java
index 04f436f5c4..299f9c79d4 100644
--- a/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java
+++ b/tests/server-side/com/vaadin/tests/server/component/table/TableColumnAlignments.java
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertArrayEquals;
import org.junit.Test;
import com.vaadin.ui.Table;
+import com.vaadin.ui.Table.Align;
public class TableColumnAlignments {
@@ -15,7 +16,7 @@ public class TableColumnAlignments {
properties, 10);
Object[] expected = new Object[properties];
for (int i = 0; i < properties; i++) {
- expected[i] = Table.ALIGN_LEFT;
+ expected[i] = Align.LEFT;
}
org.junit.Assert.assertArrayEquals("getColumnAlignments", expected,
t.getColumnAlignments());
@@ -27,9 +28,8 @@ public class TableColumnAlignments {
int properties = 5;
Table t = TableGenerator
.createTableWithDefaultContainer(properties, 10);
- String[] explicitAlignments = new String[] { Table.ALIGN_CENTER,
- Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT,
- Table.ALIGN_LEFT };
+ Align[] explicitAlignments = new Align[] { Align.CENTER, Align.LEFT,
+ Align.RIGHT, Align.RIGHT, Align.LEFT };
t.setColumnAlignments(explicitAlignments);
@@ -40,28 +40,10 @@ public class TableColumnAlignments {
@Test
public void invalidColumnAlignmentStrings() {
Table t = TableGenerator.createTableWithDefaultContainer(3, 7);
- String[] defaultAlignments = new String[] { Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT };
+ Align[] defaultAlignments = new Align[] { Align.LEFT, Align.LEFT,
+ Align.LEFT };
try {
- t.setColumnAlignments(new String[] { "a", "b", "c" });
- junit.framework.Assert
- .fail("No exception thrown for invalid array length");
- } catch (IllegalArgumentException e) {
- // Ok, expected
- }
-
- assertArrayEquals("Invalid change affected alignments",
- defaultAlignments, t.getColumnAlignments());
-
- }
-
- @Test
- public void invalidColumnAlignmentString() {
- Table t = TableGenerator.createTableWithDefaultContainer(3, 7);
- String[] defaultAlignments = new String[] { Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT };
- try {
- t.setColumnAlignment("Property 1", "a");
+ t.setColumnAlignments(new Align[] { Align.RIGHT, Align.RIGHT });
junit.framework.Assert
.fail("No exception thrown for invalid array length");
} catch (IllegalArgumentException e) {
@@ -76,10 +58,10 @@ public class TableColumnAlignments {
@Test
public void columnAlignmentForPropertyNotInContainer() {
Table t = TableGenerator.createTableWithDefaultContainer(3, 7);
- String[] defaultAlignments = new String[] { Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT };
+ Align[] defaultAlignments = new Align[] { Align.LEFT, Align.LEFT,
+ Align.LEFT };
try {
- t.setColumnAlignment("Property 1200", Table.ALIGN_LEFT);
+ t.setColumnAlignment("Property 1200", Align.LEFT);
// FIXME: Uncomment as there should be an exception (#6475)
// junit.framework.Assert
// .fail("No exception thrown for property not in container");
@@ -100,12 +82,11 @@ public class TableColumnAlignments {
@Test
public void invalidColumnAlignmentsLength() {
Table t = TableGenerator.createTableWithDefaultContainer(7, 7);
- String[] defaultAlignments = new String[] { Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT };
+ Align[] defaultAlignments = new Align[] { Align.LEFT, Align.LEFT,
+ Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT };
try {
- t.setColumnAlignments(new String[] { Table.ALIGN_LEFT });
+ t.setColumnAlignments(new Align[] { Align.LEFT });
junit.framework.Assert
.fail("No exception thrown for invalid array length");
} catch (IllegalArgumentException e) {
@@ -115,7 +96,7 @@ public class TableColumnAlignments {
defaultAlignments, t.getColumnAlignments());
try {
- t.setColumnAlignments(new String[] {});
+ t.setColumnAlignments(new Align[] {});
junit.framework.Assert
.fail("No exception thrown for invalid array length");
} catch (IllegalArgumentException e) {
@@ -125,10 +106,9 @@ public class TableColumnAlignments {
defaultAlignments, t.getColumnAlignments());
try {
- t.setColumnAlignments(new String[] { Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT,
- Table.ALIGN_LEFT });
+ t.setColumnAlignments(new Align[] { Align.LEFT, Align.LEFT,
+ Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT, Align.LEFT,
+ Align.LEFT });
junit.framework.Assert
.fail("No exception thrown for invalid array length");
} catch (IllegalArgumentException e) {
@@ -144,13 +124,11 @@ public class TableColumnAlignments {
int properties = 5;
Table t = TableGenerator
.createTableWithDefaultContainer(properties, 10);
- String[] explicitAlignments = new String[] { Table.ALIGN_CENTER,
- Table.ALIGN_LEFT, Table.ALIGN_RIGHT, Table.ALIGN_RIGHT,
- Table.ALIGN_LEFT };
+ Align[] explicitAlignments = new Align[] { Align.CENTER, Align.LEFT,
+ Align.RIGHT, Align.RIGHT, Align.LEFT };
- String[] currentAlignments = new String[] { Table.ALIGN_LEFT,
- Table.ALIGN_LEFT, Table.ALIGN_LEFT, Table.ALIGN_LEFT,
- Table.ALIGN_LEFT };
+ Align[] currentAlignments = new Align[] { Align.LEFT, Align.LEFT,
+ Align.LEFT, Align.LEFT, Align.LEFT };
for (int i = 0; i < properties; i++) {
t.setColumnAlignment("Property " + i, explicitAlignments[i]);
diff --git a/tests/server-side/com/vaadin/tests/server/component/table/TableListeners.java b/tests/server-side/com/vaadin/tests/server/component/table/TableListeners.java
index 6d9c7ed0eb..6cc522f8c7 100644
--- a/tests/server-side/com/vaadin/tests/server/component/table/TableListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/component/table/TableListeners.java
@@ -20,7 +20,8 @@ public class TableListeners extends AbstractListenerMethodsTest {
}
public void testItemClickListenerAddGetRemove() throws Exception {
- testListenerAddGetRemove(Table.class, ItemClickEvent.class, ItemClickListener.class);
+ testListenerAddGetRemove(Table.class, ItemClickEvent.class,
+ ItemClickListener.class);
}
public void testFooterClickListenerAddGetRemove() throws Exception {
diff --git a/tests/server-side/com/vaadin/tests/server/component/table/TableSerialization.java b/tests/server-side/com/vaadin/tests/server/component/table/TableSerialization.java
index 44dcd60fa5..ee6349093c 100644
--- a/tests/server-side/com/vaadin/tests/server/component/table/TableSerialization.java
+++ b/tests/server-side/com/vaadin/tests/server/component/table/TableSerialization.java
@@ -12,8 +12,9 @@ public class TableSerialization extends TestCase {
Table t = new Table();
byte[] ser = SerializationUtils.serialize(t);
Table t2 = (Table) SerializationUtils.deserialize(ser);
-
+
}
+
public void testSerializationWithRowHeaders() {
Table t = new Table();
t.setRowHeaderMode(Table.ROW_HEADER_MODE_EXPLICIT);
diff --git a/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java b/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java
index c74a3fadf1..0ef8ae5a76 100644
--- a/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java
+++ b/tests/server-side/com/vaadin/tests/server/component/tabsheet/TestTabSheet.java
@@ -7,13 +7,13 @@ import static org.junit.Assert.assertSame;
import java.util.Iterator;
+import org.junit.Test;
+
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.Tab;
-import org.junit.Test;
-
public class TestTabSheet {
@Test
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..bd6dd6c7b1 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,17 +2,15 @@ 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;
import com.vaadin.data.util.ObjectProperty;
import com.vaadin.data.util.PropertyFormatter;
-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 +18,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;
@@ -30,18 +28,24 @@ public class TextFieldWithPropertyFormatter extends TestCase {
protected void setUp() throws Exception {
super.setUp();
- field = new TextField();
+ field = new TextField() {
+ @Override
+ public void requestRepaint() {
+ repainted++;
+ super.requestRepaint();
+ }
+ };
- 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;
}
};
@@ -53,19 +57,15 @@ public class TextFieldWithPropertyFormatter extends TestCase {
listener = new Property.ValueChangeListener() {
+ @Override
public void valueChange(ValueChangeEvent event) {
listenerCalled++;
assertEquals(1, listenerCalled);
assertEquals(FORMATTED_VALUE, event.getProperty().getValue());
}
};
-
+
field.addListener(listener);
- field.addListener(new Paintable.RepaintRequestListener() {
- public void repaintRequested(RepaintRequestEvent event) {
- repainted++;
- }
- });
listenerCalled = 0;
repainted = 0;
}
@@ -81,7 +81,9 @@ public class TextFieldWithPropertyFormatter extends TestCase {
private void checkEndState() {
assertEquals(1, listenerCalled);
- assertEquals(1, repainted);
+ // setModified triggers repaint, this is done 2 times. A
+ // ValueChangeEvent triggers the third
+ assertEquals(3, repainted);
assertEquals(FORMATTED_VALUE, field.getValue());
assertEquals(FORMATTED_VALUE, formatter.getValue());
assertEquals(PARSED_VALUE, property.getValue());
diff --git a/tests/server-side/com/vaadin/tests/server/component/tree/TestListeners.java b/tests/server-side/com/vaadin/tests/server/component/tree/TestListeners.java
index 49610ff293..4984cf161b 100644
--- a/tests/server-side/com/vaadin/tests/server/component/tree/TestListeners.java
+++ b/tests/server-side/com/vaadin/tests/server/component/tree/TestListeners.java
@@ -121,12 +121,14 @@ public class TestListeners extends TestCase implements ExpandListener,
assertEquals(0, collapseCalled);
}
+ @Override
public void nodeExpand(ExpandEvent event) {
lastExpanded = event.getItemId();
expandCalled++;
}
+ @Override
public void nodeCollapse(CollapseEvent event) {
lastCollapsed = event.getItemId();
collapseCalled++;
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 70fb68b9ec..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 74859fd8b7..f8901803c3 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,24 +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 java.util.Set;
-
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);
}
}
@@ -28,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
@@ -46,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);
@@ -62,39 +61,19 @@ 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());
}
-
- @Test
- public void testChildWindowsIteratorModification() {
- Window mainWindow = new Window();
- mainWindow.addWindow(new Window());
- mainWindow.addWindow(new Window());
-
- Set<Window> childWindows = mainWindow.getChildWindows();
- for (Window window : childWindows) {
- mainWindow.removeWindow(window);
- }
-
- assertEquals(2, childWindows.size());
- assertEquals(0, mainWindow.getChildWindows().size());
- }
}
diff --git a/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java b/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java
index 5fabe40bb7..e1435ea2ab 100644
--- a/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java
+++ b/tests/server-side/com/vaadin/tests/server/component/window/AttachDetachWindow.java
@@ -3,61 +3,36 @@ package com.vaadin.tests.server.component.window;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
import com.vaadin.Application;
-import com.vaadin.ui.Component;
+import com.vaadin.terminal.WrappedRequest;
import com.vaadin.ui.Label;
+import com.vaadin.ui.Root;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
-import org.junit.Test;
-
public class AttachDetachWindow {
- private Application testApp = new Application() {
- @Override
- public void init() {
- }
- };
+ private Application testApp = new Application();
+
+ private interface TestContainer {
+ public boolean attachCalled();
+
+ public boolean detachCalled();
+
+ public TestContent getTestContent();
- private class TestWindow extends Window {
+ public Application getApplication();
+ }
+
+ private class TestWindow extends Window implements TestContainer {
boolean windowAttachCalled = false;
- boolean contentAttachCalled = false;
- boolean childAttachCalled = false;
boolean windowDetachCalled = false;
- boolean contentDetachCalled = false;
- boolean childDetachCalled = false;
+ private TestContent testContent = new TestContent();;
TestWindow() {
- setContent(new VerticalLayout() {
- @Override
- public void attach() {
- super.attach();
- contentAttachCalled = true;
- }
-
- @Override
- public void detach() {
- super.detach();
- contentDetachCalled = true;
- }
- });
- addComponent(new Label() {
- @Override
- public void attach() {
- super.attach();
- childAttachCalled = true;
- }
-
- @Override
- public void detach() {
- super.detach();
- childDetachCalled = true;
- }
- });
- }
-
- Component getChild() {
- return getComponentIterator().next();
+ setContent(testContent);
}
@Override
@@ -71,9 +46,103 @@ public class AttachDetachWindow {
super.detach();
windowDetachCalled = true;
}
+
+ @Override
+ public boolean attachCalled() {
+ return windowAttachCalled;
+ }
+
+ @Override
+ public boolean detachCalled() {
+ return windowDetachCalled;
+ }
+
+ @Override
+ public TestContent getTestContent() {
+ return testContent;
+ }
+ }
+
+ private class TestContent extends VerticalLayout {
+ boolean contentDetachCalled = false;
+ boolean childDetachCalled = false;
+ boolean contentAttachCalled = false;
+ boolean childAttachCalled = false;
+
+ private Label child = new Label() {
+ @Override
+ public void attach() {
+ super.attach();
+ childAttachCalled = true;
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ childDetachCalled = true;
+ }
+ };
+
+ public TestContent() {
+ addComponent(child);
+ }
+
+ @Override
+ public void attach() {
+ super.attach();
+ contentAttachCalled = true;
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ contentDetachCalled = true;
+ }
}
- TestWindow main = new TestWindow();
+ private class TestRoot extends Root implements TestContainer {
+ boolean rootAttachCalled = false;
+ boolean rootDetachCalled = false;
+ private TestContent testContent = new TestContent();;
+
+ public TestRoot() {
+ setContent(testContent);
+ }
+
+ @Override
+ protected void init(WrappedRequest request) {
+ // Do nothing
+ }
+
+ @Override
+ public boolean attachCalled() {
+ return rootAttachCalled;
+ }
+
+ @Override
+ public boolean detachCalled() {
+ return rootDetachCalled;
+ }
+
+ @Override
+ public TestContent getTestContent() {
+ return testContent;
+ }
+
+ @Override
+ public void attach() {
+ super.attach();
+ rootAttachCalled = true;
+ }
+
+ @Override
+ public void detach() {
+ super.detach();
+ rootDetachCalled = true;
+ }
+ }
+
+ TestRoot main = new TestRoot();
TestWindow sub = new TestWindow();
@Test
@@ -86,7 +155,7 @@ public class AttachDetachWindow {
assertUnattached(sub);
// attaching main should recurse to sub
- testApp.setMainWindow(main);
+ main.setApplication(testApp);
assertAttached(main);
assertAttached(sub);
}
@@ -96,7 +165,7 @@ public class AttachDetachWindow {
assertUnattached(main);
assertUnattached(sub);
- testApp.setMainWindow(main);
+ main.setApplication(testApp);
assertAttached(main);
assertUnattached(sub);
@@ -108,7 +177,7 @@ public class AttachDetachWindow {
@Test
public void removeSubWindowBeforeDetachingMainWindow() {
- testApp.addWindow(main);
+ main.setApplication(testApp);
main.addWindow(sub);
// sub should be detached when removing from attached main
@@ -117,18 +186,18 @@ public class AttachDetachWindow {
assertDetached(sub);
// main detach should recurse to sub
- testApp.removeWindow(main);
+ main.setApplication(null);
assertDetached(main);
assertDetached(sub);
}
@Test
public void removeSubWindowAfterDetachingMainWindow() {
- testApp.addWindow(main);
+ main.setApplication(testApp);
main.addWindow(sub);
// main detach should recurse to sub
- testApp.removeWindow(main);
+ main.setApplication(null);
assertDetached(main);
assertDetached(sub);
@@ -141,27 +210,31 @@ public class AttachDetachWindow {
* Asserts that win and its children are attached to testApp and their
* attach() methods have been called.
*/
- private void assertAttached(TestWindow win) {
- assertTrue("window attach not called", win.windowAttachCalled);
- assertTrue("window content attach not called", win.contentAttachCalled);
- assertTrue("window child attach not called", win.childAttachCalled);
+ private void assertAttached(TestContainer win) {
+ TestContent testContent = win.getTestContent();
+
+ assertTrue("window attach not called", win.attachCalled());
+ assertTrue("window content attach not called",
+ testContent.contentAttachCalled);
+ assertTrue("window child attach not called",
+ testContent.childAttachCalled);
assertSame("window not attached", win.getApplication(), testApp);
- assertSame("window content not attached", win.getContent()
- .getApplication(), testApp);
- assertSame("window children not attached", win.getChild()
- .getApplication(), testApp);
+ assertSame("window content not attached", testContent.getApplication(),
+ testApp);
+ assertSame("window children not attached",
+ testContent.child.getApplication(), testApp);
}
/**
* Asserts that win and its children are not attached.
*/
- private void assertUnattached(TestWindow win) {
+ private void assertUnattached(TestContainer win) {
assertSame("window not detached", win.getApplication(), null);
- assertSame("window content not detached", win.getContent()
- .getApplication(), null);
- assertSame("window children not detached", win.getChild()
+ assertSame("window content not detached", win.getTestContent()
.getApplication(), null);
+ assertSame("window children not detached",
+ win.getTestContent().child.getApplication(), null);
}
/**
@@ -170,10 +243,12 @@ public class AttachDetachWindow {
*
* @param win
*/
- private void assertDetached(TestWindow win) {
+ private void assertDetached(TestContainer win) {
assertUnattached(win);
- assertTrue("window detach not called", win.windowDetachCalled);
- assertTrue("window content detach not called", win.contentDetachCalled);
- assertTrue("window child detach not called", win.childDetachCalled);
+ assertTrue("window detach not called", win.detachCalled());
+ assertTrue("window content detach not called",
+ win.getTestContent().contentDetachCalled);
+ assertTrue("window child detach not called",
+ win.getTestContent().childDetachCalled);
}
}
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 fcea309e84..3512f555c9 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/ComponentAttachDetachListenerTest.java b/tests/server-side/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java
index 1e01d9a55f..3ba1c4c7f1 100644
--- a/tests/server-side/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java
+++ b/tests/server-side/com/vaadin/tests/server/components/ComponentAttachDetachListenerTest.java
@@ -46,6 +46,7 @@ public class ComponentAttachDetachListenerTest extends TestCase {
private ComponentPosition componentPosition = null;
private class MyAttachListener implements ComponentAttachListener {
+ @Override
public void componentAttachedToContainer(ComponentAttachEvent event) {
attachCounter++;
attachedComponent = event.getAttachedComponent();
@@ -75,6 +76,7 @@ public class ComponentAttachDetachListenerTest extends TestCase {
}
private class MyDetachListener implements ComponentDetachListener {
+ @Override
public void componentDetachedFromContainer(ComponentDetachEvent event) {
detachCounter++;
detachedComponent = event.getDetachedComponent();
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 3fbe1406f2..308889fa33 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,10 +22,10 @@ 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);
+ ((ComboBox) 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 2c911d5f3f..f5db67be97 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,10 +37,10 @@ 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);
+ ((TextField) 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 89d018c8a5..7713f69f68 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/navigator/ClassBasedViewProviderTest.java b/tests/server-side/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java
new file mode 100644
index 0000000000..5db0df4280
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/navigator/ClassBasedViewProviderTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2011 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.navigator;
+
+import junit.framework.TestCase;
+
+import com.vaadin.navigator.Navigator.ClassBasedViewProvider;
+import com.vaadin.navigator.View;
+import com.vaadin.ui.Label;
+
+public class ClassBasedViewProviderTest extends TestCase {
+
+ public static class TestView extends Label implements View {
+ public String parameters = null;
+
+ @Override
+ public void navigateTo(String parameters) {
+ this.parameters = parameters;
+ }
+
+ }
+
+ public static class TestView2 extends TestView {
+
+ }
+
+ public void testCreateProviderWithNullName() throws Exception {
+ try {
+ new ClassBasedViewProvider(null, TestView.class);
+ fail("Should not be able to create view provider with null name");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testCreateProviderWithEmptyStringName() throws Exception {
+ new ClassBasedViewProvider("", TestView.class);
+ }
+
+ public void testCreateProviderNullViewClass() throws Exception {
+ try {
+ new ClassBasedViewProvider("test", null);
+ fail("Should not be able to create view provider with null view class");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testViewNameGetter() throws Exception {
+ ClassBasedViewProvider provider1 = new ClassBasedViewProvider("",
+ TestView.class);
+ assertEquals("View name should be empty", "", provider1.getViewName());
+
+ ClassBasedViewProvider provider2 = new ClassBasedViewProvider("test",
+ TestView.class);
+ assertEquals("View name does not match", "test",
+ provider2.getViewName());
+ }
+
+ public void testViewClassGetter() throws Exception {
+ ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
+ TestView.class);
+ assertEquals("Incorrect view class returned by getter", TestView.class,
+ provider.getViewClass());
+ }
+
+ public void testGetViewNameForNullString() throws Exception {
+ ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
+ TestView.class);
+ assertNull("Received view name for null view string",
+ provider.getViewName((String) null));
+ }
+
+ public void testGetViewNameForEmptyString() throws Exception {
+ ClassBasedViewProvider provider1 = new ClassBasedViewProvider("",
+ TestView.class);
+ assertEquals(
+ "Did not find view name for empty view string in a provider with empty string registered",
+ "", provider1.getViewName(""));
+
+ ClassBasedViewProvider provider2 = new ClassBasedViewProvider("test",
+ TestView.class);
+ assertNull(
+ "Found view name for empty view string when none registered",
+ provider2.getViewName(""));
+ }
+
+ public void testGetViewNameWithParameters() throws Exception {
+ ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
+ TestView.class);
+ assertEquals("Incorrect view name found for view string", "test",
+ provider.getViewName("test"));
+ assertEquals(
+ "Incorrect view name found for view string ending with slash",
+ "test", provider.getViewName("test/"));
+ assertEquals(
+ "Incorrect view name found for view string with parameters",
+ "test", provider.getViewName("test/params/are/here"));
+ }
+
+ public void testGetView() throws Exception {
+ ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
+ TestView.class);
+
+ View view = provider.getView("test");
+ assertNotNull("Did not get view from a provider", view);
+ assertEquals("Incorrect view type", TestView.class, view.getClass());
+ }
+
+ public void testGetViewIncorrectViewName() throws Exception {
+ ClassBasedViewProvider provider = new ClassBasedViewProvider("test",
+ TestView.class);
+
+ View view = provider.getView("test2");
+ assertNull("Got view from a provider for incorrect view name", view);
+ }
+
+}
diff --git a/tests/server-side/com/vaadin/tests/server/navigator/NavigatorTest.java b/tests/server-side/com/vaadin/tests/server/navigator/NavigatorTest.java
new file mode 100644
index 0000000000..894b841d38
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/navigator/NavigatorTest.java
@@ -0,0 +1,575 @@
+/*
+ * Copyright 2011 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.navigator;
+
+import java.util.LinkedList;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+import com.vaadin.navigator.FragmentManager;
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.View;
+import com.vaadin.navigator.ViewChangeListener;
+import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
+import com.vaadin.navigator.ViewDisplay;
+import com.vaadin.navigator.ViewProvider;
+import com.vaadin.tests.server.navigator.ClassBasedViewProviderTest.TestView;
+import com.vaadin.tests.server.navigator.ClassBasedViewProviderTest.TestView2;
+
+public class NavigatorTest extends TestCase {
+
+ // TODO test internal parameters (and absence of them)
+ // TODO test listeners blocking navigation, multiple listeners
+
+ public static class NullDisplay implements ViewDisplay {
+ @Override
+ public void showView(View view) {
+ // do nothing
+ }
+ }
+
+ public static class NullFragmentManager implements FragmentManager {
+ @Override
+ public String getFragment() {
+ return null;
+ }
+
+ @Override
+ public void setFragment(String fragment) {
+ // do nothing
+ }
+ }
+
+ public static class TestDisplay implements ViewDisplay {
+ private View currentView;
+
+ @Override
+ public void showView(View view) {
+ currentView = view;
+ }
+
+ public View getCurrentView() {
+ return currentView;
+ }
+ }
+
+ public static class TestNavigator extends Navigator {
+ public TestNavigator() {
+ super(new NullFragmentManager(), new TestDisplay());
+ }
+
+ public View getView(String viewAndParameters) {
+ navigateTo(viewAndParameters);
+ return ((TestDisplay) getDisplay()).getCurrentView();
+ }
+ }
+
+ public static class ViewChangeTestListener implements ViewChangeListener {
+ private final LinkedList<ViewChangeEvent> referenceEvents = new LinkedList<ViewChangeListener.ViewChangeEvent>();
+ private final LinkedList<Boolean> referenceIsCheck = new LinkedList<Boolean>();
+ private final LinkedList<Boolean> checkReturnValues = new LinkedList<Boolean>();
+
+ public void addExpectedIsViewChangeAllowed(ViewChangeEvent event,
+ boolean returnValue) {
+ referenceIsCheck.add(true);
+ referenceEvents.add(event);
+ checkReturnValues.add(returnValue);
+ }
+
+ public void addExpectedNavigatorViewChange(ViewChangeEvent event) {
+ referenceIsCheck.add(false);
+ referenceEvents.add(event);
+ }
+
+ public boolean isReady() {
+ return referenceEvents.isEmpty();
+ }
+
+ public boolean equalsReferenceEvent(ViewChangeEvent event,
+ ViewChangeEvent reference) {
+ if (event == null) {
+ return false;
+ }
+ if (reference.getNavigator() != event.getNavigator()) {
+ return false;
+ }
+ if (reference.getOldView() != event.getOldView()) {
+ return false;
+ }
+ if (reference.getNewView() != event.getNewView()) {
+ return false;
+ }
+ if (!stringEquals(reference.getViewName(), event.getViewName())) {
+ return false;
+ }
+ if (!stringEquals(reference.getFragmentParameters(),
+ event.getFragmentParameters())) {
+ return false;
+ }
+ return true;
+ }
+
+ private static boolean stringEquals(String string1, String string2) {
+ if (string1 == null) {
+ return string2 == null;
+ } else {
+ return string1.equals(string2);
+ }
+ }
+
+ @Override
+ public boolean isViewChangeAllowed(ViewChangeEvent event) {
+ if (referenceEvents.isEmpty()) {
+ fail("Unexpected call to isViewChangeAllowed()");
+ }
+ ViewChangeEvent reference = referenceEvents.remove();
+ Boolean isCheck = referenceIsCheck.remove();
+ if (!isCheck) {
+ fail("Expected navigatorViewChanged(), received isViewChangeAllowed()");
+ }
+ // here to make sure exactly the correct values are removed from
+ // each queue
+ Boolean returnValue = checkReturnValues.remove();
+ if (!equalsReferenceEvent(event, reference)) {
+ fail("View change event does not match reference event");
+ }
+ return returnValue;
+ }
+
+ @Override
+ public void navigatorViewChanged(ViewChangeEvent event) {
+ if (referenceEvents.isEmpty()) {
+ fail("Unexpected call to navigatorViewChanged()");
+ }
+ ViewChangeEvent reference = referenceEvents.remove();
+ Boolean isCheck = referenceIsCheck.remove();
+ if (isCheck) {
+ fail("Expected isViewChangeAllowed(), received navigatorViewChanged()");
+ }
+ if (!equalsReferenceEvent(event, reference)) {
+ fail("View change event does not match reference event");
+ }
+ }
+ }
+
+ public void testBasicNavigation() {
+ IMocksControl control = EasyMock.createControl();
+ FragmentManager manager = control.createMock(FragmentManager.class);
+ ViewDisplay display = control.createMock(ViewDisplay.class);
+ ViewProvider provider = control.createMock(ViewProvider.class);
+ View view1 = control.createMock(View.class);
+ View view2 = control.createMock(View.class);
+
+ // prepare mocks: what to expect
+ EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("");
+ view1.navigateTo(null);
+ display.showView(view1);
+ manager.setFragment("test1");
+
+ EasyMock.expect(provider.getViewName("test2/")).andReturn("test2");
+ EasyMock.expect(provider.getView("test2")).andReturn(view2);
+ EasyMock.expect(manager.getFragment()).andReturn("view1");
+ view2.navigateTo(null);
+ display.showView(view2);
+ manager.setFragment("test2");
+
+ EasyMock.expect(provider.getViewName("test1/params"))
+ .andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("view2");
+ view1.navigateTo("params");
+ display.showView(view1);
+ manager.setFragment("test1/params");
+
+ control.replay();
+
+ // create and test navigator
+ Navigator navigator = new Navigator(manager, display);
+ navigator.registerProvider(provider);
+
+ navigator.navigateTo("test1");
+ navigator.navigateTo("test2/");
+ navigator.navigateTo("test1/params");
+ }
+
+ public void testMainView() {
+ IMocksControl control = EasyMock.createControl();
+ FragmentManager manager = control.createMock(FragmentManager.class);
+ ViewDisplay display = control.createMock(ViewDisplay.class);
+ ViewProvider provider = control.createMock(ViewProvider.class);
+ View view1 = control.createMock(View.class);
+ View view2 = control.createMock(View.class);
+
+ // prepare mocks: what to expect
+ EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
+ EasyMock.expect(provider.getView("test2")).andReturn(view2);
+ EasyMock.expect(manager.getFragment()).andReturn("view1");
+ view2.navigateTo(null);
+ display.showView(view2);
+ manager.setFragment("test2");
+
+ EasyMock.expect(provider.getViewName("")).andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("");
+ view1.navigateTo(null);
+ display.showView(view1);
+ manager.setFragment("test1");
+
+ EasyMock.expect(provider.getViewName("test1/params"))
+ .andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("view2");
+ view1.navigateTo("params");
+ display.showView(view1);
+ manager.setFragment("test1/params");
+
+ control.replay();
+
+ // create and test navigator
+ Navigator navigator = new Navigator(manager, display);
+ navigator.registerProvider(provider);
+
+ navigator.navigateTo("test2");
+ navigator.navigateTo("");
+ navigator.navigateTo("test1/params");
+ }
+
+ public void testListeners() {
+ IMocksControl control = EasyMock.createControl();
+ FragmentManager manager = control.createMock(FragmentManager.class);
+ ViewDisplay display = control.createMock(ViewDisplay.class);
+ ViewProvider provider = control.createMock(ViewProvider.class);
+ View view1 = control.createMock(View.class);
+ View view2 = control.createMock(View.class);
+ ViewChangeTestListener listener = new ViewChangeTestListener();
+
+ // create navigator to test
+ Navigator navigator = new Navigator(manager, display);
+
+ // prepare mocks: what to expect
+ EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1,
+ "test1", null);
+ listener.addExpectedIsViewChangeAllowed(event1, true);
+ EasyMock.expect(manager.getFragment()).andReturn("");
+ view1.navigateTo(null);
+ display.showView(view1);
+ manager.setFragment("test1");
+ listener.addExpectedNavigatorViewChange(event1);
+
+ EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
+ EasyMock.expect(provider.getView("test2")).andReturn(view2);
+ ViewChangeEvent event2 = new ViewChangeEvent(navigator, view1, view2,
+ "test2", null);
+ listener.addExpectedIsViewChangeAllowed(event2, true);
+ EasyMock.expect(manager.getFragment()).andReturn("view1");
+ view2.navigateTo(null);
+ display.showView(view2);
+ manager.setFragment("test2");
+ listener.addExpectedNavigatorViewChange(event2);
+
+ control.replay();
+
+ // test navigator
+ navigator.registerProvider(provider);
+ navigator.addListener(listener);
+
+ navigator.navigateTo("test1");
+ navigator.navigateTo("test2");
+
+ if (!listener.isReady()) {
+ fail("Missing listener calls");
+ }
+ }
+
+ public void testBlockNavigation() {
+ IMocksControl control = EasyMock.createControl();
+ FragmentManager manager = control.createMock(FragmentManager.class);
+ ViewDisplay display = control.createMock(ViewDisplay.class);
+ ViewProvider provider = control.createMock(ViewProvider.class);
+ View view1 = control.createMock(View.class);
+ View view2 = control.createMock(View.class);
+ ViewChangeTestListener listener1 = new ViewChangeTestListener();
+ ViewChangeTestListener listener2 = new ViewChangeTestListener();
+
+ Navigator navigator = new Navigator(manager, display);
+
+ // prepare mocks: what to expect
+ // first listener blocks first view change
+ EasyMock.expect(provider.getViewName("test1")).andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("");
+ ViewChangeEvent event1 = new ViewChangeEvent(navigator, null, view1,
+ "test1", null);
+ listener1.addExpectedIsViewChangeAllowed(event1, false);
+
+ // second listener blocks second view change
+ EasyMock.expect(provider.getViewName("test1/test")).andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("");
+ ViewChangeEvent event2 = new ViewChangeEvent(navigator, null, view1,
+ "test1", "test");
+ listener1.addExpectedIsViewChangeAllowed(event2, true);
+ listener2.addExpectedIsViewChangeAllowed(event2, false);
+
+ // both listeners allow view change
+ EasyMock.expect(provider.getViewName("test1/bar")).andReturn("test1");
+ EasyMock.expect(provider.getView("test1")).andReturn(view1);
+ EasyMock.expect(manager.getFragment()).andReturn("");
+ ViewChangeEvent event3 = new ViewChangeEvent(navigator, null, view1,
+ "test1", "bar");
+ listener1.addExpectedIsViewChangeAllowed(event3, true);
+ listener2.addExpectedIsViewChangeAllowed(event3, true);
+ view1.navigateTo("bar");
+ display.showView(view1);
+ manager.setFragment("test1/bar");
+ listener1.addExpectedNavigatorViewChange(event3);
+ listener2.addExpectedNavigatorViewChange(event3);
+
+ // both listeners allow view change from non-null view
+ EasyMock.expect(provider.getViewName("test2")).andReturn("test2");
+ EasyMock.expect(provider.getView("test2")).andReturn(view2);
+ EasyMock.expect(manager.getFragment()).andReturn("view1");
+ ViewChangeEvent event4 = new ViewChangeEvent(navigator, view1, view2,
+ "test2", null);
+ listener1.addExpectedIsViewChangeAllowed(event4, true);
+ listener2.addExpectedIsViewChangeAllowed(event4, true);
+ view2.navigateTo(null);
+ display.showView(view2);
+ manager.setFragment("test2");
+ listener1.addExpectedNavigatorViewChange(event4);
+ listener2.addExpectedNavigatorViewChange(event4);
+
+ control.replay();
+
+ // test navigator
+ navigator.registerProvider(provider);
+ navigator.addListener(listener1);
+ navigator.addListener(listener2);
+
+ navigator.navigateTo("test1");
+ navigator.navigateTo("test1/test");
+ navigator.navigateTo("test1/bar");
+ navigator.navigateTo("test2");
+
+ if (!listener1.isReady()) {
+ fail("Missing listener calls for listener1");
+ }
+ if (!listener2.isReady()) {
+ fail("Missing listener calls for listener2");
+ }
+ }
+
+ public void testAddViewInstance() throws Exception {
+ View view = new TestView();
+
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", view);
+
+ assertEquals("Registered view instance not returned by navigator",
+ view, navigator.getView("test"));
+ }
+
+ public void testAddViewInstanceSameName() throws Exception {
+ View view1 = new TestView();
+ View view2 = new TestView2();
+
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", view1);
+ navigator.addView("test", view2);
+
+ assertEquals(
+ "Adding second view with same name should override previous view",
+ view2, navigator.getView("test"));
+ }
+
+ public void testAddViewClass() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", TestView.class);
+
+ View view = navigator.getView("test");
+ assertNotNull("Received null view", view);
+ assertEquals("Received incorrect type of view", TestView.class,
+ view.getClass());
+ }
+
+ public void testAddViewClassSameName() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", TestView.class);
+ navigator.addView("test", TestView2.class);
+
+ assertEquals(
+ "Adding second view class with same name should override previous view",
+ TestView2.class, navigator.getView("test").getClass());
+ }
+
+ public void testAddViewInstanceAndClassSameName() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", TestView.class);
+ TestView2 view2 = new TestView2();
+ navigator.addView("test", view2);
+
+ assertEquals(
+ "Adding second view class with same name should override previous view",
+ view2, navigator.getView("test"));
+
+ navigator.addView("test", TestView.class);
+
+ assertEquals(
+ "Adding second view class with same name should override previous view",
+ TestView.class, navigator.getView("test").getClass());
+ }
+
+ public void testAddViewWithNullName() throws Exception {
+ Navigator navigator = new Navigator(new NullFragmentManager(),
+ new NullDisplay());
+
+ try {
+ navigator.addView(null, new TestView());
+ fail("addView() accepted null view name");
+ } catch (IllegalArgumentException e) {
+ }
+ try {
+ navigator.addView(null, TestView.class);
+ fail("addView() accepted null view name");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testAddViewWithNullInstance() throws Exception {
+ Navigator navigator = new Navigator(new NullFragmentManager(),
+ new NullDisplay());
+
+ try {
+ navigator.addView("test", (View) null);
+ fail("addView() accepted null view instance");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testAddViewWithNullClass() throws Exception {
+ Navigator navigator = new Navigator(new NullFragmentManager(),
+ new NullDisplay());
+
+ try {
+ navigator.addView("test", (Class<View>) null);
+ fail("addView() accepted null view class");
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ public void testRemoveViewInstance() throws Exception {
+ View view = new TestView();
+
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", view);
+ navigator.removeView("test");
+
+ assertNull("View not removed", navigator.getView("test"));
+ }
+
+ public void testRemoveViewInstanceNothingElse() throws Exception {
+ View view = new TestView();
+ View view2 = new TestView2();
+
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", view);
+ navigator.addView("test2", view2);
+ navigator.removeView("test");
+
+ assertEquals("Removed extra views", view2, navigator.getView("test2"));
+ }
+
+ public void testRemoveViewClass() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", TestView.class);
+ navigator.removeView("test");
+
+ assertNull("View not removed", navigator.getView("test"));
+ }
+
+ public void testRemoveViewClassNothingElse() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test", TestView.class);
+ navigator.addView("test2", TestView2.class);
+ navigator.removeView("test");
+
+ assertEquals("Removed extra views", TestView2.class,
+ navigator.getView("test2").getClass());
+ }
+
+ public void testGetViewNestedNames() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test/subview", TestView2.class);
+ navigator.addView("test", TestView.class);
+
+ assertEquals("Incorrect view name found for subview string",
+ TestView2.class, navigator.getView("test/subview").getClass());
+ assertEquals(
+ "Incorrect view name found for subview string with empty parameters",
+ TestView2.class, navigator.getView("test/subview/").getClass());
+ assertEquals(
+ "Incorrect view name found for subview string with parameters",
+ TestView2.class, navigator.getView("test/subview/parameters")
+ .getClass());
+ assertEquals("Incorrect view name found for top level view string",
+ TestView.class, navigator.getView("test").getClass());
+ assertEquals(
+ "Incorrect view name found for top level view string with empty parameters",
+ TestView.class, navigator.getView("test/").getClass());
+ assertEquals(
+ "Incorrect view name found for top level view string with parameters starting like subview name",
+ TestView.class, navigator.getView("test/subviewnothere")
+ .getClass());
+ }
+
+ public void testGetViewLongestPrefixOrder() throws Exception {
+ TestNavigator navigator = new TestNavigator();
+
+ navigator.addView("test/subview", TestView2.class);
+ navigator.addView("test", TestView.class);
+
+ assertEquals("Incorrect view name found", TestView.class, navigator
+ .getView("test").getClass());
+
+ // other order
+
+ TestNavigator navigator2 = new TestNavigator();
+
+ navigator2.addView("test", TestView.class);
+ navigator2.addView("test/subview", TestView2.class);
+
+ assertEquals("Incorrect view name found", TestView.class, navigator2
+ .getView("test").getClass());
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java b/tests/server-side/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java
new file mode 100644
index 0000000000..e342ee9005
--- /dev/null
+++ b/tests/server-side/com/vaadin/tests/server/navigator/UriFragmentManagerTest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2011 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.navigator;
+
+import junit.framework.TestCase;
+
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+import com.vaadin.navigator.Navigator;
+import com.vaadin.navigator.Navigator.UriFragmentManager;
+import com.vaadin.terminal.Page;
+import com.vaadin.terminal.Page.FragmentChangedEvent;
+
+public class UriFragmentManagerTest extends TestCase {
+
+ public void testGetSetFragment() {
+ Page page = EasyMock.createMock(Page.class);
+ UriFragmentManager manager = new UriFragmentManager(page, null);
+
+ // prepare mock
+ EasyMock.expect(page.getFragment()).andReturn("");
+ page.setFragment("test", false);
+ EasyMock.expect(page.getFragment()).andReturn("test");
+ EasyMock.replay(page);
+
+ // test manager using the mock
+ assertEquals("Incorrect fragment value", "", manager.getFragment());
+ manager.setFragment("test");
+ assertEquals("Incorrect fragment value", "test", manager.getFragment());
+ }
+
+ public void testListener() {
+ // create mocks
+ IMocksControl control = EasyMock.createControl();
+ Navigator navigator = control.createMock(Navigator.class);
+ Page page = control.createMock(Page.class);
+
+ UriFragmentManager manager = new UriFragmentManager(page, navigator);
+
+ EasyMock.expect(page.getFragment()).andReturn("test");
+ navigator.navigateTo("test");
+ control.replay();
+
+ FragmentChangedEvent event = page.new FragmentChangedEvent(page,
+ "oldtest");
+ manager.fragmentChanged(event);
+ }
+}
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..e3320b8699
--- /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 c4052c2db8..e37b97e02c 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..9e791500b0
--- /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..e84f9dd8b9
--- /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.");
+ }
+ }
+}
diff --git a/tests/server-side/com/vaadin/tests/util/UniqueSerializableTest.java b/tests/server-side/com/vaadin/tests/util/UniqueSerializableTest.java
index 578d983c4d..d62f0df332 100644
--- a/tests/server-side/com/vaadin/tests/util/UniqueSerializableTest.java
+++ b/tests/server-side/com/vaadin/tests/util/UniqueSerializableTest.java
@@ -1,5 +1,17 @@
/*
-@VaadinApache2LicenseForJavaFiles@
+ * Copyright 2011 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.util;