Changeset: 1c94185f2cb7 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/1c94185f2cb7
Modified Files:
        src/test/java/JDBC_API_Tester.java
        src/test/java/org/monetdb/jdbc/ApiTests.java
Branch: default
Log Message:

Convert Test_Driver() -> ApiTests#testDriverProperties()


diffs (193 lines):

diff --git a/src/test/java/JDBC_API_Tester.java 
b/src/test/java/JDBC_API_Tester.java
--- a/src/test/java/JDBC_API_Tester.java
+++ b/src/test/java/JDBC_API_Tester.java
@@ -174,80 +174,6 @@ public final class JDBC_API_Tester exten
                return isPostMar2025;
        }
 
-       @Test  // CHANGED
-       public void Test_Driver() {
-               sb.setLength(0);        // clear the output log buffer
-
-               try {
-                       listDriverProperties(jdbcUrl);
-                       // also test against monetdbs, this should make tls and 
cert required.
-                       sb.append("getPropertyInfo of 
jdbc:monetdbs:").append("\n");
-                       listDriverProperties("jdbc:monetdbs:");
-               } catch (SQLException e) {
-                       // this means we get what we expect
-                       sb.append("failed to get Driver class: 
").append(e.getMessage());
-                       sb.append("\n");
-               }
-
-               compareExpectedOutput("Test_Driver",
-                       "0  user  true    user name to authenticate as\n" +
-                       "1  password  true    password to authenticate with\n" +
-                       "2  host  false    IP number, domain name or one of the 
special values `localhost` and `localhost.`\n" +
-                       "3  port  false  -1  Port to connect to, 1..65535 or -1 
for 'not set'\n" +
-                       "4  database  false    name of database to connect 
to\n" +
-                       "5  autocommit  false  true  initial value of 
autocommit\n" +
-                       "6  schema  false    initial schema\n" +
-                       "7  timezone  false  <tz>  client time zone as minutes 
east of UTC\n" +
-                       "8  replysize  false  250  rows beyond this limit are 
retrieved on demand, <1 means unlimited\n" +
-                       "9  debug  false  false  enable tracing of socket 
communication for debugging\n" +
-                       "10  logfile  false    when debug is enabled its output 
will be written to this logfile\n" +
-                       "11  so_timeout  false  0  abort if network I/O does 
not complete in this many milliseconds, 0 means no timeout\n" +
-                       "12  treat_clob_as_varchar  false  true  map CLOB/TEXT 
data to type VARCHAR instead of type CLOB\n" +
-                       "13  treat_blob_as_binary  false  true  map BLOB data 
to type BINARY instead of type BLOB\n" +
-                       "14  client_info  false  true  whether to send 
ClientInfo when connecting\n" +
-                       "15  client_application  false    application name to 
send in ClientInfo\n" +
-                       "16  client_remark  false    any client remark to send 
in ClientInfo\n" +
-                       "getPropertyInfo of jdbc:monetdbs:\n" +
-                       "0  user  true    user name to authenticate as\n" +
-                       "1  password  true    password to authenticate with\n" +
-                       "2  tls  false  false  secure the connection using 
TLS\n" +
-                       "3  host  false    IP number, domain name or one of the 
special values `localhost` and `localhost.`\n" +
-                       "4  port  false  -1  Port to connect to, 1..65535 or -1 
for 'not set'\n" +
-                       "5  database  false    name of database to connect 
to\n" +
-                       "6  cert  false    path to TLS certificate to 
authenticate server with\n" +
-                       "7  certhash  false    hash of server TLS certificate 
must start with these hex digits; overrides cert\n" +
-                       "8  autocommit  false  true  initial value of 
autocommit\n" +
-                       "9  schema  false    initial schema\n" +
-                       "10  timezone  false  <tz>  client time zone as minutes 
east of UTC\n" +
-                       "11  replysize  false  250  rows beyond this limit are 
retrieved on demand, <1 means unlimited\n" +
-                       "12  debug  false  false  enable tracing of socket 
communication for debugging\n" +
-                       "13  logfile  false    when debug is enabled its output 
will be written to this logfile\n" +
-                       "14  so_timeout  false  0  abort if network I/O does 
not complete in this many milliseconds, 0 means no timeout\n" +
-                       "15  treat_clob_as_varchar  false  true  map CLOB/TEXT 
data to type VARCHAR instead of type CLOB\n" +
-                       "16  treat_blob_as_binary  false  true  map BLOB data 
to type BINARY instead of type BLOB\n" +
-                       "17  client_info  false  true  whether to send 
ClientInfo when connecting\n" +
-                       "18  client_application  false    application name to 
send in ClientInfo\n" +
-                       "19  client_remark  false    any client remark to send 
in ClientInfo\n");
-       }
-
-       private void listDriverProperties(String url) throws SQLException {
-               final Driver driver = DriverManager.getDriver(url);
-               DriverPropertyInfo[] props = driver.getPropertyInfo(url, null);
-               for (int i = 0; i < props.length; i++) {
-                       DriverPropertyInfo prop = props[i];
-                       final String name = prop.name;
-                       String value = prop.value;
-                       if (name.equals("timezone"))
-                               value = "<tz>";
-                       sb.append(i).append("  ");
-                       sb.append(name).append("  ");
-                       sb.append(prop.required).append("  ");
-                       sb.append(value).append("  ");
-                       sb.append(prop.description).append("\n");
-               }
-
-       }
-
        private void handleExecuteDDL(Statement stmt, String action, String 
objtype, String objname, String sql) {
                try {
                        int response = stmt.executeUpdate(sql);
diff --git a/src/test/java/org/monetdb/jdbc/ApiTests.java 
b/src/test/java/org/monetdb/jdbc/ApiTests.java
--- a/src/test/java/org/monetdb/jdbc/ApiTests.java
+++ b/src/test/java/org/monetdb/jdbc/ApiTests.java
@@ -1,12 +1,16 @@
 package org.monetdb.jdbc;
 
 import org.junit.jupiter.api.*;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.FieldSource;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.monetdb.testinfra.CloseOnFailure;
 import org.monetdb.testinfra.Config;
 import org.monetdb.testinfra.MonetVersionNumber;
 
 import java.sql.*;
 import java.util.ArrayList;
+import java.util.HashMap;
 
 import static org.junit.jupiter.api.Assertions.*;
 import static org.monetdb.testinfra.Assertions.assertSQLException;
@@ -25,6 +29,7 @@ public class ApiTests {
        @CloseOnFailure
        Connection conn;
        MonetVersionNumber monetVersion;
+       String[] serverURLs; // used by testDriverProperties
        Statement stmt;
        PreparedStatement pstmt;
 
@@ -41,6 +46,7 @@ public class ApiTests {
                if (conn == null || conn.isClosed()) {
                        conn = newConnection();
                        monetVersion = MonetVersionNumber.retrieve(conn);
+                       serverURLs = new String[] { Config.getServerURL() };
                }
                stmt = conn.createStatement();
        }
@@ -336,5 +342,71 @@ public class ApiTests {
 
                assertSQLException("not allowed in auto commit mode", () -> 
conn.commit());
        }
+
+       @ParameterizedTest
+       @ValueSource(strings = {"jdbc:monetdb:///demo", 
"jdbc:monetdbs:///demo", "jdbc:monetdb:",})
+       @FieldSource("serverURLs")
+       public void testDriverProperties(String url) throws SQLException {
+               // NOTE the previous version of this test called 
getDriverPropertyInfo
+               // for the test database URL (which could be anything) and 
checked
+               // that all properties came out in an exact order and with 
specific
+               // values and doc strings.
+               //
+               // Nowadays, the parameters are all centralized in enum 
org.monetdb.mcl.net.Parameter
+               // and their default values and documentation can simply be 
inspected there.
+               // We do however want to check that some properties are always 
present,
+               // never present, etc.
+
+               assertTrue(url.startsWith("jdbc:monetdb:") || 
url.startsWith("jdbc:monetdbs:"));
+
+               Driver driver = DriverManager.getDriver(url);
+               HashMap<String, DriverPropertyInfo> props = new HashMap<>();
+               for (DriverPropertyInfo entry : driver.getPropertyInfo(url, 
null)) {
+                       props.put(entry.name, entry);
+               }
+
+               // A nontrivial number of properties must be returned and they 
must
+               // be properly filled in
+               int nprops = props.size();
+               assertTrue(nprops >= 15, "found " + nprops + " driver 
properties");
+               for (DriverPropertyInfo entry : props.values()) {
+                       assertNotNull(entry.description, entry.name);
+                       assertNotNull(entry.value, entry.name);
+                       assertFalse(entry.description.isEmpty(), entry.name);
+               }
+
+               // Some properties must always be present. This is not an 
exhaustive list.
+               for (String required : new String[]{ //
+                               "host", "port", "database", //
+                               "user", "password", //
+                               "autocommit", "timezone", "replysize" //
+               }) {
+                       assertTrue(props.containsKey(required), required);
+               }
+
+               // Boolean properties have a choices list. Above we checked 
that autocommit is present.
+               assertEquals(2, props.get("autocommit").choices.length);
+
+               // Some properties exist as Parameters but are not exposed to 
the end user.
+               assertFalse(props.containsKey("sock"));
+               assertFalse(props.containsKey("sockdir"));
+               assertFalse(props.containsKey("fetchsize"));
+               assertFalse(props.containsKey("language"));
+               assertFalse(props.containsKey("hash"));
+               assertFalse(props.containsKey("tableschema"));
+               assertFalse(props.containsKey("table"));
+               assertFalse(props.containsKey("clientkey"));
+               assertFalse(props.containsKey("clientcert"));
+
+               // TLS-related properties must be omitted if this is a 
jdbc:monetdb:// URL.
+               // They must be included if this is a jdbc:monetdbs:// URL or if
+               // the URL is exactly "jdbc:monetdb:". In the latter case, TLS 
use is determined
+               // by the tls property instead of the URL schema so the 
property must be
+               // included.
+               boolean expectTLS = !url.startsWith("jdbc:monetdb:/");
+
+               assertEquals(expectTLS, props.containsKey("tls"));
+               assertEquals(expectTLS, props.containsKey("cert"));
+               assertEquals(expectTLS, props.containsKey("certhash"));
+       }
 }
-
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to