Add mssql tests

This commit is contained in:
Travis Burtrum 2018-05-16 01:34:36 -04:00
parent 7cc5af55fb
commit 62cf37dd27
5 changed files with 40 additions and 5 deletions

View File

@ -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=<YourStrong!Passw0rd>' -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=<YourStrong!Passw0rd>;'
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

View File

@ -118,6 +118,13 @@
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>${mssql.version}</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>
<build>
@ -229,6 +236,7 @@
<h2.version>1.4.191</h2.version>
<postgresql.version>42.2.2.jre6</postgresql.version>
<mariadb.version>1.7.3</mariadb.version>
<mssql.version>6.4.0.jre7</mssql.version>
</properties>
<modules>
<module>common</module>
@ -338,6 +346,7 @@
<h2.version>1.4.197</h2.version>
<postgresql.version>42.2.2</postgresql.version>
<mariadb.version>2.2.4</mariadb.version>
<mssql.version>6.4.0.jre8</mssql.version>
</properties>
<modules>
<module>common</module>

View File

@ -63,7 +63,12 @@
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb.version}</version>
<scope>test</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<scope>test</scope>
<optional>true</optional>
</dependency>

View File

@ -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"

View File

@ -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)