MockResultSet rs = new MockResultSet("myMock"); rs.addColumn("columnA", new Integer[]{1}); rs.addColumn("columnB", new String[]{"Column B Value"}); rs.addColumn("columnC", new Double[]{2}); // make sure to move the cursor to the first row try { rs.next(); } catch (SQLException sqle) { fail("unable to move resultSet"); } // process the result set MyObject obj = processor.processResultSet(rs); // run your tests using the ResultSet like you normally would assertEquals(1, obj.getColumnAValue()); assertEquals("Column B Value", obj.getColumnBValue()); assertEquals(2.0d, obj.getColumnCValue());
/** * Build a mock implementation of Result using Mockito */ private ResultSet buildMockResultSet() { MockResultSet mrs = new MockResultSet(StringUtils.EMPTY); for (MockJdbcColumn column : COLUMNS) { mrs.addColumn(column.getColumnName(), ImmutableList.of(column.getValue())); } return mrs; } }
/** * Build a mock implementation of Result using Mockito */ private ResultSet buildMockResultSet() throws Exception { MockResultSet mrs = new MockResultSet(StringUtils.EMPTY); for (MockJdbcColumn column : COLUMNS) { mrs.addColumn(column.getColumnName(), ImmutableList.of(column.getValue())); } return mrs; } }
private ResultSet buildMockResultSet() throws Exception { MockResultSet mrs = new MockResultSet(StringUtils.EMPTY); for (MockJdbcColumn column : COLUMNS) { mrs.addColumn(column.getColumnName(), ImmutableList.of(column.getValue())); } return mrs; }
private void configureMetadata() throws SQLException { ((MockDatabaseMetaData) cx.getMetaData()).setSearchStringEscape(""); MockResultSet tableTypes = new MockResultSet("TABLE_TYPES"); tableTypes.addColumn("TABLE_TYPE"); tableTypes.addRow(new Object[] {"TABLE"}); ((MockDatabaseMetaData) cx.getMetaData()).setTableTypes(tableTypes); MockResultSet tables = new MockResultSet("TABLES"); tables.addColumn("TABLE_SCHEM"); tables.addColumn("TABLE_NAME"); tables.addRow(new Object[] {"", SAMPLE_FEATURE_NAME}); ((MockDatabaseMetaData) cx.getMetaData()).setTables(tables); MockResultSet key = new MockResultSet("KEY"); key.addColumn("COLUMN_NAME"); key.addColumn("DATA_TYPE"); key.addRow(new Object[] {"ID", 1}); ((MockDatabaseMetaData) cx.getMetaData()) .setPrimaryKeys(null, null, SAMPLE_FEATURE_NAME, key); MockResultSet columns = new MockResultSet("COLUMNS"); columns.addColumn("COLUMN_NAME"); columns.addColumn("DATA_TYPE"); columns.addRow(new Object[] {"ID", 1}); ((MockDatabaseMetaData) cx.getMetaData()) .setColumns(null, null, SAMPLE_FEATURE_NAME, "ID", columns); }
/** * Adds a column to the simulated database table. * The column will get the specified name. * No data will be stored in the column. * @param columnName the column name */ public void addColumn(String columnName) { addColumn(columnName, new ArrayList()); }
/** * Adds a column to the simulated database table. * The column will get the specified name. * No data will be stored in the column. * @param columnName the column name */ public void addColumn(String columnName) { addColumn(columnName, new ArrayList()); }
/** * Adds a column to the simulated database table. * The column will get the specified name. * No data will be stored in the column. * @param columnName the column name */ public void addColumn(String columnName) { addColumn(columnName, new ArrayList<Object>()); }
/** * Adds a column to the simulated database table. * The column will get the specified name. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param columnName the column name * @param values the column data as array, the array index * corresponds to the row index, i.e. * values[0] will be stored in the first row * and so on */ public void addColumn(String columnName, Object[] values) { List columnValues = Arrays.asList(values); addColumn(columnName, columnValues); }
public void addColumns(Set<String> cols) throws Exception { if(columnMap.keySet().size() > 0) { throw new Exception("resultSet already has column"); } for(String col : cols) { addColumn(col); } }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. The first added column * will have the name <i>Column1</i>. No data will be stored * in the column. */ public void addColumn() { addColumn(determineValidColumnName()); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. The first added column * will have the name <i>Column1</i>. No data will be stored * in the column. */ public void addColumn() { addColumn(determineValidColumnName()); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. The first added column * will have the name <i>Column1</i>. No data will be stored * in the column. */ public void addColumn() { addColumn(determineValidColumnName()); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param values the column data as <code>List</code>, the index * in the <code>List</code> corresponds to the row * index, i.e. values.get(0) will be stored in the first * row and so on */ public void addColumn(List values) { addColumn(determineValidColumnName(), values); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param values the column data as array, the array index * corresponds to the row index, i.e. * values[0] will be stored in the first row * and so on */ public void addColumn(Object[] values) { addColumn(determineValidColumnName(), values); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param values the column data as <code>List</code>, the index * in the <code>List</code> corresponds to the row * index, i.e. values.get(0) will be stored in the first * row and so on */ public void addColumn(List<Object> values) { addColumn(determineValidColumnName(), values); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param values the column data as <code>List</code>, the index * in the <code>List</code> corresponds to the row * index, i.e. values.get(0) will be stored in the first * row and so on */ public void addColumn(List values) { addColumn(determineValidColumnName(), values); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param values the column data as array, the array index * corresponds to the row index, i.e. * values[0] will be stored in the first row * and so on */ public void addColumn(Object[] values) { addColumn(determineValidColumnName(), values); }
/** * Adds a column to the simulated database table. * The column will get the name <i>ColumnX</i> where * <i>X</i> is the column index. * The specified data will be stored in the new column. If there * are other columns with not enough rows, the other * columns will be extended and filled with <code>null</code> * values. * @param values the column data as array, the array index * corresponds to the row index, i.e. * values[0] will be stored in the first row * and so on */ public void addColumn(Object[] values) { addColumn(determineValidColumnName(), values); }