LiveRepositoryUpdate implements Comparable<LiveRepositoryUpdate> { public void migrate() throws IOException { repository.walk(new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { if (isArtifactDescriptor(path)) { final A artifact = loader.get(path); String formerArtifactVersion = artifact.getDesignerVersion(); for (Migration<A> migration : migrationList) { migration.migrate(artifact); } if (!StringUtils.equals(formerArtifactVersion, artifact.getDesignerVersion())) { artifact.setPreviousDesignerVersion(formerArtifactVersion); repository.updateLastUpdateAndSave(artifact); } } return CONTINUE; } }); } LiveRepositoryUpdate(Repository<A> repository,
                                AbstractLoader<A> loader,
                                List<Migration<A>> migrationList); void start(); void migrate(); @Override int compareTo(LiveRepositoryUpdate o);  }
@Test public void should_migrate_a_page() throws Exception { Migration<Page> migration = new Migration<>("1.0.2", mock(MigrationStep.class)); LiveRepositoryUpdate<Page> liveRepositoryUpdate = new LiveRepositoryUpdate<>(repository, loader, singletonList(migration)); Page page = createPage("1.0.1"); liveRepositoryUpdate.migrate(); page.setDesignerVersion("1.0.2"); verify(persister).save(folder.getRoot().toPath().resolve("pageJson"), page); }
@Test public void should_not_migrate_file_which_are_not_json() throws Exception { Migration<Page> migration = mock(Migration.class); LiveRepositoryUpdate<Page> liveRepositoryUpdate = new LiveRepositoryUpdate<>(repository, loader, singletonList(migration)); folder.newFile("whatever"); liveRepositoryUpdate.migrate(); verify(migration, never()).migrate(any(Page.class)); }
@Test public void should_not_save_an_artifact_already_migrated() throws Exception { Migration<Page> migration = new Migration<>("1.0.2", mock(MigrationStep.class)); LiveRepositoryUpdate<Page> liveRepositoryUpdate = new LiveRepositoryUpdate<>(repository, loader, singletonList(migration)); createPage("1.0.2"); liveRepositoryUpdate.migrate(); verify(persister, never()).save(any(Path.class), any(Page.class)); }
@Test public void should_exclude_assets() throws Exception { Migration<Page> migration = mock(Migration.class); LiveRepositoryUpdate<Page> liveRepositoryUpdate = new LiveRepositoryUpdate<>(repository, loader, singletonList(migration)); createPage("1.0.0"); folder.newFolder("pageJson","assets"); folder.newFile("pageJson/assets/whatever.json"); liveRepositoryUpdate.migrate(); verify(migration, only()).migrate(any(Page.class)); }