src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java in embulk-output-oracle-0.6.4 vs src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java in embulk-output-oracle-0.6.5

- old
+ new

@@ -21,21 +21,18 @@ import org.embulk.exec.PartialExecutionException; import org.embulk.input.filesplit.LocalFileSplitInputPlugin; import org.embulk.output.AbstractJdbcOutputPluginTest; import org.embulk.output.OracleOutputPlugin; -import org.embulk.output.tester.EmbulkPluginTester; import org.embulk.spi.InputPlugin; import org.embulk.spi.OutputPlugin; import org.junit.BeforeClass; import org.junit.Test; public class OracleOutputPluginTest extends AbstractJdbcOutputPluginTest { - private static boolean canTest; - private static EmbulkPluginTester tester = new EmbulkPluginTester(); static { tester.addPlugin(OutputPlugin.class, "oracle", OracleOutputPlugin.class); tester.addPlugin(InputPlugin.class, "filesplit", LocalFileSplitInputPlugin.class); } @@ -55,11 +52,11 @@ } try (Connection connection = new OracleOutputPluginTest().connect()) { String version = connection.getMetaData().getDriverVersion(); System.out.println("Driver version = " + version); - canTest = true; + enabled = true; } catch (SQLException e) { System.err.println(e); System.err.println("Warning: prepare a schema on Oracle 12c (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw', charset = UTF-8)."); // for example @@ -69,196 +66,156 @@ } @Test public void testInsert() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-insert.yml"); + test("/oracle/yml/test-insert.yml"); assertTable(table); } @Test public void testInsertCreate() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); - run("/oracle/yml/test-insert.yml"); + test("/oracle/yml/test-insert.yml"); assertGeneratedTable1(table); } @Test public void testInsertEmpty() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); new File(convertPath("/oracle/data/"), "test2").mkdir(); - run("/oracle/yml/test-insert-empty.yml"); + test("/oracle/yml/test-insert-empty.yml"); assertTableEmpty(table); } @Test public void testTruncateInsert() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); insertRecord(table); - run("/oracle/yml/test-truncate-insert.yml"); + test("/oracle/yml/test-truncate-insert.yml"); assertTable(table); } @Test public void testTruncateInsertOCIMethod() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); insertRecord(table); - run("/oracle/yml/test-truncate-insert-oci-method.yml"); + test("/oracle/yml/test-truncate-insert-oci-method.yml"); assertTable(table); } @Test public void testTruncateInsertCreate() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); - run("/oracle/yml/test-truncate-insert.yml"); + test("/oracle/yml/test-truncate-insert.yml"); assertGeneratedTable1(table); } @Test public void testInsertDirect() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-insert-direct.yml"); + test("/oracle/yml/test-insert-direct.yml"); assertTable(table); } @Test public void testInsertDirectDuplicate() throws Exception { - if (!canTest) { + if (!enabled) { return; } String table = "TEST1"; dropTable(table); createTable(table); insertRecord(table, "A002"); try { - run("/oracle/yml/test-insert-direct.yml"); + test("/oracle/yml/test-insert-direct.yml"); fail("Exception expected."); } catch (Exception e) { System.out.println(e); } } @Test public void testInsertDirectEmpty() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); new File(convertPath("/oracle/data/"), "test2").mkdir(); - run("/oracle/yml/test-insert-direct-empty.yml"); + test("/oracle/yml/test-insert-direct-empty.yml"); assertTableEmpty(table); } @Test public void testInsertDirectCreate() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); - run("/oracle/yml/test-insert-direct.yml"); + test("/oracle/yml/test-insert-direct.yml"); assertGeneratedTable1(table); } @Test public void testInsertDirectDirectMethod() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); try { - run("/oracle/yml/test-insert-direct-direct-method.yml"); + test("/oracle/yml/test-insert-direct-direct-method.yml"); } catch (PartialExecutionException e) { if (e.getCause() != null && e.getCause().getClass().equals(RuntimeException.class) && e.getCause().getCause() != null && e.getCause().getCause().getClass().equals(AssertionError.class)) { // ignore error e.printStackTrace(); @@ -272,37 +229,33 @@ } @Test public void testInsertDirectOCIMethod() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-insert-direct-oci-method.yml"); + test("/oracle/yml/test-insert-direct-oci-method.yml"); assertTable(table); } @Test public void testInsertDirectOCIMethodLarge() throws Exception { - if (!canTest) { + if (!enabled) { return; } String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-insert-direct-oci-method-large.yml"); + test("/oracle/yml/test-insert-direct-oci-method-large.yml"); List<List<Object>> rows = select(table); assertEquals(9999, rows.size()); for (int i = 0; i < rows.size(); i++) { assertEquals(String.format("%04d", i + 1), rows.get(i).get(0)); @@ -310,263 +263,211 @@ } @Test public void testInsertDirectOCIMethodDuplicate() throws Exception { - if (!canTest) { + if (!enabled) { return; } String table = "TEST1"; dropTable(table); createTable(table); insertRecord(table, "A002"); try { - run("/oracle/yml/test-insert-direct-oci-method.yml"); + test("/oracle/yml/test-insert-direct-oci-method.yml"); fail("Exception expected."); } catch (Exception e) { System.out.println(e); } } @Test public void testInsertDirectOCIMethodMultibyte() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-insert-direct-oci-method-multibyte.yml"); + test("/oracle/yml/test-insert-direct-oci-method-multibyte.yml"); assertTable(table); } @Test public void testInsertDirectOCIMethodMultibyteDuplicate() throws Exception { - if (!canTest) { + if (!enabled) { return; } String table = "TEST1"; dropTable(table); createTable(table); insertRecord(table, "A002"); try { - run("/oracle/yml/test-insert-direct-oci-method-multibyte.yml"); + test("/oracle/yml/test-insert-direct-oci-method-multibyte.yml"); fail("Exception expected."); } catch (Exception e) { System.out.println(e); } } @Test public void testInsertDirectOCIMethodSplit() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-insert-direct-oci-method-split.yml"); + test("/oracle/yml/test-insert-direct-oci-method-split.yml"); assertTable(table); } @Test public void testUrl() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-url.yml"); + test("/oracle/yml/test-url.yml"); assertTable(table); } @Test public void testLowerTable() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-lower-table.yml"); + test("/oracle/yml/test-lower-table.yml"); assertTable(table); } @Test public void testLowerColumn() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-lower-column.yml"); + test("/oracle/yml/test-lower-column.yml"); assertTable(table); } @Test public void testLowerColumnOptions() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-lower-column-options.yml"); + test("/oracle/yml/test-lower-column-options.yml"); assertTable(table); } @Test public void testReplace() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-replace.yml"); + test("/oracle/yml/test-replace.yml"); assertGeneratedTable2(table); } @Test public void testReplaceOCIMethod() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-replace-oci-method.yml"); + test("/oracle/yml/test-replace-oci-method.yml"); assertGeneratedTable2(table); } @Test public void testReplaceEmpty() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-replace-empty.yml"); + test("/oracle/yml/test-replace-empty.yml"); assertTableEmpty(table); } @Test public void testReplaceCreate() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); - run("/oracle/yml/test-replace.yml"); + test("/oracle/yml/test-replace.yml"); assertGeneratedTable2(table); } @Test public void testReplaceLongName() throws Exception { - if (!canTest) { - return; - } - String table = "TEST12345678901234567890123456"; dropTable(table); createTable(table); - run("/oracle/yml/test-replace-long-name.yml"); + test("/oracle/yml/test-replace-long-name.yml"); assertGeneratedTable2(table); } @Test public void testReplaceLongNameMultibyte() throws Exception { - if (!canTest) { - return; - } - String table = "TEST123456789012345678"; - run("/oracle/yml/test-replace-long-name-multibyte.yml"); + test("/oracle/yml/test-replace-long-name-multibyte.yml"); assertGeneratedTable2(table); } @Test public void testStringTimestamp() throws Exception { - if (!canTest) { - return; - } - String table = "TEST1"; dropTable(table); createTable(table); - run("/oracle/yml/test-string-timestamp.yml"); + test("/oracle/yml/test-string-timestamp.yml"); assertTable(table); } private void createTable(String table) throws SQLException @@ -593,10 +494,14 @@ executeSQL(String.format("INSERT INTO %s VALUES('%s', NULL, NULL, NULL, NULL, NULL, NULL)", table, id)); } private void assertTable(String table) throws Exception { + if (!enabled) { + return; + } + // datetime of UTC will be inserted by embulk. // datetime of default timezone will be selected by JDBC. TimeZone timeZone = TimeZone.getDefault(); List<List<Object>> rows = select(table); @@ -640,16 +545,24 @@ } } private void assertTableEmpty(String table) throws Exception { + if (!enabled) { + return; + } + List<List<Object>> rows = select(table); assertEquals(0, rows.size()); } private void assertGeneratedTable1(String table) throws Exception { + if (!enabled) { + return; + } + // datetime of UTC will be inserted by embulk. // datetime of default timezone will be selected by JDBC. TimeZone timeZone = TimeZone.getDefault(); List<List<Object>> rows = select(table); @@ -693,10 +606,14 @@ } } private void assertGeneratedTable2(String table) throws Exception { + if (!enabled) { + return; + } + // datetime of UTC will be inserted by embulk. // datetime of default timezone will be selected by JDBC. TimeZone timeZone = TimeZone.getDefault(); List<List<Object>> rows = select(table); @@ -774,13 +691,8 @@ @Override protected Connection connect() throws SQLException { return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TESTDB", "TEST_USER", "test_pw"); - } - - private void run(String ymlName) throws Exception - { - tester.run(convertYml(ymlName)); } }