PageUUIDMigrationStep implements MigrationStep<Page> { @Override public void migrate(Page page) { if (StringUtils.isEmpty(page.getUUID())) { String uuid; try { UUID.fromString(page.getId()); logger.info(format( "[MIGRATION] Adding UUID to page [%s] (using the same value as the page ID)", page.getName())); uuid = page.getId(); } catch (IllegalArgumentException e) { logger.info(format( "[MIGRATION] Adding generated UUID to page [%s]", page.getName())); uuid = UUID.randomUUID().toString(); } page.setUUID(uuid); } }  @Override void migrate(Page page);  }
@Test public void should_migrate_page_with_UUID_like_id() throws Exception { Page pageWithoutUUID = aPage().withId(UUID.randomUUID().toString()).withUUID(null).build(); pageUUIDMigrationStep.migrate(pageWithoutUUID); assertThat(pageWithoutUUID.getUUID()).isEqualTo(pageWithoutUUID.getId()); }
@Test public void should_migrate_page_generating_a_UUID() throws Exception { Page pageWithoutUUID = aPage().withId("maPage").withUUID(null).build(); pageUUIDMigrationStep.migrate(pageWithoutUUID); assertThat(pageWithoutUUID.getUUID()).isNotNull(); }
@Test public void should_not_migrate_a_page_with_already_a_uuid() throws Exception { String uuid = UUID.randomUUID().toString(); Page pageWithUUID = aPage().withId("maPage").withUUID(uuid).build(); pageUUIDMigrationStep.migrate(pageWithUUID); assertThat(pageWithUUID.getUUID()).isEqualTo(uuid); }