PageMigrationApplyer { public Page migrate(Page page) { long startTime = System.currentTimeMillis(); String formerArtifactVersion = page.getDesignerVersion(); for (Migration<Page> migration : migrationList) { migration.migrate(page); } migrateAllWidgetUsed(page); updatePreviousDesignerVersionIfMigrationDone(page,formerArtifactVersion,startTime); return page; } PageMigrationApplyer(List<Migration<Page>> pageMigrationStepsList, WidgetService widgetService); Page migrate(Page page);  }
@Test public void should_migrate_a_page() throws IOException { Migration<Page> migration = new Migration("1.0.2", mock(MigrationStep.class)); PageMigrationApplyer migrationApplyer = new PageMigrationApplyer(Collections.singletonList(migration), widgetService); Page page = PageBuilder.aPage().withId("myPage").withVersion("1.0.1").withPreviousDesignerVersion("1.0.0").build(); migrationApplyer.migrate(page); Assert.assertEquals(page.getPreviousDesignerVersion(),"1.0.1"); Assert.assertEquals(page.getDesignerVersion(),"1.0.2"); }
@Test public void should_not_modify_previous_designer_version_when_no_migration_done() throws Exception { Migration<Page> migration = new Migration("1.0.0", mock(MigrationStep.class)); PageMigrationApplyer migrationApplyer = new PageMigrationApplyer(Collections.singletonList(migration), widgetService); Page page = PageBuilder.aPage().withId("myPage").withVersion("1.0.0").withPreviousDesignerVersion("1.0.0").build(); migrationApplyer.migrate(page); Assert.assertEquals(page.getPreviousDesignerVersion(),"1.0.0"); Assert.assertEquals(page.getDesignerVersion(),"1.0.0"); }
@Test public void should_migrate_all_custom_widget_uses_in_page_when_page_migration_is_done(){ Migration<Page> migration = new Migration("1.0.1", mock(MigrationStep.class)); PageMigrationApplyer migrationApplyer = new PageMigrationApplyer(Collections.singletonList(migration), widgetService); Page page = PageBuilder.aPage().withId("myPage").withVersion("1.0.0").withPreviousDesignerVersion("1.0.0").build(); Page migratedPage = migrationApplyer.migrate(page); verify(widgetService).migrateAllCustomWidgetUsedInPreviewable(migratedPage); Assert.assertEquals(migratedPage.getPreviousDesignerVersion(),"1.0.0"); Assert.assertEquals(migratedPage.getDesignerVersion(),"1.0.1"); }