mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Do not fail when v1 file does not exist
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package sonia.scm.repository.update;
|
package sonia.scm.repository.update;
|
||||||
|
|
||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.io.FileSystem;
|
|
||||||
import sonia.scm.migration.UpdateStep;
|
import sonia.scm.migration.UpdateStep;
|
||||||
import sonia.scm.plugin.Extension;
|
import sonia.scm.plugin.Extension;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
@@ -49,6 +48,9 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doUpdate() throws JAXBException {
|
public void doUpdate() throws JAXBException {
|
||||||
|
if (!determineV1File().exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
JAXBContext jaxbContext = JAXBContext.newInstance(V1RepositoryDatabase.class);
|
JAXBContext jaxbContext = JAXBContext.newInstance(V1RepositoryDatabase.class);
|
||||||
V1RepositoryDatabase v1Database = readV1Database(jaxbContext);
|
V1RepositoryDatabase v1Database = readV1Database(jaxbContext);
|
||||||
v1Database.repositoryList.repositories.forEach(this::update);
|
v1Database.repositoryList.repositories.forEach(this::update);
|
||||||
@@ -109,7 +111,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
|||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@XmlRootElement(name = "permissions")
|
@XmlRootElement(name = "permissions")
|
||||||
public static class V1Permission {
|
private static class V1Permission {
|
||||||
private boolean groupPermission;
|
private boolean groupPermission;
|
||||||
private String name;
|
private String name;
|
||||||
private String type;
|
private String type;
|
||||||
@@ -117,7 +119,7 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
|||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
@XmlRootElement(name = "repositories")
|
@XmlRootElement(name = "repositories")
|
||||||
public static class V1Repository {
|
private static class V1Repository {
|
||||||
private Map<String, String> properties;
|
private Map<String, String> properties;
|
||||||
private String contact;
|
private String contact;
|
||||||
private long creationDate;
|
private long creationDate;
|
||||||
@@ -147,14 +149,14 @@ public class XmlRepositoryV1UpdateStep implements UpdateStep {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class RepositoryList {
|
private static class RepositoryList {
|
||||||
@XmlElement(name = "repository")
|
@XmlElement(name = "repository")
|
||||||
private List<V1Repository> repositories;
|
private List<V1Repository> repositories;
|
||||||
}
|
}
|
||||||
|
|
||||||
@XmlRootElement(name = "repository-db")
|
@XmlRootElement(name = "repository-db")
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public static class V1RepositoryDatabase {
|
private static class V1RepositoryDatabase {
|
||||||
private long creationTime;
|
private long creationTime;
|
||||||
private Long lastModified;
|
private Long lastModified;
|
||||||
@XmlElement(name = "repositories")
|
@XmlElement(name = "repositories")
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package sonia.scm.repository.update;
|
package sonia.scm.repository.update;
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junitpioneer.jupiter.TempDirectory;
|
import org.junitpioneer.jupiter.TempDirectory;
|
||||||
@@ -44,89 +44,98 @@ class XmlRepositoryV1UpdateStepTest {
|
|||||||
XmlRepositoryV1UpdateStep updateStep;
|
XmlRepositoryV1UpdateStep updateStep;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||||
ZippedRepositoryTestBase.extract(tempDir.toFile(), "sonia/scm/repository/update/scm-home.v1.zip");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@Nested
|
||||||
void captureStoredRepositories() {
|
class WithExistingDatabase {
|
||||||
doNothing().when(dao).add(storeCaptor.capture());
|
|
||||||
|
@BeforeEach
|
||||||
|
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||||
|
ZippedRepositoryTestBase.extract(tempDir.toFile(), "sonia/scm/repository/update/scm-home.v1.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void captureStoredRepositories() {
|
||||||
|
doNothing().when(dao).add(storeCaptor.capture());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldCreateNewRepositories() throws JAXBException {
|
||||||
|
updateStep.doUpdate();
|
||||||
|
verify(dao, times(3)).add(any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldMapAttributes() throws JAXBException {
|
||||||
|
updateStep.doUpdate();
|
||||||
|
|
||||||
|
Optional<Repository> repository = findByNamespace("git");
|
||||||
|
|
||||||
|
assertThat(repository)
|
||||||
|
.get()
|
||||||
|
.hasFieldOrPropertyWithValue("type", "git")
|
||||||
|
.hasFieldOrPropertyWithValue("contact", "arthur@dent.uk")
|
||||||
|
.hasFieldOrPropertyWithValue("description", "A simple repository without directories.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldUseRepositoryTypeAsNamespaceForNamesWithSingleElement() throws JAXBException {
|
||||||
|
updateStep.doUpdate();
|
||||||
|
|
||||||
|
Optional<Repository> repository = findByNamespace("git");
|
||||||
|
|
||||||
|
assertThat(repository)
|
||||||
|
.get()
|
||||||
|
.hasFieldOrPropertyWithValue("namespace", "git")
|
||||||
|
.hasFieldOrPropertyWithValue("name", "simple");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldUseDirectoriesForNamespaceAndNameForNamesWithTwoElements() throws JAXBException {
|
||||||
|
updateStep.doUpdate();
|
||||||
|
|
||||||
|
Optional<Repository> repository = findByNamespace("one");
|
||||||
|
|
||||||
|
assertThat(repository)
|
||||||
|
.get()
|
||||||
|
.hasFieldOrPropertyWithValue("namespace", "one")
|
||||||
|
.hasFieldOrPropertyWithValue("name", "directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldUseDirectoriesForNamespaceAndConcatenatedNameForNamesWithMoreThanTwoElements() throws JAXBException {
|
||||||
|
updateStep.doUpdate();
|
||||||
|
|
||||||
|
Optional<Repository> repository = findByNamespace("some");
|
||||||
|
|
||||||
|
assertThat(repository)
|
||||||
|
.get()
|
||||||
|
.hasFieldOrPropertyWithValue("namespace", "some")
|
||||||
|
.hasFieldOrPropertyWithValue("name", "more_directories_than_one");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldMapPermissions() throws JAXBException {
|
||||||
|
updateStep.doUpdate();
|
||||||
|
|
||||||
|
Optional<Repository> repository = findByNamespace("git");
|
||||||
|
|
||||||
|
assertThat(repository.get().getPermissions())
|
||||||
|
.hasSize(3)
|
||||||
|
.contains(
|
||||||
|
new RepositoryPermission("mice", "WRITE", true),
|
||||||
|
new RepositoryPermission("dent", "OWNER", false),
|
||||||
|
new RepositoryPermission("trillian", "READ", false)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldCreateNewRepositories() throws JAXBException {
|
void shouldNotFailIfNoOldDatabaseExists() throws JAXBException {
|
||||||
updateStep.doUpdate();
|
|
||||||
verify(dao, times(3)).add(any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldMapAttributes() throws JAXBException {
|
|
||||||
updateStep.doUpdate();
|
updateStep.doUpdate();
|
||||||
|
|
||||||
Optional<Repository> repository = findByNamespace("git");
|
|
||||||
|
|
||||||
assertThat(repository)
|
|
||||||
.get()
|
|
||||||
.hasFieldOrPropertyWithValue("type", "git")
|
|
||||||
.hasFieldOrPropertyWithValue("contact", "arthur@dent.uk")
|
|
||||||
.hasFieldOrPropertyWithValue("description", "A simple repository without directories.")
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldUseRepositoryTypeAsNamespaceForNamesWithSingleElement() throws JAXBException {
|
|
||||||
updateStep.doUpdate();
|
|
||||||
|
|
||||||
Optional<Repository> repository = findByNamespace("git");
|
|
||||||
|
|
||||||
assertThat(repository)
|
|
||||||
.get()
|
|
||||||
.hasFieldOrPropertyWithValue("namespace", "git")
|
|
||||||
.hasFieldOrPropertyWithValue("name", "simple")
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldUseDirectoriesForNamespaceAndNameForNamesWithTwoElements() throws JAXBException {
|
|
||||||
updateStep.doUpdate();
|
|
||||||
|
|
||||||
Optional<Repository> repository = findByNamespace("one");
|
|
||||||
|
|
||||||
assertThat(repository)
|
|
||||||
.get()
|
|
||||||
.hasFieldOrPropertyWithValue("namespace", "one")
|
|
||||||
.hasFieldOrPropertyWithValue("name", "directory")
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldUseDirectoriesForNamespaceAndConcatenatedNameForNamesWithMoreThanTwoElements() throws JAXBException {
|
|
||||||
updateStep.doUpdate();
|
|
||||||
|
|
||||||
Optional<Repository> repository = findByNamespace("some");
|
|
||||||
|
|
||||||
assertThat(repository)
|
|
||||||
.get()
|
|
||||||
.hasFieldOrPropertyWithValue("namespace", "some")
|
|
||||||
.hasFieldOrPropertyWithValue("name", "more_directories_than_one")
|
|
||||||
;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void shouldMapPermissions() throws JAXBException {
|
|
||||||
updateStep.doUpdate();
|
|
||||||
|
|
||||||
Optional<Repository> repository = findByNamespace("git");
|
|
||||||
|
|
||||||
assertThat(repository.get().getPermissions())
|
|
||||||
.hasSize(3)
|
|
||||||
.contains(
|
|
||||||
new RepositoryPermission("mice", "WRITE", true),
|
|
||||||
new RepositoryPermission("dent", "OWNER", false),
|
|
||||||
new RepositoryPermission("trillian", "READ", false)
|
|
||||||
)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Repository> findByNamespace(String namespace) {
|
private Optional<Repository> findByNamespace(String namespace) {
|
||||||
|
|||||||
Reference in New Issue
Block a user