BareMetalRemovalUpdater { public void updateConfigurationItem(final Connection conn, final String category, final String instance, final String component, final String name, final String value) { try (PreparedStatement preparedStatement = conn.prepareStatement(UPDATE_CONFIGURATION_ITEM)) { preparedStatement.setString(1, value); preparedStatement.setString(2, category); preparedStatement.setString(3, instance); preparedStatement.setString(4, component); preparedStatement.setString(5, name); preparedStatement.executeUpdate(); } catch (final SQLException e) { logger.error("Caught exception while updating values: " + e.getMessage()); throw new CloudRuntimeException(e); } }  void updateConfigurationValuesThatReferenceBareMetal(final Connection conn); List<Map<String, String>> createUpdatedConfigurationItemValues(final Connection conn); void updateConfigurationItems(final Connection conn, final List<Map<String, String>> updatedRows); void updateConfigurationItem(final Connection conn, final String category, final String instance, final String component, final String name, final String value); void findAndUpdateRowsThatReferenceBareMetal(final ResultSet values, final List<Map<String, String>> updatedRows); String createUpdatedValue(final String value); boolean hasReferenceToBareMetal(final String value); static final String VALUE; static final String CATEGORY; static final String INSTANCE; static final String COMPONENT; static final String NAME; static final String SELECT_CONFIGURATION_ITEMS; static final String UPDATE_CONFIGURATION_ITEM; }
@Test public void test_updateConfigurationItem_whenThereIsNoException() throws Exception { when(dbConnection.prepareStatement(BareMetalRemovalUpdater.UPDATE_CONFIGURATION_ITEM)).thenReturn(preparedStatement); bareMetalRemovalUpdater.updateConfigurationItem(dbConnection, "someCategory", "someInstance", "someComponent", "someName", "someValue"); verify(preparedStatement, times(5)).setString(anyInt(), anyString()); verify(preparedStatement, times(1)).executeUpdate(); }
@Test(expected = CloudRuntimeException.class) public void test_updateConfigurationItem_whenThereAnException() throws Exception { when(dbConnection.prepareStatement(BareMetalRemovalUpdater.UPDATE_CONFIGURATION_ITEM)).thenReturn(preparedStatement); when(preparedStatement.executeUpdate()).thenThrow(SQLException.class); bareMetalRemovalUpdater.updateConfigurationItem(dbConnection, "someCategory", "someInstance", "someComponent", "someName", "someValue"); verify(preparedStatement, times(5)).setString(anyInt(), anyString()); }