mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Enhance in-memory store factories for tests
This commit is contained in:
@@ -1,28 +1,23 @@
|
|||||||
package sonia.scm.store;
|
package sonia.scm.store;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class InMemoryConfigurationEntryStoreFactory implements ConfigurationEntryStoreFactory {
|
public class InMemoryConfigurationEntryStoreFactory implements ConfigurationEntryStoreFactory {
|
||||||
|
|
||||||
|
private final Map<String, InMemoryConfigurationEntryStore> stores = new HashMap<>();
|
||||||
|
|
||||||
|
public static InMemoryConfigurationEntryStoreFactory create() {
|
||||||
|
return new InMemoryConfigurationEntryStoreFactory();
|
||||||
private ConfigurationEntryStore store;
|
|
||||||
|
|
||||||
public static ConfigurationEntryStoreFactory create() {
|
|
||||||
return new InMemoryConfigurationEntryStoreFactory(new InMemoryConfigurationEntryStore());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InMemoryConfigurationEntryStoreFactory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public InMemoryConfigurationEntryStoreFactory(ConfigurationEntryStore store) {
|
|
||||||
this.store = store;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
|
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
|
||||||
if (store != null) {
|
String name = storeParameters.getName();
|
||||||
return store;
|
return get(name);
|
||||||
}
|
}
|
||||||
return new InMemoryConfigurationEntryStore<>();
|
|
||||||
|
public InMemoryConfigurationEntryStore get(String name) {
|
||||||
|
return stores.computeIfAbsent(name, x -> new InMemoryConfigurationEntryStore());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ package sonia.scm.store;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In memory configuration store factory for testing purposes.
|
* In memory configuration store factory for testing purposes.
|
||||||
*
|
*
|
||||||
@@ -44,24 +47,19 @@ package sonia.scm.store;
|
|||||||
*/
|
*/
|
||||||
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
|
||||||
|
|
||||||
private ConfigurationStore store;
|
private final Map<String, InMemoryConfigurationStore> stores = new HashMap<>();
|
||||||
|
|
||||||
public static ConfigurationStoreFactory create() {
|
public static InMemoryConfigurationStoreFactory create() {
|
||||||
return new InMemoryConfigurationStoreFactory(new InMemoryConfigurationStore());
|
return new InMemoryConfigurationStoreFactory();
|
||||||
}
|
|
||||||
|
|
||||||
public InMemoryConfigurationStoreFactory() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public InMemoryConfigurationStoreFactory(ConfigurationStore store) {
|
|
||||||
this.store = store;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ConfigurationStore getStore(TypedStoreParameters storeParameters) {
|
public ConfigurationStore getStore(TypedStoreParameters storeParameters) {
|
||||||
if (store != null) {
|
String name = storeParameters.getName();
|
||||||
return store;
|
return get(name);
|
||||||
}
|
}
|
||||||
return new InMemoryConfigurationStore<>();
|
|
||||||
|
public ConfigurationStore get(String name) {
|
||||||
|
return stores.computeIfAbsent(name, x -> new InMemoryConfigurationStore());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import static sonia.scm.version.Version.parse;
|
|||||||
|
|
||||||
class UpdateEngineTest {
|
class UpdateEngineTest {
|
||||||
|
|
||||||
ConfigurationEntryStoreFactory storeFactory = new InMemoryConfigurationEntryStoreFactory(new InMemoryConfigurationEntryStore());
|
ConfigurationEntryStoreFactory storeFactory = new InMemoryConfigurationEntryStoreFactory();
|
||||||
|
|
||||||
List<String> processedUpdates = new ArrayList<>();
|
List<String> processedUpdates = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class XmlRepositoryV1UpdateStepTest {
|
|||||||
@Mock
|
@Mock
|
||||||
MigrationStrategyDao migrationStrategyDao;
|
MigrationStrategyDao migrationStrategyDao;
|
||||||
|
|
||||||
ConfigurationEntryStoreFactory configurationEntryStoreFactory = new InMemoryConfigurationEntryStoreFactory(new InMemoryConfigurationEntryStore());
|
InMemoryConfigurationEntryStoreFactory configurationEntryStoreFactory = new InMemoryConfigurationEntryStoreFactory();
|
||||||
|
|
||||||
@Captor
|
@Captor
|
||||||
ArgumentCaptor<Repository> storeCaptor;
|
ArgumentCaptor<Repository> storeCaptor;
|
||||||
@@ -137,7 +137,7 @@ class XmlRepositoryV1UpdateStepTest {
|
|||||||
void shouldExtractPropertiesFromRepositories() throws JAXBException {
|
void shouldExtractPropertiesFromRepositories() throws JAXBException {
|
||||||
updateStep.doUpdate();
|
updateStep.doUpdate();
|
||||||
|
|
||||||
ConfigurationEntryStore<Object> store = configurationEntryStoreFactory.withType(null).withName("").build();
|
ConfigurationEntryStore store = configurationEntryStoreFactory.get("repository-properties-v1");
|
||||||
assertThat(store.getAll())
|
assertThat(store.getAll())
|
||||||
.hasSize(3);
|
.hasSize(3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.util.List;
|
|||||||
import static java.util.stream.Collectors.toList;
|
import static java.util.stream.Collectors.toList;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
|
||||||
|
|
||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@ExtendWith(TempDirectory.class)
|
@ExtendWith(TempDirectory.class)
|
||||||
@@ -40,8 +41,8 @@ class XmlSecurityV1UpdateStepTest {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||||
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
|
||||||
assignedPermissionStore = new InMemoryConfigurationEntryStore<>();
|
InMemoryConfigurationEntryStoreFactory inMemoryConfigurationEntryStoreFactory = create();
|
||||||
ConfigurationEntryStoreFactory inMemoryConfigurationEntryStoreFactory = new InMemoryConfigurationEntryStoreFactory(assignedPermissionStore);
|
assignedPermissionStore = inMemoryConfigurationEntryStoreFactory.get("security");
|
||||||
updateStep = new XmlSecurityV1UpdateStep(contextProvider, inMemoryConfigurationEntryStoreFactory);
|
updateStep = new XmlSecurityV1UpdateStep(contextProvider, inMemoryConfigurationEntryStoreFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
|||||||
import sonia.scm.security.AssignedPermission;
|
import sonia.scm.security.AssignedPermission;
|
||||||
import sonia.scm.security.DefaultKeyGenerator;
|
import sonia.scm.security.DefaultKeyGenerator;
|
||||||
import sonia.scm.store.ConfigurationEntryStore;
|
import sonia.scm.store.ConfigurationEntryStore;
|
||||||
|
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||||
import sonia.scm.update.UpdateStepTestUtil;
|
import sonia.scm.update.UpdateStepTestUtil;
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
@@ -46,7 +47,7 @@ class XmlUserV1UpdateStepTest {
|
|||||||
@BeforeEach
|
@BeforeEach
|
||||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||||
testUtil = new UpdateStepTestUtil(tempDir);
|
testUtil = new UpdateStepTestUtil(tempDir);
|
||||||
JAXBConfigurationEntryStoreFactory storeFactory = new JAXBConfigurationEntryStoreFactory(testUtil.getContextProvider(), null, new DefaultKeyGenerator());
|
ConfigurationEntryStoreFactory storeFactory = new JAXBConfigurationEntryStoreFactory(testUtil.getContextProvider(), null, new DefaultKeyGenerator());
|
||||||
updateStep = new XmlUserV1UpdateStep(testUtil.getContextProvider(), userDAO, storeFactory);
|
updateStep = new XmlUserV1UpdateStep(testUtil.getContextProvider(), userDAO, storeFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user