BareMetalRemovalUpdater { public void findAndUpdateRowsThatReferenceBareMetal(final ResultSet values, final List<Map<String, String>> updatedRows) throws SQLException { while (values.next()) { final String value = values.getString(VALUE); if (value != null && hasReferenceToBareMetal(value)) { final String category = values.getString(CATEGORY); final String instance = values.getString(INSTANCE); final String component = values.getString(COMPONENT); final String name = values.getString(NAME); logger.info("Found one configuration item that references BareMetal: " + printConfigurationItem(category, instance, component, name, value)); final HashMap<String, String> updatedRow = createUpdatedRow(category, instance, component, name, createUpdatedValue(value)); updatedRows.add(updatedRow); } } }  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_findAndUpdateRowsThatReferenceBareMetal_whenThereIsOneRowThatReferencesBareMetal() throws Exception { when(values.next()) .thenReturn(true) .thenReturn(true) .thenReturn(false); when(values.getString(BareMetalRemovalUpdater.VALUE)) .thenReturn("someValue") .thenReturn("hypervisor_a,baremetal"); when(values.getString(BareMetalRemovalUpdater.CATEGORY)) .thenReturn("someCategory"); when(values.getString(BareMetalRemovalUpdater.INSTANCE)) .thenReturn("someInstance"); when(values.getString(BareMetalRemovalUpdater.COMPONENT)) .thenReturn("someComponent"); when(values.getString(BareMetalRemovalUpdater.NAME)) .thenReturn("someName"); final List<Map<String, String>> updatedRows = new ArrayList<>(); bareMetalRemovalUpdater.findAndUpdateRowsThatReferenceBareMetal(values, updatedRows); assertThat(updatedRows, hasSize(1)); assertThat(updatedRows, contains( allOf( hasEntry(BareMetalRemovalUpdater.VALUE, "hypervisor_a"), hasEntry(BareMetalRemovalUpdater.CATEGORY, "someCategory"), hasEntry(BareMetalRemovalUpdater.INSTANCE, "someInstance"), hasEntry(BareMetalRemovalUpdater.COMPONENT, "someComponent"), hasEntry(BareMetalRemovalUpdater.NAME, "someName") ) )); }
@Test public void test_findAndUpdateRowsThatReferenceBareMetal_whenThereAreTwoRowsThatReferencesBareMetal() throws Exception { when(values.next()) .thenReturn(true) .thenReturn(true) .thenReturn(true) .thenReturn(false); when(values.getString(BareMetalRemovalUpdater.VALUE)) .thenReturn("BAREMETAL,hypervisor_a") .thenReturn("someValue") .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"); final List<Map<String, String>> updatedRows = new ArrayList<>(); bareMetalRemovalUpdater.findAndUpdateRowsThatReferenceBareMetal(values, updatedRows); assertThat(updatedRows, hasSize(2)); assertThat(updatedRows, contains( allOf( hasEntry(BareMetalRemovalUpdater.VALUE, "hypervisor_a"), hasEntry(BareMetalRemovalUpdater.CATEGORY, "someCategory"), hasEntry(BareMetalRemovalUpdater.INSTANCE, "someInstance"), hasEntry(BareMetalRemovalUpdater.COMPONENT, "someComponent"), hasEntry(BareMetalRemovalUpdater.NAME, "someName") ), allOf( hasEntry(BareMetalRemovalUpdater.VALUE, "hypervisor_b"), hasEntry(BareMetalRemovalUpdater.CATEGORY, "anotherCategory"), hasEntry(BareMetalRemovalUpdater.INSTANCE, "anotherInstance"), hasEntry(BareMetalRemovalUpdater.COMPONENT, "anotherComponent"), hasEntry(BareMetalRemovalUpdater.NAME, "anotherName") ) )); }
@Test public void test_findAndUpdateRowsThatReferenceBareMetal_whenThereAreNoRows() throws Exception { when(values.next()).thenReturn(false); final List<Map<String, String>> updatedRows = new ArrayList<>(); bareMetalRemovalUpdater.findAndUpdateRowsThatReferenceBareMetal(values, updatedRows); assertThat(updatedRows, hasSize(0)); }
@Test public void test_findAndUpdateRowsThatReferenceBareMetal_whenThereIsOneRowThatDoesNotReferenceBareMetal() throws Exception { when(values.next()) .thenReturn(true) .thenReturn(false); when(values.getString(BareMetalRemovalUpdater.VALUE)).thenReturn("someValue"); final List<Map<String, String>> updatedRows = new ArrayList<>(); bareMetalRemovalUpdater.findAndUpdateRowsThatReferenceBareMetal(values, updatedRows); assertThat(updatedRows, hasSize(0)); }