From 3d0fe88e20584ebb378786784f1a446e6f081021 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Wed, 22 Aug 2012 15:46:51 +0000 Subject: [PATCH] More tests for #9145 svn changeset:24221/svn branch:6.8 --- .../generator/SQLGeneratorsTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/server-side/com/vaadin/data/util/sqlcontainer/generator/SQLGeneratorsTest.java b/tests/server-side/com/vaadin/data/util/sqlcontainer/generator/SQLGeneratorsTest.java index e62a06e6e1..b8df4b1799 100644 --- a/tests/server-side/com/vaadin/data/util/sqlcontainer/generator/SQLGeneratorsTest.java +++ b/tests/server-side/com/vaadin/data/util/sqlcontainer/generator/SQLGeneratorsTest.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.easymock.EasyMock; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -14,7 +15,9 @@ import com.vaadin.data.Container.Filter; import com.vaadin.data.util.filter.Like; import com.vaadin.data.util.filter.Or; import com.vaadin.data.util.sqlcontainer.AllTests; +import com.vaadin.data.util.sqlcontainer.ColumnProperty; import com.vaadin.data.util.sqlcontainer.DataGenerator; +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.connection.JDBCConnectionPool; @@ -147,6 +150,86 @@ public class SQLGeneratorsTest { .equals(sh.getQueryString())); } + @Test + public void generateUpdateQuery_severalPrimKeys_shouldSucceed() + throws SQLException { + /* + * No need to run this for Oracle/MSSQL generators since the + * DefaultSQLGenerator method would be called anyway. + */ + if (AllTests.sqlGen instanceof MSSQLGenerator + || AllTests.sqlGen instanceof OracleGenerator) { + return; + } + + DefaultSQLGenerator sqlGen = new DefaultSQLGenerator(); + + // Create situation wihere PrimKey is a composite of two columns... + ColumnProperty cp1 = new ColumnProperty("FIRSTPK", false, true, false, + true, new Integer(1), Integer.class); + ColumnProperty cp2 = new ColumnProperty("SECONDPK", false, true, false, + true, "primKeyValue", String.class); + ColumnProperty cp3 = new ColumnProperty("NONPK", false, true, false, + false, new Integer(1), Integer.class); + + SQLContainer container = EasyMock.createNiceMock(SQLContainer.class); + + RowItem ri = new RowItem(container, new RowId(new Object[] { 0L }), + Arrays.asList(cp1, cp2, cp3)); + + StatementHelper generateUpdateQuery = sqlGen.generateUpdateQuery( + "testTable", ri); + + String queryString = generateUpdateQuery.getQueryString(); + + // Assert that the WHERE-clause has both prim keys... + Assert.assertEquals( + "UPDATE testTable SET \"NONPK\" = ?, \"SECONDPK\" = ?, \"FIRSTPK\" = ? WHERE \"SECONDPK\" = ? AND \"FIRSTPK\" = ?", + queryString); + } + + @Test + public void generateUpdateQuery_severalPrimKeysAndVersion_shouldSucceed() + throws SQLException { + /* + * No need to run this for Oracle/MSSQL generators since the + * DefaultSQLGenerator method would be called anyway. + */ + if (AllTests.sqlGen instanceof MSSQLGenerator + || AllTests.sqlGen instanceof OracleGenerator) { + return; + } + + DefaultSQLGenerator sqlGen = new DefaultSQLGenerator(); + + // Create situation wihere PrimKey is a composite of two columns... + ColumnProperty cp1 = new ColumnProperty("FIRSTPK", false, true, false, + true, new Integer(1), Integer.class); + ColumnProperty cp2 = new ColumnProperty("SECONDPK", false, true, false, + true, "primKeyValue", String.class); + ColumnProperty cp3 = new ColumnProperty("NONPK", false, true, false, + false, new Integer(1), Integer.class); + ColumnProperty cp4 = new ColumnProperty("VERSION", false, true, false, + false, new Integer(1), Integer.class); + cp4.setVersionColumn(true); + + SQLContainer container = EasyMock.createNiceMock(SQLContainer.class); + + RowItem ri = new RowItem(container, new RowId(new Object[] { 0L }), + Arrays.asList(cp1, cp2, cp3, cp4)); + + StatementHelper generateUpdateQuery = sqlGen.generateUpdateQuery( + "testTable", ri); + + String queryString = generateUpdateQuery.getQueryString(); + + // Assert that the WHERE-clause has both prim keys and version... + // Version should not be in SET... + Assert.assertEquals( + "UPDATE testTable SET \"NONPK\" = ?, \"SECONDPK\" = ?, \"FIRSTPK\" = ? WHERE \"VERSION\" = ? AND \"SECONDPK\" = ? AND \"FIRSTPK\" = ?", + queryString); + } + @Test public void generateInsertQuery_basicQuery_shouldSucceed() throws SQLException { -- 2.39.5