@Test public void appendNewKeysToExistingAndWrite() throws Exception { final String pub1 = "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="; final String priv1 = "Wl+xSyXVuuqzpvznOS7dOobhcn4C5auxkFRi7yLtgtA="; final String pub2 = "eKSr3gAw5zPubOK96dw2qkZZmIT2HUBf8Zv001ubBC0="; final String priv2 = "9YabvoCKGD1sUkUgHak4XJzbtgdwEsF/jiarLoTHeR0="; final KeyData key1 = new KeyData(); key1.setPublicKey(pub1); key1.setPrivateKey(priv1); final KeyData key2 = new KeyData(); key2.setPublicKey(pub2); key2.setPrivateKey(priv2); final List<KeyData> newKeys = Collections.singletonList(key1); final List<KeyData> existingKeys = new ArrayList<>(Collections.singletonList(key2)); final Config config = JaxbUtil.unmarshal(getClass().getResourceAsStream("/sample_full.json"), Config.class); config.getKeys().setKeyData(existingKeys); config.getKeys().setPasswords(null); final Path configDest = mock(Path.class); final ByteArrayOutputStream out = new ByteArrayOutputStream(); when(filesDelegate.newOutputStream(configDest, CREATE_NEW)).thenReturn(out); writer.updateAndWrite(newKeys, null, config, configDest); verify(filesDelegate).newOutputStream(configDest, CREATE_NEW); final Config updated = JaxbUtil.unmarshal(new ByteArrayInputStream(out.toByteArray()), Config.class); assertThat(updated).isNotNull(); assertThat(updated.getKeys().getKeyData()).hasSize(2); assertThat(updated.getKeys().getKeyData()) .usingFieldByFieldElementComparator() .containsExactlyInAnyOrder(key1, key2); }
public void updateAndWrite( List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest) throws IOException { LOGGER.info("Writing updated config to {}", configDest); update(newKeys, keyVaultConfig, config); try (OutputStream out = filesDelegate.newOutputStream(configDest, CREATE_NEW)) { JaxbUtil.marshal(config, out); LOGGER.info("Updated config written to {}", configDest); } catch (Exception e) { LOGGER.info("Writing updated config failed, cleaning up: deleting {}", configDest); filesDelegate.deleteIfExists(configDest); throw e; } }
ConfigFileUpdaterWriter { public void updateAndWrite( List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest) throws IOException { LOGGER.info("Writing updated config to {}", configDest); update(newKeys, keyVaultConfig, config); try (OutputStream out = filesDelegate.newOutputStream(configDest, CREATE_NEW)) { JaxbUtil.marshal(config, out); LOGGER.info("Updated config written to {}", configDest); } catch (Exception e) { LOGGER.info("Writing updated config failed, cleaning up: deleting {}", configDest); filesDelegate.deleteIfExists(configDest); throw e; } } }
ConfigFileUpdaterWriter { public void updateAndWrite( List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest) throws IOException { LOGGER.info("Writing updated config to {}", configDest); update(newKeys, keyVaultConfig, config); try (OutputStream out = filesDelegate.newOutputStream(configDest, CREATE_NEW)) { JaxbUtil.marshal(config, out); LOGGER.info("Updated config written to {}", configDest); } catch (Exception e) { LOGGER.info("Writing updated config failed, cleaning up: deleting {}", configDest); filesDelegate.deleteIfExists(configDest); throw e; } } ConfigFileUpdaterWriter(FilesDelegate filesDelegate); }
ConfigFileUpdaterWriter { public void updateAndWrite( List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest) throws IOException { LOGGER.info("Writing updated config to {}", configDest); update(newKeys, keyVaultConfig, config); try (OutputStream out = filesDelegate.newOutputStream(configDest, CREATE_NEW)) { JaxbUtil.marshal(config, out); LOGGER.info("Updated config written to {}", configDest); } catch (Exception e) { LOGGER.info("Writing updated config failed, cleaning up: deleting {}", configDest); filesDelegate.deleteIfExists(configDest); throw e; } } ConfigFileUpdaterWriter(FilesDelegate filesDelegate); void updateAndWrite(
        List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest); void updateAndWriteToCLI(List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config); }
ConfigFileUpdaterWriter { public void updateAndWrite( List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest) throws IOException { LOGGER.info("Writing updated config to {}", configDest); update(newKeys, keyVaultConfig, config); try (OutputStream out = filesDelegate.newOutputStream(configDest, CREATE_NEW)) { JaxbUtil.marshal(config, out); LOGGER.info("Updated config written to {}", configDest); } catch (Exception e) { LOGGER.info("Writing updated config failed, cleaning up: deleting {}", configDest); filesDelegate.deleteIfExists(configDest); throw e; } } ConfigFileUpdaterWriter(FilesDelegate filesDelegate); void updateAndWrite(
        List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config, Path configDest); void updateAndWriteToCLI(List<KeyData> newKeys, KeyVaultConfig keyVaultConfig, Config config);  }