Search in sources :

Example 6 with IConnectionProperties

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");
    }
}
Also used : FBManagedConnection(org.firebirdsql.jaybird.xca.FBManagedConnection) JaybirdSystemProperties(org.firebirdsql.gds.JaybirdSystemProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Test(org.junit.Test)

Example 7 with IConnectionProperties

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());
    }
}
Also used : FBManagedConnection(org.firebirdsql.jaybird.xca.FBManagedConnection) JaybirdSystemProperties(org.firebirdsql.gds.JaybirdSystemProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Properties(java.util.Properties) FBTestProperties(org.firebirdsql.common.FBTestProperties) IConnectionProperties(org.firebirdsql.gds.ng.IConnectionProperties) Test(org.junit.Test)

Aggregations

IConnectionProperties (org.firebirdsql.gds.ng.IConnectionProperties)7 Properties (java.util.Properties)4 FBTestProperties (org.firebirdsql.common.FBTestProperties)4 JaybirdSystemProperties (org.firebirdsql.gds.JaybirdSystemProperties)4 FBManagedConnection (org.firebirdsql.jaybird.xca.FBManagedConnection)4 Test (org.junit.Test)4 SQLException (java.sql.SQLException)3 FbDatabase (org.firebirdsql.gds.ng.FbDatabase)3