From 62cf37dd276d2b49afe2f2c931cfef27017d8b6c Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Wed, 16 May 2018 01:34:36 -0400 Subject: [PATCH] Add mssql tests --- .travis.yml | 12 +++++++++--- pom.xml | 9 +++++++++ test/pom.xml | 7 ++++++- .../jdbc/codegen/QueryMapperQmDao.java | 1 + .../com/moparisthebest/jdbc/QueryMapperTest.java | 16 +++++++++++++++- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e948a62..5e9d97c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: java -sudo: false +sudo: required dist: trusty services: - postgresql + - docker addons: mariadb: '10.2' @@ -11,8 +12,12 @@ addons: before_script: - psql -c 'create database test_db;' -U postgres || travis_terminate 1; - mysql -u root -e 'CREATE DATABASE IF NOT EXISTS test_db;' || travis_terminate 1; + - docker pull microsoft/mssql-server-linux:2017-latest + - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=' -p 1433:1433 -d microsoft/mssql-server-linux:2017-latest -script: mvn test -B '-DjdbcUrl1=jdbc:postgresql:test_db' '-DjdbcUrl2=jdbc:mariadb://127.0.0.1:3306/test_db?user=root' +script: + - docker ps -a + - mvn test -B '-DjdbcUrl1=jdbc:postgresql:test_db' '-DjdbcUrl2=jdbc:mariadb://127.0.0.1:3306/test_db?user=root' '-DjdbcUrl3=jdbc:sqlserver://localhost:1433;databaseName=master;username=sa;password=;' matrix: include: @@ -41,7 +46,8 @@ matrix: - env: JDK='OracleJDK 11' install: . ./install-jdk.sh -F 11 -L BCL -before_install: wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh +before_install: + - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh install: - if [[ "${JDK}" == 'OpenJDK 6' ]]; then diff --git a/pom.xml b/pom.xml index 0cc68e2..82ecb4d 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,13 @@ test true + + com.microsoft.sqlserver + mssql-jdbc + ${mssql.version} + test + true + @@ -229,6 +236,7 @@ 1.4.191 42.2.2.jre6 1.7.3 + 6.4.0.jre7 common @@ -338,6 +346,7 @@ 1.4.197 42.2.2 2.2.4 + 6.4.0.jre8 common diff --git a/test/pom.xml b/test/pom.xml index e2861d4..2627c85 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -63,7 +63,12 @@ org.mariadb.jdbc mariadb-java-client - ${mariadb.version} + test + true + + + com.microsoft.sqlserver + mssql-jdbc test true diff --git a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java index 12ff88b..b847fac 100644 --- a/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java +++ b/test/src/main/java/com/moparisthebest/jdbc/codegen/QueryMapperQmDao.java @@ -63,6 +63,7 @@ public class QueryMapperQmDao implements QmDao { , "org.hsqldb.jdbc.JDBCConnection" // does not support ArrayInList but *does* support UnNestArrayInList , "org.sqlite.jdbc3.JDBC3Connection" , "org.mariadb.jdbc.MariaDbConnection" + , "com.microsoft.sqlserver.jdbc.SQLServerConnection" // h2 doesn't support this with java6 either... /*IFJAVA6_START , "org.h2.jdbc.JdbcConnection" diff --git a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java index 9074884..c172544 100644 --- a/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java +++ b/test/src/test/java/com/moparisthebest/jdbc/QueryMapperTest.java @@ -115,6 +115,14 @@ public class QueryMapperTest { return getConnection(jdbcUrls.iterator().next()); } + public static boolean isWrapperFor(final Connection conn, final String className) { + try { + return conn.isWrapperFor(Class.forName(className)); + } catch(Exception e) { + return false; + } + } + public static Connection getConnection(final String url) throws SQLException { final Connection conn = DriverManager.getConnection(url); QueryMapper qm = null; @@ -126,7 +134,13 @@ public class QueryMapperTest { } catch(Exception e) { // ignore, means the database hasn't been set up yet } - qm.executeUpdate("CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date TIMESTAMP)"); + if(isWrapperFor(conn, "org.apache.derby.impl.jdbc.EmbedConnection")) { + // derby doesn't support DATETIME + qm.executeUpdate("CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date TIMESTAMP)"); + } else { + // mssql doesn't support inserting into TIMESTAMP + qm.executeUpdate("CREATE TABLE person (person_no NUMERIC, first_name VARCHAR(40), last_name VARCHAR(40), birth_date DATETIME)"); + } qm.executeUpdate("CREATE TABLE boss (person_no NUMERIC, department VARCHAR(40))"); qm.executeUpdate("CREATE TABLE val (val_no NUMERIC, num_val NUMERIC, str_val VARCHAR(40))"); for (final Person person : people)