RelationalTableRegistrationHelper { public List<SchemaColumn> getSchemaColumns(final ResultSet resultSet) throws SQLException { List<SchemaColumn> schemaColumns = new ArrayList<>(); while (resultSet.next()) { SchemaColumn schemaColumn = new SchemaColumn(); schemaColumn.setName(resultSet.getString("COLUMN_NAME")); schemaColumn.setType(resultSet.getString("TYPE_NAME")); if (resultSet.getString("TYPE_NAME").equalsIgnoreCase("NUMERIC") && StringUtils.isNotEmpty(resultSet.getString("DECIMAL_DIGITS"))) { schemaColumn.setSize(resultSet.getString("COLUMN_SIZE") + "," + resultSet.getString("DECIMAL_DIGITS")); } else { schemaColumn.setSize(resultSet.getString("COLUMN_SIZE")); } schemaColumn.setRequired(resultSet.getInt("NULLABLE") == 0); schemaColumn.setDefaultValue(resultSet.getString("COLUMN_DEF")); schemaColumns.add(schemaColumn); } return schemaColumns; }  List<SchemaColumn> getSchemaColumns(final ResultSet resultSet);  }
@Test public void testGetSchemaColumns() throws SQLException { ResultSet resultSetMock = mock(ResultSet.class); when(resultSetMock.next()).thenReturn(true).thenReturn(false); when(resultSetMock.getString("COLUMN_NAME")).thenReturn(COLUMN_NAME); when(resultSetMock.getString("TYPE_NAME")).thenReturn(NUMERIC_TYPE_NAME); when(resultSetMock.getString("COLUMN_SIZE")).thenReturn(COLUMN_SIZE); when(resultSetMock.getString("DECIMAL_DIGITS")).thenReturn(DECIMAL_DIGITS); when(resultSetMock.getInt("NULLABLE")).thenReturn(NOT_NULLABLE); when(resultSetMock.getString("COLUMN_DEF")).thenReturn(COLUMN_DEFAULT_VALUE); List<SchemaColumn> schemaColumns = relationalTableRegistrationHelper.getSchemaColumns(resultSetMock); assertThat("The list size is not correct.", schemaColumns.size(), is(equalTo(1))); assertThat("The column name is not correct.", schemaColumns.get(0).getName(), is(equalTo(COLUMN_NAME))); assertThat("The column type is not correct.", schemaColumns.get(0).getType(), is(equalTo(NUMERIC_TYPE_NAME))); assertThat("The column size is not correct.", schemaColumns.get(0).getSize(), is(equalTo(SCHEMA_COLUMNS_SIZE))); assertThat("The required column is not correct.", schemaColumns.get(0).isRequired(), is(equalTo(REQUIRED))); assertThat("The column default value is not correct.", schemaColumns.get(0).getDefaultValue(), is(equalTo(COLUMN_DEFAULT_VALUE))); verify(resultSetMock, times(2)).next(); verify(resultSetMock).getString("COLUMN_NAME"); verify(resultSetMock, times(2)).getString("TYPE_NAME"); verify(resultSetMock).getString("COLUMN_SIZE"); verify(resultSetMock, times(2)).getString("DECIMAL_DIGITS"); verify(resultSetMock).getInt("NULLABLE"); verify(resultSetMock).getString("COLUMN_DEF"); verifyNoMoreInteractions(resultSetMock); }
@Test public void testGetSchemaColumnsNonNumeric() throws SQLException { ResultSet resultSetMock = mock(ResultSet.class); when(resultSetMock.next()).thenReturn(true).thenReturn(false); when(resultSetMock.getString("COLUMN_NAME")).thenReturn(COLUMN_NAME); when(resultSetMock.getString("TYPE_NAME")).thenReturn(VARCHAR_TYPE_NAME); when(resultSetMock.getString("COLUMN_SIZE")).thenReturn(COLUMN_SIZE); when(resultSetMock.getInt("NULLABLE")).thenReturn(NOT_NULLABLE); when(resultSetMock.getString("COLUMN_DEF")).thenReturn(COLUMN_DEFAULT_VALUE); List<SchemaColumn> schemaColumns = relationalTableRegistrationHelper.getSchemaColumns(resultSetMock); assertThat("The list size is not correct.", schemaColumns.size(), is(equalTo(1))); assertThat("The column name is not correct.", schemaColumns.get(0).getName(), is(equalTo(COLUMN_NAME))); assertThat("The column type is not correct.", schemaColumns.get(0).getType(), is(equalTo(VARCHAR_TYPE_NAME))); assertThat("The column size is not correct.", schemaColumns.get(0).getSize(), is(equalTo(COLUMN_SIZE))); assertThat("The required column is not correct.", schemaColumns.get(0).isRequired(), is(equalTo(REQUIRED))); assertThat("The column default value is not correct.", schemaColumns.get(0).getDefaultValue(), is(equalTo(COLUMN_DEFAULT_VALUE))); verify(resultSetMock, times(2)).next(); verify(resultSetMock).getString("COLUMN_NAME"); verify(resultSetMock, times(2)).getString("TYPE_NAME"); verify(resultSetMock).getString("COLUMN_SIZE"); verify(resultSetMock).getInt("NULLABLE"); verify(resultSetMock).getString("COLUMN_DEF"); verifyNoMoreInteractions(resultSetMock); }
@Test public void testGetSchemaColumnsNoDecimalDigits() throws SQLException { ResultSet resultSetMock = mock(ResultSet.class); when(resultSetMock.next()).thenReturn(true).thenReturn(false); when(resultSetMock.getString("COLUMN_NAME")).thenReturn(COLUMN_NAME); when(resultSetMock.getString("TYPE_NAME")).thenReturn(NUMERIC_TYPE_NAME); when(resultSetMock.getString("COLUMN_SIZE")).thenReturn(COLUMN_SIZE); when(resultSetMock.getInt("NULLABLE")).thenReturn(NOT_NULLABLE); when(resultSetMock.getString("COLUMN_DEF")).thenReturn(COLUMN_DEFAULT_VALUE); List<SchemaColumn> schemaColumns = relationalTableRegistrationHelper.getSchemaColumns(resultSetMock); assertThat("The list size is not correct.", schemaColumns.size(), is(equalTo(1))); assertThat("The column name is not correct.", schemaColumns.get(0).getName(), is(equalTo(COLUMN_NAME))); assertThat("The column type is not correct.", schemaColumns.get(0).getType(), is(equalTo(NUMERIC_TYPE_NAME))); assertThat("The column size is not correct.", schemaColumns.get(0).getSize(), is(equalTo(COLUMN_SIZE))); assertThat("The required column is not correct.", schemaColumns.get(0).isRequired(), is(equalTo(REQUIRED))); assertThat("The column default value is not correct.", schemaColumns.get(0).getDefaultValue(), is(equalTo(COLUMN_DEFAULT_VALUE))); verify(resultSetMock, times(2)).next(); verify(resultSetMock).getString("COLUMN_NAME"); verify(resultSetMock, times(2)).getString("TYPE_NAME"); verify(resultSetMock).getString("COLUMN_SIZE"); verify(resultSetMock).getString("DECIMAL_DIGITS"); verify(resultSetMock).getInt("NULLABLE"); verify(resultSetMock).getString("COLUMN_DEF"); verifyNoMoreInteractions(resultSetMock); }
@Test public void testGetSchemaColumnsEmptyDecimalDigits() throws SQLException { ResultSet resultSetMock = mock(ResultSet.class); when(resultSetMock.next()).thenReturn(true).thenReturn(false); when(resultSetMock.getString("COLUMN_NAME")).thenReturn(COLUMN_NAME); when(resultSetMock.getString("TYPE_NAME")).thenReturn(NUMERIC_TYPE_NAME); when(resultSetMock.getString("COLUMN_SIZE")).thenReturn(COLUMN_SIZE); when(resultSetMock.getString("DECIMAL_DIGITS")).thenReturn(EMPTY_STRING); when(resultSetMock.getInt("NULLABLE")).thenReturn(NOT_NULLABLE); when(resultSetMock.getString("COLUMN_DEF")).thenReturn(COLUMN_DEFAULT_VALUE); List<SchemaColumn> schemaColumns = relationalTableRegistrationHelper.getSchemaColumns(resultSetMock); assertThat("The list size is not correct.", schemaColumns.size(), is(equalTo(1))); assertThat("The column name is not correct.", schemaColumns.get(0).getName(), is(equalTo(COLUMN_NAME))); assertThat("The column type is not correct.", schemaColumns.get(0).getType(), is(equalTo(NUMERIC_TYPE_NAME))); assertThat("The column size is not correct.", schemaColumns.get(0).getSize(), is(equalTo(COLUMN_SIZE))); assertThat("The required column is not correct.", schemaColumns.get(0).isRequired(), is(equalTo(REQUIRED))); assertThat("The column default value is not correct.", schemaColumns.get(0).getDefaultValue(), is(equalTo(COLUMN_DEFAULT_VALUE))); verify(resultSetMock, times(2)).next(); verify(resultSetMock).getString("COLUMN_NAME"); verify(resultSetMock, times(2)).getString("TYPE_NAME"); verify(resultSetMock).getString("COLUMN_SIZE"); verify(resultSetMock).getString("DECIMAL_DIGITS"); verify(resultSetMock).getInt("NULLABLE"); verify(resultSetMock).getString("COLUMN_DEF"); verifyNoMoreInteractions(resultSetMock); }