mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 23:45:44 +01:00
refactor store api
This commit is contained in:
@@ -37,12 +37,12 @@ package sonia.scm.repository;
|
||||
|
||||
import sonia.scm.Type;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -69,7 +69,7 @@ public class DummyRepositoryHandler
|
||||
*
|
||||
* @param storeFactory
|
||||
*/
|
||||
public DummyRepositoryHandler(StoreFactory storeFactory)
|
||||
public DummyRepositoryHandler(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
super(storeFactory, new DefaultFileSystem());
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ package sonia.scm.repository;
|
||||
import org.junit.Test;
|
||||
|
||||
import sonia.scm.AbstractTestBase;
|
||||
import sonia.scm.store.MemoryStoreFactory;
|
||||
import sonia.scm.store.StoreFactory;
|
||||
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -48,6 +47,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.store.ConfigurationStoreFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -74,7 +74,7 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
|
||||
* @return
|
||||
*/
|
||||
protected abstract RepositoryHandler createRepositoryHandler(
|
||||
StoreFactory factory, File directory);
|
||||
ConfigurationStoreFactory factory, File directory);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -150,11 +150,8 @@ public abstract class SimpleRepositoryHandlerTestBase extends AbstractTestBase
|
||||
@Override
|
||||
protected void postSetUp() throws Exception
|
||||
{
|
||||
MemoryStoreFactory storeFactory = new MemoryStoreFactory();
|
||||
|
||||
storeFactory.init(contextProvider);
|
||||
baseDirectory = new File(contextProvider.getBaseDirectory(),
|
||||
"repositories");
|
||||
InMemoryConfigurationStoreFactory storeFactory = new InMemoryConfigurationStoreFactory();
|
||||
baseDirectory = new File(contextProvider.getBaseDirectory(), "repositories");
|
||||
IOUtil.mkdirs(baseDirectory);
|
||||
handler = createRepositoryHandler(storeFactory, baseDirectory);
|
||||
}
|
||||
|
||||
@@ -28,48 +28,27 @@
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.store;
|
||||
|
||||
/**
|
||||
*
|
||||
* In memory store implementation of {@link ConfigurationStore}.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T>
|
||||
* @param <T> type of stored object
|
||||
*/
|
||||
public class MemoryStore<T> implements Store<T>
|
||||
{
|
||||
public class InMemoryConfigurationStore<T> implements ConfigurationStore<T> {
|
||||
|
||||
private T object;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public T get()
|
||||
{
|
||||
public T get() {
|
||||
return object;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param obejct
|
||||
*/
|
||||
@Override
|
||||
public void set(T obejct)
|
||||
{
|
||||
public void set(T obejct) {
|
||||
this.object = obejct;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private T object;
|
||||
}
|
||||
@@ -35,60 +35,16 @@ package sonia.scm.store;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.SCMContextProvider;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* In memory configuration store factory for testing purposes.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class MemoryStoreFactory implements StoreFactory
|
||||
{
|
||||
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Override
|
||||
public void close() throws IOException
|
||||
public <T> ConfigurationStore<T> getStore(Class<T> type, String name)
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
*/
|
||||
@Override
|
||||
public void init(SCMContextProvider context)
|
||||
{
|
||||
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param type
|
||||
* @param name
|
||||
* @param <T>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public <T> Store<T> getStore(Class<T> type, String name)
|
||||
{
|
||||
return new MemoryStore<T>();
|
||||
return new InMemoryConfigurationStore<>();
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract StoreFactory createStoreFactory();
|
||||
protected abstract ConfigurationStoreFactory createStoreFactory();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -65,7 +65,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testGet()
|
||||
{
|
||||
Store<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
|
||||
assertNotNull(store);
|
||||
@@ -82,7 +82,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testSet()
|
||||
{
|
||||
Store<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().getStore(StoreObject.class,
|
||||
"test");
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
Reference in New Issue
Block a user