mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-04 19:30:51 +01:00
Make type optional
This commit is contained in:
@@ -73,9 +73,9 @@ public abstract class AbstractRepositoryHandler<C extends RepositoryConfig>
|
||||
* @param storeFactory
|
||||
*/
|
||||
protected AbstractRepositoryHandler(ConfigurationStoreFactory storeFactory) {
|
||||
this.store = storeFactory.
|
||||
forType(getConfigClass())
|
||||
this.store = storeFactory
|
||||
.withName(getType().getName())
|
||||
.withType(getConfigClass())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ public interface StoreFactory<STORE> {
|
||||
|
||||
STORE getStore(final StoreParameters storeParameters);
|
||||
|
||||
default FloatingStoreParameters<STORE>.WithType forType(Class type) {
|
||||
return new FloatingStoreParameters<>(this).new WithType(type);
|
||||
default FloatingStoreParameters<STORE>.Builder withName(String name) {
|
||||
return new FloatingStoreParameters<>(this).new Builder(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,36 +35,22 @@ final class FloatingStoreParameters<STORE> implements StoreParameters {
|
||||
return repository;
|
||||
}
|
||||
|
||||
public class WithType {
|
||||
public class Builder {
|
||||
|
||||
WithType(Class type) {
|
||||
FloatingStoreParameters.this.type = type;
|
||||
}
|
||||
|
||||
public FloatingStoreParameters<STORE>.WithTypeAndName withName(String name){
|
||||
return new WithTypeAndName(name);
|
||||
}
|
||||
|
||||
}
|
||||
public class WithTypeAndName {
|
||||
|
||||
private WithTypeAndName(String name) {
|
||||
Builder(String name) {
|
||||
FloatingStoreParameters.this.name = name;
|
||||
}
|
||||
|
||||
public FloatingStoreParameters<STORE>.WithTypeNameAndRepository forRepository(Repository repository){
|
||||
return new WithTypeNameAndRepository(repository);
|
||||
public FloatingStoreParameters<STORE>.Builder withType(Class type) {
|
||||
FloatingStoreParameters.this.type = type;
|
||||
return this;
|
||||
}
|
||||
public STORE build(){
|
||||
return factory.getStore(FloatingStoreParameters.this);
|
||||
}
|
||||
}
|
||||
|
||||
public class WithTypeNameAndRepository {
|
||||
|
||||
private WithTypeNameAndRepository(Repository repository) {
|
||||
public FloatingStoreParameters<STORE>.Builder forRepository(Repository repository) {
|
||||
FloatingStoreParameters.this.repository = repository;
|
||||
return this;
|
||||
}
|
||||
|
||||
public STORE build(){
|
||||
return factory.getStore(FloatingStoreParameters.this);
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ public class XmlGroupDAO extends AbstractXmlDAO<Group, XmlGroupDatabase>
|
||||
*/
|
||||
@Inject
|
||||
public XmlGroupDAO(ConfigurationStoreFactory storeFactory) {
|
||||
super(storeFactory.
|
||||
forType(XmlGroupDatabase.class)
|
||||
.withName(STORE_NAME)
|
||||
.build());
|
||||
super(storeFactory
|
||||
.withName(STORE_NAME)
|
||||
.withType(XmlGroupDatabase.class)
|
||||
.build());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -64,9 +64,10 @@ public class XmlUserDAO extends AbstractXmlDAO<User, XmlUserDatabase>
|
||||
@Inject
|
||||
public XmlUserDAO(ConfigurationStoreFactory storeFactory)
|
||||
{
|
||||
super(storeFactory.forType(XmlUserDatabase.class)
|
||||
.withName(STORE_NAME)
|
||||
.build());
|
||||
super(storeFactory
|
||||
.withName(STORE_NAME)
|
||||
.withType(XmlUserDatabase.class)
|
||||
.build());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -65,11 +65,11 @@ public class FileBlobStoreTest extends BlobStoreTestBase
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldStoreAndLoadInRepository() {
|
||||
BlobStore store = createBlobStoreFactory().
|
||||
forType(StoreObject.class)
|
||||
.withName("test")
|
||||
.forRepository(new Repository("id", "git", "ns", "n"))
|
||||
.build();
|
||||
BlobStore store = createBlobStoreFactory()
|
||||
.withName("test")
|
||||
.withType(StoreObject.class)
|
||||
.forRepository(new Repository("id", "git", "ns", "n"))
|
||||
.build();
|
||||
|
||||
Blob createdBlob = store.create("abc");
|
||||
List<Blob> storedBlobs = store.getAll();
|
||||
@@ -78,6 +78,6 @@ public class FileBlobStoreTest extends BlobStoreTestBase
|
||||
assertThat(storedBlobs)
|
||||
.isNotNull()
|
||||
.hasSize(1)
|
||||
.usingElementComparatorOnFields("id").containsExactly(createdBlob);
|
||||
.usingElementComparatorOnFields("id").containsExactly(createdBlob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,10 +132,10 @@ public class JAXBConfigurationEntryStoreTest
|
||||
ConfigurationEntryStore<AssignedPermission> store = createPermissionStore(RESOURCE_FIXED, name);
|
||||
|
||||
store.put("a45", new AssignedPermission("tuser4", "repository:create"));
|
||||
store = createConfigurationStoreFactory().
|
||||
forType(AssignedPermission.class)
|
||||
.withName(name)
|
||||
.build();
|
||||
store = createConfigurationStoreFactory()
|
||||
.withName(name)
|
||||
.withType(AssignedPermission.class)
|
||||
.build();
|
||||
|
||||
AssignedPermission ap = store.get("a45");
|
||||
|
||||
@@ -231,9 +231,9 @@ public class JAXBConfigurationEntryStoreTest
|
||||
}
|
||||
|
||||
copy(resource, name);
|
||||
return createConfigurationStoreFactory().
|
||||
forType(AssignedPermission.class)
|
||||
.withName(name)
|
||||
.build();
|
||||
return createConfigurationStoreFactory()
|
||||
.withName(name)
|
||||
.withType(AssignedPermission.class)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +56,11 @@ public class JAXBConfigurationStoreTest extends StoreTestBase {
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldStoreAndLoadInRepository()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().
|
||||
forType(StoreObject.class)
|
||||
.withName("test")
|
||||
.forRepository(new Repository("id", "git", "ns", "n"))
|
||||
.build();
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory()
|
||||
.withName("test")
|
||||
.withType(StoreObject.class)
|
||||
.forRepository(new Repository("id", "git", "ns", "n"))
|
||||
.build();
|
||||
|
||||
store.set(new StoreObject("value"));
|
||||
StoreObject storeObject = store.get();
|
||||
|
||||
@@ -61,16 +61,18 @@ public class JAXBDataStoreTest extends DataStoreTestBase {
|
||||
|
||||
@Override
|
||||
protected DataStore getDataStore(Class type, Repository repository) {
|
||||
return createDataStoreFactory().forType(type)
|
||||
return createDataStoreFactory()
|
||||
.withName("test")
|
||||
.withType(type)
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DataStore getDataStore(Class type) {
|
||||
return createDataStoreFactory().forType(type)
|
||||
return createDataStoreFactory()
|
||||
.withName("test")
|
||||
.withType(type)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class LfsBlobStoreFactory {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BlobStore getLfsBlobStore(Repository repository) {
|
||||
return blobStoreFactory.forType(String.class)
|
||||
return blobStoreFactory
|
||||
.withName(repository.getId() + GIT_LFS_REPOSITORY_POSTFIX)
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
|
||||
@@ -86,7 +86,7 @@ public class GitRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Before
|
||||
public void initFactory() {
|
||||
when(factory.forType(any())).thenCallRealMethod();
|
||||
when(factory.withName(any())).thenCallRealMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,7 +63,7 @@ public class LfsBlobStoreFactoryTest {
|
||||
|
||||
@Test
|
||||
public void getBlobStore() {
|
||||
when(blobStoreFactory.forType(any())).thenCallRealMethod();
|
||||
when(blobStoreFactory.withName(any())).thenCallRealMethod();
|
||||
Repository repository = new Repository("the-id", "GIT", "space", "the-name");
|
||||
lfsBlobStoreFactory.getLfsBlobStore(repository);
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class HgRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Before
|
||||
public void initFactory() {
|
||||
when(factory.forType(any())).thenCallRealMethod();
|
||||
when(factory.withName(any())).thenCallRealMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -107,7 +107,7 @@ public class SvnRepositoryHandlerTest extends SimpleRepositoryHandlerTestBase {
|
||||
|
||||
@Test
|
||||
public void getDirectory() {
|
||||
when(factory.forType(any())).thenCallRealMethod();
|
||||
when(factory.withName(any())).thenCallRealMethod();
|
||||
SvnRepositoryHandler repositoryHandler = new SvnRepositoryHandler(factory,
|
||||
facade, locationResolver);
|
||||
|
||||
|
||||
@@ -69,11 +69,10 @@ public abstract class BlobStoreTestBase extends AbstractTestBase
|
||||
@Before
|
||||
public void createBlobStore()
|
||||
{
|
||||
store = createBlobStoreFactory().
|
||||
forType(Blob.class)
|
||||
.withName("test")
|
||||
.forRepository(RepositoryTestData.createHeartOfGold())
|
||||
.build();
|
||||
store = createBlobStoreFactory()
|
||||
.withName("test")
|
||||
.forRepository(RepositoryTestData.createHeartOfGold())
|
||||
.build();
|
||||
store.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,15 +51,17 @@ public abstract class ConfigurationEntryStoreTestBase extends KeyValueStoreTestB
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
@Override
|
||||
protected ConfigurationEntryStore getDataStore(Class type) {
|
||||
return this.createConfigurationStoreFactory().forType(type)
|
||||
return this.createConfigurationStoreFactory()
|
||||
.withName(storeName)
|
||||
.withType(type)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConfigurationEntryStore getDataStore(Class type, Repository repository) {
|
||||
return this.createConfigurationStoreFactory().forType(type)
|
||||
return this.createConfigurationStoreFactory()
|
||||
.withName(repoStoreName)
|
||||
.withType(type)
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -69,8 +69,9 @@ public abstract class DataStoreTestBase extends KeyValueStoreTestBase
|
||||
StoreObject obj = new StoreObject("test-1");
|
||||
Repository repository = RepositoryTestData.createHeartOfGold();
|
||||
|
||||
DataStore<StoreObject> store = dataStoreFactory.forType(StoreObject.class)
|
||||
DataStore<StoreObject> store = dataStoreFactory
|
||||
.withName("test")
|
||||
.withType(StoreObject.class)
|
||||
.forRepository(repository)
|
||||
.build();
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testGet()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().forType(StoreObject.class).withName("test").build();
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().withName("test").withType(StoreObject.class).build();
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
@@ -82,7 +82,7 @@ public abstract class StoreTestBase extends AbstractTestBase
|
||||
@Test
|
||||
public void testSet()
|
||||
{
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().forType(StoreObject.class).withName("test").build();
|
||||
ConfigurationStore<StoreObject> store = createStoreFactory().withName("test").withType(StoreObject.class).build();
|
||||
|
||||
assertNotNull(store);
|
||||
|
||||
|
||||
@@ -111,10 +111,10 @@ public class DefaultSecuritySystem implements SecuritySystem
|
||||
@SuppressWarnings("unchecked")
|
||||
public DefaultSecuritySystem(ConfigurationEntryStoreFactory storeFactory)
|
||||
{
|
||||
store = storeFactory.
|
||||
forType(AssignedPermission.class)
|
||||
.withName(NAME)
|
||||
.build();
|
||||
store = storeFactory
|
||||
.withName(NAME)
|
||||
.withType(AssignedPermission.class)
|
||||
.build();
|
||||
readAvailablePermissions();
|
||||
}
|
||||
|
||||
|
||||
@@ -90,10 +90,10 @@ public class SecureKeyResolver extends SigningKeyResolverAdapter
|
||||
@SuppressWarnings("unchecked")
|
||||
public SecureKeyResolver(ConfigurationEntryStoreFactory storeFactory)
|
||||
{
|
||||
store = storeFactory.
|
||||
forType(SecureKey.class)
|
||||
.withName(STORE_NAME)
|
||||
.build();
|
||||
store = storeFactory
|
||||
.withName(STORE_NAME)
|
||||
.withType(SecureKey.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
@@ -67,7 +67,7 @@ public class AutoCompleteResourceTest {
|
||||
xmlDB = mock(XmlDatabase.class);
|
||||
when(storeConfig.get()).thenReturn(xmlDB);
|
||||
when(storeFactory.getStore(any())).thenReturn(storeConfig);
|
||||
when(storeFactory.forType(any())).thenCallRealMethod();
|
||||
when(storeFactory.withName(any())).thenCallRealMethod();
|
||||
XmlUserDAO userDao = new XmlUserDAO(storeFactory);
|
||||
this.userDao = spy(userDao);
|
||||
XmlGroupDAO groupDAO = new XmlGroupDAO(storeFactory);
|
||||
|
||||
@@ -126,7 +126,7 @@ public class SecureKeyResolverTest
|
||||
{
|
||||
ConfigurationEntryStoreFactory factory = mock(ConfigurationEntryStoreFactory.class);
|
||||
|
||||
when(factory.forType(any())).thenCallRealMethod();
|
||||
when(factory.withName(any())).thenCallRealMethod();
|
||||
when(factory.getStore(argThat(storeParameters -> {
|
||||
assertThat(storeParameters.getName()).isEqualTo(SecureKeyResolver.STORE_NAME);
|
||||
assertThat(storeParameters.getType()).isEqualTo(SecureKey.class);
|
||||
|
||||
Reference in New Issue
Block a user