mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-02 03:25:56 +01:00
Do no longer expose StoreParameters
This commit is contained in:
@@ -49,8 +49,6 @@ import java.io.IOException;
|
|||||||
import sonia.scm.store.ConfigurationStore;
|
import sonia.scm.store.ConfigurationStore;
|
||||||
import sonia.scm.store.ConfigurationStoreFactory;
|
import sonia.scm.store.ConfigurationStoreFactory;
|
||||||
|
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -75,11 +73,10 @@ public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
|
|||||||
* @param storeFactory
|
* @param storeFactory
|
||||||
*/
|
*/
|
||||||
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory) {
|
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory) {
|
||||||
this.store = storeFactory.getStore(
|
this.store = storeFactory.
|
||||||
forType(getConfigClass())
|
forType(getConfigClass())
|
||||||
.withName(getType().getName())
|
.withName(getType().getName())
|
||||||
.build()
|
.build();
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|||||||
@@ -2,5 +2,9 @@ package sonia.scm.store;
|
|||||||
|
|
||||||
public interface StoreFactory<STORE> {
|
public interface StoreFactory<STORE> {
|
||||||
|
|
||||||
STORE getStore(final StoreParameters storeParameters);
|
STORE getStore(final StoreParameters<STORE> storeParameters);
|
||||||
|
|
||||||
|
default StoreParameters<STORE>.WithType forType(Class type) {
|
||||||
|
return new StoreParameters<>(this).new WithType(type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,18 @@ import sonia.scm.repository.Repository;
|
|||||||
* @author Mohamed Karray
|
* @author Mohamed Karray
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class StoreParameters {
|
public class StoreParameters<STORE> {
|
||||||
|
|
||||||
private Class type;
|
private Class type;
|
||||||
private String name;
|
private String name;
|
||||||
private Repository repository;
|
private Repository repository;
|
||||||
|
|
||||||
|
private final StoreFactory<STORE> factory;
|
||||||
|
|
||||||
|
StoreParameters(StoreFactory<STORE> factory) {
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
public Class getType() {
|
public Class getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -26,17 +32,13 @@ public class StoreParameters {
|
|||||||
return repository;
|
return repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WithType forType(Class type){
|
|
||||||
return new StoreParameters().new WithType(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WithType {
|
public class WithType {
|
||||||
|
|
||||||
private WithType(Class type) {
|
WithType(Class type) {
|
||||||
StoreParameters.this.type = type;
|
StoreParameters.this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WithTypeAndName withName(String name){
|
public StoreParameters<STORE>.WithTypeAndName withName(String name){
|
||||||
return new WithTypeAndName(name);
|
return new WithTypeAndName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,11 +49,11 @@ public class StoreParameters {
|
|||||||
StoreParameters.this.name = name;
|
StoreParameters.this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WithTypeNameAndRepository forRepository(Repository repository){
|
public StoreParameters<STORE>.WithTypeNameAndRepository forRepository(Repository repository){
|
||||||
return new WithTypeNameAndRepository(repository);
|
return new WithTypeNameAndRepository(repository);
|
||||||
}
|
}
|
||||||
public StoreParameters build(){
|
public STORE build(){
|
||||||
return StoreParameters.this;
|
return factory.getStore(StoreParameters.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +62,8 @@ public class StoreParameters {
|
|||||||
private WithTypeNameAndRepository(Repository repository) {
|
private WithTypeNameAndRepository(Repository repository) {
|
||||||
StoreParameters.this.repository = repository;
|
StoreParameters.this.repository = repository;
|
||||||
}
|
}
|
||||||
public StoreParameters build(){
|
public STORE build(){
|
||||||
return StoreParameters.this;
|
return factory.getStore(StoreParameters.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,8 +43,6 @@ import sonia.scm.xml.AbstractXmlDAO;
|
|||||||
|
|
||||||
import sonia.scm.store.ConfigurationStoreFactory;
|
import sonia.scm.store.ConfigurationStoreFactory;
|
||||||
|
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -67,10 +65,10 @@ public class XmlGroupDAO extends AbstractXmlDAO<Group, XmlGroupDatabase>
|
|||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public XmlGroupDAO(ConfigurationStoreFactory storeFactory) {
|
public XmlGroupDAO(ConfigurationStoreFactory storeFactory) {
|
||||||
super(storeFactory.getStore(
|
super(storeFactory.
|
||||||
forType(XmlGroupDatabase.class)
|
forType(XmlGroupDatabase.class)
|
||||||
.withName(STORE_NAME)
|
.withName(STORE_NAME)
|
||||||
.build()));
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -41,8 +41,6 @@ import sonia.scm.user.User;
|
|||||||
import sonia.scm.user.UserDAO;
|
import sonia.scm.user.UserDAO;
|
||||||
import sonia.scm.xml.AbstractXmlDAO;
|
import sonia.scm.xml.AbstractXmlDAO;
|
||||||
|
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -66,10 +64,9 @@ public class XmlUserDAO extends AbstractXmlDAO<User, XmlUserDatabase>
|
|||||||
@Inject
|
@Inject
|
||||||
public XmlUserDAO(ConfigurationStoreFactory storeFactory)
|
public XmlUserDAO(ConfigurationStoreFactory storeFactory)
|
||||||
{
|
{
|
||||||
super(storeFactory.getStore(
|
super(storeFactory.forType(XmlUserDatabase.class)
|
||||||
forType(XmlUserDatabase.class)
|
|
||||||
.withName(STORE_NAME)
|
.withName(STORE_NAME)
|
||||||
.build()));
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -66,11 +65,11 @@ public class FileBlobStoreTest extends BlobStoreTestBase
|
|||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void shouldStoreAndLoadInRepository() {
|
public void shouldStoreAndLoadInRepository() {
|
||||||
BlobStore store = createBlobStoreFactory().getStore(
|
BlobStore store = createBlobStoreFactory().
|
||||||
forType(StoreObject.class)
|
forType(StoreObject.class)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
.forRepository(new Repository("id", "git", "ns", "n"))
|
.forRepository(new Repository("id", "git", "ns", "n"))
|
||||||
.build());
|
.build();
|
||||||
|
|
||||||
Blob createdBlob = store.create("abc");
|
Blob createdBlob = store.create("abc");
|
||||||
List<Blob> storedBlobs = store.getAll();
|
List<Blob> storedBlobs = store.getAll();
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -133,10 +132,10 @@ public class JAXBConfigurationEntryStoreTest
|
|||||||
ConfigurationEntryStore<AssignedPermission> store = createPermissionStore(RESOURCE_FIXED, name);
|
ConfigurationEntryStore<AssignedPermission> store = createPermissionStore(RESOURCE_FIXED, name);
|
||||||
|
|
||||||
store.put("a45", new AssignedPermission("tuser4", "repository:create"));
|
store.put("a45", new AssignedPermission("tuser4", "repository:create"));
|
||||||
store = createConfigurationStoreFactory().getStore(
|
store = createConfigurationStoreFactory().
|
||||||
forType(AssignedPermission.class)
|
forType(AssignedPermission.class)
|
||||||
.withName(name)
|
.withName(name)
|
||||||
.build());
|
.build();
|
||||||
|
|
||||||
AssignedPermission ap = store.get("a45");
|
AssignedPermission ap = store.get("a45");
|
||||||
|
|
||||||
@@ -232,9 +231,9 @@ public class JAXBConfigurationEntryStoreTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
copy(resource, name);
|
copy(resource, name);
|
||||||
return createConfigurationStoreFactory().getStore(
|
return createConfigurationStoreFactory().
|
||||||
forType(AssignedPermission.class)
|
forType(AssignedPermission.class)
|
||||||
.withName(name)
|
.withName(name)
|
||||||
.build());
|
.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,11 +35,8 @@ package sonia.scm.store;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link JAXBConfigurationStore}.
|
* Unit tests for {@link JAXBConfigurationStore}.
|
||||||
@@ -57,13 +54,13 @@ public class JAXBConfigurationStoreTest extends StoreTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void shouldStoreAndLoadInRepository() throws IOException
|
public void shouldStoreAndLoadInRepository()
|
||||||
{
|
{
|
||||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(
|
ConfigurationStore<StoreObject> store = createStoreFactory().
|
||||||
forType(StoreObject.class)
|
forType(StoreObject.class)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
.forRepository(new Repository("id", "git", "ns", "n"))
|
.forRepository(new Repository("id", "git", "ns", "n"))
|
||||||
.build());
|
.build();
|
||||||
|
|
||||||
store.set(new StoreObject("value"));
|
store.set(new StoreObject("value"));
|
||||||
StoreObject storeObject = store.get();
|
StoreObject storeObject = store.get();
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import sonia.scm.security.UUIDKeyGenerator;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -62,17 +61,17 @@ public class JAXBDataStoreTest extends DataStoreTestBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataStore getDataStore(Class type, Repository repository) {
|
protected DataStore getDataStore(Class type, Repository repository) {
|
||||||
return createDataStoreFactory().getStore(forType(type)
|
return createDataStoreFactory().forType(type)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
.forRepository(repository)
|
.forRepository(repository)
|
||||||
.build());
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected DataStore getDataStore(Class type) {
|
protected DataStore getDataStore(Class type) {
|
||||||
return createDataStoreFactory().getStore(forType(type)
|
return createDataStoreFactory().forType(type)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
.build());
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ import sonia.scm.repository.Repository;
|
|||||||
import sonia.scm.store.BlobStore;
|
import sonia.scm.store.BlobStore;
|
||||||
import sonia.scm.store.BlobStoreFactory;
|
import sonia.scm.store.BlobStoreFactory;
|
||||||
|
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates {@link BlobStore} objects to store lfs objects.
|
* Creates {@link BlobStore} objects to store lfs objects.
|
||||||
*
|
*
|
||||||
@@ -78,11 +76,9 @@ public class LfsBlobStoreFactory {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public BlobStore getLfsBlobStore(Repository repository) {
|
public BlobStore getLfsBlobStore(Repository repository) {
|
||||||
return blobStoreFactory.getStore(
|
return blobStoreFactory.forType(String.class)
|
||||||
forType(String.class)
|
|
||||||
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
|
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
|
||||||
.forRepository(repository)
|
.forRepository(repository)
|
||||||
.build()
|
.build();
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ package sonia.scm.repository;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -44,6 +45,8 @@ import java.io.File;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -81,6 +84,10 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
|||||||
assertTrue(refs.isDirectory());
|
assertTrue(refs.isDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initFactory() {
|
||||||
|
when(factory.forType(any())).thenCallRealMethod();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
|
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory,
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ import sonia.scm.repository.Repository;
|
|||||||
import sonia.scm.store.BlobStoreFactory;
|
import sonia.scm.store.BlobStoreFactory;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link LfsBlobStoreFactory}.
|
* Unit tests for {@link LfsBlobStoreFactory}.
|
||||||
@@ -61,6 +63,7 @@ public class LfsBlobStoreFactoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBlobStore() {
|
public void getBlobStore() {
|
||||||
|
when(blobStoreFactory.forType(any())).thenCallRealMethod();
|
||||||
Repository repository = new Repository("the-id", "GIT", "space", "the-name");
|
Repository repository = new Repository("the-id", "GIT", "space", "the-name");
|
||||||
lfsBlobStoreFactory.getLfsBlobStore(repository);
|
lfsBlobStoreFactory.getLfsBlobStore(repository);
|
||||||
|
|
||||||
@@ -73,7 +76,7 @@ public class LfsBlobStoreFactoryTest {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// make sure there have been no further usages of the factory
|
// make sure there have been no further usages of the factory
|
||||||
verifyNoMoreInteractions(blobStoreFactory);
|
verify(blobStoreFactory, times(1)).getStore(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ package sonia.scm.repository;
|
|||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -44,6 +45,8 @@ import java.io.File;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -67,6 +70,11 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
|||||||
assertTrue(hgDirectory.isDirectory());
|
assertTrue(hgDirectory.isDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void initFactory() {
|
||||||
|
when(factory.forType(any())).thenCallRealMethod();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory, RepositoryLocationResolver locationResolver, File directory) {
|
protected RepositoryHandler createRepositoryHandler(ConfigurationStoreFactory factory, RepositoryLocationResolver locationResolver, File directory) {
|
||||||
HgRepositoryHandler handler = new HgRepositoryHandler(factory, new HgContextProvider(), locationResolver);
|
HgRepositoryHandler handler = new HgRepositoryHandler(factory, new HgContextProvider(), locationResolver);
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
package sonia.scm.repository;
|
package sonia.scm.repository;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@@ -42,12 +43,14 @@ import sonia.scm.store.ConfigurationStore;
|
|||||||
import sonia.scm.store.ConfigurationStoreFactory;
|
import sonia.scm.store.ConfigurationStoreFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.MockitoAnnotations.initMocks;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -55,15 +58,11 @@ import static org.mockito.Mockito.when;
|
|||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
|
||||||
public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private ConfigurationStoreFactory factory;
|
private ConfigurationStoreFactory factory;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private ConfigurationStore store;
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private com.google.inject.Provider<RepositoryManager> repositoryManagerProvider;
|
private com.google.inject.Provider<RepositoryManager> repositoryManagerProvider;
|
||||||
|
|
||||||
@@ -71,6 +70,12 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
|||||||
|
|
||||||
private HookEventFacade facade = new HookEventFacade(repositoryManagerProvider, hookContextFactory);
|
private HookEventFacade facade = new HookEventFacade(repositoryManagerProvider, hookContextFactory);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void postSetUp() throws IOException, RepositoryPathNotFoundException {
|
||||||
|
initMocks(this);
|
||||||
|
super.postSetUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void checkDirectory(File directory) {
|
protected void checkDirectory(File directory) {
|
||||||
File format = new File(directory, "format");
|
File format = new File(directory, "format");
|
||||||
@@ -102,7 +107,7 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getDirectory() {
|
public void getDirectory() {
|
||||||
when(factory.getStore(any())).thenReturn(store);
|
when(factory.forType(any())).thenCallRealMethod();
|
||||||
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
|
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
|
||||||
facade, locationResolver);
|
facade, locationResolver);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -70,12 +69,11 @@ public abstract class BlobStoreTestBase extends AbstractTestBase
|
|||||||
@Before
|
@Before
|
||||||
public void createBlobStore()
|
public void createBlobStore()
|
||||||
{
|
{
|
||||||
store = createBlobStoreFactory().getStore(
|
store = createBlobStoreFactory().
|
||||||
forType(Blob.class)
|
forType(Blob.class)
|
||||||
.withName("test")
|
.withName("test")
|
||||||
.forRepository(RepositoryTestData.createHeartOfGold())
|
.forRepository(RepositoryTestData.createHeartOfGold())
|
||||||
.build()
|
.build();
|
||||||
);
|
|
||||||
store.clear();
|
store.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ package sonia.scm.store;
|
|||||||
|
|
||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
|
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
@@ -53,18 +51,16 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
|
|||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurationEntryStore getDataStore(Class type) {
|
protected ConfigurationEntryStore getDataStore(Class type) {
|
||||||
StoreParameters params = forType(type)
|
return this.createConfigurationStoreFactory().forType(type)
|
||||||
.withName(storeName)
|
.withName(storeName)
|
||||||
.build();
|
.build();
|
||||||
return this.createConfigurationStoreFactory().getStore(params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
|
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
|
||||||
StoreParameters params = forType(type)
|
return this.createConfigurationStoreFactory().forType(type)
|
||||||
.withName(repoStoreName)
|
.withName(repoStoreName)
|
||||||
.forRepository(repository)
|
.forRepository(repository)
|
||||||
.build();
|
.build();
|
||||||
return this.createConfigurationStoreFactory().getStore(params);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ import sonia.scm.repository.RepositoryTestData;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -57,12 +56,6 @@ public abstract class DataStoreTestBase extends KeyValueStoreTestBase
|
|||||||
protected abstract DataStoreFactory createDataStoreFactory();
|
protected abstract DataStoreFactory createDataStoreFactory();
|
||||||
|
|
||||||
|
|
||||||
protected StoreParameters getStoreParametersWithRepository(Repository repository) {
|
|
||||||
return forType(StoreObject.class)
|
|
||||||
.withName("test")
|
|
||||||
.forRepository(repository)
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +69,10 @@ public abstract class DataStoreTestBase extends KeyValueStoreTestBase
|
|||||||
StoreObject obj = new StoreObject("test-1");
|
StoreObject obj = new StoreObject("test-1");
|
||||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||||
|
|
||||||
DataStore<StoreObject> store = dataStoreFactory.getStore(getStoreParametersWithRepository(repository));
|
DataStore<StoreObject> store = dataStoreFactory.forType(StoreObject.class)
|
||||||
|
.withName("test")
|
||||||
|
.forRepository(repository)
|
||||||
|
.build();
|
||||||
|
|
||||||
String id = store.put(obj);
|
String id = store.put(obj);
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import sonia.scm.AbstractTestBase;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -67,7 +66,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
|||||||
@Test
|
@Test
|
||||||
public void testGet()
|
public void testGet()
|
||||||
{
|
{
|
||||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(forType(StoreObject.class).withName("test").build());
|
ConfigurationStore<StoreObject> store = createStoreFactory().forType(StoreObject.class).withName("test").build();
|
||||||
|
|
||||||
assertNotNull(store);
|
assertNotNull(store);
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
|||||||
@Test
|
@Test
|
||||||
public void testSet()
|
public void testSet()
|
||||||
{
|
{
|
||||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(forType(StoreObject.class).withName("test").build());
|
ConfigurationStore<StoreObject> store = createStoreFactory().forType(StoreObject.class).withName("test").build();
|
||||||
|
|
||||||
assertNotNull(store);
|
assertNotNull(store);
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ import sonia.scm.event.ScmEventBus;
|
|||||||
import sonia.scm.group.GroupEvent;
|
import sonia.scm.group.GroupEvent;
|
||||||
import sonia.scm.store.ConfigurationEntryStore;
|
import sonia.scm.store.ConfigurationEntryStore;
|
||||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||||
import sonia.scm.store.StoreParameters;
|
|
||||||
import sonia.scm.user.UserEvent;
|
import sonia.scm.user.UserEvent;
|
||||||
import sonia.scm.util.ClassLoaders;
|
import sonia.scm.util.ClassLoaders;
|
||||||
|
|
||||||
@@ -77,8 +76,6 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
|||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO add events
|
* TODO add events
|
||||||
*
|
*
|
||||||
@@ -114,10 +111,10 @@ public class DefaultSecuritySystem implements SecuritySystem
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory)
|
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory)
|
||||||
{
|
{
|
||||||
store = storeFactory.getStore(
|
store = storeFactory.
|
||||||
forType(AssignedPermission.class)
|
forType(AssignedPermission.class)
|
||||||
.withName(NAME)
|
.withName(NAME)
|
||||||
.build());
|
.build();
|
||||||
readAvailablePermissions();
|
readAvailablePermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ import sonia.scm.store.ConfigurationEntryStore;
|
|||||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.*;
|
import static com.google.common.base.Preconditions.*;
|
||||||
import static sonia.scm.store.StoreParameters.forType;
|
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
@@ -91,10 +90,10 @@ public class SecureKeyResolver extends SigningKeyResolverAdapter
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory)
|
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory)
|
||||||
{
|
{
|
||||||
store = storeFactory.getStore(
|
store = storeFactory.
|
||||||
forType(SecureKey.class)
|
forType(SecureKey.class)
|
||||||
.withName(STORE_NAME)
|
.withName(STORE_NAME)
|
||||||
.build());
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public class AutoCompleteResourceTest {
|
|||||||
xmlDB = mock(XmlDatabase.class);
|
xmlDB = mock(XmlDatabase.class);
|
||||||
when(storeConfig.get()).thenReturn(xmlDB);
|
when(storeConfig.get()).thenReturn(xmlDB);
|
||||||
when(storeFactory.getStore(any())).thenReturn(storeConfig);
|
when(storeFactory.getStore(any())).thenReturn(storeConfig);
|
||||||
|
when(storeFactory.forType(any())).thenCallRealMethod();
|
||||||
XmlUserDAO userDao = new XmlUserDAO(storeFactory);
|
XmlUserDAO userDao = new XmlUserDAO(storeFactory);
|
||||||
this.userDao = spy(userDao);
|
this.userDao = spy(userDao);
|
||||||
XmlGroupDAO groupDAO = new XmlGroupDAO(storeFactory);
|
XmlGroupDAO groupDAO = new XmlGroupDAO(storeFactory);
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Mockito.argThat;
|
import static org.mockito.Mockito.argThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -125,6 +126,7 @@ public class SecureKeyResolverTest
|
|||||||
{
|
{
|
||||||
ConfigurationEntryStoreFactory factory = mock(ConfigurationEntryStoreFactory.class);
|
ConfigurationEntryStoreFactory factory = mock(ConfigurationEntryStoreFactory.class);
|
||||||
|
|
||||||
|
when(factory.forType(any())).thenCallRealMethod();
|
||||||
when(factory.getStore(argThat(storeParameters -> {
|
when(factory.getStore(argThat(storeParameters -> {
|
||||||
assertThat(storeParameters.getName()).isEqualTo(SecureKeyResolver.STORE_NAME);
|
assertThat(storeParameters.getName()).isEqualTo(SecureKeyResolver.STORE_NAME);
|
||||||
assertThat(storeParameters.getType()).isEqualTo(SecureKey.class);
|
assertThat(storeParameters.getType()).isEqualTo(SecureKey.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user