@Test public void chekGetAllRowsWithEmptyParam() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals( new ArrayList<String>(), sqlSourceHelper.getAllRows(new ArrayList<List<Object>>())); }
@Test public void checkStatusFileCorrectlyCreated() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); // sqlSourceHelper.setCurrentIndex(10); sqlSourceHelper.updateStatusFile(); File file = new File("/tmp/flume/statusFileName.txt"); assertEquals(true, file.exists()); if (file.exists()) { file.delete(); file.getParentFile().delete(); } }
@Test public void checkStatusFileCorrectlyUpdated() throws Exception { File file = File.createTempFile("statusFileName", ".txt"); when(context.getString("status.file.path", "/var/lib/flume")).thenReturn(file.getParent()); when(context.getString("status.file.name")).thenReturn(file.getName()); SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); sqlSourceHelper.setCurrentIndex(10); sqlSourceHelper.updateStatusFile(); SQLSourceHelper sqlSourceHelper2 = new SQLSourceHelper(context, "Source Name"); assertEquals(10L, sqlSourceHelper2.getCurrentIndex()); }
@SuppressWarnings("deprecation") @Test public void chekGetAllRows() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); List<List<Object>> queryResult = new ArrayList<List<Object>>(2); List<String[]> expectedResult = new ArrayList<String[]>(2); String string1 = "string1"; String string2 = "string2"; int int1 = 1; int int2 = 2; Date date1 = new Date(115, 0, 1); Date date2 = new Date(115, 1, 2); List<Object> row1 = new ArrayList<Object>(3); String[] expectedRow1 = new String[3]; row1.add(string1); expectedRow1[0] = string1; row1.add(int1); expectedRow1[1] = Integer.toString(int1); row1.add(date1); expectedRow1[2] = date1.toString(); queryResult.add(row1); expectedResult.add(expectedRow1); List<Object> row2 = new ArrayList<Object>(3); String[] expectedRow2 = new String[3]; row2.add(string2); expectedRow2[0] = string2; row2.add(int2); expectedRow2[1] = Integer.toString(int2); row2.add(date2); expectedRow2[2] = date2.toString(); queryResult.add(row2); expectedResult.add(expectedRow2); assertArrayEquals(expectedResult.get(0), sqlSourceHelper.getAllRows(queryResult).get(0)); assertArrayEquals(expectedResult.get(1), sqlSourceHelper.getAllRows(queryResult).get(1)); }
@Test public void getCustomQuery() { when(context.getString("custom.query")).thenReturn("SELECT column FROM table"); SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals("SELECT column FROM table", sqlSourceHelper.getQuery()); }
@Test public void getQuery() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals("SELECT * FROM table", sqlSourceHelper.getQuery()); }
@Test public void getBatchSize() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals(100, sqlSourceHelper.getBatchSize()); }
@Test public void getRunQueryDelay() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals(10000, sqlSourceHelper.getRunQueryDelay()); }
@Test public void getPassword() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals("password", sqlSourceHelper.getPassword()); }
@Test public void getUser() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals("user", sqlSourceHelper.getUser()); }
@Test public void setCurrentIndex() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); sqlSourceHelper.setCurrentIndex(10); assertEquals(10, sqlSourceHelper.getCurrentIndex()); }
@Test public void getConnectionURL() { SQLSourceHelper sqlSourceHelper = new SQLSourceHelper(context, "Source Name"); assertEquals("jdbc:mysql://host:3306/database", sqlSourceHelper.getConnectionURL()); }