BareMetalRemovalUpdater { public void updateConfigurationItems(final Connection conn, final List<Map<String, String>> updatedRows) { for (final Map<String, String> row : updatedRows) { final String category = row.get(CATEGORY); final String instance = row.get(INSTANCE); final String component = row.get(COMPONENT); final String name = row.get(NAME); final String value = row.get(VALUE); logger.info("Updating configuration item: " + printConfigurationItem(category, instance, component, name, value)); updateConfigurationItem(conn, category, instance, component, name, value); } }  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_updateConfigurationItems_whenThereAreNoUpdates() throws Exception { bareMetalRemovalUpdater.updateConfigurationItems(dbConnection, Collections.<Map<String, String>>emptyList()); verify(dbConnection, never()).prepareStatement(anyString()); }
@Test public void test_updateConfigurationItems_whenThereIsOneUpdate() throws Exception { when(dbConnection.prepareStatement(BareMetalRemovalUpdater.UPDATE_CONFIGURATION_ITEM)).thenReturn(preparedStatement); final List<Map<String, String>> updatedRows = new ArrayList<>(); final HashMap<String, String> updatedRow = new HashMap<>(); updatedRow.put(BareMetalRemovalUpdater.VALUE, "hypervisor_a"); updatedRow.put(BareMetalRemovalUpdater.CATEGORY, "someCategory"); updatedRow.put(BareMetalRemovalUpdater.INSTANCE, "someInstance"); updatedRow.put(BareMetalRemovalUpdater.COMPONENT, "someComponent"); updatedRow.put(BareMetalRemovalUpdater.NAME, "someName"); updatedRows.add(updatedRow); bareMetalRemovalUpdater.updateConfigurationItems(dbConnection, updatedRows); verify(preparedStatement, times(5)).setString(anyInt(), anyString()); verify(preparedStatement, times(1)).executeUpdate(); }
@Test public void test_updateConfigurationItems_whenThereAreTwoUpdates() throws Exception { when(dbConnection.prepareStatement(BareMetalRemovalUpdater.UPDATE_CONFIGURATION_ITEM)).thenReturn(preparedStatement); final List<Map<String, String>> updatedRows = new ArrayList<>(); final HashMap<String, String> updatedRow1 = new HashMap<>(); updatedRow1.put(BareMetalRemovalUpdater.VALUE, "hypervisor_a"); updatedRow1.put(BareMetalRemovalUpdater.CATEGORY, "someCategory"); updatedRow1.put(BareMetalRemovalUpdater.INSTANCE, "someInstance"); updatedRow1.put(BareMetalRemovalUpdater.COMPONENT, "someComponent"); updatedRow1.put(BareMetalRemovalUpdater.NAME, "someName"); final HashMap<String, String> updatedRow2 = new HashMap<>(); updatedRow1.put(BareMetalRemovalUpdater.VALUE, "hypervisor_b"); updatedRow1.put(BareMetalRemovalUpdater.CATEGORY, "anotherCategory"); updatedRow1.put(BareMetalRemovalUpdater.INSTANCE, "anotherInstance"); updatedRow1.put(BareMetalRemovalUpdater.COMPONENT, "anotherCmponent"); updatedRow1.put(BareMetalRemovalUpdater.NAME, "anotherName"); updatedRows.add(updatedRow1); updatedRows.add(updatedRow2); bareMetalRemovalUpdater.updateConfigurationItems(dbConnection, updatedRows); verify(preparedStatement, times(10)).setString(anyInt(), anyString()); verify(preparedStatement, times(2)).executeUpdate(); }