summaryrefslogtreecommitdiffstats
path: root/server/tests/src
diff options
context:
space:
mode:
authorJarno Rantala <jarno.rantala@vaadin.com>2013-12-11 15:31:30 +0200
committerHenri Sara <hesara@vaadin.com>2013-12-16 13:07:52 +0000
commit681864fee3c95dd281493f881db276b7b7abe87d (patch)
tree1e3d793ec7cbee3931543f32430ed9c971e56248 /server/tests/src
parent1dd2ed36b73404f17863765ec34a56f8fdb0b40f (diff)
downloadvaadin-framework-681864fee3c95dd281493f881db276b7b7abe87d.tar.gz
vaadin-framework-681864fee3c95dd281493f881db276b7b7abe87d.zip
Backported null value support for NestedMethodProperty to 7.1 (#12884)
Support for null values in NestedMethodProperty was already implemented in master branch (#11435) This changeset includes changesets made for that. Change-Id: I10696467f792e234326075bbcdd5aad487905a7e Merge: no
Diffstat (limited to 'server/tests/src')
-rw-r--r--server/tests/src/com/vaadin/data/util/BeanContainerTest.java13
-rw-r--r--server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java12
-rw-r--r--server/tests/src/com/vaadin/data/util/NestedMethodPropertyTest.java40
-rw-r--r--server/tests/src/com/vaadin/data/util/PropertyDescriptorTest.java18
4 files changed, 63 insertions, 20 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..684ab5d6bc 100644
--- a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java
@@ -457,4 +457,17 @@ 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"));
+ 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..767a9e2e4d 100644
--- a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
+++ b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java
@@ -714,4 +714,16 @@ 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"));
+ assertNull(container.getContainerProperty(john, "address.street")
+ .getValue());
+ }
}
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());
+ }
+
}