diff --git a/.travis.yml b/.travis.yml index 91a3716b..9e1288ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,5 @@ jdk: script: - mvn clean test +dist: trusty #- mvn clean test -Pperformance-test diff --git a/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java b/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java index 7b19fdf2..51d40c0a 100644 --- a/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java +++ b/neo4j-jdbc/src/main/java/org/neo4j/jdbc/impl/Neo4jConnectionImpl.java @@ -75,6 +75,8 @@ protected Neo4jConnectionImpl(Properties properties, String url, int defaultHold this.holdability = defaultHoldability; } + Neo4jConnectionImpl() {} + public static boolean hasDebug(Properties properties) { return "true".equalsIgnoreCase(properties.getProperty("debug", "false")); } @@ -229,7 +231,7 @@ protected void checkTypeParams(int resultSetType) throws SQLException { */ protected void checkTransactionIsolation(int level) throws SQLException { // @formatter:off - int[] invalid = { + Integer[] invalid = { TRANSACTION_NONE, TRANSACTION_READ_COMMITTED, TRANSACTION_READ_UNCOMMITTED, @@ -238,7 +240,7 @@ protected void checkTransactionIsolation(int level) throws SQLException { }; if(!Arrays.asList(invalid).contains(level)){ - throw new SQLException(); + throw new SQLException("Unsupported isolation level"); } // @formatter:on } diff --git a/neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java b/neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java new file mode 100644 index 00000000..59ff59c5 --- /dev/null +++ b/neo4j-jdbc/src/test/java/org/neo4j/jdbc/impl/Neo4jConnectionImplTest.java @@ -0,0 +1,102 @@ +package org.neo4j.jdbc.impl; + +import org.junit.Test; + +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.junit.Assert.fail; + +/** + * @description + * @time 创建时间:2019/9/3 0:44 + * @param + * @author xin.gong + */ +public class Neo4jConnectionImplTest { + + Neo4jConnectionImpl neo4jConnection = new Neo4jConnectionImpl(){ + @Override public Statement createStatement() throws SQLException { + return null; + } + + @Override public PreparedStatement prepareStatement(String sql) throws SQLException { + return null; + } + + @Override public void setAutoCommit(boolean autoCommit) throws SQLException { + + } + + @Override public boolean getAutoCommit() throws SQLException { + return false; + } + + @Override public void commit() throws SQLException { + + } + + @Override public void rollback() throws SQLException { + + } + + @Override public void close() throws SQLException { + + } + + @Override public boolean isClosed() throws SQLException { + return false; + } + + @Override public DatabaseMetaData getMetaData() throws SQLException { + return null; + } + + @Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { + return null; + } + + @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return null; + } + + @Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return null; + } + + @Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return null; + } + + @Override public boolean isValid(int timeout) throws SQLException { + return false; + } + }; + @Test public void checkTransactionIsolationShouldReturnNothing() { + Integer[] levels = {0, 1, 2, 4, 8}; + for (int level : levels) { + try { + neo4jConnection.checkTransactionIsolation(level); + } catch (SQLException e) { + fail(); + } + } + } + + @Test public void checkTransactionIsolationShouldThrowExceptionWhenInputErrorLevel() { + Integer[] levels = {3, 5, 7, 9}; + for (int level : levels) { + try { + neo4jConnection.checkTransactionIsolation(level); + fail(); + } catch (SQLException e) { + // OK + } + } + } +}