Search in sources :

Example 1 with MySqlWriterCommands

use of org.apache.gobblin.writer.commands.MySqlWriterCommands in project incubator-gobblin by apache.

the class JdbcWriterCommandsTest method testMySqlDateTypeRetrieval.

@Test
public void testMySqlDateTypeRetrieval() throws SQLException {
    Connection conn = mock(Connection.class);
    PreparedStatement pstmt = mock(PreparedStatement.class);
    when(conn.prepareStatement(any(String.class))).thenReturn(pstmt);
    ResultSet rs = createMockResultSet();
    when(pstmt.executeQuery()).thenReturn(rs);
    MySqlWriterCommands writerCommands = new MySqlWriterCommands(new State(), conn);
    Map<String, JdbcType> actual = writerCommands.retrieveDateColumns("db", "users");
    ImmutableMap.Builder<String, JdbcType> builder = ImmutableMap.builder();
    builder.put("date_of_birth", JdbcType.DATE);
    builder.put("last_modified", JdbcType.TIME);
    builder.put("created", JdbcType.TIMESTAMP);
    Map<String, JdbcType> expected = builder.build();
    Assert.assertEquals(expected, actual);
}
Also used : State(org.apache.gobblin.configuration.State) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JdbcType(org.apache.gobblin.converter.jdbc.JdbcType) PreparedStatement(java.sql.PreparedStatement) MySqlWriterCommands(org.apache.gobblin.writer.commands.MySqlWriterCommands) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.testng.annotations.Test)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 State (org.apache.gobblin.configuration.State)1 JdbcType (org.apache.gobblin.converter.jdbc.JdbcType)1 MySqlWriterCommands (org.apache.gobblin.writer.commands.MySqlWriterCommands)1 Test (org.testng.annotations.Test)1