From 8c104cd1c5db142097a99dbef0e7b43a8663e5c2 Mon Sep 17 00:00:00 2001 From: Jonatan Kronqvist Date: Thu, 8 Sep 2011 10:14:31 +0000 Subject: Fix for #7434 svn changeset:20923/svn branch:6.7 --- .../container/sqlcontainer/ColumnPropertyTest.java | 28 ++++++++++++++++++---- .../server/container/sqlcontainer/TicketTests.java | 26 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) (limited to 'tests/src/com') diff --git a/tests/src/com/vaadin/tests/server/container/sqlcontainer/ColumnPropertyTest.java b/tests/src/com/vaadin/tests/server/container/sqlcontainer/ColumnPropertyTest.java index efe539f2c7..464c65d9ce 100644 --- a/tests/src/com/vaadin/tests/server/container/sqlcontainer/ColumnPropertyTest.java +++ b/tests/src/com/vaadin/tests/server/container/sqlcontainer/ColumnPropertyTest.java @@ -11,7 +11,6 @@ import com.vaadin.data.util.sqlcontainer.ColumnProperty; import com.vaadin.data.util.sqlcontainer.RowId; import com.vaadin.data.util.sqlcontainer.RowItem; import com.vaadin.data.util.sqlcontainer.SQLContainer; -import com.vaadin.data.util.sqlcontainer.ColumnProperty.NotNullableException; public class ColumnPropertyTest { @@ -56,7 +55,7 @@ public class ColumnPropertyTest { Assert.assertEquals("Kalle", cp.getValue()); EasyMock.verify(container); } - */ + */ @Test(expected = ReadOnlyException.class) public void setValue_readOnlyNullable_shouldFail() { @@ -101,7 +100,7 @@ public class ColumnPropertyTest { Assert.assertNotNull(cp.getValue()); EasyMock.verify(container); } - */ + */ @Test public void getType_normal_returnsStringClass() { @@ -165,7 +164,7 @@ public class ColumnPropertyTest { Assert.assertTrue(cp.isModified()); EasyMock.verify(container); } - */ + */ @Test public void isModified_valueNotModified_returnsFalse() { @@ -174,4 +173,25 @@ public class ColumnPropertyTest { Assert.assertFalse(cp.isModified()); } + @Test + public void setValue_nullOnNullable_shouldWork() { + ColumnProperty cp = new ColumnProperty("NAME", false, true, true, + "asdf", String.class); + SQLContainer container = EasyMock.createMock(SQLContainer.class); + new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); + cp.setValue(null); + Assert.assertNull(cp.getValue()); + } + + @Test + public void setValue_resetTonullOnNullable_shouldWork() { + ColumnProperty cp = new ColumnProperty("NAME", false, true, true, null, + String.class); + SQLContainer container = EasyMock.createMock(SQLContainer.class); + new RowItem(container, new RowId(new Object[] { 1 }), Arrays.asList(cp)); + cp.setValue("asdf"); + Assert.assertEquals("asdf", cp.getValue()); + cp.setValue(null); + Assert.assertNull(cp.getValue()); + } } diff --git a/tests/src/com/vaadin/tests/server/container/sqlcontainer/TicketTests.java b/tests/src/com/vaadin/tests/server/container/sqlcontainer/TicketTests.java index 8123cdb516..8c86bc8df1 100644 --- a/tests/src/com/vaadin/tests/server/container/sqlcontainer/TicketTests.java +++ b/tests/src/com/vaadin/tests/server/container/sqlcontainer/TicketTests.java @@ -13,6 +13,7 @@ import org.junit.Before; import org.junit.Test; import com.vaadin.data.Container.Filter; +import com.vaadin.data.Item; import com.vaadin.data.util.filter.Compare.Equal; import com.vaadin.data.util.sqlcontainer.SQLContainer; import com.vaadin.data.util.sqlcontainer.connection.SimpleJDBCConnectionPool; @@ -154,4 +155,29 @@ public class TicketTests { } } + @Test + public void ticket7434_getItem_Modified_Changed_Unchanged() + throws SQLException { + SQLContainer container = new SQLContainer(new TableQuery("people", + connectionPool, AllTests.sqlGen)); + + Object id = container.firstItemId(); + Item item = container.getItem(id); + String name = (String) item.getItemProperty("NAME").getValue(); + + // set a different name + item.getItemProperty("NAME").setValue("otherName"); + Assert.assertEquals("otherName", item.getItemProperty("NAME") + .getValue()); + + // access the item and reset the name to its old value + Item item2 = container.getItem(id); + item2.getItemProperty("NAME").setValue(name); + Assert.assertEquals(name, item2.getItemProperty("NAME").getValue()); + + Item item3 = container.getItem(id); + String name3 = (String) item3.getItemProperty("NAME").getValue(); + + Assert.assertEquals(name, name3); + } } -- cgit v1.2.3