mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 01:15:44 +01:00
Verify that migration strategies are set before migration starts
This commit is contained in:
@@ -83,7 +83,10 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
JAXBContext jaxbContext = JAXBContext.newInstance(V1RepositoryDatabase.class);
|
||||
readV1Database(jaxbContext).ifPresent(
|
||||
v1Database -> v1Database.repositoryList.repositories.forEach(this::update)
|
||||
v1Database -> {
|
||||
v1Database.repositoryList.repositories.forEach(this::readMigrationStrategy);
|
||||
v1Database.repositoryList.repositories.forEach(this::update);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,12 +104,15 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
||||
}
|
||||
|
||||
private Path handleDataDirectory(V1Repository v1Repository) {
|
||||
MigrationStrategy dataMigrationStrategy =
|
||||
migrationStrategyDao.get(v1Repository.id)
|
||||
.orElseThrow(() -> new IllegalStateException("no strategy found for repository with id " + v1Repository.id + " and name " + v1Repository.name));
|
||||
MigrationStrategy dataMigrationStrategy = readMigrationStrategy(v1Repository);
|
||||
return dataMigrationStrategy.from(injector).migrate(v1Repository.id, v1Repository.name, v1Repository.type);
|
||||
}
|
||||
|
||||
private MigrationStrategy readMigrationStrategy(V1Repository v1Repository) {
|
||||
return migrationStrategyDao.get(v1Repository.id)
|
||||
.orElseThrow(() -> new IllegalStateException("no strategy found for repository with id " + v1Repository.id + " and name " + v1Repository.name));
|
||||
}
|
||||
|
||||
private RepositoryPermission[] createPermissions(V1Repository v1Repository) {
|
||||
if (v1Repository.permissions == null) {
|
||||
return new RepositoryPermission[0];
|
||||
|
||||
@@ -24,8 +24,10 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Optional.empty;
|
||||
import static java.util.Optional.of;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
@@ -72,7 +74,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
|
||||
@BeforeEach
|
||||
void captureStoredRepositories() {
|
||||
doNothing().when(repositoryDAO).add(storeCaptor.capture(), locationCaptor.capture());
|
||||
lenient().doNothing().when(repositoryDAO).add(storeCaptor.capture(), locationCaptor.capture());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
@@ -162,6 +164,12 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
|
||||
assertThat(locationCaptor.getAllValues()).contains(targetDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailForMissingMigrationStrategy() throws JAXBException {
|
||||
lenient().when(migrationStrategyDao.get("c1597b4f-a9f0-49f7-ad1f-37d3aae1c55f")).thenReturn(empty());
|
||||
assertThrows(IllegalStateException.class, () -> updateStep.doUpdate());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user