aboutsummaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/data/util/BeanContainerTest.java15
-rw-r--r--server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java198
-rw-r--r--server/tests/src/com/vaadin/data/util/NestedMethodPropertyTest.java40
-rw-r--r--server/tests/src/com/vaadin/data/util/PropertyDescriptorTest.java18
-rw-r--r--server/tests/src/com/vaadin/data/util/TestIndexedContainer.java113
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java5
-rw-r--r--server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java1
-rw-r--r--server/tests/src/com/vaadin/server/VaadinSessionTest.java2
-rw-r--r--server/tests/src/com/vaadin/tests/data/bean/BeanToValidate.java13
-rw-r--r--server/tests/src/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java3
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToBigDecimalConverter.java53
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java24
-rw-r--r--server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java1
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java9
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java26
-rw-r--r--server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java29
16 files changed, 493 insertions, 57 deletions
diff --git a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
index 9037e303a8..a6c3bb0b8b 100644
--- a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
@@ -457,4 +457,19 @@ public class BeanContainerTest extends AbstractBeanContainerTest {
.getValue());
}
+ public void testNestedContainerPropertyWithNullBean() {
+ BeanContainer<String, NestedMethodPropertyTest.Person> container = new BeanContainer<String, NestedMethodPropertyTest.Person>(
+ NestedMethodPropertyTest.Person.class);
+ container.setBeanIdProperty("name");
+
+ container.addBean(new NestedMethodPropertyTest.Person("John", null));
+ assertTrue(container
+ .addNestedContainerProperty("address.postalCodeObject"));
+ assertTrue(container.addNestedContainerProperty("address.street"));
+ // the nested properties added with allowNullBean setting should return
+ // null
+ assertNull(container.getContainerProperty("John", "address.street")
+ .getValue());
+ }
+
}
diff --git a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
index 6b88eb336d..b9633753b4 100644
--- a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
@@ -10,8 +10,15 @@ import java.util.Map;
import junit.framework.Assert;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+
import com.vaadin.data.Container;
+import com.vaadin.data.Container.Indexed.ItemAddEvent;
+import com.vaadin.data.Container.Indexed.ItemRemoveEvent;
+import com.vaadin.data.Container.ItemSetChangeListener;
import com.vaadin.data.Item;
+import com.vaadin.data.util.filter.Compare;
/**
* Test basic functionality of BeanItemContainer.
@@ -714,4 +721,195 @@ public class BeanItemContainerTest extends AbstractBeanContainerTest {
.getValue());
}
+ public void testNestedContainerPropertyWithNullBean() {
+ BeanItemContainer<NestedMethodPropertyTest.Person> container = new BeanItemContainer<NestedMethodPropertyTest.Person>(
+ NestedMethodPropertyTest.Person.class);
+ NestedMethodPropertyTest.Person john = new NestedMethodPropertyTest.Person(
+ "John", null);
+ assertNotNull(container.addBean(john));
+ assertTrue(container
+ .addNestedContainerProperty("address.postalCodeObject"));
+ assertTrue(container.addNestedContainerProperty("address.street"));
+ // the nested properties should return null
+ assertNull(container.getContainerProperty(john, "address.street")
+ .getValue());
+ }
+
+ public void testItemAddedEvent() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ addListener.containerItemSetChange(EasyMock.isA(ItemAddEvent.class));
+ EasyMock.replay(addListener);
+
+ container.addItem(bean);
+
+ EasyMock.verify(addListener);
+ }
+
+ public void testItemAddedEvent_AddedItem() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+
+ container.addItem(bean);
+
+ assertEquals(bean, capturedEvent.getValue().getFirstItemId());
+ }
+
+ public void testItemAddedEvent_addItemAt_IndexOfAddedItem() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ container.addItem(bean);
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+
+ container.addItemAt(1, new Person(""));
+
+ assertEquals(1, capturedEvent.getValue().getFirstIndex());
+ }
+
+ public void testItemAddedEvent_addItemAfter_IndexOfAddedItem() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ container.addItem(bean);
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+
+ container.addItemAfter(bean, new Person(""));
+
+ assertEquals(1, capturedEvent.getValue().getFirstIndex());
+ }
+
+ public void testItemAddedEvent_amountOfAddedItems() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+ List<Person> beans = Arrays.asList(new Person("Jack"), new Person(
+ "John"));
+
+ container.addAll(beans);
+
+ assertEquals(2, capturedEvent.getValue().getAddedItemsCount());
+ }
+
+ public void testItemAddedEvent_someItemsAreFiltered_amountOfAddedItemsIsReducedByAmountOfFilteredItems() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+ List<Person> beans = Arrays.asList(new Person("Jack"), new Person(
+ "John"));
+ container.addFilter(new Compare.Equal("name", "John"));
+
+ container.addAll(beans);
+
+ assertEquals(1, capturedEvent.getValue().getAddedItemsCount());
+ }
+
+ public void testItemAddedEvent_someItemsAreFiltered_addedItemIsTheFirstVisibleItem() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+ List<Person> beans = Arrays.asList(new Person("Jack"), bean);
+ container.addFilter(new Compare.Equal("name", "John"));
+
+ container.addAll(beans);
+
+ assertEquals(bean, capturedEvent.getValue().getFirstItemId());
+ }
+
+ public void testItemRemovedEvent() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ container.addItem(bean);
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ removeListener.containerItemSetChange(EasyMock
+ .isA(ItemRemoveEvent.class));
+ EasyMock.replay(removeListener);
+
+ container.removeItem(bean);
+
+ EasyMock.verify(removeListener);
+ }
+
+ public void testItemRemovedEvent_RemovedItem() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ Person bean = new Person("John");
+ container.addItem(bean);
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener);
+ EasyMock.replay(removeListener);
+
+ container.removeItem(bean);
+
+ assertEquals(bean, capturedEvent.getValue().getFirstItemId());
+ }
+
+ public void testItemRemovedEvent_indexOfRemovedItem() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ container.addItem(new Person("Jack"));
+ Person secondBean = new Person("John");
+ container.addItem(secondBean);
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener);
+ EasyMock.replay(removeListener);
+
+ container.removeItem(secondBean);
+
+ assertEquals(1, capturedEvent.getValue().getFirstIndex());
+ }
+
+ public void testItemRemovedEvent_amountOfRemovedItems() {
+ BeanItemContainer<Person> container = new BeanItemContainer<Person>(
+ Person.class);
+ container.addItem(new Person("Jack"));
+ container.addItem(new Person("John"));
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener);
+ EasyMock.replay(removeListener);
+
+ container.removeAllItems();
+
+ assertEquals(2, capturedEvent.getValue().getRemovedItemsCount());
+ }
+
+ private Capture<ItemAddEvent> captureAddEvent(
+ ItemSetChangeListener addListener) {
+ Capture<ItemAddEvent> capturedEvent = new Capture<ItemAddEvent>();
+ addListener.containerItemSetChange(EasyMock.capture(capturedEvent));
+ return capturedEvent;
+ }
+
+ private Capture<ItemRemoveEvent> captureRemoveEvent(
+ ItemSetChangeListener removeListener) {
+ Capture<ItemRemoveEvent> capturedEvent = new Capture<ItemRemoveEvent>();
+ removeListener.containerItemSetChange(EasyMock.capture(capturedEvent));
+ return capturedEvent;
+ }
+
+ private ItemSetChangeListener createListenerMockFor(
+ BeanItemContainer<Person> container) {
+ ItemSetChangeListener listener = EasyMock
+ .createNiceMock(ItemSetChangeListener.class);
+ container.addItemSetChangeListener(listener);
+ return listener;
+ }
}
diff --git a/server/tests/src/com/vaadin/data/util/NestedMethodPropertyTest.java b/server/tests/src/com/vaadin/data/util/NestedMethodPropertyTest.java
index 640ede8743..1133626df9 100644
--- a/server/tests/src/com/vaadin/data/util/NestedMethodPropertyTest.java
+++ b/server/tests/src/com/vaadin/data/util/NestedMethodPropertyTest.java
@@ -7,9 +7,10 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import junit.framework.Assert;
import junit.framework.TestCase;
+import org.junit.Assert;
+
public class NestedMethodPropertyTest extends TestCase {
public static class Address implements Serializable {
@@ -248,29 +249,16 @@ public class NestedMethodPropertyTest extends TestCase {
vaadin, "manager.address.street");
joonas.setAddress(null);
- try {
- streetProperty.getValue();
- fail();
- } catch (Exception e) {
- // should get exception
- }
+ assertNull(streetProperty.getValue());
vaadin.setManager(null);
- try {
- managerNameProperty.getValue();
- fail();
- } catch (Exception e) {
- // should get exception
- }
- try {
- streetProperty.getValue();
- fail();
- } catch (Exception e) {
- // should get exception
- }
+ assertNull(managerNameProperty.getValue());
+ assertNull(streetProperty.getValue());
vaadin.setManager(joonas);
Assert.assertEquals("Joonas", managerNameProperty.getValue());
+ Assert.assertNull(streetProperty.getValue());
+
}
public void testMultiLevelNestedPropertySetValue() {
@@ -314,6 +302,20 @@ public class NestedMethodPropertyTest extends TestCase {
Assert.assertEquals("Ruukinkatu 2-4", property2.getValue());
}
+ public void testSerializationWithIntermediateNull() throws IOException,
+ ClassNotFoundException {
+ vaadin.setManager(null);
+ NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>(
+ vaadin, "manager.address.street");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ new ObjectOutputStream(baos).writeObject(streetProperty);
+ @SuppressWarnings("unchecked")
+ NestedMethodProperty<String> property2 = (NestedMethodProperty<String>) new ObjectInputStream(
+ new ByteArrayInputStream(baos.toByteArray())).readObject();
+
+ Assert.assertNull(property2.getValue());
+ }
+
public void testIsReadOnly() {
NestedMethodProperty<String> streetProperty = new NestedMethodProperty<String>(
vaadin, "manager.address.street");
diff --git a/server/tests/src/com/vaadin/data/util/PropertyDescriptorTest.java b/server/tests/src/com/vaadin/data/util/PropertyDescriptorTest.java
index 14e70d76d4..12ded84fe2 100644
--- a/server/tests/src/com/vaadin/data/util/PropertyDescriptorTest.java
+++ b/server/tests/src/com/vaadin/data/util/PropertyDescriptorTest.java
@@ -39,7 +39,8 @@ public class PropertyDescriptorTest extends TestCase {
Assert.assertEquals("John", property.getValue());
}
- public void testNestedPropertyDescriptorSerialization() throws Exception {
+ public void testSimpleNestedPropertyDescriptorSerialization()
+ throws Exception {
NestedPropertyDescriptor<Person> pd = new NestedPropertyDescriptor<Person>(
"name", Person.class);
@@ -52,4 +53,19 @@ public class PropertyDescriptorTest extends TestCase {
Property<?> property = pd2.createProperty(new Person("John", null));
Assert.assertEquals("John", property.getValue());
}
+
+ public void testNestedPropertyDescriptorSerialization() throws Exception {
+ NestedPropertyDescriptor<Person> pd = new NestedPropertyDescriptor<Person>(
+ "address.street", Person.class);
+
+ 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));
+ Assert.assertNull(property.getValue());
+ }
+
}
diff --git a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java
index 09e5a26c15..5da0bdc8a2 100644
--- a/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java
+++ b/server/tests/src/com/vaadin/data/util/TestIndexedContainer.java
@@ -4,6 +4,12 @@ import java.util.List;
import junit.framework.Assert;
+import org.easymock.Capture;
+import org.easymock.EasyMock;
+
+import com.vaadin.data.Container.Indexed.ItemAddEvent;
+import com.vaadin.data.Container.Indexed.ItemRemoveEvent;
+import com.vaadin.data.Container.ItemSetChangeListener;
import com.vaadin.data.Item;
public class TestIndexedContainer extends AbstractInMemoryContainerTest {
@@ -271,6 +277,113 @@ public class TestIndexedContainer extends AbstractInMemoryContainerTest {
counter.assertNone();
}
+ public void testItemAddedEvent() {
+ IndexedContainer container = new IndexedContainer();
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ addListener.containerItemSetChange(EasyMock.isA(ItemAddEvent.class));
+ EasyMock.replay(addListener);
+
+ container.addItem();
+
+ EasyMock.verify(addListener);
+ }
+
+ public void testItemAddedEvent_AddedItem() {
+ IndexedContainer container = new IndexedContainer();
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+
+ Object itemId = container.addItem();
+
+ assertEquals(itemId, capturedEvent.getValue().getFirstItemId());
+ }
+
+ public void testItemAddedEvent_IndexOfAddedItem() {
+ IndexedContainer container = new IndexedContainer();
+ ItemSetChangeListener addListener = createListenerMockFor(container);
+ container.addItem();
+ Capture<ItemAddEvent> capturedEvent = captureAddEvent(addListener);
+ EasyMock.replay(addListener);
+
+ container.addItemAt(1);
+
+ assertEquals(1, capturedEvent.getValue().getFirstIndex());
+ }
+
+ public void testItemRemovedEvent() {
+ IndexedContainer container = new IndexedContainer();
+ Object itemId = container.addItem();
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ removeListener.containerItemSetChange(EasyMock
+ .isA(ItemRemoveEvent.class));
+ EasyMock.replay(removeListener);
+
+ container.removeItem(itemId);
+
+ EasyMock.verify(removeListener);
+ }
+
+ public void testItemRemovedEvent_RemovedItem() {
+ IndexedContainer container = new IndexedContainer();
+ Object itemId = container.addItem();
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener);
+ EasyMock.replay(removeListener);
+
+ container.removeItem(itemId);
+
+ assertEquals(itemId, capturedEvent.getValue().getFirstItemId());
+ }
+
+ public void testItemRemovedEvent_indexOfRemovedItem() {
+ IndexedContainer container = new IndexedContainer();
+ container.addItem();
+ Object secondItemId = container.addItem();
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener);
+ EasyMock.replay(removeListener);
+
+ container.removeItem(secondItemId);
+
+ assertEquals(1, capturedEvent.getValue().getFirstIndex());
+ }
+
+ public void testItemRemovedEvent_amountOfRemovedItems() {
+ IndexedContainer container = new IndexedContainer();
+ container.addItem();
+ container.addItem();
+ ItemSetChangeListener removeListener = createListenerMockFor(container);
+ Capture<ItemRemoveEvent> capturedEvent = captureRemoveEvent(removeListener);
+ EasyMock.replay(removeListener);
+
+ container.removeAllItems();
+
+ assertEquals(2, capturedEvent.getValue().getRemovedItemsCount());
+ }
+
+ private Capture<ItemAddEvent> captureAddEvent(
+ ItemSetChangeListener addListener) {
+ Capture<ItemAddEvent> capturedEvent = new Capture<ItemAddEvent>();
+ addListener.containerItemSetChange(EasyMock.capture(capturedEvent));
+ return capturedEvent;
+ }
+
+ private Capture<ItemRemoveEvent> captureRemoveEvent(
+ ItemSetChangeListener removeListener) {
+ Capture<ItemRemoveEvent> capturedEvent = new Capture<ItemRemoveEvent>();
+ removeListener.containerItemSetChange(EasyMock.capture(capturedEvent));
+ return capturedEvent;
+ }
+
+ private ItemSetChangeListener createListenerMockFor(
+ IndexedContainer container) {
+ ItemSetChangeListener listener = EasyMock
+ .createNiceMock(ItemSetChangeListener.class);
+ container.addItemSetChangeListener(listener);
+ return listener;
+ }
+
// Ticket 8028
public void testGetItemIdsRangeIndexOutOfBounds() {
IndexedContainer ic = new IndexedContainer();
diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
index 844ef705b1..4c132eba30 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/SQLContainerTest.java
@@ -1917,7 +1917,6 @@ public class SQLContainerTest {
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
@Override
- @SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
@@ -1990,7 +1989,6 @@ public class SQLContainerTest {
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
@Override
- @SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
@@ -2134,7 +2132,6 @@ public class SQLContainerTest {
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
@Override
- @SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
@@ -2213,7 +2210,6 @@ public class SQLContainerTest {
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
@Override
- @SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
@@ -2292,7 +2288,6 @@ public class SQLContainerTest {
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
@Override
- @SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
diff --git a/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java b/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java
index 8e8c83d234..110225e206 100644
--- a/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java
+++ b/server/tests/src/com/vaadin/data/util/sqlcontainer/TicketTests.java
@@ -88,7 +88,6 @@ public class TicketTests {
EasyMock.expect(delegate.getCountStatement())
.andAnswer(new IAnswer<StatementHelper>() {
@Override
- @SuppressWarnings("deprecation")
public StatementHelper answer() throws Throwable {
StatementHelper sh = new StatementHelper();
StringBuffer query = new StringBuffer(
diff --git a/server/tests/src/com/vaadin/server/VaadinSessionTest.java b/server/tests/src/com/vaadin/server/VaadinSessionTest.java
index 68f198410c..51ae2a2d13 100644
--- a/server/tests/src/com/vaadin/server/VaadinSessionTest.java
+++ b/server/tests/src/com/vaadin/server/VaadinSessionTest.java
@@ -100,7 +100,7 @@ public class VaadinSessionTest {
}
};
- ui.doInit(vaadinRequest, session.getNextUIid());
+ ui.doInit(vaadinRequest, session.getNextUIid(), null);
ui.setSession(session);
session.addUI(ui);
diff --git a/server/tests/src/com/vaadin/tests/data/bean/BeanToValidate.java b/server/tests/src/com/vaadin/tests/data/bean/BeanToValidate.java
index 416563baba..034609764f 100644
--- a/server/tests/src/com/vaadin/tests/data/bean/BeanToValidate.java
+++ b/server/tests/src/com/vaadin/tests/data/bean/BeanToValidate.java
@@ -4,6 +4,7 @@ import javax.validation.constraints.Digits;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
public class BeanToValidate {
@@ -21,6 +22,10 @@ public class BeanToValidate {
@Digits(integer = 3, fraction = 2)
private String decimals;
+ @Pattern(regexp = "V*", message = "Must start with letter V")
+ @Size(min = 3, max = 6, message = "Must contain 3 - 6 letters")
+ private String nickname;
+
public String getFirstname() {
return firstname;
}
@@ -53,4 +58,12 @@ public class BeanToValidate {
this.decimals = decimals;
}
+ public String getNickname() {
+ return nickname;
+ }
+
+ public void setNickname(String nickname) {
+ this.nickname = nickname;
+ }
+
}
diff --git a/server/tests/src/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java b/server/tests/src/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java
index 93b2273263..575730d946 100644
--- a/server/tests/src/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java
+++ b/server/tests/src/com/vaadin/tests/data/bean/PersonWithBeanValidationAnnotations.java
@@ -8,12 +8,15 @@ import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
+import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
public class PersonWithBeanValidationAnnotations {
@NotNull
@Size(min = 5, max = 20)
+ @Pattern(regexp = "A.*")
private String firstName;
+
@NotNull
private String lastName;
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigDecimalConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigDecimalConverter.java
new file mode 100644
index 0000000000..5db33691b6
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigDecimalConverter.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2000-2013 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.math.BigDecimal;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.util.converter.StringToBigDecimalConverter;
+
+public class TestStringToBigDecimalConverter extends TestCase {
+
+ StringToBigDecimalConverter converter = new StringToBigDecimalConverter();
+
+ public void testNullConversion() {
+ assertEquals(null,
+ converter.convertToModel(null, BigDecimal.class, null));
+ }
+
+ public void testEmptyStringConversion() {
+ assertEquals(null, converter.convertToModel("", BigDecimal.class, null));
+ }
+
+ public void testValueParsing() {
+ BigDecimal converted = converter.convertToModel("10", BigDecimal.class,
+ null);
+ BigDecimal expected = new BigDecimal(10);
+ assertEquals(expected, converted);
+ }
+
+ public void testValueFormatting() {
+ BigDecimal bd = new BigDecimal(12.5);
+ String expected = "12,5";
+
+ String converted = converter.convertToPresentation(bd, String.class,
+ Locale.GERMAN);
+ assertEquals(expected, converted);
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java
deleted file mode 100644
index 66fc4f6532..0000000000
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.vaadin.tests.data.converter;
-
-import junit.framework.TestCase;
-
-import com.vaadin.data.util.converter.StringToNumberConverter;
-
-public class TestStringToNumberConverter extends TestCase {
-
- StringToNumberConverter converter = new StringToNumberConverter();
-
- public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Number.class, null));
- }
-
- public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Number.class, null));
- }
-
- public void testValueConversion() {
- assertEquals(Long.valueOf(10),
- converter.convertToModel("10", Number.class, null));
- assertEquals(10.5, converter.convertToModel("10.5", Number.class, null));
- }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java b/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java
index e5420b8921..705bae3d98 100644
--- a/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java
+++ b/server/tests/src/com/vaadin/tests/server/TestClassesSerializable.java
@@ -42,6 +42,7 @@ public class TestClassesSerializable extends TestCase {
"com\\.vaadin\\.event\\.FieldEvents", //
"com\\.vaadin\\.event\\.LayoutEvents", //
"com\\.vaadin\\.event\\.MouseEvents", //
+ "com\\.vaadin\\.event\\.UIEvents", //
"com\\.vaadin\\.server\\.VaadinPortlet", //
"com\\.vaadin\\.server\\.MockServletConfig", //
"com\\.vaadin\\.server\\.MockServletContext", //
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java
index a5e825bddb..85116dd152 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java
@@ -205,14 +205,15 @@ public class AbsFieldValueConversions extends TestCase {
}
+ // Now specific to Integer because StringToNumberConverter has been removed
public static class NumberBean {
- private Number number;
+ private Integer number;
- public Number getNumber() {
+ public Integer getNumber() {
return number;
}
- public void setNumber(Number number) {
+ public void setNumber(Integer number) {
this.number = number;
}
@@ -239,7 +240,7 @@ public class AbsFieldValueConversions extends TestCase {
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",
+ "StringToInteger 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/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java
new file mode 100644
index 0000000000..5575b8fd3d
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractselect/TestVarargsItemAddition.java
@@ -0,0 +1,26 @@
+package com.vaadin.tests.server.component.abstractselect;
+
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.junit.Assert;
+
+import com.vaadin.ui.OptionGroup;
+
+public class TestVarargsItemAddition extends TestCase {
+
+ public void itemAddition() throws Exception {
+
+ OptionGroup optionGroup = new OptionGroup();
+
+ optionGroup.addItems("foo", "bar", "car");
+
+ Collection<?> itemIds = optionGroup.getItemIds();
+ Assert.assertEquals(3, itemIds.size());
+ Assert.assertTrue(itemIds.contains("foo"));
+ Assert.assertTrue(itemIds.contains("bar"));
+ Assert.assertTrue(itemIds.contains("car"));
+
+ }
+}
diff --git a/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java b/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java
index e1d08a989b..1d1a3c297e 100644
--- a/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java
+++ b/server/tests/src/com/vaadin/tests/server/validation/TestBeanValidation.java
@@ -1,7 +1,6 @@
package com.vaadin.tests.server.validation;
-import junit.framework.Assert;
-
+import org.junit.Assert;
import org.junit.Test;
import com.vaadin.data.Validator.InvalidValueException;
@@ -59,6 +58,32 @@ public class TestBeanValidation {
}
@Test
+ public void testBeanValidationException_OneValidationError() {
+ InvalidValueException[] causes = null;
+ BeanValidator validator = new BeanValidator(BeanToValidate.class,
+ "lastname");
+ try {
+ validator.validate(null);
+ } catch (InvalidValueException e) {
+ causes = e.getCauses();
+ }
+
+ Assert.assertEquals(1, causes.length);
+ }
+
+ @Test
+ public void testBeanValidationsException_TwoValidationErrors() {
+ InvalidValueException[] causes = null;
+ BeanValidator validator = new BeanValidator(BeanToValidate.class,
+ "nickname");
+ try {
+ validator.validate("A");
+ } catch (InvalidValueException e) {
+ causes = e.getCauses();
+ }
+
+ Assert.assertEquals(2, causes.length);
+ }
public void testBeanValidationNotAddedTwice() {
// See ticket #11045
BeanFieldGroup<BeanToValidate> fieldGroup = new BeanFieldGroup<BeanToValidate>(