summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-08-22 15:46:51 +0000
committerJohannes Dahlström <johannes.dahlstrom@vaadin.com>2012-08-22 15:46:51 +0000
commit3d0fe88e20584ebb378786784f1a446e6f081021 (patch)
tree9d1c3e48851db09d4889d7aafe1278d213704b92 /tests
parent8c226ab0f258f7b294701612b51a1c8f96471f83 (diff)
downloadvaadin-framework-3d0fe88e20584ebb378786784f1a446e6f081021.tar.gz
vaadin-framework-3d0fe88e20584ebb378786784f1a446e6f081021.zip
More tests for #9145
svn changeset:24221/svn branch:6.8
Diffstat (limited to 'tests')
-rw-r--r--tests/server-side/com/vaadin/data/util/sqlcontainer/generator/SQLGeneratorsTest.java83
1 files changed, 83 insertions, 0 deletions
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;
@@ -148,6 +151,86 @@ public class SQLGeneratorsTest {
}
@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 {
/*