AssetIdMigrationStep implements MigrationStep<A> { @Override public void migrate(A artifact) { for (Asset asset : artifact.getAssets()) { if (asset.getId() == null) { asset.setId(UUID.randomUUID().toString()); logger.info(format("[MIGRATION] A uuid <%s> has been added to asset <%s> (Id was introduced in 1.0.2)", asset.getId(), asset.getName())); } } }  @Override void migrate(A artifact);  }
@Test public void should_migrate_artifact_assets() throws Exception { AssetIdMigrationStep<Page> migrationStep = new AssetIdMigrationStep<>(); Page page = aPage() .withAsset(anAsset() .withId(null)) .build(); migrationStep.migrate(page); assertThat(page.getAssets().iterator().next().getId()).isNotNull(); }
@Test public void should_not_change_an_asset_id() throws Exception { AssetIdMigrationStep<Page> migrationStep = new AssetIdMigrationStep<>(); Page page = aPage() .withAsset(anAsset() .withId("123")) .build(); migrationStep.migrate(page); assertThat(page.getAssets().iterator().next().getId()).isEqualTo("123"); }