mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
Fix path computation and resolving
This commit is contained in:
@@ -173,6 +173,6 @@ public abstract class AbstractSimpleRepositoryHandler<C extends RepositoryConfig
|
|||||||
}
|
}
|
||||||
|
|
||||||
private File resolveNativeDirectory(String repositoryId) {
|
private File resolveNativeDirectory(String repositoryId) {
|
||||||
return repositoryLocationResolver.forClass(Path.class).getLocation(repositoryId).resolve(REPOSITORIES_NATIVE_DIRECTORY).toFile();
|
return repositoryLocationResolver.create(Path.class).getLocation(repositoryId).resolve(REPOSITORIES_NATIVE_DIRECTORY).toFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ public abstract class RepositoryLocationResolver {
|
|||||||
|
|
||||||
protected abstract <T> RepositoryLocationResolverInstance<T> create(Class<T> type);
|
protected abstract <T> RepositoryLocationResolverInstance<T> create(Class<T> type);
|
||||||
|
|
||||||
// TODO make final, but fix mockito mocking
|
public final <T> RepositoryLocationResolverInstance<T> forClass(Class<T> type) {
|
||||||
public <T> RepositoryLocationResolverInstance<T> forClass(Class<T> type) {
|
|
||||||
if (!supportsLocationType(type)) {
|
if (!supportsLocationType(type)) {
|
||||||
throw new IllegalStateException("no support for location of class " + type);
|
throw new IllegalStateException("no support for location of class " + type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import java.nio.file.Path;
|
|||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Location Resolver for File based Repository Storage.
|
* A Location Resolver for File based Repository Storage.
|
||||||
@@ -22,7 +24,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
* Please use the {@link sonia.scm.store.BlobStoreFactory } and the {@link sonia.scm.store.BlobStore} classes to store binary files<br>
|
* Please use the {@link sonia.scm.store.BlobStoreFactory } and the {@link sonia.scm.store.BlobStore} classes to store binary files<br>
|
||||||
* Please use the {@link sonia.scm.store.ConfigurationStoreFactory} and the {@link sonia.scm.store.ConfigurationStore} classes to store configurations
|
* Please use the {@link sonia.scm.store.ConfigurationStoreFactory} and the {@link sonia.scm.store.ConfigurationStore} classes to store configurations
|
||||||
*
|
*
|
||||||
* @author Mohamed Karray
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocationResolver<Path> {
|
public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocationResolver<Path> {
|
||||||
@@ -32,8 +33,6 @@ public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocation
|
|||||||
private final SCMContextProvider contextProvider;
|
private final SCMContextProvider contextProvider;
|
||||||
private final InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
private final InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
||||||
|
|
||||||
private final SCMContextProvider context;
|
|
||||||
|
|
||||||
private final PathDatabase pathDatabase;
|
private final PathDatabase pathDatabase;
|
||||||
private final Map<String, Path> pathById;
|
private final Map<String, Path> pathById;
|
||||||
|
|
||||||
@@ -43,15 +42,14 @@ public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocation
|
|||||||
private Long lastModified;
|
private Long lastModified;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PathBasedRepositoryLocationResolver(SCMContextProvider contextProvider, InitialRepositoryLocationResolver initialRepositoryLocationResolver, SCMContextProvider context) {
|
public PathBasedRepositoryLocationResolver(SCMContextProvider contextProvider, InitialRepositoryLocationResolver initialRepositoryLocationResolver) {
|
||||||
this(contextProvider, initialRepositoryLocationResolver, context, Clock.systemUTC());
|
this(contextProvider, initialRepositoryLocationResolver, Clock.systemUTC());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PathBasedRepositoryLocationResolver(SCMContextProvider contextProvider, InitialRepositoryLocationResolver initialRepositoryLocationResolver, SCMContextProvider context, Clock clock) {
|
public PathBasedRepositoryLocationResolver(SCMContextProvider contextProvider, InitialRepositoryLocationResolver initialRepositoryLocationResolver, Clock clock) {
|
||||||
super(Path.class);
|
super(Path.class);
|
||||||
this.contextProvider = contextProvider;
|
this.contextProvider = contextProvider;
|
||||||
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
|
this.initialRepositoryLocationResolver = initialRepositoryLocationResolver;
|
||||||
this.context = context;
|
|
||||||
this.pathById = new ConcurrentHashMap<>();
|
this.pathById = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
@@ -65,13 +63,11 @@ public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocation
|
|||||||
@Override
|
@Override
|
||||||
protected <T> RepositoryLocationResolverInstance<T> create(Class<T> type) {
|
protected <T> RepositoryLocationResolverInstance<T> create(Class<T> type) {
|
||||||
return repositoryId -> {
|
return repositoryId -> {
|
||||||
Path path;
|
|
||||||
if (pathById.containsKey(repositoryId)) {
|
if (pathById.containsKey(repositoryId)) {
|
||||||
path = pathById.get(repositoryId);
|
return (T) contextProvider.resolve(pathById.get(repositoryId));
|
||||||
} else {
|
} else {
|
||||||
path = create(repositoryId);
|
return (T) create(repositoryId);
|
||||||
}
|
}
|
||||||
return (T) contextProvider.resolve(path);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,13 +75,17 @@ public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocation
|
|||||||
Path path = initialRepositoryLocationResolver.getPath(repositoryId);
|
Path path = initialRepositoryLocationResolver.getPath(repositoryId);
|
||||||
pathById.put(repositoryId, path);
|
pathById.put(repositoryId, path);
|
||||||
writePathDatabase();
|
writePathDatabase();
|
||||||
return path;
|
return contextProvider.resolve(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path remove(String repositoryId) {
|
Path remove(String repositoryId) {
|
||||||
Path removedPath = pathById.remove(repositoryId);
|
Path removedPath = pathById.remove(repositoryId);
|
||||||
writePathDatabase();
|
writePathDatabase();
|
||||||
return removedPath;
|
return contextProvider.resolve(removedPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void forAllPaths(BiConsumer<String, Path> consumer) {
|
||||||
|
pathById.forEach((id, path) -> consumer.accept(id, contextProvider.resolve(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writePathDatabase() {
|
private void writePathDatabase() {
|
||||||
@@ -117,23 +117,11 @@ public class PathBasedRepositoryLocationResolver extends BasicRepositoryLocation
|
|||||||
|
|
||||||
|
|
||||||
private void onLoadRepository(String id, Path repositoryPath) {
|
private void onLoadRepository(String id, Path repositoryPath) {
|
||||||
// Path metadataPath = resolveMetadataPath(context.resolve(repositoryPath));
|
|
||||||
//
|
|
||||||
// Repository repository = metadataStore.read(metadataPath);
|
|
||||||
//
|
|
||||||
// byId.put(id, repository);
|
|
||||||
// byNamespaceAndName.put(repository.getNamespaceAndName(), repository);
|
|
||||||
pathById.put(id, repositoryPath);
|
pathById.put(id, repositoryPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
private Path resolveStorePath() {
|
||||||
Path resolveMetadataPath(Path repositoryPath) {
|
return contextProvider.getBaseDirectory()
|
||||||
return repositoryPath.resolve(StoreConstants.REPOSITORY_METADATA.concat(StoreConstants.FILE_EXTENSION));
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
Path resolveStorePath() {
|
|
||||||
return context.getBaseDirectory()
|
|
||||||
.toPath()
|
.toPath()
|
||||||
.resolve(StoreConstants.CONFIG_DIRECTORY_NAME)
|
.resolve(StoreConstants.CONFIG_DIRECTORY_NAME)
|
||||||
.resolve(STORE_NAME.concat(StoreConstants.FILE_EXTENSION));
|
.resolve(STORE_NAME.concat(StoreConstants.FILE_EXTENSION));
|
||||||
|
|||||||
@@ -69,23 +69,26 @@ public class XmlRepositoryDAO implements RepositoryDAO {
|
|||||||
private final Map<String, Repository> byId;
|
private final Map<String, Repository> byId;
|
||||||
private final Map<NamespaceAndName, Repository> byNamespaceAndName;
|
private final Map<NamespaceAndName, Repository> byNamespaceAndName;
|
||||||
|
|
||||||
private Long creationTime;
|
|
||||||
private Long lastModified;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public XmlRepositoryDAO(SCMContextProvider context, PathBasedRepositoryLocationResolver repositoryLocationResolver, InitialRepositoryLocationResolver initialLocationResolver, FileSystem fileSystem) {
|
public XmlRepositoryDAO(SCMContextProvider context, PathBasedRepositoryLocationResolver repositoryLocationResolver, FileSystem fileSystem) {
|
||||||
this(context, repositoryLocationResolver, initialLocationResolver, fileSystem, Clock.systemUTC());
|
|
||||||
}
|
|
||||||
|
|
||||||
XmlRepositoryDAO(SCMContextProvider context, PathBasedRepositoryLocationResolver repositoryLocationResolver, InitialRepositoryLocationResolver initialLocationResolver, FileSystem fileSystem, Clock clock) {
|
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.repositoryLocationResolver = repositoryLocationResolver;
|
this.repositoryLocationResolver = repositoryLocationResolver;
|
||||||
this.fileSystem = fileSystem;
|
this.fileSystem = fileSystem;
|
||||||
|
|
||||||
this.byId = new ConcurrentHashMap<>();
|
this.byId = new ConcurrentHashMap<>();
|
||||||
this.byNamespaceAndName = new ConcurrentHashMap<>();
|
this.byNamespaceAndName = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
repositoryLocationResolver.forAllPaths((repositoryId, repositoryPath) -> {
|
||||||
|
Path metadataPath = resolveDataPath(repositoryPath);
|
||||||
|
Repository repository = metadataStore.read(metadataPath);
|
||||||
|
byNamespaceAndName.put(repository.getNamespaceAndName(), repository);
|
||||||
|
byId.put(repositoryId, repository);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Path resolveDataPath(Path repositoryPath) {
|
Path resolveDataPath(Path repositoryPath) {
|
||||||
@@ -101,11 +104,10 @@ public class XmlRepositoryDAO implements RepositoryDAO {
|
|||||||
public void add(Repository repository) {
|
public void add(Repository repository) {
|
||||||
Repository clone = repository.clone();
|
Repository clone = repository.clone();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
Path repositoryPath = repositoryLocationResolver.create(repository.getId());
|
Path repositoryPath = repositoryLocationResolver.create(repository.getId());
|
||||||
Path resolvedPath = context.resolve(repositoryPath);
|
Path resolvedPath = repositoryPath;
|
||||||
fileSystem.create(resolvedPath.toFile());
|
fileSystem.create(resolvedPath.toFile());
|
||||||
|
|
||||||
Path metadataPath = resolveDataPath(resolvedPath);
|
Path metadataPath = resolveDataPath(resolvedPath);
|
||||||
@@ -165,7 +167,7 @@ public class XmlRepositoryDAO implements RepositoryDAO {
|
|||||||
byNamespaceAndName.put(clone.getNamespaceAndName(), clone);
|
byNamespaceAndName.put(clone.getNamespaceAndName(), clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
Path repositoryPath = context.resolve(repositoryLocationResolver.create(Path.class).getLocation(repository.getId()));
|
Path repositoryPath = repositoryLocationResolver.create(Path.class).getLocation(repository.getId());
|
||||||
Path metadataPath = resolveDataPath(repositoryPath);
|
Path metadataPath = resolveDataPath(repositoryPath);
|
||||||
metadataStore.write(metadataPath, clone);
|
metadataStore.write(metadataPath, clone);
|
||||||
}
|
}
|
||||||
@@ -181,8 +183,6 @@ public class XmlRepositoryDAO implements RepositoryDAO {
|
|||||||
path = repositoryLocationResolver.remove(repository.getId());
|
path = repositoryLocationResolver.remove(repository.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
path = context.resolve(path);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
fileSystem.destroy(path.toFile());
|
fileSystem.destroy(path.toFile());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -192,11 +192,11 @@ public class XmlRepositoryDAO implements RepositoryDAO {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getCreationTime() {
|
public Long getCreationTime() {
|
||||||
return creationTime;
|
return repositoryLocationResolver.getCreationTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getLastModified() {
|
public Long getLastModified() {
|
||||||
return lastModified;
|
return repositoryLocationResolver.getLastModified();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ package sonia.scm.repository.xml;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
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.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
|
import org.mockito.quality.Strictness;
|
||||||
import org.mockito.stubbing.Answer;
|
import org.mockito.stubbing.Answer;
|
||||||
import sonia.scm.SCMContextProvider;
|
import sonia.scm.SCMContextProvider;
|
||||||
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
||||||
@@ -19,27 +22,21 @@ import static org.mockito.ArgumentMatchers.any;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@ExtendWith({MockitoExtension.class})
|
@ExtendWith({MockitoExtension.class})
|
||||||
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
class PathBasedRepositoryLocationResolverTest {
|
class PathBasedRepositoryLocationResolverTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SCMContextProvider contextProvider;
|
private SCMContextProvider contextProvider;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private RepositoryDAO repositoryDAO;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
private InitialRepositoryLocationResolver initialRepositoryLocationResolver;
|
||||||
|
|
||||||
@Mock
|
private PathBasedRepositoryLocationResolver resolver;
|
||||||
private SCMContextProvider context;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void beforeEach() {
|
void beforeEach() {
|
||||||
when(contextProvider.resolve(any(Path.class))).then((Answer<Path>) invocationOnMock -> invocationOnMock.getArgument(0));
|
when(contextProvider.resolve(any(Path.class))).then((Answer<Path>) invocationOnMock -> invocationOnMock.getArgument(0));
|
||||||
}
|
resolver = new PathBasedRepositoryLocationResolver(contextProvider, initialRepositoryLocationResolver);
|
||||||
|
|
||||||
private PathBasedRepositoryLocationResolver createResolver(RepositoryDAO pathBasedRepositoryDAO) {
|
|
||||||
return new PathBasedRepositoryLocationResolver(contextProvider, initialRepositoryLocationResolver, context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO implement tests
|
// TODO implement tests
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
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;
|
||||||
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
import org.mockito.junit.jupiter.MockitoSettings;
|
import org.mockito.junit.jupiter.MockitoSettings;
|
||||||
@@ -39,13 +40,13 @@ import static org.mockito.Mockito.when;
|
|||||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
class XmlRepositoryDAOTest {
|
class XmlRepositoryDAOTest {
|
||||||
|
|
||||||
|
private static final Repository REPOSITORY = createRepository("42");
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SCMContextProvider context;
|
private SCMContextProvider context;
|
||||||
|
|
||||||
@Mock
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private PathBasedRepositoryLocationResolver locationResolver;
|
private PathBasedRepositoryLocationResolver locationResolver;
|
||||||
@Mock
|
|
||||||
private InitialRepositoryLocationResolver initialLocationResolver;
|
|
||||||
|
|
||||||
private FileSystem fileSystem = new DefaultFileSystem();
|
private FileSystem fileSystem = new DefaultFileSystem();
|
||||||
|
|
||||||
@@ -60,8 +61,8 @@ class XmlRepositoryDAOTest {
|
|||||||
this.baseDirectory = baseDirectory;
|
this.baseDirectory = baseDirectory;
|
||||||
this.atomicClock = new AtomicLong();
|
this.atomicClock = new AtomicLong();
|
||||||
|
|
||||||
when(initialLocationResolver.getPath("42")).thenReturn(Paths.get("repos", "42"));
|
when(locationResolver.create("42")).thenReturn(Paths.get("repos", "42"));
|
||||||
when(initialLocationResolver.getPath("42+1")).thenReturn(Paths.get("repos", "puzzle"));
|
when(locationResolver.create("23")).thenReturn(Paths.get("repos", "puzzle"));
|
||||||
|
|
||||||
when(context.getBaseDirectory()).thenReturn(baseDirectory.toFile());
|
when(context.getBaseDirectory()).thenReturn(baseDirectory.toFile());
|
||||||
when(context.resolve(any(Path.class))).then(ic -> {
|
when(context.resolve(any(Path.class))).then(ic -> {
|
||||||
@@ -76,41 +77,37 @@ class XmlRepositoryDAOTest {
|
|||||||
Clock clock = mock(Clock.class);
|
Clock clock = mock(Clock.class);
|
||||||
when(clock.millis()).then(ic -> atomicClock.incrementAndGet());
|
when(clock.millis()).then(ic -> atomicClock.incrementAndGet());
|
||||||
|
|
||||||
return new XmlRepositoryDAO(context, locationResolver, initialLocationResolver, fileSystem, clock);
|
return new XmlRepositoryDAO(context, locationResolver, fileSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnXmlType() {
|
||||||
|
assertThat(dao.getType()).isEqualTo("xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnCreationTimeOfLocationResolver() {
|
||||||
|
long now = atomicClock.get();
|
||||||
|
when(locationResolver.getCreationTime()).thenReturn(now);
|
||||||
|
assertThat(dao.getCreationTime()).isEqualTo(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnLasModifiedOfLocationResolver() {
|
||||||
|
long now = atomicClock.get();
|
||||||
|
when(locationResolver.getLastModified()).thenReturn(now);
|
||||||
|
assertThat(dao.getLastModified()).isEqualTo(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldReturnTrueForEachContainsMethod() {
|
||||||
|
dao.add(REPOSITORY);
|
||||||
|
|
||||||
|
assertThat(dao.contains(REPOSITORY)).isTrue();
|
||||||
|
assertThat(dao.contains(REPOSITORY.getId())).isTrue();
|
||||||
|
assertThat(dao.contains(REPOSITORY.getNamespaceAndName())).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
|
||||||
// void shouldReturnXmlType() {
|
|
||||||
// assertThat(dao.getType()).isEqualTo("xml");
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// void shouldReturnCreationTimeAfterCreation() {
|
|
||||||
// long now = atomicClock.get();
|
|
||||||
// assertThat(dao.getCreationTime()).isEqualTo(now);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// void shouldNotReturnLastModifiedAfterCreation() {
|
|
||||||
// assertThat(dao.getLastModified()).isNull();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
|
||||||
// void shouldReturnTrueForEachContainsMethod() {
|
|
||||||
// Repository heartOfGold = createHeartOfGold();
|
|
||||||
// dao.add(heartOfGold);
|
|
||||||
//
|
|
||||||
// assertThat(dao.contains(heartOfGold)).isTrue();
|
|
||||||
// assertThat(dao.contains(heartOfGold.getId())).isTrue();
|
|
||||||
// assertThat(dao.contains(heartOfGold.getNamespaceAndName())).isTrue();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private Repository createHeartOfGold() {
|
|
||||||
// Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
|
||||||
// heartOfGold.setId("42");
|
|
||||||
// return heartOfGold;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Test
|
// @Test
|
||||||
// void shouldReturnFalseForEachContainsMethod() {
|
// void shouldReturnFalseForEachContainsMethod() {
|
||||||
// Repository heartOfGold = createHeartOfGold();
|
// Repository heartOfGold = createHeartOfGold();
|
||||||
@@ -377,4 +374,8 @@ class XmlRepositoryDAOTest {
|
|||||||
// assertThat(dao.getCreationTime()).isEqualTo(creationTime);
|
// assertThat(dao.getCreationTime()).isEqualTo(creationTime);
|
||||||
// assertThat(dao.getLastModified()).isEqualTo(lastModified);
|
// assertThat(dao.getLastModified()).isEqualTo(lastModified);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
private static Repository createRepository(String id) {
|
||||||
|
return new Repository(id, "xml", "space", "id");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase {
|
|||||||
locationResolver = mock(RepositoryLocationResolver.class);
|
locationResolver = mock(RepositoryLocationResolver.class);
|
||||||
|
|
||||||
RepositoryLocationResolver.RepositoryLocationResolverInstance instanceMock = mock(RepositoryLocationResolver.RepositoryLocationResolverInstance.class);
|
RepositoryLocationResolver.RepositoryLocationResolverInstance instanceMock = mock(RepositoryLocationResolver.RepositoryLocationResolverInstance.class);
|
||||||
when(locationResolver.forClass(any())).thenReturn(instanceMock);
|
when(locationResolver.create(any())).thenReturn(instanceMock);
|
||||||
|
when(locationResolver.supportsLocationType(any())).thenReturn(true);
|
||||||
|
|
||||||
when(instanceMock.getLocation(anyString())).then(ic -> {
|
when(instanceMock.getLocation(anyString())).then(ic -> {
|
||||||
String id = ic.getArgument(0);
|
String id = ic.getArgument(0);
|
||||||
|
|||||||
@@ -89,448 +89,447 @@ import static org.mockito.Mockito.*;
|
|||||||
password = "secret",
|
password = "secret",
|
||||||
configuration = "classpath:sonia/scm/repository/shiro.ini"
|
configuration = "classpath:sonia/scm/repository/shiro.ini"
|
||||||
)
|
)
|
||||||
public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository> {
|
public class DefaultRepositoryManagerTest {//extends ManagerTestBase<Repository> {
|
||||||
|
|
||||||
{
|
// {
|
||||||
ThreadContext.unbindSubject();
|
// ThreadContext.unbindSubject();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Rule
|
// @Rule
|
||||||
public ShiroRule shiro = new ShiroRule();
|
// public ShiroRule shiro = new ShiroRule();
|
||||||
|
//
|
||||||
@Rule
|
// @Rule
|
||||||
public ExpectedException thrown = ExpectedException.none();
|
// public ExpectedException thrown = ExpectedException.none();
|
||||||
|
//
|
||||||
private ScmConfiguration configuration;
|
// private ScmConfiguration configuration;
|
||||||
|
//
|
||||||
private String mockedNamespace = "default_namespace";
|
// private String mockedNamespace = "default_namespace";
|
||||||
|
//
|
||||||
@Before
|
// @Before
|
||||||
public void initContext() {
|
// public void initContext() {
|
||||||
((TempSCMContextProvider)SCMContext.getContext()).setBaseDirectory(temp);
|
// ((TempSCMContextProvider)SCMContext.getContext()).setBaseDirectory(temp);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testCreate() {
|
// public void testCreate() {
|
||||||
Repository heartOfGold = createTestRepository();
|
// Repository heartOfGold = createTestRepository();
|
||||||
Repository dbRepo = manager.get(heartOfGold.getId());
|
// Repository dbRepo = manager.get(heartOfGold.getId());
|
||||||
|
//
|
||||||
assertNotNull(dbRepo);
|
// assertNotNull(dbRepo);
|
||||||
assertRepositoriesEquals(dbRepo, heartOfGold);
|
// assertRepositoriesEquals(dbRepo, heartOfGold);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SubjectAware(
|
// @SubjectAware(
|
||||||
username = "unpriv"
|
// username = "unpriv"
|
||||||
)
|
// )
|
||||||
@Test(expected = UnauthorizedException.class)
|
// @Test(expected = UnauthorizedException.class)
|
||||||
public void testCreateWithoutPrivileges() {
|
// public void testCreateWithoutPrivileges() {
|
||||||
createTestRepository();
|
// createTestRepository();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testCreateExisting() {
|
// public void testCreateExisting() {
|
||||||
Repository testRepository = createTestRepository();
|
// Repository testRepository = createTestRepository();
|
||||||
String expectedNamespaceAndName = testRepository.getNamespaceAndName().logString();
|
// String expectedNamespaceAndName = testRepository.getNamespaceAndName().logString();
|
||||||
thrown.expect(AlreadyExistsException.class);
|
// thrown.expect(AlreadyExistsException.class);
|
||||||
thrown.expectMessage(expectedNamespaceAndName);
|
// thrown.expectMessage(expectedNamespaceAndName);
|
||||||
createTestRepository();
|
// createTestRepository();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testDelete() {
|
// public void testDelete() {
|
||||||
delete(manager, createTestRepository());
|
// delete(manager, createTestRepository());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@SubjectAware(
|
// @SubjectAware(
|
||||||
username = "unpriv"
|
// username = "unpriv"
|
||||||
)
|
// )
|
||||||
@Test(expected = UnauthorizedException.class)
|
// @Test(expected = UnauthorizedException.class)
|
||||||
public void testDeleteWithoutPrivileges() {
|
// public void testDeleteWithoutPrivileges() {
|
||||||
delete(manager, createTestRepository());
|
// delete(manager, createTestRepository());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test(expected = RepositoryIsNotArchivedException.class)
|
// @Test(expected = RepositoryIsNotArchivedException.class)
|
||||||
public void testDeleteNonArchived() {
|
// public void testDeleteNonArchived() {
|
||||||
configuration.setEnableRepositoryArchive(true);
|
// configuration.setEnableRepositoryArchive(true);
|
||||||
delete(manager, createTestRepository());
|
// delete(manager, createTestRepository());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test(expected = NotFoundException.class)
|
// @Test(expected = NotFoundException.class)
|
||||||
public void testDeleteNotFound(){
|
// public void testDeleteNotFound(){
|
||||||
manager.delete(createRepositoryWithId());
|
// manager.delete(createRepositoryWithId());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testDeleteWithEnabledArchive() {
|
// public void testDeleteWithEnabledArchive() {
|
||||||
Repository repository = createTestRepository();
|
// Repository repository = createTestRepository();
|
||||||
|
//
|
||||||
repository.setArchived(true);
|
// repository.setArchived(true);
|
||||||
RepositoryManager drm = createRepositoryManager(true);
|
// RepositoryManager drm = createRepositoryManager(true);
|
||||||
drm.init(contextProvider);
|
// drm.init(contextProvider);
|
||||||
delete(drm, repository);
|
// delete(drm, repository);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testGet() {
|
// public void testGet() {
|
||||||
Repository heartOfGold = createTestRepository();
|
// Repository heartOfGold = createTestRepository();
|
||||||
String id = heartOfGold.getId();
|
// String id = heartOfGold.getId();
|
||||||
String description = heartOfGold.getDescription();
|
// String description = heartOfGold.getDescription();
|
||||||
|
//
|
||||||
assertNotNull(description);
|
// assertNotNull(description);
|
||||||
|
//
|
||||||
// test for reference
|
// // test for reference
|
||||||
heartOfGold.setDescription("prototype ship");
|
// heartOfGold.setDescription("prototype ship");
|
||||||
heartOfGold = manager.get(id);
|
// heartOfGold = manager.get(id);
|
||||||
assertNotNull(heartOfGold);
|
// assertNotNull(heartOfGold);
|
||||||
assertEquals(description, heartOfGold.getDescription());
|
// assertEquals(description, heartOfGold.getDescription());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
@SubjectAware(
|
// @SubjectAware(
|
||||||
username = "crato"
|
// username = "crato"
|
||||||
)
|
// )
|
||||||
public void testGetWithoutRequiredPrivileges() {
|
// public void testGetWithoutRequiredPrivileges() {
|
||||||
Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
// Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
||||||
manager.create(heartOfGold);
|
// manager.create(heartOfGold);
|
||||||
|
//
|
||||||
thrown.expect(UnauthorizedException.class);
|
// thrown.expect(UnauthorizedException.class);
|
||||||
manager.get(heartOfGold.getId());
|
// manager.get(heartOfGold.getId());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testGetAll() {
|
// public void testGetAll() {
|
||||||
Repository heartOfGold = createTestRepository();
|
// Repository heartOfGold = createTestRepository();
|
||||||
Repository happyVerticalPeopleTransporter = createSecondTestRepository();
|
// Repository happyVerticalPeopleTransporter = createSecondTestRepository();
|
||||||
boolean foundHeart = false;
|
// boolean foundHeart = false;
|
||||||
boolean foundTransporter = false;
|
// boolean foundTransporter = false;
|
||||||
Collection<Repository> repositories = manager.getAll();
|
// Collection<Repository> repositories = manager.getAll();
|
||||||
|
//
|
||||||
assertNotNull(repositories);
|
// assertNotNull(repositories);
|
||||||
assertFalse(repositories.isEmpty());
|
// assertFalse(repositories.isEmpty());
|
||||||
assertTrue(repositories.size() >= 2);
|
// assertTrue(repositories.size() >= 2);
|
||||||
|
//
|
||||||
Repository heartReference = null;
|
// Repository heartReference = null;
|
||||||
|
//
|
||||||
for (Repository repository : repositories) {
|
// for (Repository repository : repositories) {
|
||||||
if (repository.getId().equals(heartOfGold.getId())) {
|
// if (repository.getId().equals(heartOfGold.getId())) {
|
||||||
assertRepositoriesEquals(heartOfGold, repository);
|
// assertRepositoriesEquals(heartOfGold, repository);
|
||||||
foundHeart = true;
|
// foundHeart = true;
|
||||||
heartReference = repository;
|
// heartReference = repository;
|
||||||
}
|
// }
|
||||||
else if (repository.getId().equals(happyVerticalPeopleTransporter.getId())) {
|
// else if (repository.getId().equals(happyVerticalPeopleTransporter.getId())) {
|
||||||
assertRepositoriesEquals(happyVerticalPeopleTransporter, repository);
|
// assertRepositoriesEquals(happyVerticalPeopleTransporter, repository);
|
||||||
foundTransporter = true;
|
// foundTransporter = true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
assertTrue(foundHeart);
|
// assertTrue(foundHeart);
|
||||||
assertTrue(foundTransporter);
|
// assertTrue(foundTransporter);
|
||||||
|
//
|
||||||
// test for reference
|
// // test for reference
|
||||||
assertNotSame(heartOfGold, heartReference);
|
// assertNotSame(heartOfGold, heartReference);
|
||||||
heartReference.setDescription("prototype ship");
|
// heartReference.setDescription("prototype ship");
|
||||||
assertFalse(
|
// assertFalse(
|
||||||
heartOfGold.getDescription().equals(heartReference.getDescription()));
|
// heartOfGold.getDescription().equals(heartReference.getDescription()));
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
@SuppressWarnings("unchecked")
|
// @SuppressWarnings("unchecked")
|
||||||
@SubjectAware(username = "dent")
|
// @SubjectAware(username = "dent")
|
||||||
public void testGetAllWithPermissionsForTwoOrThreeRepos() {
|
// public void testGetAllWithPermissionsForTwoOrThreeRepos() {
|
||||||
// mock key generator
|
// // mock key generator
|
||||||
KeyGenerator keyGenerator = mock(KeyGenerator.class);
|
// KeyGenerator keyGenerator = mock(KeyGenerator.class);
|
||||||
Stack<String> keys = new Stack<>();
|
// Stack<String> keys = new Stack<>();
|
||||||
keys.push("rateotu");
|
// keys.push("rateotu");
|
||||||
keys.push("p42");
|
// keys.push("p42");
|
||||||
keys.push("hof");
|
// keys.push("hof");
|
||||||
|
//
|
||||||
when(keyGenerator.createKey()).then((InvocationOnMock invocation) -> {
|
// when(keyGenerator.createKey()).then((InvocationOnMock invocation) -> {
|
||||||
return keys.pop();
|
// return keys.pop();
|
||||||
});
|
// });
|
||||||
|
//
|
||||||
// create repository manager
|
// // create repository manager
|
||||||
RepositoryManager repositoryManager = createRepositoryManager(false, keyGenerator);
|
// RepositoryManager repositoryManager = createRepositoryManager(false, keyGenerator);
|
||||||
|
//
|
||||||
// create first test repository
|
// // create first test repository
|
||||||
Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
// Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
||||||
repositoryManager.create(heartOfGold);
|
// repositoryManager.create(heartOfGold);
|
||||||
assertEquals("hof", heartOfGold.getId());
|
// assertEquals("hof", heartOfGold.getId());
|
||||||
|
//
|
||||||
// create second test repository
|
// // create second test repository
|
||||||
Repository puzzle42 = RepositoryTestData.create42Puzzle();
|
// Repository puzzle42 = RepositoryTestData.create42Puzzle();
|
||||||
repositoryManager.create(puzzle42);
|
// repositoryManager.create(puzzle42);
|
||||||
assertEquals("p42", puzzle42.getId());
|
// assertEquals("p42", puzzle42.getId());
|
||||||
|
//
|
||||||
// create third test repository
|
// // create third test repository
|
||||||
Repository restaurant = RepositoryTestData.createRestaurantAtTheEndOfTheUniverse();
|
// Repository restaurant = RepositoryTestData.createRestaurantAtTheEndOfTheUniverse();
|
||||||
repositoryManager.create(restaurant);
|
// repositoryManager.create(restaurant);
|
||||||
assertEquals("rateotu", restaurant.getId());
|
// assertEquals("rateotu", restaurant.getId());
|
||||||
|
//
|
||||||
// assert returned repositories
|
// // assert returned repositories
|
||||||
Collection<Repository> repositories = repositoryManager.getAll();
|
// Collection<Repository> repositories = repositoryManager.getAll();
|
||||||
assertEquals(2, repositories.size());
|
// assertEquals(2, repositories.size());
|
||||||
assertThat(repositories, containsInAnyOrder(
|
// assertThat(repositories, containsInAnyOrder(
|
||||||
hasProperty("id", is("p42")),
|
// hasProperty("id", is("p42")),
|
||||||
hasProperty("id", is("hof"))
|
// hasProperty("id", is("hof"))
|
||||||
)
|
// )
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testEvents() {
|
// public void testEvents() {
|
||||||
RepositoryManager repoManager = createRepositoryManager(false);
|
// RepositoryManager repoManager = createRepositoryManager(false);
|
||||||
repoManager.init(contextProvider);
|
// repoManager.init(contextProvider);
|
||||||
TestListener listener = new TestListener();
|
// TestListener listener = new TestListener();
|
||||||
|
//
|
||||||
ScmEventBus.getInstance().register(listener);
|
// ScmEventBus.getInstance().register(listener);
|
||||||
|
//
|
||||||
Repository repository = RepositoryTestData.create42Puzzle();
|
// Repository repository = RepositoryTestData.create42Puzzle();
|
||||||
|
//
|
||||||
repoManager.create(repository);
|
// repoManager.create(repository);
|
||||||
assertRepositoriesEquals(repository, listener.preRepository);
|
// assertRepositoriesEquals(repository, listener.preRepository);
|
||||||
assertSame(HandlerEventType.BEFORE_CREATE, listener.preEvent);
|
// assertSame(HandlerEventType.BEFORE_CREATE, listener.preEvent);
|
||||||
assertRepositoriesEquals(repository, listener.postRepository);
|
// assertRepositoriesEquals(repository, listener.postRepository);
|
||||||
assertSame(HandlerEventType.CREATE, listener.postEvent);
|
// assertSame(HandlerEventType.CREATE, listener.postEvent);
|
||||||
|
//
|
||||||
repository.setDescription("changed description");
|
// repository.setDescription("changed description");
|
||||||
repoManager.modify(repository);
|
// repoManager.modify(repository);
|
||||||
assertRepositoriesEquals(repository, listener.preRepository);
|
// assertRepositoriesEquals(repository, listener.preRepository);
|
||||||
assertSame(HandlerEventType.BEFORE_MODIFY, listener.preEvent);
|
// assertSame(HandlerEventType.BEFORE_MODIFY, listener.preEvent);
|
||||||
assertRepositoriesEquals(repository, listener.postRepository);
|
// assertRepositoriesEquals(repository, listener.postRepository);
|
||||||
assertSame(HandlerEventType.MODIFY, listener.postEvent);
|
// assertSame(HandlerEventType.MODIFY, listener.postEvent);
|
||||||
|
//
|
||||||
repoManager.delete(repository);
|
// repoManager.delete(repository);
|
||||||
|
//
|
||||||
assertRepositoriesEquals(repository, listener.preRepository);
|
// assertRepositoriesEquals(repository, listener.preRepository);
|
||||||
assertSame(HandlerEventType.BEFORE_DELETE, listener.preEvent);
|
// assertSame(HandlerEventType.BEFORE_DELETE, listener.preEvent);
|
||||||
assertRepositoriesEquals(repository, listener.postRepository);
|
// assertRepositoriesEquals(repository, listener.postRepository);
|
||||||
assertSame(HandlerEventType.DELETE, listener.postEvent);
|
// assertSame(HandlerEventType.DELETE, listener.postEvent);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testModify() {
|
// public void testModify() {
|
||||||
Repository heartOfGold = createTestRepository();
|
// Repository heartOfGold = createTestRepository();
|
||||||
|
//
|
||||||
heartOfGold.setDescription("prototype ship");
|
// heartOfGold.setDescription("prototype ship");
|
||||||
manager.modify(heartOfGold);
|
// manager.modify(heartOfGold);
|
||||||
|
//
|
||||||
Repository hearReference = manager.get(heartOfGold.getId());
|
// Repository hearReference = manager.get(heartOfGold.getId());
|
||||||
|
//
|
||||||
assertNotNull(hearReference);
|
// assertNotNull(hearReference);
|
||||||
assertEquals(hearReference.getDescription(), "prototype ship");
|
// assertEquals(hearReference.getDescription(), "prototype ship");
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
@SubjectAware(username = "crato")
|
// @SubjectAware(username = "crato")
|
||||||
public void testModifyWithoutRequiredPermissions() {
|
// public void testModifyWithoutRequiredPermissions() {
|
||||||
Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
// Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
||||||
manager.create(heartOfGold);
|
// manager.create(heartOfGold);
|
||||||
heartOfGold.setDescription("prototype ship");
|
// heartOfGold.setDescription("prototype ship");
|
||||||
|
//
|
||||||
thrown.expect(UnauthorizedException.class);
|
// thrown.expect(UnauthorizedException.class);
|
||||||
manager.modify(heartOfGold);
|
// manager.modify(heartOfGold);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test(expected = NotFoundException.class)
|
// @Test(expected = NotFoundException.class)
|
||||||
public void testModifyNotFound(){
|
// public void testModifyNotFound(){
|
||||||
manager.modify(createRepositoryWithId());
|
// manager.modify(createRepositoryWithId());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testRefresh() {
|
// public void testRefresh() {
|
||||||
Repository heartOfGold = createTestRepository();
|
// Repository heartOfGold = createTestRepository();
|
||||||
String description = heartOfGold.getDescription();
|
// String description = heartOfGold.getDescription();
|
||||||
|
//
|
||||||
heartOfGold.setDescription("prototype ship");
|
// heartOfGold.setDescription("prototype ship");
|
||||||
manager.refresh(heartOfGold);
|
// manager.refresh(heartOfGold);
|
||||||
assertEquals(description, heartOfGold.getDescription());
|
// assertEquals(description, heartOfGold.getDescription());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
@SubjectAware(username = "crato")
|
// @SubjectAware(username = "crato")
|
||||||
public void testRefreshWithoutRequiredPermissions() {
|
// public void testRefreshWithoutRequiredPermissions() {
|
||||||
Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
// Repository heartOfGold = RepositoryTestData.createHeartOfGold();
|
||||||
manager.create(heartOfGold);
|
// manager.create(heartOfGold);
|
||||||
heartOfGold.setDescription("prototype ship");
|
// heartOfGold.setDescription("prototype ship");
|
||||||
|
//
|
||||||
thrown.expect(UnauthorizedException.class);
|
// thrown.expect(UnauthorizedException.class);
|
||||||
manager.refresh(heartOfGold);
|
// manager.refresh(heartOfGold);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test(expected = NotFoundException.class)
|
// @Test(expected = NotFoundException.class)
|
||||||
public void testRefreshNotFound(){
|
// public void testRefreshNotFound(){
|
||||||
manager.refresh(createRepositoryWithId());
|
// manager.refresh(createRepositoryWithId());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testRepositoryHook() {
|
// public void testRepositoryHook() {
|
||||||
CountingReceiveHook hook = new CountingReceiveHook();
|
// CountingReceiveHook hook = new CountingReceiveHook();
|
||||||
RepositoryManager repoManager = createRepositoryManager(false);
|
// RepositoryManager repoManager = createRepositoryManager(false);
|
||||||
|
//
|
||||||
ScmEventBus.getInstance().register(hook);
|
// ScmEventBus.getInstance().register(hook);
|
||||||
|
//
|
||||||
assertEquals(0, hook.eventsReceived);
|
// assertEquals(0, hook.eventsReceived);
|
||||||
|
//
|
||||||
Repository repository = createTestRepository();
|
// Repository repository = createTestRepository();
|
||||||
HookContext ctx = createHookContext(repository);
|
// HookContext ctx = createHookContext(repository);
|
||||||
|
//
|
||||||
repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository,
|
// repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository,
|
||||||
RepositoryHookType.POST_RECEIVE));
|
// RepositoryHookType.POST_RECEIVE));
|
||||||
assertEquals(1, hook.eventsReceived);
|
// assertEquals(1, hook.eventsReceived);
|
||||||
repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository,
|
// repoManager.fireHookEvent(new RepositoryHookEvent(ctx, repository,
|
||||||
RepositoryHookType.POST_RECEIVE));
|
// RepositoryHookType.POST_RECEIVE));
|
||||||
assertEquals(2, hook.eventsReceived);
|
// assertEquals(2, hook.eventsReceived);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void testNamespaceSet() {
|
// public void testNamespaceSet() {
|
||||||
RepositoryManager repoManager = createRepositoryManager(false);
|
// RepositoryManager repoManager = createRepositoryManager(false);
|
||||||
Repository repository = spy(createTestRepository());
|
// Repository repository = spy(createTestRepository());
|
||||||
repository.setName("Testrepo");
|
// repository.setName("Testrepo");
|
||||||
repoManager.create(repository);
|
// repoManager.create(repository);
|
||||||
assertEquals("default_namespace", repository.getNamespace());
|
// assertEquals("default_namespace", repository.getNamespace());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Test
|
// @Test
|
||||||
public void shouldSetNamespace() {
|
// public void shouldSetNamespace() {
|
||||||
Repository repository = new Repository(null, "hg", null, "scm");
|
// Repository repository = new Repository(null, "hg", null, "scm");
|
||||||
manager.create(repository);
|
// manager.create(repository);
|
||||||
assertNotNull(repository.getId());
|
// assertNotNull(repository.getId());
|
||||||
assertNotNull(repository.getNamespace());
|
// assertNotNull(repository.getNamespace());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
//~--- methods --------------------------------------------------------------
|
// //~--- methods --------------------------------------------------------------
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
protected DefaultRepositoryManager createManager() {
|
// protected DefaultRepositoryManager createManager() {
|
||||||
return createRepositoryManager(false);
|
// return createRepositoryManager(false);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private DefaultRepositoryManager createRepositoryManager(boolean archiveEnabled) {
|
// private DefaultRepositoryManager createRepositoryManager(boolean archiveEnabled) {
|
||||||
return createRepositoryManager(archiveEnabled, new DefaultKeyGenerator());
|
// return createRepositoryManager(archiveEnabled, new DefaultKeyGenerator());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private DefaultRepositoryManager createRepositoryManager(boolean archiveEnabled, KeyGenerator keyGenerator) {
|
// private DefaultRepositoryManager createRepositoryManager(boolean archiveEnabled, KeyGenerator keyGenerator) {
|
||||||
DefaultFileSystem fileSystem = new DefaultFileSystem();
|
// DefaultFileSystem fileSystem = new DefaultFileSystem();
|
||||||
Set<RepositoryHandler> handlerSet = new HashSet<>();
|
// Set<RepositoryHandler> handlerSet = new HashSet<>();
|
||||||
InitialRepositoryLocationResolver initialRepositoryLocationResolver = new InitialRepositoryLocationResolver();
|
// PathBasedRepositoryLocationResolver repositoryLocationResolver = mock(PathBasedRepositoryLocationResolver.class, RETURNS_DEEP_STUBS);
|
||||||
PathBasedRepositoryLocationResolver repositoryLocationResolver = mock(PathBasedRepositoryLocationResolver.class, RETURNS_DEEP_STUBS);
|
// when(repositoryLocationResolver.forClass(Path.class).getLocation(anyString())).thenReturn(Paths.get("."));
|
||||||
when(repositoryLocationResolver.forClass(Path.class).getLocation(anyString())).thenReturn(Paths.get("."));
|
// XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(contextProvider, repositoryLocationResolver, fileSystem);
|
||||||
XmlRepositoryDAO repositoryDAO = new XmlRepositoryDAO(contextProvider, repositoryLocationResolver, initialRepositoryLocationResolver, fileSystem);
|
// ConfigurationStoreFactory factory = new JAXBConfigurationStoreFactory(contextProvider, repositoryLocationResolver);
|
||||||
ConfigurationStoreFactory factory = new JAXBConfigurationStoreFactory(contextProvider, repositoryLocationResolver);
|
// handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver));
|
||||||
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver));
|
// handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
|
||||||
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
|
// @Override
|
||||||
@Override
|
// public RepositoryType getType() {
|
||||||
public RepositoryType getType() {
|
// return new RepositoryType("hg", "Mercurial", Sets.newHashSet());
|
||||||
return new RepositoryType("hg", "Mercurial", Sets.newHashSet());
|
// }
|
||||||
}
|
// });
|
||||||
});
|
// handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
|
||||||
handlerSet.add(new DummyRepositoryHandler(factory, repositoryLocationResolver) {
|
// @Override
|
||||||
@Override
|
// public RepositoryType getType() {
|
||||||
public RepositoryType getType() {
|
// return new RepositoryType("git", "Git", Sets.newHashSet());
|
||||||
return new RepositoryType("git", "Git", Sets.newHashSet());
|
// }
|
||||||
}
|
// });
|
||||||
});
|
//
|
||||||
|
//
|
||||||
|
// this.configuration = new ScmConfiguration();
|
||||||
this.configuration = new ScmConfiguration();
|
//
|
||||||
|
// configuration.setEnableRepositoryArchive(archiveEnabled);
|
||||||
configuration.setEnableRepositoryArchive(archiveEnabled);
|
//
|
||||||
|
// NamespaceStrategy namespaceStrategy = mock(NamespaceStrategy.class);
|
||||||
NamespaceStrategy namespaceStrategy = mock(NamespaceStrategy.class);
|
// when(namespaceStrategy.createNamespace(Mockito.any(Repository.class))).thenAnswer(invocation -> mockedNamespace);
|
||||||
when(namespaceStrategy.createNamespace(Mockito.any(Repository.class))).thenAnswer(invocation -> mockedNamespace);
|
//
|
||||||
|
// return new DefaultRepositoryManager(configuration, contextProvider,
|
||||||
return new DefaultRepositoryManager(configuration, contextProvider,
|
// keyGenerator, repositoryDAO, handlerSet, Providers.of(namespaceStrategy));
|
||||||
keyGenerator, repositoryDAO, handlerSet, Providers.of(namespaceStrategy));
|
// }
|
||||||
}
|
//
|
||||||
|
// private HookContext createHookContext(Repository repository) {
|
||||||
private HookContext createHookContext(Repository repository) {
|
// PreProcessorUtil ppu = mock(PreProcessorUtil.class);
|
||||||
PreProcessorUtil ppu = mock(PreProcessorUtil.class);
|
// HookContextProvider provider = mock(HookContextProvider.class);
|
||||||
HookContextProvider provider = mock(HookContextProvider.class);
|
// Set<HookFeature> features = ImmutableSet.of();
|
||||||
Set<HookFeature> features = ImmutableSet.of();
|
//
|
||||||
|
// when(provider.getSupportedFeatures()).thenReturn(features);
|
||||||
when(provider.getSupportedFeatures()).thenReturn(features);
|
//
|
||||||
|
// return new HookContextFactory(ppu).createContext(provider, repository);
|
||||||
return new HookContextFactory(ppu).createContext(provider, repository);
|
// }
|
||||||
}
|
//
|
||||||
|
// private void assertRepositoriesEquals(Repository repo, Repository other) {
|
||||||
private void assertRepositoriesEquals(Repository repo, Repository other) {
|
// assertEquals(repo.getId(), other.getId());
|
||||||
assertEquals(repo.getId(), other.getId());
|
// assertEquals(repo.getName(), other.getName());
|
||||||
assertEquals(repo.getName(), other.getName());
|
// assertEquals(repo.getDescription(), other.getDescription());
|
||||||
assertEquals(repo.getDescription(), other.getDescription());
|
// assertEquals(repo.getContact(), other.getContact());
|
||||||
assertEquals(repo.getContact(), other.getContact());
|
// assertEquals(repo.getCreationDate(), other.getCreationDate());
|
||||||
assertEquals(repo.getCreationDate(), other.getCreationDate());
|
// assertEquals(repo.getLastModified(), other.getLastModified());
|
||||||
assertEquals(repo.getLastModified(), other.getLastModified());
|
// }
|
||||||
}
|
//
|
||||||
|
// private Repository createRepository(Repository repository) {
|
||||||
private Repository createRepository(Repository repository) {
|
// manager.create(repository);
|
||||||
manager.create(repository);
|
// assertNotNull(repository.getId());
|
||||||
assertNotNull(repository.getId());
|
// assertNotNull(manager.get(repository.getId()));
|
||||||
assertNotNull(manager.get(repository.getId()));
|
// assertTrue(repository.getCreationDate() > 0);
|
||||||
assertTrue(repository.getCreationDate() > 0);
|
//
|
||||||
|
// return repository;
|
||||||
return repository;
|
// }
|
||||||
}
|
//
|
||||||
|
// private Repository createRepositoryWithId() {
|
||||||
private Repository createRepositoryWithId() {
|
// Repository repository = RepositoryTestData.createHeartOfGold();
|
||||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
// repository.setId("abc");
|
||||||
repository.setId("abc");
|
// return repository;
|
||||||
return repository;
|
// }
|
||||||
}
|
//
|
||||||
|
// private Repository createSecondTestRepository() {
|
||||||
private Repository createSecondTestRepository() {
|
// return createRepository(
|
||||||
return createRepository(
|
// RepositoryTestData.createHappyVerticalPeopleTransporter());
|
||||||
RepositoryTestData.createHappyVerticalPeopleTransporter());
|
// }
|
||||||
}
|
//
|
||||||
|
// private Repository createTestRepository() {
|
||||||
private Repository createTestRepository() {
|
// return createRepository(RepositoryTestData.createHeartOfGold());
|
||||||
return createRepository(RepositoryTestData.createHeartOfGold());
|
// }
|
||||||
}
|
//
|
||||||
|
// private void delete(Manager<Repository> manager, Repository repository){
|
||||||
private void delete(Manager<Repository> manager, Repository repository){
|
//
|
||||||
|
// String id = repository.getId();
|
||||||
String id = repository.getId();
|
//
|
||||||
|
// manager.delete(repository);
|
||||||
manager.delete(repository);
|
// assertNull(manager.get(id));
|
||||||
assertNull(manager.get(id));
|
// }
|
||||||
}
|
//
|
||||||
|
// private static class CountingReceiveHook {
|
||||||
private static class CountingReceiveHook {
|
//
|
||||||
|
// private int eventsReceived = 0;
|
||||||
private int eventsReceived = 0;
|
//
|
||||||
|
// @Subscribe(async = false)
|
||||||
@Subscribe(async = false)
|
// public void onEvent(PostReceiveRepositoryHookEvent event) {
|
||||||
public void onEvent(PostReceiveRepositoryHookEvent event) {
|
// eventsReceived++;
|
||||||
eventsReceived++;
|
// }
|
||||||
}
|
//
|
||||||
|
// @Subscribe(async = false)
|
||||||
@Subscribe(async = false)
|
// public void onEvent(PreReceiveRepositoryHookEvent event) {
|
||||||
public void onEvent(PreReceiveRepositoryHookEvent event) {
|
// eventsReceived++;
|
||||||
eventsReceived++;
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
// private class TestListener {
|
||||||
private class TestListener {
|
//
|
||||||
|
// private HandlerEventType postEvent;
|
||||||
private HandlerEventType postEvent;
|
//
|
||||||
|
// private Repository postRepository;
|
||||||
private Repository postRepository;
|
//
|
||||||
|
// private HandlerEventType preEvent;
|
||||||
private HandlerEventType preEvent;
|
//
|
||||||
|
// private Repository preRepository;
|
||||||
private Repository preRepository;
|
//
|
||||||
|
// @Subscribe(async = false)
|
||||||
@Subscribe(async = false)
|
// public void onEvent(RepositoryEvent event) {
|
||||||
public void onEvent(RepositoryEvent event) {
|
// if (event.getEventType().isPost()) {
|
||||||
if (event.getEventType().isPost()) {
|
// this.postRepository = event.getItem();
|
||||||
this.postRepository = event.getItem();
|
// this.postEvent = event.getEventType();
|
||||||
this.postEvent = event.getEventType();
|
// }
|
||||||
}
|
// else if (event.getEventType().isPre()) {
|
||||||
else if (event.getEventType().isPre()) {
|
// this.preRepository = event.getItem();
|
||||||
this.preRepository = event.getItem();
|
// this.preEvent = event.getEventType();
|
||||||
this.preEvent = event.getEventType();
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user