In-memory implementations of the store api using JaxB

The new implementations are ment to be used in test
classes replacing the older implementations like
`InMemoryConfigurationStoreFactory`. The benefit
of these new classes is that the serialization using JaxB
is testet implicitly avoiding mistakes made with XML
annotations on the data classes.

Committed-by: Eduard Heimbuch <eduard.heimbuch@cloudogu.com>
Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
Rene Pfeuffer
2023-06-07 10:04:50 +02:00
parent b0eebc7a2e
commit 86b8be9f17
21 changed files with 379 additions and 49 deletions

View File

@@ -0,0 +1,2 @@
- type: added
description: New in-memory implementations of the store api for unit tests using JaxB

View File

@@ -24,6 +24,8 @@
package sonia.scm.store;
import com.google.common.collect.Collections2;
import java.util.Collection;
import java.util.function.Predicate;
@@ -42,10 +44,13 @@ public interface ConfigurationEntryStore<V> extends DataStore<V> {
/**
* Return all values matching the given {@link Predicate}.
*
* Default implementation since 2.44.0
*
* @param predicate predicate to match values
*
* @return filtered collection of values
*/
Collection<V> getMatchingValues(Predicate<V> predicate);
default Collection<V> getMatchingValues(Predicate<V> predicate) {
return Collections2.filter(getAll().values(), predicate::test);
}
}

View File

@@ -131,11 +131,6 @@ public class JAXBConfigurationEntryStore<V> implements ConfigurationEntryStore<V
return Collections.unmodifiableMap(entries);
}
@Override
public Collection<V> getMatchingValues(Predicate<V> predicate) {
return Collections2.filter(entries.values(), predicate::test);
}
private void load() {
LOG.debug("load configuration from {}", file);
execute(() ->

View File

@@ -27,7 +27,7 @@ package sonia.scm.store;
import java.util.HashMap;
import java.util.Map;
public class InMemoryBlobStoreFactory implements BlobStoreFactory {
public class InMemoryBlobStoreFactory implements BlobStoreFactory, InMemoryStoreParameterNameComputer {
private final Map<String, BlobStore> stores = new HashMap<>();
@@ -49,12 +49,4 @@ public class InMemoryBlobStoreFactory implements BlobStoreFactory {
return fixedStore;
}
}
private String computeKey(StoreParameters storeParameters) {
if (storeParameters.getRepositoryId() == null) {
return storeParameters.getName();
} else {
return storeParameters.getName() + "/" + storeParameters.getRepositoryId();
}
}
}

View File

@@ -0,0 +1,98 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
import sonia.scm.security.KeyGenerator;
import sonia.scm.security.UUIDKeyGenerator;
import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class InMemoryByteConfigurationEntryStore<V> implements ConfigurationEntryStore<V> {
private final Class<V> type;
private final KeyGenerator generator = new UUIDKeyGenerator();
private final Map<String, byte[]> store = new HashMap<>();
public InMemoryByteConfigurationEntryStore(Class<V> type) {
this.type = type;
}
@Override
public String put(V item) {
String id = generator.createKey();
put(id, item);
return id;
}
@Override
public void put(String id, V item) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JAXB.marshal(item, baos);
store.put(id, baos.toByteArray());
}
/**
* This method can be used to mock stores with old types to test update steps or otherwise the compatability of
* objects with old versions.
*/
public void putOldObject(String id, Object item) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JAXB.marshal(item, baos);
store.put(id, baos.toByteArray());
}
@Override
public Map<String, V> getAll() {
Map<String, V> all = new HashMap<>();
for (String id : store.keySet()) {
all.put(id, get(id));
}
return Collections.unmodifiableMap(all);
}
@Override
public void clear() {
store.clear();
}
@Override
public void remove(String id) {
store.remove(id);
}
@Override
public V get(String id) {
byte[] bytes = store.get(id);
if (bytes != null) {
return JAXB.unmarshal(new ByteArrayInputStream(bytes), type);
}
return null;
}
}

View File

@@ -0,0 +1,56 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
import java.util.HashMap;
import java.util.Map;
/**
* Stores data in memory but in contrast to {@link InMemoryConfigurationEntryStoreFactory}
* it uses jaxb to marshal and unmarshall the objects.
*
* @since 2.44.0
*/
public class InMemoryByteConfigurationEntryStoreFactory implements ConfigurationEntryStoreFactory, InMemoryStoreParameterNameComputer {
@SuppressWarnings("rawtypes")
private final Map<String, InMemoryByteConfigurationEntryStore> stores = new HashMap<>();
public static InMemoryByteConfigurationEntryStoreFactory create() {
return new InMemoryByteConfigurationEntryStoreFactory();
}
@Override
public <T> ConfigurationEntryStore<T> getStore(TypedStoreParameters<T> storeParameters) {
String name = computeKey(storeParameters);
Class<T> type = storeParameters.getType();
return get(type, name);
}
@SuppressWarnings("unchecked")
public <T> ConfigurationEntryStore<T> get(Class<T> type, String name) {
return stores.computeIfAbsent(name, n -> new InMemoryByteConfigurationEntryStore<>(type));
}
}

View File

@@ -0,0 +1,67 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
/**
* In memory store implementation of {@link ConfigurationStore} using a byte array to store the serialized object.
*/
public class InMemoryByteConfigurationStore<T> implements ConfigurationStore<T> {
private final Class<T> type;
byte[] store;
public InMemoryByteConfigurationStore(Class<T> type) {
this.type = type;
}
@Override
public T get() {
if (store != null) {
return JAXB.unmarshal(new ByteArrayInputStream(store), type);
}
return null;
}
@Override
public void set(T object) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JAXB.marshal(object, baos);
store = baos.toByteArray();
}
/**
* This method can be used to mock stores with old types to test update steps or otherwise the compatability of
* objects with old versions.
*/
public void setOldObject(Object object) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JAXB.marshal(object, baos);
store = baos.toByteArray();
}
}

View File

@@ -0,0 +1,51 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
import java.util.HashMap;
import java.util.Map;
/**
* In memory configuration store factory for testing purposes that uses JaxB for serialization.
*
* @since 2.44.0
*/
public class InMemoryByteConfigurationStoreFactory implements ConfigurationStoreFactory, InMemoryStoreParameterNameComputer {
@SuppressWarnings("rawtypes")
private final Map<String, InMemoryByteConfigurationStore> stores = new HashMap<>();
@Override
public <T> ConfigurationStore<T> getStore(TypedStoreParameters<T> storeParameters) {
String name = computeKey(storeParameters);
Class<T> type = storeParameters.getType();
return getStore(type, name);
}
@SuppressWarnings("unchecked")
public <T> ConfigurationStore<T> getStore(Class<T> type, String name) {
return stores.computeIfAbsent(name, n -> new InMemoryByteConfigurationStore<>(type));
}
}

View File

@@ -58,6 +58,16 @@ public class InMemoryByteDataStore<T> implements DataStore<T> {
store.put(id, baos.toByteArray());
}
/**
* This method can be used to mock stores with old types to test update steps or otherwise the compatability of
* objects with old versions.
*/
public void putOldObject(String id, Object item) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JAXB.marshal(item, baos);
store.put(id, baos.toByteArray());
}
@Override
public Map<String, T> getAll() {
Map<String, T> all = new HashMap<>();

View File

@@ -33,15 +33,20 @@ import java.util.Map;
*
* @since 2.18.0
*/
public class InMemoryByteDataStoreFactory implements DataStoreFactory {
public class InMemoryByteDataStoreFactory implements DataStoreFactory, InMemoryStoreParameterNameComputer {
@SuppressWarnings("rawtypes")
private final Map<String, InMemoryByteDataStore> stores = new HashMap<>();
@Override
@SuppressWarnings("unchecked")
public <T> DataStore<T> getStore(TypedStoreParameters<T> storeParameters) {
String name = storeParameters.getName();
return stores.computeIfAbsent(name, n -> new InMemoryByteDataStore<T>(storeParameters.getType()));
String name = computeKey(storeParameters);
Class<T> type = storeParameters.getType();
return getStore(type, name);
}
@SuppressWarnings("unchecked")
public <T> DataStore<T> getStore(Class<T> type, String name) {
return stores.computeIfAbsent(name, n -> new InMemoryByteDataStore<>(type));
}
}

View File

@@ -33,6 +33,10 @@ import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Collectors;
/**
* @deprecated Replaced by {@link InMemoryByteConfigurationEntryStore}
*/
@Deprecated(since = "2.44.0")
public class InMemoryConfigurationEntryStore<V> implements ConfigurationEntryStore<V> {
private final Map<String, V> values = new HashMap<>();

View File

@@ -27,6 +27,10 @@ package sonia.scm.store;
import java.util.HashMap;
import java.util.Map;
/**
* @deprecated Use {@link InMemoryByteConfigurationEntryStoreFactory} instead to verify JaxB serialization, too.
*/
@Deprecated(since = "2.44.0")
public class InMemoryConfigurationEntryStoreFactory implements ConfigurationEntryStoreFactory {
private final Map<String, InMemoryConfigurationEntryStore> stores = new HashMap<>();

View File

@@ -21,16 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
/**
* In memory store implementation of {@link ConfigurationStore}.
*
*
* @author Sebastian Sdorra
*
* @param <T> type of stored object
*
* @deprecated Replaced by the {@link InMemoryByteConfigurationStore}
*/
@Deprecated(since = "2.44.0")
public class InMemoryConfigurationStore<T> implements ConfigurationStore<T> {
private T object;

View File

@@ -21,10 +21,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
//~--- non-JDK imports --------------------------------------------------------
package sonia.scm.store;
import java.util.HashMap;
import java.util.Map;
@@ -32,10 +30,11 @@ import java.util.Map;
/**
* In memory configuration store factory for testing purposes.
*
* Use {@link #create()} to get a store that creates the same store on each request.
*
* @author Sebastian Sdorra
*
* @deprecated Use the {@link InMemoryByteConfigurationStoreFactory} to verify JaxB serialization, too.
*/
@Deprecated(since = "2.44.0")
public class InMemoryConfigurationStoreFactory implements ConfigurationStoreFactory {
private final Map<String, InMemoryConfigurationStore> stores = new HashMap<>();

View File

@@ -0,0 +1,38 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.store;
interface InMemoryStoreParameterNameComputer {
default String computeKey(StoreParameters storeParameters) {
if (storeParameters.getNamespace() != null) {
return storeParameters.getName() + "/" + storeParameters.getNamespace();
} else if (storeParameters.getRepositoryId() != null) {
return storeParameters.getName() + "/" + storeParameters.getRepositoryId();
} else {
return storeParameters.getName();
}
}
}

View File

@@ -34,7 +34,7 @@ import org.junit.rules.ExpectedException;
import sonia.scm.NotFoundException;
import sonia.scm.auditlog.Auditor;
import sonia.scm.plugin.PluginLoader;
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory;
import sonia.scm.util.ClassLoaders;
import java.util.Arrays;
@@ -70,7 +70,7 @@ public class PermissionAssignerTest {
PluginLoader pluginLoader = mock(PluginLoader.class);
when(pluginLoader.getUberClassLoader()).thenReturn(ClassLoaders.getContextClassLoader(DefaultSecuritySystem.class));
securitySystem = new DefaultSecuritySystem(new InMemoryConfigurationEntryStoreFactory(), pluginLoader, Set.of(auditor)) {
securitySystem = new DefaultSecuritySystem(new InMemoryByteConfigurationEntryStoreFactory(), pluginLoader, Set.of(auditor)) {
@Override
public Collection<PermissionDescriptor> getAvailablePermissions() {
return Arrays.stream(new String[]{"perm:read:1", "perm:read:2", "perm:read:3", "perm:read:4"})

View File

@@ -30,7 +30,7 @@ import sonia.scm.migration.RepositoryUpdateContext;
import sonia.scm.migration.RepositoryUpdateStep;
import sonia.scm.migration.UpdateStep;
import sonia.scm.store.ConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory;
import sonia.scm.version.Version;
import java.util.ArrayList;
@@ -50,7 +50,7 @@ import static sonia.scm.version.Version.parse;
class UpdateEngineTest {
ConfigurationEntryStoreFactory storeFactory = new InMemoryConfigurationEntryStoreFactory();
ConfigurationEntryStoreFactory storeFactory = new InMemoryByteConfigurationEntryStoreFactory();
RepositoryUpdateIterator repositoryUpdateIterator = mock(RepositoryUpdateIterator.class, CALLS_REAL_METHODS);
UpdateStepStore updateStepStore = new UpdateStepStore(storeFactory);

View File

@@ -36,7 +36,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.group.Group;
import sonia.scm.group.xml.XmlGroupDAO;
import sonia.scm.store.ConfigurationEntryStore;
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory;
import sonia.scm.update.UpdateStepTestUtil;
import sonia.scm.update.V1Properties;
@@ -51,7 +51,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
import static sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory.create;
@ExtendWith(MockitoExtension.class)
class XmlGroupV1UpdateStepTest {
@@ -62,7 +62,7 @@ class XmlGroupV1UpdateStepTest {
@Captor
ArgumentCaptor<Group> groupCaptor;
InMemoryConfigurationEntryStoreFactory storeFactory = create();
InMemoryByteConfigurationEntryStoreFactory storeFactory = create();
XmlGroupV1UpdateStep updateStep;
@@ -111,7 +111,7 @@ class XmlGroupV1UpdateStepTest {
@Test
void shouldExtractProperties() throws JAXBException {
updateStep.doUpdate();
ConfigurationEntryStore<V1Properties> propertiesStore = storeFactory.get("group-properties-v1");
ConfigurationEntryStore<V1Properties> propertiesStore = storeFactory.get(V1Properties.class, "group-properties-v1");
V1Properties properties = propertiesStore.get("normals");
assertThat(properties).isNotNull();
assertThat(properties.get("mostly")).isEqualTo("humans");

View File

@@ -40,8 +40,9 @@ import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryPermission;
import sonia.scm.repository.xml.XmlRepositoryDAO;
import sonia.scm.store.ConfigurationEntryStore;
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory;
import sonia.scm.update.UpdateStepTestUtil;
import sonia.scm.update.V1Properties;
import javax.xml.bind.JAXBException;
import java.io.IOException;
@@ -72,7 +73,7 @@ class XmlRepositoryV1UpdateStepTest {
@Mock
DefaultMigrationStrategyDAO migrationStrategyDao;
InMemoryConfigurationEntryStoreFactory configurationEntryStoreFactory = new InMemoryConfigurationEntryStoreFactory();
InMemoryByteConfigurationEntryStoreFactory configurationEntryStoreFactory = new InMemoryByteConfigurationEntryStoreFactory();
@Captor
ArgumentCaptor<Repository> storeCaptor;
@@ -172,7 +173,7 @@ class XmlRepositoryV1UpdateStepTest {
void shouldExtractPropertiesFromRepositories() throws JAXBException {
updateStep.doUpdate();
ConfigurationEntryStore store = configurationEntryStoreFactory.get("repository-properties-v1");
ConfigurationEntryStore store = configurationEntryStoreFactory.get(V1Properties.class,"repository-properties-v1");
assertThat(store.getAll())
.hasSize(3);
}

View File

@@ -35,7 +35,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.SCMContextProvider;
import sonia.scm.security.AssignedPermission;
import sonia.scm.store.ConfigurationEntryStore;
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory;
import javax.xml.bind.JAXBException;
import java.io.IOException;
@@ -43,12 +43,11 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
import static sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory.create;
@ExtendWith(MockitoExtension.class)
class XmlSecurityV1UpdateStepTest {
@@ -65,8 +64,8 @@ class XmlSecurityV1UpdateStepTest {
@BeforeEach
void mockScmHome() {
when(contextProvider.getBaseDirectory()).thenReturn(tempDir.toFile());
InMemoryConfigurationEntryStoreFactory inMemoryConfigurationEntryStoreFactory = create();
assignedPermissionStore = inMemoryConfigurationEntryStoreFactory.get("security");
InMemoryByteConfigurationEntryStoreFactory inMemoryConfigurationEntryStoreFactory = create();
assignedPermissionStore = inMemoryConfigurationEntryStoreFactory.get(AssignedPermission.class, "security");
updateStep = new XmlSecurityV1UpdateStep(contextProvider, inMemoryConfigurationEntryStoreFactory);
}
@@ -129,8 +128,9 @@ class XmlSecurityV1UpdateStepTest {
.filter(a -> a.getPermission().getValue().contains("repository:"))
.map(AssignedPermission::getName)
.collect(toList());
assertThat(assignedPermission).contains("scmadmin");
assertThat(assignedPermission).contains("test");
assertThat(assignedPermission)
.contains("scmadmin")
.contains("test");
}
@Test

View File

@@ -35,7 +35,7 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.security.AssignedPermission;
import sonia.scm.store.ConfigurationEntryStore;
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
import sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory;
import sonia.scm.update.UpdateStepTestUtil;
import sonia.scm.update.V1Properties;
import sonia.scm.user.User;
@@ -51,7 +51,7 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static sonia.scm.store.InMemoryConfigurationEntryStoreFactory.create;
import static sonia.scm.store.InMemoryByteConfigurationEntryStoreFactory.create;
@ExtendWith(MockitoExtension.class)
class XmlUserV1UpdateStepTest {
@@ -62,7 +62,7 @@ class XmlUserV1UpdateStepTest {
@Captor
ArgumentCaptor<User> userCaptor;
InMemoryConfigurationEntryStoreFactory storeFactory = create();
InMemoryByteConfigurationEntryStoreFactory storeFactory = create();
XmlUserV1UpdateStep updateStep;
@@ -91,7 +91,7 @@ class XmlUserV1UpdateStepTest {
void shouldCreateNewPermissionsForV1AdminUser() throws JAXBException {
updateStep.doUpdate();
Optional<AssignedPermission> assignedPermission =
storeFactory.<AssignedPermission>get("security")
storeFactory.<AssignedPermission>get(AssignedPermission.class, "security")
.getAll()
.values()
.stream()
@@ -126,7 +126,7 @@ class XmlUserV1UpdateStepTest {
@Test
void shouldExtractProperties() throws JAXBException {
updateStep.doUpdate();
ConfigurationEntryStore<V1Properties> propertiesStore = storeFactory.<V1Properties>get("user-properties-v1");
ConfigurationEntryStore<V1Properties> propertiesStore = storeFactory.<V1Properties>get(V1Properties.class, "user-properties-v1");
V1Properties properties = propertiesStore.get("dent");
assertThat(properties).isNotNull();
assertThat(properties.get("born.on")).isEqualTo("earth");