diff --git a/vertx-db2-client/src/main/asciidoc/dataobjects.adoc b/vertx-db2-client/src/main/asciidoc/dataobjects.adoc index 1d74ad1ffc..f681269be7 100644 --- a/vertx-db2-client/src/main/asciidoc/dataobjects.adoc +++ b/vertx-db2-client/src/main/asciidoc/dataobjects.adoc @@ -23,6 +23,7 @@ |[[hostnameVerificationAlgorithm]]`@hostnameVerificationAlgorithm`|`String`|- |[[idleTimeout]]`@idleTimeout`|`Number (int)`|- |[[idleTimeoutUnit]]`@idleTimeoutUnit`|`link:enums.html#TimeUnit[TimeUnit]`|- +|[[kind]]`@kind`|`String`|- |[[localAddress]]`@localAddress`|`String`|- |[[logActivity]]`@logActivity`|`Boolean`|- |[[metricsName]]`@metricsName`|`String`|- diff --git a/vertx-db2-client/src/main/java/io/vertx/db2client/DB2ConnectOptions.java b/vertx-db2-client/src/main/java/io/vertx/db2client/DB2ConnectOptions.java index 55b2bc76cf..856ff10a24 100644 --- a/vertx-db2-client/src/main/java/io/vertx/db2client/DB2ConnectOptions.java +++ b/vertx-db2-client/src/main/java/io/vertx/db2client/DB2ConnectOptions.java @@ -26,6 +26,7 @@ import io.vertx.db2client.impl.DB2ConnectionUriParser; import io.vertx.db2client.impl.drda.SQLState; import io.vertx.db2client.impl.drda.SqlCode; +import io.vertx.db2client.spi.DB2Driver; import io.vertx.sqlclient.SqlConnectOptions; /** @@ -88,6 +89,22 @@ public DB2ConnectOptions(DB2ConnectOptions other) { super(other); this.pipeliningLimit = other.pipeliningLimit; } + + @Override + public String getKind() { + return DB2Driver.KIND; + } + + @Override + public DB2ConnectOptions setKind(String kind) { + Objects.requireNonNull(kind, "Database kind must be non-null"); + // Tolerate setting the kind to DB2, but raise an error otherwise + if (!DB2Driver.KIND.equalsIgnoreCase(kind)) { + throw new IllegalArgumentException("Database kind for " + getClass() + + " must be of type " + DB2Driver.KIND + " but " + kind + " was specified"); + } + return this; + } @Override public DB2ConnectOptions setHost(String host) { @@ -182,6 +199,7 @@ public DB2ConnectOptions addProperty(String key, String value) { protected void init() { this.setHost(DEFAULT_HOST); this.setPort(DEFAULT_PORT); + this.setKind(DB2Driver.KIND); this.setProperties(new HashMap<>(DEFAULT_CONNECTION_ATTRIBUTES)); } diff --git a/vertx-db2-client/src/main/java/io/vertx/db2client/DB2Exception.java b/vertx-db2-client/src/main/java/io/vertx/db2client/DB2Exception.java index ec5ac85c62..c036ef1ebd 100644 --- a/vertx-db2-client/src/main/java/io/vertx/db2client/DB2Exception.java +++ b/vertx-db2-client/src/main/java/io/vertx/db2client/DB2Exception.java @@ -55,6 +55,6 @@ public String getSqlState() { */ @Override public String getMessage() { - return super.getMessage(); + return super.getMessage() + "; errorCode=" + errorCode + "; sqlState=" + sqlState; } } diff --git a/vertx-db2-client/src/main/java/io/vertx/db2client/spi/DB2Driver.java b/vertx-db2-client/src/main/java/io/vertx/db2client/spi/DB2Driver.java index b4805ed595..4d4c84a05d 100644 --- a/vertx-db2-client/src/main/java/io/vertx/db2client/spi/DB2Driver.java +++ b/vertx-db2-client/src/main/java/io/vertx/db2client/spi/DB2Driver.java @@ -18,12 +18,15 @@ import io.vertx.core.Vertx; import io.vertx.db2client.DB2ConnectOptions; import io.vertx.db2client.DB2Pool; +import io.vertx.sqlclient.DatabaseKind; import io.vertx.sqlclient.Pool; import io.vertx.sqlclient.PoolOptions; import io.vertx.sqlclient.SqlConnectOptions; import io.vertx.sqlclient.spi.Driver; public class DB2Driver implements Driver { + + public static final String KIND = DatabaseKind.DB2; @Override public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) { @@ -37,7 +40,14 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO @Override public boolean acceptsOptions(SqlConnectOptions options) { - return options instanceof DB2ConnectOptions || SqlConnectOptions.class.equals(options.getClass()); + if (options instanceof DB2ConnectOptions) { + return true; + } + if (SqlConnectOptions.class.equals(options.getClass())) { + return KIND.equalsIgnoreCase(options.getKind()) || + SqlConnectOptions.DEFAULT_KIND.equalsIgnoreCase(options.getKind()); + } + return false; } private static DB2ConnectOptions wrap(SqlConnectOptions options) { diff --git a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2DriverTest.java b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2DriverTest.java index ca0ce2a7ef..0da33de2c9 100644 --- a/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2DriverTest.java +++ b/vertx-db2-client/src/test/java/io/vertx/db2client/tck/DB2DriverTest.java @@ -45,5 +45,10 @@ public void printTestName(TestContext ctx) throws Exception { protected SqlConnectOptions defaultOptions() { return rule.options(); } + + @Override + protected String getKind() { + return "db2"; + } } diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/MSSQLConnectOptions.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/MSSQLConnectOptions.java index c804c8c120..c788f220b3 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/MSSQLConnectOptions.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/MSSQLConnectOptions.java @@ -24,10 +24,14 @@ import io.vertx.core.net.ProxyOptions; import io.vertx.core.net.SSLEngineOptions; import io.vertx.core.net.TrustOptions; +import io.vertx.db2client.DB2ConnectOptions; +import io.vertx.db2client.spi.DB2Driver; +import io.vertx.mssqlclient.spi.MSSQLDriver; import io.vertx.sqlclient.SqlConnectOptions; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -68,6 +72,22 @@ public MSSQLConnectOptions(SqlConnectOptions other) { public MSSQLConnectOptions(MSSQLConnectOptions other) { super(other); } + + @Override + public String getKind() { + return MSSQLDriver.KIND; + } + + @Override + public MSSQLConnectOptions setKind(String kind) { + Objects.requireNonNull(kind, "Database kind must be non-null"); + // Tolerate setting the kind to the same thing, but raise an error otherwise + if (!MSSQLDriver.KIND.equalsIgnoreCase(kind)) { + throw new IllegalArgumentException("Database kind for " + getClass() + + " must be of type " + MSSQLDriver.KIND + " but " + kind + " was specified"); + } + return this; + } @Override public MSSQLConnectOptions setHost(String host) { @@ -323,6 +343,7 @@ protected void init() { this.setUser(DEFAULT_USER); this.setPassword(DEFAULT_PASSWORD); this.setDatabase(DEFAULT_SCHEMA); + this.setKind(MSSQLDriver.KIND); this.setProperties(new HashMap<>(DEFAULT_PROPERTIES)); } diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/spi/MSSQLDriver.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/spi/MSSQLDriver.java index 9e501a1a1c..02dccb53f9 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/spi/MSSQLDriver.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/spi/MSSQLDriver.java @@ -18,12 +18,15 @@ import io.vertx.core.Vertx; import io.vertx.mssqlclient.MSSQLConnectOptions; import io.vertx.mssqlclient.MSSQLPool; +import io.vertx.sqlclient.DatabaseKind; import io.vertx.sqlclient.Pool; import io.vertx.sqlclient.PoolOptions; import io.vertx.sqlclient.SqlConnectOptions; import io.vertx.sqlclient.spi.Driver; public class MSSQLDriver implements Driver { + + public static final String KIND = DatabaseKind.MICROSOFT_SQL_SERVER; @Override public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) { @@ -37,7 +40,14 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO @Override public boolean acceptsOptions(SqlConnectOptions options) { - return options instanceof MSSQLConnectOptions || SqlConnectOptions.class.equals(options.getClass()); + if (options instanceof MSSQLConnectOptions) { + return true; + } + if (SqlConnectOptions.class.equals(options.getClass())) { + return KIND.equalsIgnoreCase(options.getKind()) || + SqlConnectOptions.DEFAULT_KIND.equalsIgnoreCase(options.getKind()); + } + return false; } private static MSSQLConnectOptions wrap(SqlConnectOptions options) { diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLDriverTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLDriverTest.java index 7c903a06df..f659164bce 100644 --- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLDriverTest.java +++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/tck/MSSQLDriverTest.java @@ -33,5 +33,10 @@ public class MSSQLDriverTest extends DriverTestBase { protected SqlConnectOptions defaultOptions() { return rule.options(); } + + @Override + protected String getKind() { + return "sqlserver"; + } } diff --git a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLConnectOptions.java b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLConnectOptions.java index ffbdb330a7..5e50ec46c3 100644 --- a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLConnectOptions.java +++ b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/MySQLConnectOptions.java @@ -18,6 +18,8 @@ import io.vertx.core.net.*; import io.vertx.mysqlclient.impl.MySQLCollation; import io.vertx.mysqlclient.impl.MySQLConnectionUriParser; +import io.vertx.mysqlclient.spi.MySQLDriver; +import io.vertx.sqlclient.DatabaseKind; import io.vertx.sqlclient.SqlConnectOptions; import java.nio.charset.Charset; @@ -92,6 +94,22 @@ public MySQLConnectOptions(MySQLConnectOptions other) { this.serverRsaPublicKeyPath = other.serverRsaPublicKeyPath; this.serverRsaPublicKeyValue = other.serverRsaPublicKeyValue != null ? other.serverRsaPublicKeyValue.copy() : null; } + + @Override + public String getKind() { + return MySQLDriver.KIND; + } + + @Override + public MySQLConnectOptions setKind(String kind) { + Objects.requireNonNull(kind, "Database kind must be non-null"); + // Tolerate setting the kind to the same thing, but raise an error otherwise + if (!MySQLDriver.KIND.equalsIgnoreCase(kind) && !DatabaseKind.MARIADB.equalsIgnoreCase(kind)) { + throw new IllegalArgumentException("Database kind for " + getClass() + + " must be of type " + MySQLDriver.KIND + " or " + DatabaseKind.MARIADB + " but " + kind + " was specified"); + } + return this; + } /** * Get the collation for the connection. @@ -528,6 +546,7 @@ protected void init() { this.setUser(DEFAULT_USER); this.setPassword(DEFAULT_PASSWORD); this.setDatabase(DEFAULT_SCHEMA); + this.setKind(MySQLDriver.KIND); this.setProperties(new HashMap<>(DEFAULT_CONNECTION_ATTRIBUTES)); } diff --git a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/spi/MySQLDriver.java b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/spi/MySQLDriver.java index 37820bb9da..fa83b869a1 100644 --- a/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/spi/MySQLDriver.java +++ b/vertx-mysql-client/src/main/java/io/vertx/mysqlclient/spi/MySQLDriver.java @@ -18,12 +18,15 @@ import io.vertx.core.Vertx; import io.vertx.mysqlclient.MySQLConnectOptions; import io.vertx.mysqlclient.MySQLPool; +import io.vertx.sqlclient.DatabaseKind; import io.vertx.sqlclient.Pool; import io.vertx.sqlclient.PoolOptions; import io.vertx.sqlclient.SqlConnectOptions; import io.vertx.sqlclient.spi.Driver; public class MySQLDriver implements Driver { + + public static final String KIND = DatabaseKind.MYSQL; @Override public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) { @@ -37,7 +40,15 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO @Override public boolean acceptsOptions(SqlConnectOptions options) { - return options instanceof MySQLConnectOptions || SqlConnectOptions.class.equals(options.getClass()); + if (options instanceof MySQLConnectOptions) { + return true; + } + if (SqlConnectOptions.class.equals(options.getClass())) { + return KIND.equalsIgnoreCase(options.getKind()) || + DatabaseKind.MARIADB.equalsIgnoreCase(options.getKind()) || + SqlConnectOptions.DEFAULT_KIND.equalsIgnoreCase(options.getKind()); + } + return false; } private static MySQLConnectOptions wrap(SqlConnectOptions options) { diff --git a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLDriverTest.java b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLDriverTest.java index 916d58c015..e1b445de58 100644 --- a/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLDriverTest.java +++ b/vertx-mysql-client/src/test/java/io/vertx/mysqlclient/tck/MySQLDriverTest.java @@ -34,5 +34,10 @@ public class MySQLDriverTest extends DriverTestBase { protected SqlConnectOptions defaultOptions() { return rule.options(); } + + @Override + protected String getKind() { + return "mysql"; + } } diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnectOptions.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnectOptions.java index 839054e504..90bcffeb79 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnectOptions.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/PgConnectOptions.java @@ -19,15 +19,19 @@ import io.vertx.codegen.annotations.GenIgnore; import io.vertx.pgclient.impl.PgConnectionUriParser; +import io.vertx.pgclient.spi.PgDriver; import io.vertx.codegen.annotations.DataObject; import io.vertx.core.buffer.Buffer; import io.vertx.core.json.JsonObject; import io.vertx.core.net.*; +import io.vertx.db2client.DB2ConnectOptions; +import io.vertx.db2client.spi.DB2Driver; import io.vertx.sqlclient.SqlConnectOptions; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -135,6 +139,24 @@ public PgConnectOptions(PgConnectOptions other) { pipeliningLimit = other.pipeliningLimit; sslMode = other.sslMode; } + + @Override + public String getKind() { + return PgDriver.KIND; + } + + @Override + public PgConnectOptions setKind(String kind) { + Objects.requireNonNull(kind, "Database kind must be non-null"); + // Tolerate setting the kind to the same thing, but raise an error otherwise + if (!PgDriver.KIND.equalsIgnoreCase(kind) && + !"postgre".equalsIgnoreCase(kind) && + !"postgres".equalsIgnoreCase(kind)) { + throw new IllegalArgumentException("Database kind for " + getClass() + + " must be of type " + PgDriver.KIND + ", postgre, or postgres but " + kind + " was specified"); + } + return this; + } @Override public PgConnectOptions setHost(String host) { diff --git a/vertx-pg-client/src/main/java/io/vertx/pgclient/spi/PgDriver.java b/vertx-pg-client/src/main/java/io/vertx/pgclient/spi/PgDriver.java index 9a1282dbca..8edc68fb37 100644 --- a/vertx-pg-client/src/main/java/io/vertx/pgclient/spi/PgDriver.java +++ b/vertx-pg-client/src/main/java/io/vertx/pgclient/spi/PgDriver.java @@ -3,12 +3,15 @@ import io.vertx.core.Vertx; import io.vertx.pgclient.PgConnectOptions; import io.vertx.pgclient.PgPool; +import io.vertx.sqlclient.DatabaseKind; import io.vertx.sqlclient.Pool; import io.vertx.sqlclient.PoolOptions; import io.vertx.sqlclient.SqlConnectOptions; import io.vertx.sqlclient.spi.Driver; public class PgDriver implements Driver { + + public static final String KIND = DatabaseKind.POSTGRESQL; @Override public Pool createPool(SqlConnectOptions options, PoolOptions poolOptions) { @@ -22,7 +25,16 @@ public Pool createPool(Vertx vertx, SqlConnectOptions options, PoolOptions poolO @Override public boolean acceptsOptions(SqlConnectOptions options) { - return options instanceof PgConnectOptions || SqlConnectOptions.class.equals(options.getClass()); + if (options instanceof PgConnectOptions) { + return true; + } + if (SqlConnectOptions.class.equals(options.getClass())) { + return KIND.equalsIgnoreCase(options.getKind()) || + "postgre".equalsIgnoreCase(options.getKind()) || + "postgres".equalsIgnoreCase(options.getKind()) || + SqlConnectOptions.DEFAULT_KIND.equalsIgnoreCase(options.getKind()); + } + return false; } private static PgConnectOptions wrap(SqlConnectOptions options) { diff --git a/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgDriverTest.java b/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgDriverTest.java index 1f4c395de7..dc1c55076e 100644 --- a/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgDriverTest.java +++ b/vertx-pg-client/src/test/java/io/vertx/pgclient/tck/PgDriverTest.java @@ -33,5 +33,10 @@ public class PgDriverTest extends DriverTestBase { protected SqlConnectOptions defaultOptions() { return rule.options(); } + + @Override + protected String getKind() { + return "postgresql"; + } } diff --git a/vertx-sql-client/src/main/asciidoc/dataobjects.adoc b/vertx-sql-client/src/main/asciidoc/dataobjects.adoc index 886fe3219a..c415e6007b 100644 --- a/vertx-sql-client/src/main/asciidoc/dataobjects.adoc +++ b/vertx-sql-client/src/main/asciidoc/dataobjects.adoc @@ -50,6 +50,9 @@ Specify the host for connecting to the server. |[[hostnameVerificationAlgorithm]]`@hostnameVerificationAlgorithm`|`String`|- |[[idleTimeout]]`@idleTimeout`|`Number (int)`|- |[[idleTimeoutUnit]]`@idleTimeoutUnit`|`link:enums.html#TimeUnit[TimeUnit]`|- +|[[kind]]`@kind`|`String`|+++ +Specify the kind of database the connect options are for. ++++ |[[localAddress]]`@localAddress`|`String`|- |[[logActivity]]`@logActivity`|`Boolean`|- |[[metricsName]]`@metricsName`|`String`|- diff --git a/vertx-sql-client/src/main/generated/io/vertx/sqlclient/SqlConnectOptionsConverter.java b/vertx-sql-client/src/main/generated/io/vertx/sqlclient/SqlConnectOptionsConverter.java index 0ee90416f0..02250249a6 100644 --- a/vertx-sql-client/src/main/generated/io/vertx/sqlclient/SqlConnectOptionsConverter.java +++ b/vertx-sql-client/src/main/generated/io/vertx/sqlclient/SqlConnectOptionsConverter.java @@ -30,6 +30,11 @@ public static void fromJson(Iterable> json, obj.setHost((String)member.getValue()); } break; + case "kind": + if (member.getValue() instanceof String) { + obj.setKind((String)member.getValue()); + } + break; case "password": if (member.getValue() instanceof String) { obj.setPassword((String)member.getValue()); @@ -81,6 +86,9 @@ public static void toJson(SqlConnectOptions obj, java.util.Map j if (obj.getHost() != null) { json.put("host", obj.getHost()); } + if (obj.getKind() != null) { + json.put("kind", obj.getKind()); + } if (obj.getPassword() != null) { json.put("password", obj.getPassword()); } diff --git a/vertx-sql-client/src/main/java/io/vertx/sqlclient/DatabaseKind.java b/vertx-sql-client/src/main/java/io/vertx/sqlclient/DatabaseKind.java new file mode 100644 index 0000000000..257e20be68 --- /dev/null +++ b/vertx-sql-client/src/main/java/io/vertx/sqlclient/DatabaseKind.java @@ -0,0 +1,11 @@ +package io.vertx.sqlclient; + +public interface DatabaseKind { + + String DB2 = "db2"; + String MICROSOFT_SQL_SERVER = "sqlserver"; + String MYSQL = "mysql"; + String MARIADB = "mariadb"; + String POSTGRESQL = "postgresql"; + +} diff --git a/vertx-sql-client/src/main/java/io/vertx/sqlclient/SqlConnectOptions.java b/vertx-sql-client/src/main/java/io/vertx/sqlclient/SqlConnectOptions.java index 7fff1715df..e84fd21d95 100644 --- a/vertx-sql-client/src/main/java/io/vertx/sqlclient/SqlConnectOptions.java +++ b/vertx-sql-client/src/main/java/io/vertx/sqlclient/SqlConnectOptions.java @@ -25,6 +25,8 @@ */ @DataObject(generateConverter = true) public class SqlConnectOptions extends NetClientOptions { + + public static final String DEFAULT_KIND = "ANY"; public static final boolean DEFAULT_CACHE_PREPARED_STATEMENTS = false; public static final int DEFAULT_PREPARED_STATEMENT_CACHE_MAX_SIZE = 256; public static final int DEFAULT_PREPARED_STATEMENT_CACHE_SQL_LIMIT = 2048; @@ -34,6 +36,7 @@ public class SqlConnectOptions extends NetClientOptions { private String user; private String password; private String database; + private String kind = DEFAULT_KIND; private boolean cachePreparedStatements = DEFAULT_CACHE_PREPARED_STATEMENTS; private int preparedStatementCacheMaxSize = DEFAULT_PREPARED_STATEMENT_CACHE_MAX_SIZE; private int preparedStatementCacheSqlLimit = DEFAULT_PREPARED_STATEMENT_CACHE_SQL_LIMIT; @@ -64,6 +67,24 @@ public SqlConnectOptions(SqlConnectOptions other) { this.properties = new HashMap<>(other.properties); } } + + /** + * @return The kind of database the options correspond to. See {@link DatabaseKind} for some well-known values. + */ + public String getKind() { + return kind; + } + + /** + * Specify the kind of database the connect options are for. + * @param kind The kind of database the options correspond to. See {@link DatabaseKind} for some well-known values. + * @return a reference to this, so the API can be used fluently + */ + public SqlConnectOptions setKind(String kind) { + Objects.requireNonNull(kind, "Database kind cannot be null"); + this.kind = kind; + return this; + } /** * Get the host for connecting to the server. diff --git a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java index 9653c5eabe..12c72d0ce7 100644 --- a/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java +++ b/vertx-sql-client/src/test/java/io/vertx/sqlclient/tck/DriverTestBase.java @@ -22,6 +22,8 @@ public abstract class DriverTestBase { protected abstract SqlConnectOptions defaultOptions(); + protected abstract String getKind(); + @Test public void testServiceLoader(TestContext ctx) { List drivers = new ArrayList<>(); @@ -46,6 +48,34 @@ public void testRejectsOtherOptions(TestContext ctx) { assertFalse(getDriver().acceptsOptions(new BogusOptions())); } + @Test + public void testOtherKindRejected(TestContext ctx) { + SqlConnectOptions bogusKindOptions = new SqlConnectOptions(defaultOptions()).setKind("bogus"); + assertFalse(getDriver().acceptsOptions(bogusKindOptions)); + } + + @Test + public void testDefaultKind(TestContext ctx) { + System.out.println("@AGG expect: " + getKind()); + System.out.println("@AGG actual: " + defaultOptions().getKind()); + ctx.assertEquals(getKind(), defaultOptions().getKind()); + } + + @Test + public void testGenericDefaultKind(TestContext ctx) { + ctx.assertEquals("ANY", new SqlConnectOptions().getKind()); + } + + @Test + public void testSetSameKindAllowed(TestContext ctx) { + defaultOptions().setKind(getKind()); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetBogusKindRejected(TestContext ctx) { + defaultOptions().setKind("bogus"); + } + @Test public void testCreatePoolFromDriver01(TestContext ctx) { Pool p = getDriver().createPool(defaultOptions());