mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 21:45:43 +01:00
add the interface StoreFactory and refactor storeFactories
This commit is contained in:
@@ -35,8 +35,10 @@ package sonia.scm.web.lfs;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.Blob;
|
||||
import sonia.scm.store.BlobStore;
|
||||
import sonia.scm.store.BlobStoreFactory;
|
||||
import sonia.scm.store.StoreParameters;
|
||||
|
||||
/**
|
||||
* Creates {@link BlobStore} objects to store lfs objects.
|
||||
@@ -74,7 +76,13 @@ public class LfsBlobStoreFactory {
|
||||
*
|
||||
* @return blob store for the corresponding scm repository
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BlobStore getLfsBlobStore(Repository repository) {
|
||||
return blobStoreFactory.getBlobStore(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX);
|
||||
return blobStoreFactory.getStore(new StoreParameters()
|
||||
.withType(Blob.class)
|
||||
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
|
||||
.forRepository(repository)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,12 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.schedule.Scheduler;
|
||||
import sonia.scm.store.ConfigurationStore;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -40,7 +40,8 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.store.BlobStoreFactory;
|
||||
|
||||
import static org.mockito.Matchers.matches;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
@@ -59,12 +60,17 @@ public class LfsBlobStoreFactoryTest {
|
||||
private LfsBlobStoreFactory lfsBlobStoreFactory;
|
||||
|
||||
@Test
|
||||
public void getBlobStore() throws Exception {
|
||||
lfsBlobStoreFactory.getLfsBlobStore(new Repository("the-id", "GIT", "space", "the-name"));
|
||||
public void getBlobStore() {
|
||||
Repository repository = new Repository("the-id", "GIT", "space", "the-name");
|
||||
lfsBlobStoreFactory.getLfsBlobStore(repository);
|
||||
|
||||
// just make sure the right parameter is passed, as properly validating the return value is nearly impossible with
|
||||
// the return value (and should not be part of this test)
|
||||
verify(blobStoreFactory).getBlobStore(matches("the-id-git-lfs"));
|
||||
verify(blobStoreFactory).getStore(argThat(blobStoreParameters -> {
|
||||
assertThat(blobStoreParameters.getName()).isEqualTo("the-id-git-lfs");
|
||||
assertThat(blobStoreParameters.getRepository()).isEqualTo(repository);
|
||||
return true;
|
||||
}));
|
||||
|
||||
// make sure there have been no further usages of the factory
|
||||
verifyNoMoreInteractions(blobStoreFactory);
|
||||
|
||||
Reference in New Issue
Block a user