private void executeAndCheckForOutputFile( final Executable<?> executable, final String outputFilename) throws Exception { executable.execute(testUtility.getDataSource()); final File outputFile = new File(outputFilename); assertTrue(outputFile.exists()); assertTrue(outputFile.length() > 0); if (!outputFile.delete()) { fail("Cannot delete output file"); } }
@Test public void columns() throws SQLException { final String[] columnNames = { "PUBLIC.CUSTOMER.FIRSTNAME", "PUBLIC.CUSTOMER.LASTNAME", "ADDRESS", "", }; final String[] columnDataTypes = { "VARCHAR", "VARCHAR", "VARCHAR", "DOUBLE", }; final String sql = "SELECT " + " CUSTOMER.FIRSTNAME, " + " CUSTOMER.LASTNAME, " + " CUSTOMER.STREET + ', ' + CUSTOMER.CITY AS ADDRESS, " + " SUM(INVOICE.TOTAL) " + "FROM " + " CUSTOMER " + " INNER JOIN INVOICE " + " ON INVOICE.CUSTOMERID = CUSTOMER.ID " + "GROUP BY " + " CUSTOMER.FIRSTNAME, " + " CUSTOMER.LASTNAME, " + " CUSTOMER.STREET, " + " CUSTOMER.CITY " + "ORDER BY " + " SUM(INVOICE.TOTAL) DESC"; final Connection connection = testUtility.getDataSource().getConnection(); final Statement statement = connection.createStatement(); final ResultSet resultSet = statement.executeQuery(sql); final ResultsColumns resultColumns = DatabaseSchemaCrawler.getResultColumns(resultSet); connection.close(); assertNotNull("Could not obtain result columns", resultColumns); final ResultsColumn[] columns = resultColumns.getColumns(); assertEquals("Column count does not match", 4, columns.length); for (int columnIdx = 0; columnIdx < columns.length; columnIdx++) { final ResultsColumn column = columns[columnIdx]; LOGGER.log(Level.FINE, column.toString()); assertEquals("Column full name does not match", columnNames[columnIdx], column.getFullName()); assertEquals( "Column type does not match", columnDataTypes[columnIdx], column.getType().getDatabaseSpecificTypeName()); assertEquals( "Column JDBC type does not match", columnDataTypes[columnIdx], column.getType().getTypeName()); } }