StyleAssetMigrationStep implements MigrationStep<Page> { @Override public void migrate(Page artifact) { Asset style = new Asset() .setName(getAssetName(artifact)) .setType(CSS); assetService.save(artifact, style, getContent()); logger.info(format( "[MIGRATION] Adding default CSS asset [%s] to %s [%s] (introduced in 1.4.8)", style.getName(), artifact.getType(), artifact.getName())); } @Inject  StyleAssetMigrationStep(@Named("pageAssetService") AssetService<Page> assetService); @Override void migrate(Page artifact); byte[] getContent();  }
@Test public void should_add_new_style_asset_to_migrated_pages() throws Exception { Page page = aPage().withVersion("1.4.7").build(); step.migrate(page); Page migratedPage = pageRepository.get(page.getId()); assertThat(migratedPage.getAssets()).contains(expectedAsset("style.css")); verify(assetRepository).save(page.getId(), expectedAsset("style.css"), expectedAssetContent()); }
@Test public void should_add_new_style_asset_with_different_name_while_already_existing() throws Exception { Page page = aPage().withVersion("1.4.7") .withAsset(anAsset().withType(CSS).withName("style.css")) .withAsset(anAsset().withType(CSS).withName("style1.css")).build(); step.migrate(page); Page migratedPage = pageRepository.get(page.getId()); assertThat(migratedPage.getAssets()).contains(expectedAsset("style2.css")); verify(assetRepository).save(page.getId(), expectedAsset("style2.css"), expectedAssetContent()); }