BareMetalRemovalUpdater { public void updateConfigurationValuesThatReferenceBareMetal(final Connection conn) { logger.info("Updating configuration items that reference BareMetal and removing that reference"); final List<Map<String, String>> updatedRows = createUpdatedConfigurationItemValues(conn); if (!updatedRows.isEmpty()) { updateConfigurationItems(conn, updatedRows); } }  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_updateConfigurationValuesThatReferenceBareMetal_whenThereAreNoConfigurationItems() throws Exception { when(dbConnection.prepareStatement(BareMetalRemovalUpdater.SELECT_CONFIGURATION_ITEMS)).thenReturn(preparedStatement); when(preparedStatement.executeQuery()).thenReturn(values); when(values.next()).thenReturn(false); bareMetalRemovalUpdater.updateConfigurationValuesThatReferenceBareMetal(dbConnection); verify(preparedStatement, never()).executeUpdate(); }
@Test public void test_updateConfigurationValuesThatReferenceBareMetal_whenThereAreConfigurationItems() throws Exception { when(dbConnection.prepareStatement(BareMetalRemovalUpdater.SELECT_CONFIGURATION_ITEMS)).thenReturn(preparedStatement); when(dbConnection.prepareStatement(BareMetalRemovalUpdater.UPDATE_CONFIGURATION_ITEM)).thenReturn(preparedStatement); when(preparedStatement.executeQuery()).thenReturn(values); when(values.next()) .thenReturn(true) .thenReturn(true) .thenReturn(false); when(values.getString(BareMetalRemovalUpdater.VALUE)) .thenReturn("BAREMETAL,hypervisor_a") .thenReturn("hypervisor_b,baremetal"); when(values.getString(BareMetalRemovalUpdater.CATEGORY)) .thenReturn("someCategory") .thenReturn("anotherCategory"); when(values.getString(BareMetalRemovalUpdater.INSTANCE)) .thenReturn("someInstance") .thenReturn("anotherInstance"); when(values.getString(BareMetalRemovalUpdater.COMPONENT)) .thenReturn("someComponent") .thenReturn("anotherComponent"); when(values.getString(BareMetalRemovalUpdater.NAME)) .thenReturn("someName") .thenReturn("anotherName"); bareMetalRemovalUpdater.updateConfigurationValuesThatReferenceBareMetal(dbConnection); verify(preparedStatement, times(2)).executeUpdate(); }