mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-08 07:39:15 +01:00
add the interface StoreFactory and refactor storeFactories
This commit is contained in:
@@ -46,10 +46,15 @@ import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.repository.InitialRepositoryLocationResolver;
|
||||
import sonia.scm.repository.RepositoryDAO;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -66,10 +71,29 @@ import java.util.logging.Logger;
|
||||
public class AbstractTestBase
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static ThreadState subjectThreadState;
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
private File tempDirectory;
|
||||
|
||||
protected DefaultFileSystem fileSystem;
|
||||
|
||||
protected RepositoryDAO repositoryDAO = mock(RepositoryDAO.class);
|
||||
protected RepositoryLocationResolver repositoryLocationResolver;
|
||||
|
||||
@Before
|
||||
public void setUpTest() throws Exception
|
||||
{
|
||||
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
|
||||
UUID.randomUUID().toString());
|
||||
assertTrue(tempDirectory.mkdirs());
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempDirectory);
|
||||
fileSystem = new DefaultFileSystem();
|
||||
InitialRepositoryLocationResolver initialRepoLocationResolver = new InitialRepositoryLocationResolver(contextProvider,fileSystem);
|
||||
repositoryLocationResolver = new RepositoryLocationResolver(repositoryDAO, initialRepoLocationResolver);
|
||||
postSetUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -165,25 +189,6 @@ public class AbstractTestBase
|
||||
}
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Before
|
||||
public void setUpTest() throws Exception
|
||||
{
|
||||
tempDirectory = new File(System.getProperty("java.io.tmpdir"),
|
||||
UUID.randomUUID().toString());
|
||||
assertTrue(tempDirectory.mkdirs());
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempDirectory);
|
||||
postSetUp();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Clears Shiro's thread state, ensuring the thread remains clean for
|
||||
@@ -249,12 +254,4 @@ public class AbstractTestBase
|
||||
subjectThreadState = createThreadState(subject);
|
||||
subjectThreadState.bind();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
/** Field description */
|
||||
private File tempDirectory;
|
||||
}
|
||||
|
||||
@@ -37,10 +37,13 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -54,12 +57,14 @@ public abstract class ManagerTestBase<T extends ModelObject>
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
protected RepositoryLocationResolver locationResolver;
|
||||
|
||||
protected Manager<T> manager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempFolder.newFolder());
|
||||
locationResolver = mock(RepositoryLocationResolver.class);
|
||||
manager = createManager();
|
||||
manager.init(contextProvider);
|
||||
}
|
||||
|
||||
@@ -35,22 +35,24 @@ package sonia.scm.store;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -58,12 +60,6 @@ import java.util.List;
|
||||
public abstract class BlobStoreTestBase extends AbstractTestBase
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract BlobStoreFactory createBlobStoreFactory();
|
||||
|
||||
/**
|
||||
@@ -73,7 +69,12 @@ public abstract class BlobStoreTestBase extends AbstractTestBase
|
||||
@Before
|
||||
public void createBlobStore()
|
||||
{
|
||||
store = createBlobStoreFactory().getBlobStore("test");
|
||||
store = createBlobStoreFactory().getStore(new StoreParameters()
|
||||
.withType(Blob.class)
|
||||
.withName("test")
|
||||
.forRepository(RepositoryTestData.createHeartOfGold())
|
||||
.build()
|
||||
);
|
||||
store.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,12 +32,13 @@
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestBase
|
||||
{
|
||||
public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestBase {
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -48,17 +49,22 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
|
||||
protected abstract ConfigurationEntryStoreFactory createConfigurationStoreFactory();
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected ConfigurationEntryStore<StoreObject> getDataStore()
|
||||
{
|
||||
return createConfigurationStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
protected ConfigurationEntryStore getDataStore(Class type) {
|
||||
StoreParameters params = new StoreParameters()
|
||||
.withType(type)
|
||||
.withName("test")
|
||||
.build();
|
||||
return this.createConfigurationStoreFactory().getStore(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
|
||||
StoreParameters params = new StoreParameters()
|
||||
.withType(type)
|
||||
.withName("test")
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
return this.createConfigurationStoreFactory().getStore(params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -48,17 +55,33 @@ public abstract class DataStoreTestBase extends KeyValueStoreTestBase
|
||||
*/
|
||||
protected abstract DataStoreFactory createDataStoreFactory();
|
||||
|
||||
|
||||
protected StoreParameters getStoreParametersWithRepository(Repository repository) {
|
||||
return new StoreParameters()
|
||||
.withType(StoreObject.class)
|
||||
.withName("test")
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
}
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected DataStore<StoreObject> getDataStore()
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
// TODO
|
||||
public void shouldStoreRepositorySpecificData()
|
||||
{
|
||||
return createDataStoreFactory().getStore(StoreObject.class, "test");
|
||||
StoreFactory<DataStore > dataStoreFactory = createDataStoreFactory();
|
||||
StoreObject obj = new StoreObject("test-1");
|
||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
|
||||
DataStore<StoreObject> store = dataStoreFactory.getStore(getStoreParametersWithRepository(repository));
|
||||
|
||||
String id = store.put(obj);
|
||||
|
||||
assertNotNull(id);
|
||||
|
||||
assertEquals(obj, store.get(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ package sonia.scm.store;
|
||||
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
||||
|
||||
@Override
|
||||
public <T> ConfigurationStore<T> getStore(Class<T> type, String name)
|
||||
{
|
||||
public ConfigurationStore getStore(StoreParameters storeParameters) {
|
||||
return new InMemoryConfigurationStore<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryTestData;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -56,13 +58,19 @@ import java.util.Map;
|
||||
public abstract class KeyValueStoreTestBase extends AbstractTestBase
|
||||
{
|
||||
|
||||
private Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
private DataStore<StoreObject> store;
|
||||
private DataStore<StoreObject> repoStore;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract DataStore<StoreObject> getDataStore();
|
||||
protected abstract <STORE_OBJECT> DataStore<STORE_OBJECT> getDataStore(Class<STORE_OBJECT> type , Repository repository);
|
||||
protected abstract <STORE_OBJECT> DataStore<STORE_OBJECT> getDataStore(Class<STORE_OBJECT> type );
|
||||
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -73,8 +81,10 @@ public abstract class KeyValueStoreTestBase extends AbstractTestBase
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
store = getDataStore();
|
||||
store = getDataStore(StoreObject.class);
|
||||
repoStore = getDataStore(StoreObject.class, repository);
|
||||
store.clear();
|
||||
repoStore.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -215,8 +225,5 @@ public abstract class KeyValueStoreTestBase extends AbstractTestBase
|
||||
assertNull(store.get("2"));
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private DataStore<StoreObject> store;
|
||||
}
|
||||
|
||||
@@ -35,10 +35,12 @@ package sonia.scm.store;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -58,6 +60,13 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
*/
|
||||
protected abstract ConfigurationStoreFactory createStoreFactory();
|
||||
|
||||
protected StoreParameters getStoreParameters() {
|
||||
return new StoreParameters()
|
||||
.withType(StoreObject.class)
|
||||
.withName("test")
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -65,8 +74,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testGet()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(getStoreParameters());
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
@@ -82,8 +90,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testSet()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(getStoreParameters());
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user