mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
Merge branch 'develop' into feature/packaging
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
@@ -33,16 +33,23 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.WriteListener;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -173,7 +180,7 @@ public class ProxyPushStateDispatcherTest {
|
||||
|
||||
private class DevServletInputStream extends ServletInputStream {
|
||||
|
||||
private InputStream inputStream;
|
||||
private ByteArrayInputStream inputStream;
|
||||
|
||||
private DevServletInputStream(String content) {
|
||||
inputStream = new ByteArrayInputStream(content.getBytes(Charsets.UTF_8));
|
||||
@@ -183,6 +190,20 @@ public class ProxyPushStateDispatcherTest {
|
||||
public int read() throws IOException {
|
||||
return inputStream.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return inputStream.available() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return inputStream.available() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadListener(ReadListener readListener) {
|
||||
}
|
||||
}
|
||||
|
||||
private class DevServletOutputStream extends ServletOutputStream {
|
||||
@@ -193,6 +214,15 @@ public class ProxyPushStateDispatcherTest {
|
||||
public void write(int b) {
|
||||
stream.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWriteListener(WriteListener writeListener) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ package sonia.scm;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@@ -36,14 +36,14 @@ import java.util.Properties;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith({MockitoExtension.class, TempDirectory.class})
|
||||
@ExtendWith({MockitoExtension.class})
|
||||
class ScmLogFilePropertyDefinerTest {
|
||||
|
||||
@Mock
|
||||
private SCMContextProvider context;
|
||||
|
||||
@Test
|
||||
void shouldReturnPath(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldReturnPath(@TempDir Path tempDir) {
|
||||
when(context.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
ScmLogFilePropertyDefiner definer = builder().create();
|
||||
|
||||
@@ -52,7 +52,7 @@ class ScmLogFilePropertyDefinerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnOsxPath(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldReturnOsxPath(@TempDir Path tempDir) {
|
||||
ScmLogFilePropertyDefiner definer = builder()
|
||||
.withOs("Mac OS X")
|
||||
.withUserHome(tempDir.toAbsolutePath().toString())
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
@@ -37,6 +37,7 @@ import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.plugin.UberWebResourceLoader;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.WriteListener;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -152,6 +153,15 @@ public class WebResourceServletTest {
|
||||
public void write(int b) {
|
||||
buffer.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWriteListener(WriteListener writeListener) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.api;
|
||||
|
||||
import org.jboss.resteasy.mock.MockDispatcherFactory;
|
||||
import org.jboss.resteasy.mock.MockHttpRequest;
|
||||
import org.jboss.resteasy.mock.MockHttpResponse;
|
||||
import org.jboss.resteasy.spi.Dispatcher;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class InvalidFormatExceptionMapperTest {
|
||||
|
||||
@Test
|
||||
void shouldMapInvalidFormatExceptionDueToInvalidEnum() throws URISyntaxException, UnsupportedEncodingException {
|
||||
Dispatcher dispatcher = MockDispatcherFactory.createDispatcher();
|
||||
dispatcher.getRegistry().addSingletonResource(new SimpleResource());
|
||||
dispatcher.getProviderFactory().registerProvider(InvalidFormatExceptionMapper.class);
|
||||
|
||||
MockHttpRequest request = MockHttpRequest
|
||||
.post("/")
|
||||
.contentType("application/json")
|
||||
.content("{\"e\": \"NONE\"}".getBytes());
|
||||
MockHttpResponse response = new MockHttpResponse();
|
||||
|
||||
dispatcher.invoke(request, response);
|
||||
|
||||
assertThat(response.getStatus()).isEqualTo(400);
|
||||
assertThat(response.getContentAsString()).contains("2qRyyaVcJ1");
|
||||
}
|
||||
|
||||
@Path("/")
|
||||
static class SimpleResource {
|
||||
@POST
|
||||
public void post(ObjectWithEnum o) {
|
||||
}
|
||||
}
|
||||
|
||||
static class ObjectWithEnum {
|
||||
public Enum e;
|
||||
}
|
||||
|
||||
enum Enum {
|
||||
ONE, TWO
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import de.otto.edison.hal.Link;
|
||||
@@ -35,11 +35,13 @@ import sonia.scm.repository.api.DiffResult;
|
||||
import sonia.scm.repository.api.Hunk;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
import static java.net.URI.create;
|
||||
import static java.util.Collections.emptyIterator;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -60,6 +62,8 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
assertAddedFile(files.get(0), "A.java", "abc", "java");
|
||||
assertModifiedFile(files.get(1), "B.ts", "abc", "def", "typescript");
|
||||
assertDeletedFile(files.get(2), "C.go", "ghi", "golang");
|
||||
assertRenamedFile(files.get(3), "typo.ts", "okay.ts", "def", "fixed", "typescript");
|
||||
assertCopiedFile(files.get(4), "good.ts", "better.ts", "def", "fixed", "typescript");
|
||||
|
||||
DiffResultDto.HunkDto hunk = files.get(1).getHunks().get(0);
|
||||
assertHunk(hunk, "@@ -3,4 1,2 @@", 1, 2, 3, 4);
|
||||
@@ -104,7 +108,9 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
deletedLine("c", 3)
|
||||
)
|
||||
),
|
||||
deletedFile("C.go", "ghi")
|
||||
deletedFile("C.go", "ghi"),
|
||||
renamedFile("okay.ts", "typo.ts", "fixed", "def"),
|
||||
copiedFile("better.ts", "good.ts", "fixed", "def")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,6 +167,24 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
assertThat(file.getLanguage()).isEqualTo(language);
|
||||
}
|
||||
|
||||
private void assertRenamedFile(DiffResultDto.FileDto file, String oldPath, String newPath, String oldRevision, String newRevision, String language) {
|
||||
assertThat(file.getOldPath()).isEqualTo(oldPath);
|
||||
assertThat(file.getNewPath()).isEqualTo(newPath);
|
||||
assertThat(file.getOldRevision()).isEqualTo(oldRevision);
|
||||
assertThat(file.getNewRevision()).isEqualTo(newRevision);
|
||||
assertThat(file.getType()).isEqualTo("rename");
|
||||
assertThat(file.getLanguage()).isEqualTo(language);
|
||||
}
|
||||
|
||||
private void assertCopiedFile(DiffResultDto.FileDto file, String oldPath, String newPath, String oldRevision, String newRevision, String language) {
|
||||
assertThat(file.getOldPath()).isEqualTo(oldPath);
|
||||
assertThat(file.getNewPath()).isEqualTo(newPath);
|
||||
assertThat(file.getOldRevision()).isEqualTo(oldRevision);
|
||||
assertThat(file.getNewRevision()).isEqualTo(newRevision);
|
||||
assertThat(file.getType()).isEqualTo("copy");
|
||||
assertThat(file.getLanguage()).isEqualTo(language);
|
||||
}
|
||||
|
||||
private DiffResult result(DiffFile... files) {
|
||||
DiffResult result = mock(DiffResult.class);
|
||||
when(result.iterator()).thenReturn(Arrays.asList(files).iterator());
|
||||
@@ -171,6 +195,7 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
DiffFile file = mock(DiffFile.class);
|
||||
when(file.getNewPath()).thenReturn(path);
|
||||
when(file.getNewRevision()).thenReturn(revision);
|
||||
when(file.getChangeType()).thenReturn(DiffFile.ChangeType.ADD);
|
||||
when(file.iterator()).thenReturn(Arrays.asList(hunks).iterator());
|
||||
return file;
|
||||
}
|
||||
@@ -179,6 +204,7 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
DiffFile file = mock(DiffFile.class);
|
||||
when(file.getOldPath()).thenReturn(path);
|
||||
when(file.getOldRevision()).thenReturn(revision);
|
||||
when(file.getChangeType()).thenReturn(DiffFile.ChangeType.DELETE);
|
||||
when(file.iterator()).thenReturn(Arrays.asList(hunks).iterator());
|
||||
return file;
|
||||
}
|
||||
@@ -189,10 +215,33 @@ class DiffResultToDiffResultDtoMapperTest {
|
||||
when(file.getNewRevision()).thenReturn(newRevision);
|
||||
when(file.getOldPath()).thenReturn(path);
|
||||
when(file.getOldRevision()).thenReturn(oldRevision);
|
||||
when(file.getChangeType()).thenReturn(DiffFile.ChangeType.MODIFY);
|
||||
when(file.iterator()).thenReturn(Arrays.asList(hunks).iterator());
|
||||
return file;
|
||||
}
|
||||
|
||||
private DiffFile renamedFile(String newPath, String oldPath, String newRevision, String oldRevision) {
|
||||
DiffFile file = mock(DiffFile.class);
|
||||
when(file.getNewPath()).thenReturn(newPath);
|
||||
when(file.getNewRevision()).thenReturn(newRevision);
|
||||
when(file.getOldPath()).thenReturn(oldPath);
|
||||
when(file.getOldRevision()).thenReturn(oldRevision);
|
||||
when(file.getChangeType()).thenReturn(DiffFile.ChangeType.RENAME);
|
||||
when(file.iterator()).thenReturn(emptyIterator());
|
||||
return file;
|
||||
}
|
||||
|
||||
private DiffFile copiedFile(String newPath, String oldPath, String newRevision, String oldRevision) {
|
||||
DiffFile file = mock(DiffFile.class);
|
||||
when(file.getNewPath()).thenReturn(newPath);
|
||||
when(file.getNewRevision()).thenReturn(newRevision);
|
||||
when(file.getOldPath()).thenReturn(oldPath);
|
||||
when(file.getOldRevision()).thenReturn(oldRevision);
|
||||
when(file.getChangeType()).thenReturn(DiffFile.ChangeType.COPY);
|
||||
when(file.iterator()).thenReturn(emptyIterator());
|
||||
return file;
|
||||
}
|
||||
|
||||
private Hunk hunk(String rawHeader, int newStart, int newLineCount, int oldStart, int oldLineCount, DiffLine... lines) {
|
||||
Hunk hunk = mock(Hunk.class);
|
||||
when(hunk.getRawHeader()).thenReturn(rawHeader);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.api.v2.resources;
|
||||
|
||||
import com.google.inject.util.Providers;
|
||||
@@ -30,7 +30,6 @@ import org.apache.shiro.subject.Subject;
|
||||
import org.apache.shiro.subject.support.SubjectThreadState;
|
||||
import org.apache.shiro.util.ThreadContext;
|
||||
import org.apache.shiro.util.ThreadState;
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.jboss.resteasy.mock.MockHttpRequest;
|
||||
import org.jboss.resteasy.mock.MockHttpResponse;
|
||||
import org.junit.After;
|
||||
@@ -40,9 +39,12 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.repository.Added;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.NamespaceAndName;
|
||||
import sonia.scm.repository.Removed;
|
||||
import sonia.scm.repository.Modified;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.ModificationsCommandBuilder;
|
||||
import sonia.scm.repository.api.RepositoryService;
|
||||
@@ -141,7 +143,6 @@ public class ModificationsResourceTest extends RepositoryTestBase {
|
||||
|
||||
@Test
|
||||
public void shouldGetModifications() throws Exception {
|
||||
Modifications modifications = new Modifications();
|
||||
String revision = "revision";
|
||||
String addedFile_1 = "a.txt";
|
||||
String addedFile_2 = "b.txt";
|
||||
@@ -149,10 +150,13 @@ public class ModificationsResourceTest extends RepositoryTestBase {
|
||||
String modifiedFile_2 = "c.txt";
|
||||
String removedFile_1 = "e.txt";
|
||||
String removedFile_2 = "f.txt";
|
||||
modifications.setRevision(revision);
|
||||
modifications.setAdded(Lists.newArrayList(addedFile_1, addedFile_2));
|
||||
modifications.setModified(Lists.newArrayList(modifiedFile_1, modifiedFile_2));
|
||||
modifications.setRemoved(Lists.newArrayList(removedFile_1, removedFile_2));
|
||||
Modifications modifications = new Modifications(revision,
|
||||
new Added(addedFile_1),
|
||||
new Added(addedFile_2),
|
||||
new Modified(modifiedFile_1),
|
||||
new Modified(modifiedFile_2),
|
||||
new Removed(removedFile_1),
|
||||
new Removed(removedFile_2));
|
||||
when(modificationsCommandBuilder.getModifications()).thenReturn(modifications);
|
||||
when(modificationsCommandBuilder.revision(eq(revision))).thenReturn(modificationsCommandBuilder);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.lifecycle;
|
||||
|
||||
import com.github.legman.Subscribe;
|
||||
@@ -34,6 +34,7 @@ import sonia.scm.Stage;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.event.ScmTestEventBus;
|
||||
|
||||
import javax.servlet.ReadListener;
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -128,6 +129,21 @@ public class RestartServletTest {
|
||||
|
||||
private ServletInputStream createServletInputStream(final InputStream inputStream) {
|
||||
return new ServletInputStream() {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReady() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReadListener(ReadListener readListener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return inputStream.read();
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.lifecycle;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@@ -41,7 +41,7 @@ import java.nio.file.Paths;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
@ExtendWith({MockitoExtension.class, TempDirectory.class})
|
||||
@ExtendWith({MockitoExtension.class})
|
||||
class VersionsTest {
|
||||
|
||||
@Mock
|
||||
@@ -51,7 +51,7 @@ class VersionsTest {
|
||||
private Versions versions;
|
||||
|
||||
@Test
|
||||
void shouldReturnTrueForVersionsPreviousTo160(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
void shouldReturnTrueForVersionsPreviousTo160(@TempDir Path directory) throws IOException {
|
||||
setVersion(directory, "1.59");
|
||||
assertThat(versions.isPreviousVersionTooOld()).isTrue();
|
||||
|
||||
@@ -60,19 +60,19 @@ class VersionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseForVersion160(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
void shouldReturnFalseForVersion160(@TempDir Path directory) throws IOException {
|
||||
setVersion(directory, "1.60");
|
||||
assertThat(versions.isPreviousVersionTooOld()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotFailIfVersionContainsLineBreak(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
void shouldNotFailIfVersionContainsLineBreak(@TempDir Path directory) throws IOException {
|
||||
setVersion(directory, "1.59\n");
|
||||
assertThat(versions.isPreviousVersionTooOld()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseForVersionsNewerAs160(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
void shouldReturnFalseForVersionsNewerAs160(@TempDir Path directory) throws IOException {
|
||||
setVersion(directory, "1.61");
|
||||
assertThat(versions.isPreviousVersionTooOld()).isFalse();
|
||||
|
||||
@@ -81,13 +81,13 @@ class VersionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnFalseForNonExistingVersionFile(@TempDirectory.TempDir Path directory) {
|
||||
void shouldReturnFalseForNonExistingVersionFile(@TempDir Path directory) {
|
||||
setVersionFile(directory.resolve("version.txt"));
|
||||
assertThat(versions.isPreviousVersionTooOld()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldWriteNewVersion(@TempDirectory.TempDir Path directory) {
|
||||
void shouldWriteNewVersion(@TempDir Path directory) {
|
||||
Path config = directory.resolve("config");
|
||||
doReturn(config).when(contextProvider).resolve(Paths.get("config"));
|
||||
doReturn("2.0.0").when(contextProvider).getVersion();
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -48,7 +48,6 @@ import sonia.scm.lifecycle.Restarter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -56,7 +55,6 @@ import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singleton;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.in;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
@@ -72,7 +70,6 @@ import static sonia.scm.plugin.PluginTestHelper.createAvailable;
|
||||
import static sonia.scm.plugin.PluginTestHelper.createInstalled;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class DefaultPluginManagerTest {
|
||||
|
||||
@Mock
|
||||
@@ -372,7 +369,7 @@ class DefaultPluginManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCreateUninstallFile(@TempDirectory.TempDir Path temp) {
|
||||
void shouldCreateUninstallFile(@TempDir Path temp) {
|
||||
InstalledPlugin mailPlugin = createInstalled("scm-mail-plugin");
|
||||
when(mailPlugin.getDirectory()).thenReturn(temp);
|
||||
|
||||
@@ -384,7 +381,7 @@ class DefaultPluginManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldMarkPluginForUninstall(@TempDirectory.TempDir Path temp) {
|
||||
void shouldMarkPluginForUninstall(@TempDir Path temp) {
|
||||
InstalledPlugin mailPlugin = createInstalled("scm-mail-plugin");
|
||||
when(mailPlugin.getDirectory()).thenReturn(temp);
|
||||
|
||||
@@ -414,7 +411,7 @@ class DefaultPluginManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionWhenUninstallingCorePlugin(@TempDirectory.TempDir Path temp) {
|
||||
void shouldThrowExceptionWhenUninstallingCorePlugin(@TempDir Path temp) {
|
||||
InstalledPlugin mailPlugin = createInstalled("scm-mail-plugin");
|
||||
when(mailPlugin.getDirectory()).thenReturn(temp);
|
||||
when(mailPlugin.isCore()).thenReturn(true);
|
||||
@@ -484,7 +481,7 @@ class DefaultPluginManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUndoPendingInstallations(@TempDirectory.TempDir Path temp) throws IOException {
|
||||
void shouldUndoPendingInstallations(@TempDir Path temp) throws IOException {
|
||||
InstalledPlugin mailPlugin = createInstalled("scm-ssh-plugin");
|
||||
Path mailPluginPath = temp.resolve("scm-mail-plugin");
|
||||
Files.createDirectories(mailPluginPath);
|
||||
|
||||
@@ -21,12 +21,12 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@@ -39,14 +39,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith({MockitoExtension.class, TempDirectory.class})
|
||||
@ExtendWith({MockitoExtension.class})
|
||||
class PendingPluginInstallationTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private AvailablePlugin plugin;
|
||||
|
||||
@Test
|
||||
void shouldDeleteFileOnCancel(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
void shouldDeleteFileOnCancel(@TempDir Path directory) throws IOException {
|
||||
Path file = directory.resolve("file");
|
||||
Files.write(file, "42".getBytes());
|
||||
|
||||
@@ -59,7 +59,7 @@ class PendingPluginInstallationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldThrowExceptionIfCancelFailed(@TempDirectory.TempDir Path directory) {
|
||||
void shouldThrowExceptionIfCancelFailed(@TempDir Path directory) {
|
||||
Path file = directory.resolve("file");
|
||||
when(plugin.getDescriptor().getInformation().getName()).thenReturn("scm-awesome-plugin");
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
@@ -45,9 +45,13 @@ import java.util.Collections;
|
||||
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.*;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.anyInt;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith({MockitoExtension.class, TempDirectory.class})
|
||||
@ExtendWith({MockitoExtension.class})
|
||||
class PluginInstallerTest {
|
||||
|
||||
@Mock
|
||||
@@ -65,7 +69,7 @@ class PluginInstallerTest {
|
||||
private Path directory;
|
||||
|
||||
@BeforeEach
|
||||
void setUpContext(@TempDirectory.TempDir Path directory) throws IOException {
|
||||
void setUpContext(@TempDir Path directory) throws IOException {
|
||||
this.directory = directory;
|
||||
lenient().when(context.resolve(any())).then(ic -> {
|
||||
Path arg = ic.getArgument(0);
|
||||
|
||||
@@ -21,13 +21,12 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -38,7 +37,6 @@ import java.util.zip.ZipOutputStream;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class SmpDescriptorExtractorTest {
|
||||
|
||||
private static final String PLUGIN_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
|
||||
@@ -66,7 +64,7 @@ class SmpDescriptorExtractorTest {
|
||||
"</plugin>\n";
|
||||
|
||||
@Test
|
||||
void shouldExtractPluginXml(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldExtractPluginXml(@TempDir Path tempDir) throws IOException {
|
||||
Path pluginFile = createZipFile(tempDir, "META-INF/scm/plugin.xml", PLUGIN_XML);
|
||||
|
||||
InstalledPluginDescriptor installedPluginDescriptor = new SmpDescriptorExtractor().extractPluginDescriptor(pluginFile);
|
||||
@@ -75,14 +73,14 @@ class SmpDescriptorExtractorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithoutPluginXml(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldFailWithoutPluginXml(@TempDir Path tempDir) throws IOException {
|
||||
Path pluginFile = createZipFile(tempDir, "META-INF/wrong/plugin.xml", PLUGIN_XML);
|
||||
|
||||
assertThrows(IOException.class, () -> new SmpDescriptorExtractor().extractPluginDescriptor(pluginFile));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFailWithIllegalPluginXml(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldFailWithIllegalPluginXml(@TempDir Path tempDir) throws IOException {
|
||||
Path pluginFile = createZipFile(tempDir, "META-INF/scm/plugin.xml", "<not><parsable>content</parsable></not>");
|
||||
|
||||
assertThrows(IOException.class, () -> new SmpDescriptorExtractor().extractPluginDescriptor(pluginFile));
|
||||
|
||||
@@ -21,14 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.plugin;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.Resources;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
@@ -43,13 +42,12 @@ import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class UberClassLoaderTest {
|
||||
|
||||
private final URLClassLoader parentClassLoader = new URLClassLoader(new URL[0]);
|
||||
|
||||
@Test
|
||||
void shouldOnlyUseClassloaderOnce(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldOnlyUseClassloaderOnce(@TempDir Path tempDir) throws IOException {
|
||||
ClassLoader mailClassLoader = createClassLoader(tempDir, "plugin.txt", "mail");
|
||||
ClassLoader reviewClassLoader = createClassLoader(mailClassLoader, tempDir, "plugin.txt", "review");
|
||||
|
||||
@@ -61,7 +59,7 @@ class UberClassLoaderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldReturnResourceFromEachPluginClassLoader(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldReturnResourceFromEachPluginClassLoader(@TempDir Path tempDir) throws IOException {
|
||||
ClassLoader mailClassLoader = createClassLoader(tempDir, "scm.txt", "mail");
|
||||
ClassLoader reviewClassLoader = createClassLoader(tempDir, "scm.txt", "review");
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.group;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -39,7 +39,6 @@ import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
|
||||
import sonia.scm.update.UpdateStepTestUtil;
|
||||
import sonia.scm.update.V1Properties;
|
||||
import sonia.scm.update.V1Property;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.IOException;
|
||||
@@ -55,7 +54,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class XmlGroupV1UpdateStepTest {
|
||||
|
||||
@Mock
|
||||
@@ -72,7 +70,7 @@ class XmlGroupV1UpdateStepTest {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockScmHome(@TempDir Path tempDir) {
|
||||
testUtil = new UpdateStepTestUtil(tempDir);
|
||||
updateStep = new XmlGroupV1UpdateStep(testUtil.getContextProvider(), groupDAO, storeFactory);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -44,7 +44,6 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CopyMigrationStrategyTest {
|
||||
|
||||
@@ -54,30 +53,30 @@ class CopyMigrationStrategyTest {
|
||||
RepositoryLocationResolver locationResolver;
|
||||
|
||||
@BeforeEach
|
||||
void mockContextProvider(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockContextProvider(@TempDir Path tempDir) {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void mockLocationResolver(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockLocationResolver(@TempDir Path tempDir) {
|
||||
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(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldUseStandardDirectory(@TempDir Path tempDir) {
|
||||
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(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldCopyDataDirectory(@TempDir Path tempDir) {
|
||||
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
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
@@ -29,7 +29,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -43,7 +43,6 @@ import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.update.repository.MigrationStrategy.INLINE;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class DefaultMigrationStrategyDAOTest {
|
||||
|
||||
@Mock
|
||||
@@ -52,7 +51,7 @@ class DefaultMigrationStrategyDAOTest {
|
||||
private ConfigurationStoreFactory storeFactory;
|
||||
|
||||
@BeforeEach
|
||||
void initStore(@TempDirectory.TempDir Path tempDir) {
|
||||
void initStore(@TempDir Path tempDir) {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
storeFactory = new JAXBConfigurationStoreFactory(contextProvider, null);
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -41,7 +41,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class InlineMigrationStrategyTest {
|
||||
|
||||
@@ -53,25 +52,25 @@ class InlineMigrationStrategyTest {
|
||||
RepositoryLocationResolver.RepositoryLocationResolverInstance locationResolverInstance;
|
||||
|
||||
@BeforeEach
|
||||
void mockContextProvider(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockContextProvider(@TempDir Path tempDir) {
|
||||
when(locationResolver.forClass(Path.class)).thenReturn(locationResolverInstance);
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseExistingDirectory(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldUseExistingDirectory(@TempDir Path tempDir) {
|
||||
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(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldMoveDataDirectory(@TempDir Path tempDir) {
|
||||
new InlineMigrationStrategy(contextProvider, locationResolver).migrate("b4f-a9f0-49f7-ad1f-37d3aae1c55f", "some/more/directories/than/one", "git");
|
||||
assertThat(resolveOldDirectory(tempDir).resolve("data")).exists();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
@@ -29,7 +29,7 @@ import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@@ -51,7 +51,6 @@ import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class MigrateVerbsToPermissionRolesTest {
|
||||
|
||||
private static final String EXISTING_REPOSITORY_ID = "id";
|
||||
@@ -65,7 +64,7 @@ class MigrateVerbsToPermissionRolesTest {
|
||||
private MigrateVerbsToPermissionRoles migration;
|
||||
|
||||
@BeforeEach
|
||||
void init(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void init(@TempDir Path tempDir) throws IOException {
|
||||
URL metadataUrl = Resources.getResource("sonia/scm/update/repository/metadataWithoutRoles.xml");
|
||||
Files.copy(metadataUrl.openStream(), tempDir.resolve("metadata.xml"));
|
||||
doAnswer(invocation -> {
|
||||
@@ -76,7 +75,7 @@ class MigrateVerbsToPermissionRolesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUpdateToRolesIfPossible(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldUpdateToRolesIfPossible(@TempDir Path tempDir) throws IOException {
|
||||
migration.doUpdate();
|
||||
|
||||
List<String> newMetadata = Files.readAllLines(tempDir.resolve("metadata.xml"));
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -41,7 +41,6 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MoveMigrationStrategyTest {
|
||||
|
||||
@@ -51,30 +50,30 @@ class MoveMigrationStrategyTest {
|
||||
RepositoryLocationResolver locationResolver;
|
||||
|
||||
@BeforeEach
|
||||
void mockContextProvider(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockContextProvider(@TempDir Path tempDir) {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void mockLocationResolver(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockLocationResolver(@TempDir Path tempDir) {
|
||||
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(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldUseStandardDirectory(@TempDir Path tempDir) {
|
||||
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(@TempDirectory.TempDir Path tempDir) {
|
||||
void shouldMoveDataDirectory(@TempDir Path tempDir) {
|
||||
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
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -35,7 +35,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryPermission;
|
||||
import sonia.scm.repository.RepositoryRolePermissions;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
import sonia.scm.repository.xml.XmlRepositoryDAO;
|
||||
import sonia.scm.update.UpdateStepTestUtil;
|
||||
@@ -49,7 +48,6 @@ import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junitpioneer.jupiter.TempDirectory.TempDir;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -58,7 +56,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class PublicFlagUpdateStepTest {
|
||||
|
||||
@Mock
|
||||
|
||||
@@ -21,14 +21,13 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.repository.xml.PathBasedRepositoryLocationResolver;
|
||||
import sonia.scm.repository.xml.XmlRepositoryDAO;
|
||||
@@ -43,19 +42,18 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class XmlRepositoryFileNameUpdateStepTest {
|
||||
|
||||
SCMContextProvider contextProvider = mock(SCMContextProvider.class);
|
||||
XmlRepositoryDAO repositoryDAO = mock(XmlRepositoryDAO.class);
|
||||
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockScmHome(@TempDir Path tempDir) {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldCopyRepositoriesFileToRepositoryPathsFile(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldCopyRepositoriesFileToRepositoryPathsFile(@TempDir Path tempDir) throws IOException {
|
||||
XmlRepositoryFileNameUpdateStep updateStep = new XmlRepositoryFileNameUpdateStep(contextProvider, repositoryDAO);
|
||||
URL url = Resources.getResource("sonia/scm/update/repository/formerV2RepositoryFile.xml");
|
||||
Path configDir = tempDir.resolve("config");
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.repository;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
@@ -30,7 +30,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -63,7 +63,6 @@ import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.update.repository.MigrationStrategy.MOVE;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class XmlRepositoryV1UpdateStepTest {
|
||||
|
||||
Injector injectorMock = MigrationStrategyMock.init();
|
||||
@@ -85,7 +84,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
XmlRepositoryV1UpdateStep updateStep;
|
||||
|
||||
@BeforeEach
|
||||
void createUpdateStepFromMocks(@TempDirectory.TempDir Path tempDir) {
|
||||
void createUpdateStepFromMocks(@TempDir Path tempDir) {
|
||||
testUtil = new UpdateStepTestUtil(tempDir);
|
||||
updateStep = new XmlRepositoryV1UpdateStep(
|
||||
testUtil.getContextProvider(),
|
||||
@@ -100,7 +99,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
class WithExistingDatabase {
|
||||
|
||||
@BeforeEach
|
||||
void createV1Home(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void createV1Home(@TempDir Path tempDir) throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
}
|
||||
|
||||
@@ -165,7 +164,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseDirectoryFromStrategy(@TempDirectory.TempDir Path tempDir) throws JAXBException {
|
||||
void shouldUseDirectoryFromStrategy(@TempDir Path tempDir) 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));
|
||||
@@ -195,7 +194,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldBackupOldRepositoryDatabaseFile(@TempDirectory.TempDir Path tempDir) throws JAXBException {
|
||||
void shouldBackupOldRepositoryDatabaseFile(@TempDir Path tempDir) throws JAXBException {
|
||||
updateStep.doUpdate();
|
||||
|
||||
assertThat(tempDir.resolve("config").resolve("repositories.xml")).doesNotExist();
|
||||
@@ -209,14 +208,14 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotFailIfFormerV2DatabaseExists(@TempDirectory.TempDir Path tempDir) throws JAXBException, IOException {
|
||||
void shouldNotFailIfFormerV2DatabaseExists(@TempDir Path tempDir) throws JAXBException, IOException {
|
||||
createFormerV2RepositoriesFile(tempDir);
|
||||
|
||||
updateStep.doUpdate();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldNotBackupFormerV2DatabaseFile(@TempDirectory.TempDir Path tempDir) throws JAXBException, IOException {
|
||||
void shouldNotBackupFormerV2DatabaseFile(@TempDir Path tempDir) throws JAXBException, IOException {
|
||||
createFormerV2RepositoriesFile(tempDir);
|
||||
|
||||
updateStep.doUpdate();
|
||||
@@ -226,14 +225,14 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldGetNoMissingStrategiesWithFormerV2DatabaseFile(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldGetNoMissingStrategiesWithFormerV2DatabaseFile(@TempDir Path tempDir) throws IOException {
|
||||
createFormerV2RepositoriesFile(tempDir);
|
||||
|
||||
assertThat(updateStep.getRepositoriesWithoutMigrationStrategies()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldFindMissingStrategies(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void shouldFindMissingStrategies(@TempDir Path tempDir) throws IOException {
|
||||
V1RepositoryFileSystem.createV1Home(tempDir);
|
||||
|
||||
assertThat(updateStep.getRepositoriesWithoutMigrationStrategies())
|
||||
@@ -244,7 +243,7 @@ class XmlRepositoryV1UpdateStepTest {
|
||||
"454972da-faf9-4437-b682-dc4a4e0aa8eb");
|
||||
}
|
||||
|
||||
private void createFormerV2RepositoriesFile(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
private void createFormerV2RepositoriesFile(@TempDir Path tempDir) throws IOException {
|
||||
URL url = Resources.getResource("sonia/scm/update/repository/formerV2RepositoryFile.xml");
|
||||
Path configDir = tempDir.resolve("config");
|
||||
Files.createDirectories(configDir);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.security;
|
||||
|
||||
import com.google.common.io.Resources;
|
||||
@@ -29,7 +29,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
@@ -50,7 +50,6 @@ import static org.mockito.Mockito.when;
|
||||
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class XmlSecurityV1UpdateStepTest {
|
||||
|
||||
@Mock
|
||||
@@ -60,7 +59,7 @@ class XmlSecurityV1UpdateStepTest {
|
||||
ConfigurationEntryStore<AssignedPermission> assignedPermissionStore;
|
||||
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockScmHome(@TempDir Path tempDir) {
|
||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||
InMemoryConfigurationEntryStoreFactory inMemoryConfigurationEntryStoreFactory = create();
|
||||
assignedPermissionStore = inMemoryConfigurationEntryStoreFactory.get("security");
|
||||
@@ -71,7 +70,7 @@ class XmlSecurityV1UpdateStepTest {
|
||||
class WithExistingDatabase {
|
||||
|
||||
@BeforeEach
|
||||
void createConfigV1XML(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void createConfigV1XML(@TempDir Path tempDir) throws IOException {
|
||||
Path configDir = tempDir.resolve("config");
|
||||
Files.createDirectories(configDir);
|
||||
copyTestDatabaseFile(configDir, "config.xml");
|
||||
@@ -109,7 +108,7 @@ class XmlSecurityV1UpdateStepTest {
|
||||
class WithExistingSecurityXml {
|
||||
|
||||
@BeforeEach
|
||||
void createSecurityV1XML(@TempDirectory.TempDir Path tempDir) throws IOException {
|
||||
void createSecurityV1XML(@TempDir Path tempDir) throws IOException {
|
||||
Path configDir = tempDir.resolve("config");
|
||||
Files.createDirectories(configDir);
|
||||
copyTestDatabaseFile(configDir, "securityV1.xml");
|
||||
|
||||
@@ -21,14 +21,14 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.update.user;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junitpioneer.jupiter.TempDirectory;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
@@ -38,7 +38,6 @@ import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
|
||||
import sonia.scm.update.UpdateStepTestUtil;
|
||||
import sonia.scm.update.V1Properties;
|
||||
import sonia.scm.update.V1Property;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.xml.XmlUserDAO;
|
||||
|
||||
@@ -55,7 +54,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
class XmlUserV1UpdateStepTest {
|
||||
|
||||
@Mock
|
||||
@@ -71,7 +69,7 @@ class XmlUserV1UpdateStepTest {
|
||||
private UpdateStepTestUtil testUtil;
|
||||
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
void mockScmHome(@TempDir Path tempDir) {
|
||||
testUtil = new UpdateStepTestUtil(tempDir);
|
||||
updateStep = new XmlUserV1UpdateStep(testUtil.getContextProvider(), userDAO, storeFactory);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user