diff --git a/data-prepper-plugins/rds-source/src/main/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManager.java b/data-prepper-plugins/rds-source/src/main/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManager.java index 90a93428c0..542724d49d 100644 --- a/data-prepper-plugins/rds-source/src/main/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManager.java +++ b/data-prepper-plugins/rds-source/src/main/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManager.java @@ -12,6 +12,13 @@ public class ConnectionManager { static final String JDBC_URL_FORMAT = "jdbc:mysql://%s:%d"; + static final String USERNAME_KEY = "user"; + static final String PASSWORD_KEY = "password"; + static final String USE_SSL_KEY = "useSSL"; + static final String REQUIRE_SSL_KEY = "requireSSL"; + static final String TINY_INT_ONE_IS_BIT_KEY = "tinyInt1isBit"; + static final String TRUE_VALUE = "true"; + static final String FALSE_VALUE = "false"; private final String hostName; private final int port; private final String username; @@ -28,14 +35,15 @@ public ConnectionManager(String hostName, int port, String username, String pass public Connection getConnection() throws SQLException { final Properties props = new Properties(); - props.setProperty("user", username); - props.setProperty("password", password); + props.setProperty(USERNAME_KEY, username); + props.setProperty(PASSWORD_KEY, password); if (requireSSL) { - props.setProperty("useSSL", "true"); - props.setProperty("requireSSL", "true"); + props.setProperty(USE_SSL_KEY, TRUE_VALUE); + props.setProperty(REQUIRE_SSL_KEY, TRUE_VALUE); } else { - props.setProperty("useSSL", "false"); + props.setProperty(USE_SSL_KEY, FALSE_VALUE); } + props.setProperty(TINY_INT_ONE_IS_BIT_KEY, FALSE_VALUE); final String jdbcUrl = String.format(JDBC_URL_FORMAT, hostName, port); return doGetConnection(jdbcUrl, props); } diff --git a/data-prepper-plugins/rds-source/src/test/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManagerTest.java b/data-prepper-plugins/rds-source/src/test/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManagerTest.java index 7705ac967b..83c93d91c3 100644 --- a/data-prepper-plugins/rds-source/src/test/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManagerTest.java +++ b/data-prepper-plugins/rds-source/src/test/java/org/opensearch/dataprepper/plugins/source/rds/schema/ConnectionManagerTest.java @@ -20,6 +20,13 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.FALSE_VALUE; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.PASSWORD_KEY; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.REQUIRE_SSL_KEY; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.TINY_INT_ONE_IS_BIT_KEY; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.TRUE_VALUE; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.USERNAME_KEY; +import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.USE_SSL_KEY; class ConnectionManagerTest { @@ -51,10 +58,11 @@ void test_getConnection_when_requireSSL_is_true() throws SQLException { assertThat(jdbcUrlArgumentCaptor.getValue(), is(String.format(ConnectionManager.JDBC_URL_FORMAT, hostName, port))); final Properties properties = propertiesArgumentCaptor.getValue(); - assertThat(properties.getProperty("user"), is(username)); - assertThat(properties.getProperty("password"), is(password)); - assertThat(properties.getProperty("useSSL"), is("true")); - assertThat(properties.getProperty("requireSSL"), is("true")); + assertThat(properties.getProperty(USERNAME_KEY), is(username)); + assertThat(properties.getProperty(PASSWORD_KEY), is(password)); + assertThat(properties.getProperty(USE_SSL_KEY), is(TRUE_VALUE)); + assertThat(properties.getProperty(REQUIRE_SSL_KEY), is(TRUE_VALUE)); + assertThat(properties.getProperty(TINY_INT_ONE_IS_BIT_KEY), is(FALSE_VALUE)); } @Test @@ -69,9 +77,10 @@ void test_getConnection_when_requireSSL_is_false() throws SQLException { assertThat(jdbcUrlArgumentCaptor.getValue(), is(String.format(ConnectionManager.JDBC_URL_FORMAT, hostName, port))); final Properties properties = propertiesArgumentCaptor.getValue(); - assertThat(properties.getProperty("user"), is(username)); - assertThat(properties.getProperty("password"), is(password)); - assertThat(properties.getProperty("useSSL"), is("false")); + assertThat(properties.getProperty(USERNAME_KEY), is(username)); + assertThat(properties.getProperty(PASSWORD_KEY), is(password)); + assertThat(properties.getProperty(USE_SSL_KEY), is(FALSE_VALUE)); + assertThat(properties.getProperty(TINY_INT_ONE_IS_BIT_KEY), is(FALSE_VALUE)); } private ConnectionManager createObjectUnderTest() {