#1340 - Split SQL Server Platform into SqlServer16 and SqlServer17 (where 2017 which uses UTF8 types nvarchar etc and prefers Sequences).

test changes
This commit is contained in:
Rob Bygrave
2018-03-08 17:40:11 +13:00
parent 8e0d2f8749
commit f840cfc2ae
17 changed files with 260 additions and 38 deletions
+1 -1
View File
@@ -93,7 +93,7 @@ public abstract class BaseTestCase {
* so tests that do this need to be skipped for SQL Server.
*/
public boolean isSqlServer() {
return Platform.SQLSERVER == platform();
return Platform.SQLSERVER17 == platform();
}
public boolean isH2() {
@@ -42,6 +42,10 @@ public class ConditionalTestRunner extends BlockJUnit4ClassRunner {
if (p.equals(current)) {
return true;
}
if (p == Platform.SQLSERVER && current == Platform.SQLSERVER17) {
// treat SQLSERVER as SQLSERVER17 in testing
return true;
}
}
return false;
}
@@ -142,7 +142,13 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
if (isSqlServer()) {
assertThat(sql.get(0)).contains("select top 10 t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
} else {
assertThat(sql.get(0)).contains("select t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
}
}
@Test
@@ -171,7 +177,11 @@ public class DtoQueryFromOrmTest extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
if (isSqlServer()) {
assertThat(sql.get(0)).contains("select top 10 t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
} else {
assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) fullName from contact t0 where t0.email is not null and t0.last_name is not null order by t0.last_name");
}
}
@Test
@@ -1,7 +1,7 @@
package io.ebean.config;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
@@ -18,7 +18,7 @@ public class MatchingNamingConventionTest {
@Test
public void getColumnFromProperty_when_allQuoted() {
SqlServerPlatform platform = new SqlServerPlatform();
SqlServer17Platform platform = new SqlServer17Platform();
ServerConfig config = new ServerConfig();
config.setAllQuotedIdentifiers(true);
@@ -0,0 +1,134 @@
package io.ebean.config;
import io.ebean.EbeanServer;
import io.ebean.EbeanServerFactory;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import org.junit.Ignore;
import org.junit.Test;
import org.tests.model.basic.EBasicVer;
import javax.persistence.PersistenceException;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
public class ServerConfigSqlServerTest {
@Ignore
@ForPlatform({Platform.SQLSERVER, Platform.SQLSERVER17, Platform.SQLSERVER16})
@Test(expected = PersistenceException.class)
public void need_explicitPlatform() {
Properties props = props("some_sqlserver");
// no explicit databasePlatformName set ..
//props.setProperty("ebean.some_sqlserver.databasePlatformName", "sqlserver17");
ServerConfig config = new ServerConfig();
config.setName("some_sqlserver");
config.loadFromProperties(props);
// not explicitly set ... so we fail to start
// config.setDatabasePlatform(new SqlServer17Platform());
// config.setDatabasePlatformName("sqlserver17");
config.setDefaultServer(false);
config.setRegister(false);
config.getClasses().add(EBasicVer.class);
EbeanServer sqlServer = EbeanServerFactory.create(config);
assertThat(sqlServer).isNotNull();
// javax.persistence.PersistenceException: java.lang.IllegalArgumentException: For SqlServer please choose the more specific sqlserver16 or sqlserver17 platform via ServerConfig.setDatabasePlatformName. Refer to issue #1340 for details
//
// at io.ebeaninternal.server.core.DatabasePlatformFactory.create(DatabasePlatformFactory.java:62)
// at io.ebeaninternal.server.core.DefaultContainer.setDatabasePlatform(DefaultContainer.java:266)
// at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:126)
// at io.ebeaninternal.server.core.DefaultContainer.createServer(DefaultContainer.java:45)
// at io.ebean.EbeanServerFactory.createInternal(EbeanServerFactory.java:109)
// at io.ebean.EbeanServerFactory.create(EbeanServerFactory.java:70)
// at io.ebean.config.ServerConfigSqlServerTest.need_explicitPlatform(ServerConfigSqlServerTest.java:35)
}
@Ignore
@ForPlatform({Platform.SQLSERVER, Platform.SQLSERVER17, Platform.SQLSERVER16})
@Test
public void explicit_17() {
String name = "testsqlserver17";
ServerConfig config = new ServerConfig();
config.setName(name);
Properties props = props(name);
// set via properties
//props.setProperty("ebean.testsqlserver17.databasePlatformName", "sqlserver17");
// or set programmatically ...
config.setDatabasePlatformName("sqlserver17");
config.setDefaultServer(false);
config.setRegister(false);
config.setDdlGenerate(true);
config.setDdlRun(true);
config.loadFromProperties(props);
config.getClasses().add(EBasicVer.class);
EbeanServer sqlServer = EbeanServerFactory.create(config);
assertThat(sqlServer).isNotNull();
}
@Ignore
@ForPlatform({Platform.SQLSERVER, Platform.SQLSERVER17, Platform.SQLSERVER16})
@Test
public void explicit_16() {
String name = "testsqlserver16";
Properties props = props(name);
//props.setProperty("ebean.testsqlserver16.databasePlatformName", "sqlserver16");
ServerConfig config = new ServerConfig();
config.setDefaultServer(false);
config.setRegister(false);
config.setDdlGenerate(true);
config.setDdlRun(true);
config.setName(name); // match dataSource
config.setDatabasePlatformName("sqlserver16");
config.loadFromProperties(props);
config.getClasses().add(EBasicVer.class);
EbeanServer sqlServer = EbeanServerFactory.create(config);
assertThat(sqlServer).isNotNull();
}
private Properties props(String dbName) {
Properties props = new Properties();
// automatically start docker sqlserver 2017 container ...
props.setProperty("ebean.test.platform", "sqlserver");
props.setProperty("ebean.test.dbName", "test_ebean");
props.setProperty("ebean.test.ddlMode", "dropCreate");
//props.setProperty("ebean.test.containerMode","dropCreate");
props.setProperty(key(dbName, "username"), "test_ebean");
props.setProperty(key(dbName, "password"), "SqlS3rv#r");
props.setProperty(key(dbName, "url"), "jdbc:sqlserver://localhost:1433;databaseName=test_ebean");
props.setProperty(key(dbName, "driver"), "com.microsoft.sqlserver.jdbc.SQLServerDriver");
return props;
}
private String key(String dbName, String key) {
return "datasource." + dbName + "." + key;
}
}
@@ -1,12 +1,12 @@
package io.ebean.config.dbplatform;
import io.ebean.config.DbTypeConfig;
import io.ebean.annotation.Platform;
import io.ebean.config.DbTypeConfig;
import io.ebean.config.MatchingNamingConvention;
import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -20,7 +20,7 @@ public class DatabasePlatformTest {
config.setAllQuotedIdentifiers(true);
config.setNamingConvention(new MatchingNamingConvention());
DatabasePlatform dbPlatform = new SqlServerPlatform();
DatabasePlatform dbPlatform = new SqlServer17Platform();
dbPlatform.configure(config.getDbTypeConfig(), config.isAllQuotedIdentifiers());
assertEquals(dbPlatform.convertQuotedIdentifiers("order"),"[order]");
@@ -33,7 +33,7 @@ public class DatabasePlatformTest {
ServerConfig config = new ServerConfig();
DatabasePlatform dbPlatform = new SqlServerPlatform();
DatabasePlatform dbPlatform = new SqlServer17Platform();
dbPlatform.configure(config.getDbTypeConfig(), config.isAllQuotedIdentifiers());
assertEquals(dbPlatform.convertQuotedIdentifiers("order"),"order");
@@ -2,7 +2,7 @@ package io.ebean.config.dbplatform.sqlserver;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
/**
* @author Vilmos Nagy <vilmos.nagy@outlook.com>
@@ -11,7 +11,7 @@ public class SqlServer2016PlatformTest {
@Test
public void testHistorySupport() {
SqlServerPlatform platform = new SqlServerPlatform();
SqlServer17Platform platform = new SqlServer17Platform();
assertTrue(platform.getHistorySupport() instanceof SqlServerHistorySupport);
}
}
@@ -0,0 +1,28 @@
package io.ebean.dbmigration;
import io.ebean.annotation.Platform;
import org.junit.Test;
public class DbMigrationSqlServerTest {
@Test(expected = IllegalArgumentException.class)
public void need_explicitPlatform() {
DbMigration dbMigration = DbMigration.create();
dbMigration.setPlatform(Platform.SQLSERVER);
}
@Test
public void explicit_16_isGood() {
DbMigration dbMigration = DbMigration.create();
dbMigration.setPlatform(Platform.SQLSERVER16);
}
@Test
public void explicit_17_isGood() {
DbMigration dbMigration = DbMigration.create();
dbMigration.setPlatform(Platform.SQLSERVER17);
}
}
@@ -6,14 +6,17 @@ import io.ebean.EbeanServerFactory;
import io.ebean.bean.BeanCollection;
import io.ebean.common.BeanList;
import io.ebean.config.ServerConfig;
import org.junit.Test;
import org.tests.example.ModUuidGenerator;
import org.tests.model.basic.EBasic;
import org.tests.model.basic.ECustomId;
import org.tests.example.ModUuidGenerator;
import org.junit.Test;
import java.util.List;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class BeanFindControllerTest extends BaseTestCase {
@@ -39,6 +42,8 @@ public class BeanFindControllerTest extends BaseTestCase {
EbeanServer ebeanServer = EbeanServerFactory.create(config);
System.clearProperty("ebean.ignoreExtraDdl");
assertFalse(findController.calledInterceptFind);
ebeanServer.find(EBasic.class, 42);
assertTrue(findController.calledInterceptFind);
@@ -6,20 +6,19 @@ import io.ebean.annotation.Platform;
import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.IdType;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import org.junit.*;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
/**
* This is the Migrationscript generator. It generates 3 migrationscript for the models
@@ -57,7 +56,7 @@ public class DbMigrationGenerateTest {
migration.addPlatform(Platform.SQLITE, "sqlite");
// we need sequence here, so that migration will work properly
DatabasePlatform sqlServer = new SqlServerPlatform();
DatabasePlatform sqlServer = new SqlServer17Platform();
sqlServer.getDbIdentity().setIdType(IdType.SEQUENCE);
migration.addDatabasePlatform(sqlServer, "sqlserver");
@@ -6,7 +6,7 @@ import io.ebean.config.ServerConfig;
import io.ebean.config.dbplatform.DatabasePlatform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.dbmigration.migration.ChangeSet;
import io.ebeaninternal.dbmigration.model.CurrentModel;
@@ -34,7 +34,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
}
private DdlHandler sqlserverHandler() {
return handler(new SqlServerPlatform());
return handler(new SqlServer17Platform());
}
@Test
@@ -46,7 +46,7 @@ public class BaseDdlHandlerTest extends BaseTestCase {
write = new DdlWrite();
sqlserverHandler().generate(write, Helper.getAddColumn());
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add added_to_foo varchar(20);\n\n");
assertThat(write.apply().getBuffer()).isEqualTo("alter table foo add added_to_foo nvarchar(20);\n\n");
}
@Test
@@ -7,7 +7,7 @@ import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import io.ebeaninternal.dbmigration.migration.AlterColumn;
import io.ebeaninternal.dbmigration.migration.IdentityType;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
@@ -23,7 +23,7 @@ public class PlatformDdl_AlterColumnTest {
private PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
private PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
private PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServerPlatform());
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServer17Platform());
{
ServerConfig serverConfig = Ebean.getDefaultServer().getPluginApi().getServerConfig();
@@ -76,7 +76,7 @@ public class PlatformDdl_AlterColumnTest {
assertEquals("alter table mytab modify acol varchar(5) not null", sql);
sql = sqlServerDdl.alterColumnBaseAttributes(alterColumn);
assertEquals("alter table mytab alter column acol varchar(5) not null", sql);
assertEquals("alter table mytab alter column acol nvarchar(5) not null", sql);
alterColumn.setNotnull(Boolean.FALSE);
sql = mysqlDdl.alterColumnBaseAttributes(alterColumn);
@@ -1,10 +1,10 @@
package io.ebeaninternal.dbmigration.ddlgeneration.platform;
import io.ebean.config.dbplatform.h2.H2Platform;
import io.ebean.config.dbplatform.sqlserver.SqlServerPlatform;
import io.ebean.config.dbplatform.mysql.MySqlPlatform;
import io.ebean.config.dbplatform.oracle.OraclePlatform;
import io.ebean.config.dbplatform.postgres.PostgresPlatform;
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
import io.ebeaninternal.server.core.PlatformDdlBuilder;
import org.junit.Test;
@@ -17,7 +17,7 @@ public class PlatformDdl_dropUniqueConstraintTest {
private PlatformDdl pgDdl = PlatformDdlBuilder.create(new PostgresPlatform());
private PlatformDdl mysqlDdl = PlatformDdlBuilder.create(new MySqlPlatform());
private PlatformDdl oraDdl = PlatformDdlBuilder.create(new OraclePlatform());
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServerPlatform());
private PlatformDdl sqlServerDdl = PlatformDdlBuilder.create(new SqlServer17Platform());
@Test
public void test() throws Exception {
@@ -3,12 +3,14 @@ package io.ebeaninternal.extraddl.model;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class ExtraDdlXmlReaderTest {
@Test
public void read() throws Exception {
public void read(){
ExtraDdl read = ExtraDdlXmlReader.read("/extra-ddl.xml");
assertNotNull(read);
@@ -44,4 +46,37 @@ public class ExtraDdlXmlReaderTest {
assertThat(ddl).doesNotContain(" -- oracle only script");
}
@Test
public void matchPlatform() {
assertTrue(ExtraDdlXmlReader.matchPlatform("h2", "h2"));
assertTrue(ExtraDdlXmlReader.matchPlatform("h2", "mysql,h2"));
assertTrue(ExtraDdlXmlReader.matchPlatform("h2", "mysql,h2,"));
assertTrue(ExtraDdlXmlReader.matchPlatform("h2", "mysql , h2 ,"));
assertTrue(ExtraDdlXmlReader.matchPlatform("h2", "mysql , h2, oracle"));
assertTrue(ExtraDdlXmlReader.matchPlatform("h2", "mysql , h2, oracle"));
assertTrue(ExtraDdlXmlReader.matchPlatform("sqlserver17", "sqlserver17"));
assertTrue(ExtraDdlXmlReader.matchPlatform("sqlserver16", "sqlserver16"));
}
@Test
public void matchPlatform_sqlserver17_matchAlsoToGenericName() {
assertTrue(ExtraDdlXmlReader.matchPlatform("sqlserver17", "sqlserver"));
}
@Test
public void matchPlatform_sqlserver16_matchAlsoToGenericName() {
assertTrue(ExtraDdlXmlReader.matchPlatform("sqlserver16", "sqlserver"));
}
@Test
public void matchPlatform_sqlserver_nonMatch() {
assertFalse(ExtraDdlXmlReader.matchPlatform("sqlserver16", "sqlserver17"));
assertFalse(ExtraDdlXmlReader.matchPlatform("sqlserver17", "sqlserver16"));
}
}
@@ -351,7 +351,7 @@ public class TestAggregationCount extends BaseTestCase {
assertThat(maxLastName).isNotNull();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select max(t0.last_name) from contact t0");
assertThat(trimSql(sql.get(0))).contains("select max(t0.last_name) from contact t0");
}
@Test
@@ -370,7 +370,7 @@ public class TestAggregationCount extends BaseTestCase {
assertThat(count).isNotNull();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select count(distinct t0.last_name) from contact t0 where not exists (select 1 from contact_note x where x.contact_id = t0.id)");
assertThat(trimSql(sql.get(0))).contains("select count(distinct t0.last_name) from contact t0 where not exists (select 1 from contact_note x where x.contact_id = t0.id)");
}
@Test
@@ -391,7 +391,7 @@ public class TestAggregationCount extends BaseTestCase {
assertThat(names).isNotEmpty();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select concat(t0.last_name,', ',t0.first_name) from contact t0 where t0.phone is null order by t0.last_name");
assertThat(trimSql(sql.get(0))).contains("select concat(t0.last_name,', ',t0.first_name) from contact t0 where t0.phone is null order by t0.last_name");
}
@Test
@@ -412,7 +412,7 @@ public class TestAggregationCount extends BaseTestCase {
assertThat(names).isNotEmpty();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select concat(t0.updtime,', ',t0.first_name) from contact t0");
assertThat(trimSql(sql.get(0))).contains("select concat(t0.updtime,', ',t0.first_name) from contact t0");
}
@Test
@@ -432,7 +432,7 @@ public class TestAggregationCount extends BaseTestCase {
assertThat(instant).isNotNull();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select max(t0.updtime) from contact t0 where t0.phone is null");
assertThat(trimSql(sql.get(0))).contains("select max(t0.updtime) from contact t0 where t0.phone is null");
}
@@ -459,7 +459,7 @@ public class TestAggregationCount extends BaseTestCase {
}
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) lastName from contact t0 where t0.phone is null order by t0.last_name; --bind()");
assertThat(trimSql(sql.get(0))).contains("select t0.id, t0.email, concat(t0.last_name,', ',t0.first_name) lastName from contact t0 where t0.phone is null order by t0.last_name; --bind()");
}
}
@@ -5,6 +5,8 @@ import io.ebean.EbeanServer;
import io.ebean.EbeanServerFactory;
import io.ebean.Query;
import io.ebean.Transaction;
import io.ebean.annotation.ForPlatform;
import io.ebean.annotation.Platform;
import io.ebean.config.ServerConfig;
import io.ebean.config.properties.PropertiesLoader;
import org.avaje.datasource.DataSourceConfig;
@@ -24,6 +26,7 @@ import static org.junit.Assert.assertTrue;
public class TestExplicitTransactionMode extends BaseTestCase {
@ForPlatform(Platform.H2)
@Test
public void test() throws SQLException {
@@ -56,6 +59,8 @@ public class TestExplicitTransactionMode extends BaseTestCase {
EbeanServer ebeanServer = EbeanServerFactory.create(config);
System.clearProperty("ebean.ignoreExtraDdl");
Query<UTMaster> query = ebeanServer.find(UTMaster.class);
List<UTMaster> details = ebeanServer.findList(query, null);
assertEquals(0, details.size());