use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBConnectionTest method testNoCharacterSetWarningWithDefaultConnectionEncoding.
/**
* Test if not explicitly specifying a connection character set results in a warning on the connection when
* system property {@code org.firebirdsql.jdbc.defaultConnectionEncoding} has been set.
*/
@Test
public void testNoCharacterSetWarningWithDefaultConnectionEncoding() throws Exception {
String defaultConnectionEncoding = System.getProperty("org.firebirdsql.jdbc.defaultConnectionEncoding");
assumeThat("Test only works if org.firebirdsql.jdbc.defaultConnectionEncoding has not been specified", defaultConnectionEncoding, nullValue());
try {
System.setProperty("org.firebirdsql.jdbc.defaultConnectionEncoding", "WIN1252");
Properties props = getDefaultPropertiesForConnection();
props.remove("lc_ctype");
try (Connection con = DriverManager.getConnection(getUrl(), props)) {
SQLWarning warnings = con.getWarnings();
assertNotNull("Expected a warning for not specifying connection character set", warnings);
assertEquals("Unexpected warning message for not specifying connection character set", FBManagedConnection.WARNING_NO_CHARSET + "WIN1252", warnings.getMessage());
IConnectionProperties connectionProperties = con.unwrap(FirebirdConnection.class).getFbDatabase().getConnectionProperties();
assertEquals("Unexpected connection encoding", "WIN1252", connectionProperties.getEncoding());
}
} finally {
System.clearProperty("org.firebirdsql.jdbc.defaultConnectionEncoding");
}
}
use of org.firebirdsql.gds.ng.IConnectionProperties in project jaybird by FirebirdSQL.
the class FBConnectionTest method testNoCharacterSetWithoutDefaultConnectionEncodingDefaultsToNONEIfEncodingNotRequired.
/**
* Test if not explicitly specifying a connection character set does not result in an exception on the connection
* and sets encoding to NONE when system properties {@code org.firebirdsql.jdbc.defaultConnectionEncoding} and
* {@code org.firebirdsql.jdbc.requireConnectionEncoding} have not been set.
*/
@Test
public void testNoCharacterSetWithoutDefaultConnectionEncodingDefaultsToNONEIfEncodingNotRequired() throws Exception {
String defaultConnectionEncoding = System.getProperty("org.firebirdsql.jdbc.defaultConnectionEncoding");
assumeThat("Test only works if org.firebirdsql.jdbc.defaultConnectionEncoding has not been specified", defaultConnectionEncoding, nullValue());
String requireConnectionEncoding = System.getProperty("org.firebirdsql.jdbc.requireConnectionEncoding");
assumeThat("Test only works if org.firebirdsql.jdbc.requireConnectionEncoding has not been specified", requireConnectionEncoding, nullValue());
Properties props = getDefaultPropertiesForConnection();
props.remove("lc_ctype");
// noinspection EmptyTryBlock
try (Connection connection = DriverManager.getConnection(getUrl(), props)) {
SQLWarning warnings = connection.getWarnings();
assertNotNull("Expected a warning for not specifying connection character set", warnings);
assertEquals("Unexpected warning message for not specifying connection character set", FBManagedConnection.WARNING_NO_CHARSET + "NONE", warnings.getMessage());
IConnectionProperties connectionProperties = connection.unwrap(FirebirdConnection.class).getFbDatabase().getConnectionProperties();
assertEquals("Unexpected connection encoding", "NONE", connectionProperties.getEncoding());
}
}
Aggregations