mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-10-26 08:06:09 +01:00
Retry failing integration tests
This uses 'RetryingTest' from junit jupiter to retry integration tests that are known to fail from time to time. We explicitly mark single tests in contrast to set a global retry to be able to trace those, whenever this is intended. To do so, we have to update to the latest version of JUnit. Unfortunately, this brought a new behaviour for the @TempDir annotation: In contrast to the former behaviour where for one test all annotated parameters got the same directory, in the new version the parameters get different directories assigned. This led to the need of some consolidation between @BeforeEach methods and the related tests. Committed-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com> Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
committed by
SCM-Manager
parent
796330f883
commit
68110ee6b3
@@ -16,7 +16,7 @@ ext {
|
||||
jettyVersion = '9.4.44.v20210927'
|
||||
luceneVersion = '8.9.0'
|
||||
|
||||
junitJupiterVersion = '5.7.0'
|
||||
junitJupiterVersion = '5.9.2'
|
||||
hamcrestVersion = '2.1'
|
||||
mockitoVersion = '3.6.28'
|
||||
jerseyClientVersion = '1.19.4'
|
||||
@@ -167,7 +167,7 @@ ext {
|
||||
junit: 'junit:junit:4.13.1',
|
||||
|
||||
// junit 5 extensions
|
||||
junitPioneer: 'org.junit-pioneer:junit-pioneer:1.6.2',
|
||||
junitPioneer: 'org.junit-pioneer:junit-pioneer:2.0.0',
|
||||
|
||||
// assertions
|
||||
hamcrestCore: "org.hamcrest:hamcrest-core:${hamcrestVersion}",
|
||||
|
||||
@@ -61,8 +61,11 @@ class JAXBPropertyFileAccessTest {
|
||||
|
||||
JAXBPropertyFileAccess fileAccess;
|
||||
|
||||
@TempDir
|
||||
private Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void initTempDir(@TempDir Path tempDir) {
|
||||
void initTempDir() {
|
||||
lenient().when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
lenient().when(contextProvider.resolve(any())).thenAnswer(invocation -> tempDir.resolve(invocation.getArgument(0).toString()));
|
||||
|
||||
@@ -98,8 +101,8 @@ class JAXBPropertyFileAccessTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMoveStoreFileToRepositoryBasedLocation(@TempDir Path tempDir) throws IOException {
|
||||
createV1StoreFile(tempDir, "myStore.xml");
|
||||
void shouldMoveStoreFileToRepositoryBasedLocation() throws IOException {
|
||||
createV1StoreFile("myStore.xml");
|
||||
|
||||
fileAccess.forStoreName(STORE_NAME).moveAsRepositoryStore(Paths.get("myStore.xml"), REPOSITORY_ID);
|
||||
|
||||
@@ -107,11 +110,11 @@ class JAXBPropertyFileAccessTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMoveAllStoreFilesToRepositoryBasedLocations(@TempDir Path tempDir) throws IOException {
|
||||
void shouldMoveAllStoreFilesToRepositoryBasedLocations() throws IOException {
|
||||
locationResolver.forClass(Path.class).createLocation("repoId2");
|
||||
|
||||
createV1StoreFile(tempDir, REPOSITORY_ID + ".xml");
|
||||
createV1StoreFile(tempDir, "repoId2.xml");
|
||||
createV1StoreFile(REPOSITORY_ID + ".xml");
|
||||
createV1StoreFile("repoId2.xml");
|
||||
|
||||
PropertyFileAccess.StoreFileTools statisticStoreAccess = fileAccess.forStoreName(STORE_NAME);
|
||||
statisticStoreAccess.forStoreFiles(statisticStoreAccess::moveAsRepositoryStore);
|
||||
@@ -121,7 +124,7 @@ class JAXBPropertyFileAccessTest {
|
||||
}
|
||||
}
|
||||
|
||||
private void createV1StoreFile(@TempDir Path tempDir, String name) throws IOException {
|
||||
private void createV1StoreFile(String name) throws IOException {
|
||||
Path v1Dir = tempDir.resolve("var").resolve("data").resolve(STORE_NAME);
|
||||
IOUtil.mkdirs(v1Dir.toFile());
|
||||
Files.createFile(v1Dir.resolve(name));
|
||||
@@ -131,8 +134,8 @@ class JAXBPropertyFileAccessTest {
|
||||
class ForMissingRepository {
|
||||
|
||||
@Test
|
||||
void shouldIgnoreStoreFile(@TempDir Path tempDir) throws IOException {
|
||||
createV1StoreFile(tempDir, "myStore.xml");
|
||||
void shouldIgnoreStoreFile() throws IOException {
|
||||
createV1StoreFile("myStore.xml");
|
||||
|
||||
fileAccess.forStoreName(STORE_NAME).moveAsRepositoryStore(Paths.get("myStore.xml"), REPOSITORY_ID);
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ dependencies {
|
||||
testImplementation libraries.jerseyClientRuntime
|
||||
testImplementation libraries.jacksonJaxbAnnotations
|
||||
|
||||
testImplementation libraries.junitPioneer
|
||||
|
||||
itWebApp project(path: ':scm-webapp', configuration: 'webapp')
|
||||
itPlugin project(path: ':scm-plugins:scm-integration-test-plugin', configuration: 'smp')
|
||||
}
|
||||
|
||||
@@ -21,17 +21,16 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.assertj.core.api.AbstractCharSequenceAssert;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junitpioneer.jupiter.RetryingTest;
|
||||
import sonia.scm.it.utils.RepositoryUtil;
|
||||
import sonia.scm.it.utils.ScmRequests;
|
||||
import sonia.scm.it.utils.TestData;
|
||||
@@ -52,27 +51,23 @@ import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.nio.file.Files.createDirectories;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static sonia.scm.it.utils.RestUtil.ADMIN_PASSWORD;
|
||||
import static sonia.scm.it.utils.RestUtil.ADMIN_USERNAME;
|
||||
|
||||
public class DiffITCase {
|
||||
class DiffITCase {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
@TempDir public Path tempFolder;
|
||||
private RepositoryClient svnRepositoryClient;
|
||||
private RepositoryClient gitRepositoryClient;
|
||||
private RepositoryClient hgRepositoryClient;
|
||||
private ScmRequests.RepositoryResponse<ScmRequests.IndexResponse> svnRepositoryResponse;
|
||||
private ScmRequests.RepositoryResponse<ScmRequests.IndexResponse> hgRepositoryResponse;
|
||||
private ScmRequests.RepositoryResponse<ScmRequests.IndexResponse> gitRepositoryResponse;
|
||||
private File svnFolder;
|
||||
private File gitFolder;
|
||||
private File hgFolder;
|
||||
|
||||
@Before
|
||||
public void init() throws IOException {
|
||||
@BeforeEach
|
||||
void init() throws IOException {
|
||||
TestData.createDefault();
|
||||
String namespace = ADMIN_USERNAME;
|
||||
String repo = TestData.getDefaultRepoName("svn");
|
||||
@@ -81,7 +76,7 @@ public class DiffITCase {
|
||||
.requestIndexResource(ADMIN_USERNAME, ADMIN_PASSWORD)
|
||||
.requestRepository(namespace, repo)
|
||||
.assertStatusCode(HttpStatus.SC_OK);
|
||||
svnFolder = tempFolder.newFolder("svn");
|
||||
File svnFolder = createDirectories(tempFolder.resolve("svn")).toFile();
|
||||
svnRepositoryClient = RepositoryUtil.createRepositoryClient("svn", svnFolder);
|
||||
|
||||
repo = TestData.getDefaultRepoName("git");
|
||||
@@ -90,7 +85,7 @@ public class DiffITCase {
|
||||
.requestIndexResource(ADMIN_USERNAME, ADMIN_PASSWORD)
|
||||
.requestRepository(namespace, repo)
|
||||
.assertStatusCode(HttpStatus.SC_OK);
|
||||
gitFolder = tempFolder.newFolder("git");
|
||||
File gitFolder = createDirectories(tempFolder.resolve("git")).toFile();
|
||||
gitRepositoryClient = RepositoryUtil.createRepositoryClient("git", gitFolder);
|
||||
|
||||
repo = TestData.getDefaultRepoName("hg");
|
||||
@@ -99,12 +94,12 @@ public class DiffITCase {
|
||||
.requestIndexResource(ADMIN_USERNAME, ADMIN_PASSWORD)
|
||||
.requestRepository(namespace, repo)
|
||||
.assertStatusCode(HttpStatus.SC_OK);
|
||||
hgFolder = tempFolder.newFolder("hg");
|
||||
File hgFolder = createDirectories(tempFolder.resolve("hg")).toFile();
|
||||
hgRepositoryClient = RepositoryUtil.createRepositoryClient("hg", hgFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindDiffsInGitFormat() throws IOException {
|
||||
void shouldFindDiffsInGitFormat() throws IOException {
|
||||
String svnDiff = getDiff(RepositoryUtil.createAndCommitFile(svnRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a"), svnRepositoryResponse);
|
||||
String gitDiff = getDiff(RepositoryUtil.createAndCommitFile(gitRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a"), gitRepositoryResponse);
|
||||
String hgDiff = getDiff(RepositoryUtil.createAndCommitFile(hgRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a"), hgRepositoryResponse);
|
||||
@@ -115,7 +110,7 @@ public class DiffITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnAddFileDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
void svnAddFileDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
String svnDiff = getDiff(RepositoryUtil.createAndCommitFile(svnRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a"), svnRepositoryResponse);
|
||||
String gitDiff = getDiff(RepositoryUtil.createAndCommitFile(gitRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a"), gitRepositoryResponse);
|
||||
|
||||
@@ -123,8 +118,8 @@ public class DiffITCase {
|
||||
assertDiffsAreEqual(svnDiff, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnDeleteFileDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
@RetryingTest(3)
|
||||
void svnDeleteFileDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
RepositoryUtil.createAndCommitFile(svnRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a");
|
||||
RepositoryUtil.createAndCommitFile(gitRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a");
|
||||
|
||||
@@ -136,7 +131,7 @@ public class DiffITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnUpdateFileDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
void svnUpdateFileDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
RepositoryUtil.createAndCommitFile(svnRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a");
|
||||
RepositoryUtil.createAndCommitFile(gitRepositoryClient, ADMIN_USERNAME, "a.txt", "content of a");
|
||||
|
||||
@@ -147,8 +142,8 @@ public class DiffITCase {
|
||||
assertDiffsAreEqual(svnDiff, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnMultipleChangesDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
@RetryingTest(3)
|
||||
void svnMultipleChangesDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
String svnDiff = getDiff(applyMultipleChanges(svnRepositoryClient, "fileToBeDeleted.txt", "fileToBeUpdated.txt", "addedFile.txt"), svnRepositoryResponse);
|
||||
String gitDiff = getDiff(applyMultipleChanges(gitRepositoryClient, "fileToBeDeleted.txt", "fileToBeUpdated.txt", "addedFile.txt"), gitRepositoryResponse);
|
||||
|
||||
@@ -162,7 +157,7 @@ public class DiffITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnMultipleSubFolderChangesDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
void svnMultipleSubFolderChangesDiffShouldBeConvertedToGitDiff() throws IOException {
|
||||
String svnDiff = getDiff(applyMultipleChanges(svnRepositoryClient, "a/b/fileToBeDeleted.txt", "a/c/fileToBeUpdated.txt", "a/d/addedFile.txt"), svnRepositoryResponse);
|
||||
String gitDiff = getDiff(applyMultipleChanges(gitRepositoryClient, "a/b/fileToBeDeleted.txt", "a/c/fileToBeUpdated.txt", "a/d/addedFile.txt"), gitRepositoryResponse);
|
||||
|
||||
@@ -176,7 +171,7 @@ public class DiffITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnLargeChangesDiffShouldBeConvertedToGitDiff() throws IOException, URISyntaxException {
|
||||
void svnLargeChangesDiffShouldBeConvertedToGitDiff() throws IOException, URISyntaxException {
|
||||
String fileName = "SvnDiffGenerator_forTest";
|
||||
RepositoryUtil.createAndCommitFile(svnRepositoryClient, ADMIN_USERNAME, fileName, "");
|
||||
RepositoryUtil.createAndCommitFile(gitRepositoryClient, ADMIN_USERNAME, fileName, "");
|
||||
@@ -201,9 +196,9 @@ public class DiffITCase {
|
||||
* FIXME: the binary Git Diff output is not GIT conform
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
@SuppressWarnings("squid:S1607")
|
||||
public void svnBinaryChangesDiffShouldBeConvertedToGitDiff() throws IOException, URISyntaxException {
|
||||
void svnBinaryChangesDiffShouldBeConvertedToGitDiff() throws IOException, URISyntaxException {
|
||||
String fileName = "binary";
|
||||
File file = new File(svnRepositoryClient.getWorkingCopy(), fileName);
|
||||
Files.copy(Paths.get(getClass().getResource("/diff/binaryfile/echo").toURI()), Paths.get(file.toURI()));
|
||||
@@ -220,7 +215,7 @@ public class DiffITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void svnRenameChangesDiffShouldBeConvertedToGitDiff() throws IOException, URISyntaxException {
|
||||
void svnRenameChangesDiffShouldBeConvertedToGitDiff() throws IOException, URISyntaxException {
|
||||
String fileName = "a.txt";
|
||||
RepositoryUtil.createAndCommitFile(svnRepositoryClient, ADMIN_USERNAME, fileName, "content of a");
|
||||
RepositoryUtil.createAndCommitFile(gitRepositoryClient, ADMIN_USERNAME, fileName, "content of a");
|
||||
|
||||
@@ -34,12 +34,12 @@ import org.eclipse.jgit.transport.PushResult;
|
||||
import org.eclipse.jgit.transport.RemoteRefUpdate;
|
||||
import org.eclipse.jgit.transport.RemoteRefUpdate.Status;
|
||||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junitpioneer.jupiter.RetryingTest;
|
||||
import sonia.scm.it.utils.RestUtil;
|
||||
import sonia.scm.it.utils.TestData;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
@@ -47,44 +47,45 @@ import sonia.scm.web.VndMediaType;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static sonia.scm.it.utils.RestUtil.given;
|
||||
|
||||
/**
|
||||
* Integration Tests for Git with non fast-forward pushes.
|
||||
*/
|
||||
public class GitNonFastForwardITCase {
|
||||
class GitNonFastForwardITCase {
|
||||
|
||||
private File workingCopy;
|
||||
private Git git;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
private Path tempFolder;
|
||||
|
||||
@Before
|
||||
public void createAndCloneTestRepository() throws IOException, GitAPIException {
|
||||
@BeforeEach
|
||||
void createAndCloneTestRepository() throws GitAPIException {
|
||||
TestData.createDefault();
|
||||
this.workingCopy = tempFolder.newFolder();
|
||||
this.workingCopy = tempFolder.toFile();
|
||||
|
||||
this.git = clone(RestUtil.BASE_URL.toASCIIString() + "repo/scmadmin/HeartOfGold-git");
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() {
|
||||
@AfterEach
|
||||
void cleanup() {
|
||||
TestData.cleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the normal behaviour (non fast-forward is allowed), is restored after the tests are executed.
|
||||
*/
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void allowNonFastForward() {
|
||||
setNonFastForwardDisallowed(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitPushAmendWithoutForce() throws IOException, GitAPIException {
|
||||
void testGitPushAmendWithoutForce() throws IOException, GitAPIException {
|
||||
setNonFastForwardDisallowed(false);
|
||||
|
||||
addTestFileToWorkingCopyAndCommit("a");
|
||||
@@ -95,7 +96,7 @@ public class GitNonFastForwardITCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitPushAmendWithForce() throws IOException, GitAPIException {
|
||||
void testGitPushAmendWithForce() throws IOException, GitAPIException {
|
||||
setNonFastForwardDisallowed(false);
|
||||
|
||||
addTestFileToWorkingCopyAndCommit("a");
|
||||
@@ -105,8 +106,8 @@ public class GitNonFastForwardITCase {
|
||||
pushAndAssert(true, Status.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGitPushAmendForceWithDisallowNonFastForward() throws GitAPIException, IOException {
|
||||
@RetryingTest(3)
|
||||
void testGitPushAmendForceWithDisallowNonFastForward() throws GitAPIException, IOException {
|
||||
setNonFastForwardDisallowed(true);
|
||||
|
||||
addTestFileToWorkingCopyAndCommit("a");
|
||||
@@ -172,7 +173,7 @@ public class GitNonFastForwardITCase {
|
||||
|
||||
private void assertStatus(PushResult pushResult, Status expectedStatus) {
|
||||
for ( RemoteRefUpdate remoteRefUpdate : pushResult.getRemoteUpdates() ) {
|
||||
assertEquals(expectedStatus, remoteRefUpdate.getStatus());
|
||||
assertThat(remoteRefUpdate.getStatus()).isEqualTo(expectedStatus);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,9 @@ import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.junitpioneer.jupiter.RetryingTest;
|
||||
import sonia.scm.it.utils.RepositoryUtil;
|
||||
import sonia.scm.it.utils.RestUtil;
|
||||
import sonia.scm.it.utils.TestData;
|
||||
@@ -126,7 +128,7 @@ class MergeDetectionITCase {
|
||||
Assertions.assertThat(getMergeDetectionResult("postMergeDetection", 0)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@RetryingTest(3)
|
||||
void shouldDetectNormalPushAsNotMerged(@TempDir Path tempDir) throws IOException {
|
||||
client.getCheckoutCommand().checkout("develop");
|
||||
writeFile(tempDir, developFile, "other content");
|
||||
|
||||
@@ -41,7 +41,6 @@ import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -72,15 +71,18 @@ class GitRepositoryContextResolverTest {
|
||||
@Nested
|
||||
class WithRepository {
|
||||
|
||||
@TempDir
|
||||
Path repositoryPath;
|
||||
|
||||
@BeforeEach
|
||||
void mockRepository(@TempDir Path repositoryPath) throws IOException {
|
||||
void mockRepository() {
|
||||
when(scmConfiguration.getBaseUrl()).thenReturn("https://hog.hitchhiker.com/scm");
|
||||
when(repositoryManager.get(new NamespaceAndName("space", "X"))).thenReturn(REPOSITORY);
|
||||
when(locationResolver.forClass(any()).getLocation("id")).thenReturn(repositoryPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveCorrectRepository(@TempDir Path repositoryPath) {
|
||||
void shouldResolveCorrectRepository() {
|
||||
RepositoryContext context = resolver.resolve(new String[]{"git", "repo/space/X/something/else"});
|
||||
|
||||
assertThat(context.getRepository()).isSameAs(REPOSITORY);
|
||||
@@ -88,7 +90,7 @@ class GitRepositoryContextResolverTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldResolveCorrectRepositoryWithContextPath(@TempDir Path repositoryPath) throws IOException {
|
||||
void shouldResolveCorrectRepositoryWithContextPath() {
|
||||
RepositoryContext context = resolver.resolve(new String[]{"git", "scm/repo/space/X/something/else"});
|
||||
|
||||
assertThat(context.getRepository()).isSameAs(REPOSITORY);
|
||||
|
||||
@@ -58,13 +58,16 @@ class GitV2UpdateStepTest {
|
||||
@InjectMocks
|
||||
GitV2UpdateStep updateStep;
|
||||
|
||||
@TempDir
|
||||
Path temp;
|
||||
|
||||
@BeforeEach
|
||||
void createDataDirectory(@TempDir Path temp) throws IOException {
|
||||
void createDataDirectory() throws IOException {
|
||||
Files.createDirectories(temp.resolve("data"));
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void initRepositoryFolder(@TempDir Path temp) {
|
||||
void initRepositoryFolder() {
|
||||
when(locationResolver.forClass(Path.class)).thenReturn(locationResolverInstance);
|
||||
when(repositoryMetadataAccess.read(temp)).thenReturn(new Repository("123", "git", "space", "X"));
|
||||
doAnswer(invocation -> {
|
||||
@@ -74,14 +77,14 @@ class GitV2UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWriteConfigFileForBareRepositories(@TempDir Path temp) {
|
||||
void shouldWriteConfigFileForBareRepositories() {
|
||||
updateStep.doUpdate();
|
||||
|
||||
assertThat(temp.resolve("data").resolve("config")).exists();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWriteConfigFileForNonBareRepositories(@TempDir Path temp) throws IOException {
|
||||
void shouldWriteConfigFileForNonBareRepositories() throws IOException {
|
||||
Files.createDirectories(temp.resolve("data").resolve(".git"));
|
||||
|
||||
updateStep.doUpdate();
|
||||
|
||||
@@ -29,7 +29,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
api platform(project(':'))
|
||||
|
||||
|
||||
implementation libraries.commonsDaemon
|
||||
implementation libraries.jettyServer
|
||||
implementation libraries.jettyWebapp
|
||||
|
||||
@@ -165,12 +165,12 @@ class HealthCheckTest {
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
private void setUp() {
|
||||
void setUp() {
|
||||
servers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
private void shutdown() {
|
||||
void shutdown() {
|
||||
for (Server server : servers) {
|
||||
try {
|
||||
server.stop();
|
||||
|
||||
@@ -51,32 +51,34 @@ class CopyMigrationStrategyTest {
|
||||
SCMContextProvider contextProvider;
|
||||
@Mock
|
||||
RepositoryLocationResolver locationResolver;
|
||||
@TempDir
|
||||
private Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void mockContextProvider(@TempDir Path tempDir) {
|
||||
void mockContextProvider() {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
void createV1Home() throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void mockLocationResolver(@TempDir Path tempDir) {
|
||||
void mockLocationResolver() {
|
||||
RepositoryLocationResolver.RepositoryLocationResolverInstance instanceMock = mock(RepositoryLocationResolver.RepositoryLocationResolverInstance.class);
|
||||
when(locationResolver.forClass(Path.class)).thenReturn(instanceMock);
|
||||
when(instanceMock.createLocation(anyString())).thenAnswer(invocation -> tempDir.resolve((String) invocation.getArgument(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseStandardDirectory(@TempDir Path tempDir) {
|
||||
void shouldUseStandardDirectory() {
|
||||
Path target = new CopyMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git").get();
|
||||
assertThat(target).isEqualTo(tempDir.resolve("b4f-a9f0-49f7-ad1f-37d3aae1c55f"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCopyDataDirectory(@TempDir Path tempDir) {
|
||||
void shouldCopyDataDirectory() {
|
||||
Path target = new CopyMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git").get();
|
||||
assertThat(target.resolve("data")).exists();
|
||||
Path originalDataDir = tempDir
|
||||
|
||||
@@ -50,27 +50,29 @@ class InlineMigrationStrategyTest {
|
||||
PathBasedRepositoryLocationResolver locationResolver;
|
||||
@Mock
|
||||
RepositoryLocationResolver.RepositoryLocationResolverInstance locationResolverInstance;
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void mockContextProvider(@TempDir Path tempDir) {
|
||||
void mockContextProvider() {
|
||||
when(locationResolver.forClass(Path.class)).thenReturn(locationResolverInstance);
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
void createV1Home() throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseExistingDirectory(@TempDir Path tempDir) {
|
||||
void shouldUseExistingDirectory() {
|
||||
Path target = new InlineMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git").get();
|
||||
assertThat(target).isEqualTo(resolveOldDirectory(tempDir));
|
||||
verify(locationResolverInstance).setLocation("b4f-a9f0-49f7-ad1f-37d3aae1c55f", target);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMoveDataDirectory(@TempDir Path tempDir) {
|
||||
void shouldMoveDataDirectory() {
|
||||
new InlineMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git");
|
||||
assertThat(resolveOldDirectory(tempDir).resolve("data")).exists();
|
||||
}
|
||||
|
||||
@@ -63,8 +63,11 @@ class MigrateVerbsToPermissionRolesTest {
|
||||
@InjectMocks
|
||||
private MigrateVerbsToPermissionRoles migration;
|
||||
|
||||
@TempDir
|
||||
private Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void init(@TempDir Path tempDir) throws IOException {
|
||||
void init() throws IOException {
|
||||
URL metadataUrl = Resources.getResource("sonia/scm/update/repository/metadataWithoutRoles.xml");
|
||||
Files.copy(metadataUrl.openStream(), tempDir.resolve("metadata.xml"));
|
||||
doAnswer(invocation -> {
|
||||
@@ -75,7 +78,7 @@ class MigrateVerbsToPermissionRolesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateToRolesIfPossible(@TempDir Path tempDir) throws IOException {
|
||||
void shouldUpdateToRolesIfPossible() throws IOException {
|
||||
migration.doUpdate();
|
||||
|
||||
List<String> newMetadata = Files.readAllLines(tempDir.resolve("metadata.xml"));
|
||||
|
||||
@@ -48,32 +48,34 @@ class MoveMigrationStrategyTest {
|
||||
SCMContextProvider contextProvider;
|
||||
@Mock
|
||||
RepositoryLocationResolver locationResolver;
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void mockContextProvider(@TempDir Path tempDir) {
|
||||
void mockContextProvider() {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
void createV1Home() throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void mockLocationResolver(@TempDir Path tempDir) {
|
||||
void mockLocationResolver() {
|
||||
RepositoryLocationResolver.RepositoryLocationResolverInstance instanceMock = mock(RepositoryLocationResolver.RepositoryLocationResolverInstance.class);
|
||||
when(locationResolver.forClass(Path.class)).thenReturn(instanceMock);
|
||||
when(instanceMock.createLocation(anyString())).thenAnswer(invocation -> tempDir.resolve((String) invocation.getArgument(0)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseStandardDirectory(@TempDir Path tempDir) {
|
||||
void shouldUseStandardDirectory() {
|
||||
Path target = new MoveMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git").get();
|
||||
assertThat(target).isEqualTo(tempDir.resolve("b4f-a9f0-49f7-ad1f-37d3aae1c55f"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMoveDataDirectory(@TempDir Path tempDir) {
|
||||
void shouldMoveDataDirectory() {
|
||||
Path target = new MoveMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git").get();
|
||||
assertThat(target.resolve("data")).exists();
|
||||
Path originalDataDir = tempDir
|
||||
|
||||
@@ -47,13 +47,16 @@ class XmlRepositoryFileNameUpdateStepTest {
|
||||
SCMContextProvider contextProvider = mock(SCMContextProvider.class);
|
||||
XmlRepositoryDAO repositoryDAO = mock(XmlRepositoryDAO.class);
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDir Path tempDir) {
|
||||
void mockScmHome() {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCopyRepositoriesFileToRepositoryPathsFile(@TempDir Path tempDir) throws IOException {
|
||||
void shouldCopyRepositoriesFileToRepositoryPathsFile() throws IOException {
|
||||
XmlRepositoryFileNameUpdateStep updateStep = new XmlRepositoryFileNameUpdateStep(contextProvider, repositoryDAO);
|
||||
URL url = Resources.getResource("sonia/scm/update/repository/formerV2RepositoryFile.xml");
|
||||
Path configDir = tempDir.resolve("config");
|
||||
|
||||
@@ -82,9 +82,11 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
UpdateStepTestUtil testUtil;
|
||||
|
||||
XmlRepositoryV1UpdateStep updateStep;
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void createUpdateStepFromMocks(@TempDir Path tempDir) {
|
||||
void createUpdateStepFromMocks() {
|
||||
testUtil = new UpdateStepTestUtil(tempDir);
|
||||
updateStep = new XmlRepositoryV1UpdateStep(
|
||||
testUtil.getContextProvider(),
|
||||
@@ -99,7 +101,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
class WithExistingDatabase {
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
void createV1Home() throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@@ -176,7 +178,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseDirectoryFromStrategy(@TempDir Path tempDir) throws JAXBException {
|
||||
void shouldUseDirectoryFromStrategy() throws JAXBException {
|
||||
Path targetDir = tempDir.resolve("someDir");
|
||||
MigrationStrategy.Instance strategyMock = injectorMock.getInstance(MoveMigrationStrategy.class);
|
||||
when(strategyMock.migrate("454972da-faf9-4437-b682-dc4a4e0aa8eb", "simple", "git")).thenReturn(of(targetDir));
|
||||
@@ -206,7 +208,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBackupOldRepositoryDatabaseFile(@TempDir Path tempDir) throws JAXBException {
|
||||
void shouldBackupOldRepositoryDatabaseFile() throws JAXBException {
|
||||
updateStep.doUpdate();
|
||||
|
||||
assertThat(tempDir.resolve("config").resolve("repositories.xml")).doesNotExist();
|
||||
@@ -220,15 +222,15 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotFailIfFormerV2DatabaseExists(@TempDir Path tempDir) throws JAXBException, IOException {
|
||||
createFormerV2RepositoriesFile(tempDir);
|
||||
void shouldNotFailIfFormerV2DatabaseExists() throws JAXBException, IOException {
|
||||
createFormerV2RepositoriesFile();
|
||||
|
||||
updateStep.doUpdate();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotBackupFormerV2DatabaseFile(@TempDir Path tempDir) throws JAXBException, IOException {
|
||||
createFormerV2RepositoriesFile(tempDir);
|
||||
void shouldNotBackupFormerV2DatabaseFile() throws JAXBException, IOException {
|
||||
createFormerV2RepositoriesFile();
|
||||
|
||||
updateStep.doUpdate();
|
||||
|
||||
@@ -237,14 +239,14 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldGetNoMissingStrategiesWithFormerV2DatabaseFile(@TempDir Path tempDir) throws IOException {
|
||||
createFormerV2RepositoriesFile(tempDir);
|
||||
void shouldGetNoMissingStrategiesWithFormerV2DatabaseFile() throws IOException {
|
||||
createFormerV2RepositoriesFile();
|
||||
|
||||
assertThat(updateStep.getRepositoriesWithoutMigrationStrategies()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindMissingStrategies(@TempDir Path tempDir) throws IOException {
|
||||
void shouldFindMissingStrategies() throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
|
||||
assertThat(updateStep.getRepositoriesWithoutMigrationStrategies())
|
||||
@@ -255,7 +257,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
"454972da-faf9-4437-b682-dc4a4e0aa8eb");
|
||||
}
|
||||
|
||||
private void createFormerV2RepositoriesFile(@TempDir Path tempDir) throws IOException {
|
||||
private void createFormerV2RepositoriesFile() throws IOException {
|
||||
URL url = Resources.getResource("sonia/scm/update/repository/formerV2RepositoryFile.xml");
|
||||
Path configDir = tempDir.resolve("config");
|
||||
Files.createDirectories(configDir);
|
||||
|
||||
@@ -59,8 +59,11 @@ class XmlSecurityV1UpdateStepTest {
|
||||
XmlSecurityV1UpdateStep updateStep;
|
||||
ConfigurationEntryStore<AssignedPermission> assignedPermissionStore;
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDir Path tempDir) {
|
||||
void mockScmHome() {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
InMemoryConfigurationEntryStoreFactory inMemoryConfigurationEntryStoreFactory = create();
|
||||
assignedPermissionStore = inMemoryConfigurationEntryStoreFactory.get("security");
|
||||
@@ -71,7 +74,7 @@ class XmlSecurityV1UpdateStepTest {
|
||||
class WithExistingDatabase {
|
||||
|
||||
@BeforeEach
|
||||
void createConfigV1XML(@TempDir Path tempDir) throws IOException {
|
||||
void createConfigV1XML() throws IOException {
|
||||
Path configDir = tempDir.resolve("config");
|
||||
Files.createDirectories(configDir);
|
||||
copyTestDatabaseFile(configDir, "config.xml");
|
||||
@@ -111,7 +114,7 @@ class XmlSecurityV1UpdateStepTest {
|
||||
private Path configDir;
|
||||
|
||||
@BeforeEach
|
||||
void createSecurityV1XML(@TempDir Path tempDir) throws IOException {
|
||||
void createSecurityV1XML() throws IOException {
|
||||
configDir = tempDir.resolve("config");
|
||||
Files.createDirectories(configDir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user