mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
Check stored values instead of resulting xml files
This commit is contained in:
@@ -17,7 +17,7 @@ public class InMemoryConfigurationEntryStoreFactory implements ConfigurationEntr
|
||||
return get(name);
|
||||
}
|
||||
|
||||
public InMemoryConfigurationEntryStore get(String name) {
|
||||
public <T> InMemoryConfigurationEntryStore<T> get(String name) {
|
||||
return stores.computeIfAbsent(name, x -> new InMemoryConfigurationEntryStore());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,6 @@ public class UpdateStepTestUtil {
|
||||
copyTestDatabaseFile(configDir, fileName, targetFileName);
|
||||
}
|
||||
|
||||
public Path getFile(String name) {
|
||||
return tempDir.resolve("config").resolve(name);
|
||||
}
|
||||
|
||||
private void copyTestDatabaseFile(Path configDir, String fileName) throws IOException {
|
||||
Path targetFileName = Paths.get(fileName).getFileName();
|
||||
copyTestDatabaseFile(configDir, fileName, targetFileName.toString());
|
||||
|
||||
@@ -6,9 +6,15 @@ import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.unmodifiableList;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlRootElement(name = "properties")
|
||||
public class V1Properties {
|
||||
@XmlElement(name = "item")
|
||||
private List<V1Property> properties;
|
||||
|
||||
public List<V1Property> getProperties() {
|
||||
return unmodifiableList(properties);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,48 @@ package sonia.scm.update.properties;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import java.util.Objects;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class V1Property {
|
||||
private String key;
|
||||
private String value;
|
||||
|
||||
public V1Property() {
|
||||
}
|
||||
|
||||
public V1Property(String key, String value) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
V1Property that = (V1Property) o;
|
||||
return Objects.equals(key, that.key) &&
|
||||
Objects.equals(value, that.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "V1Property{" +
|
||||
"key='" + key + '\'' +
|
||||
", value='" + value + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.group.Group;
|
||||
import sonia.scm.group.xml.XmlGroupDAO;
|
||||
import sonia.scm.security.DefaultKeyGenerator;
|
||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
|
||||
import sonia.scm.update.UpdateStepTestUtil;
|
||||
import sonia.scm.update.properties.V1Properties;
|
||||
import sonia.scm.update.properties.V1Property;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.IOException;
|
||||
@@ -22,11 +24,11 @@ import java.util.Optional;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.linesOf;
|
||||
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;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
@@ -38,6 +40,8 @@ class XmlGroupV1UpdateStepTest {
|
||||
@Captor
|
||||
ArgumentCaptor<Group> groupCaptor;
|
||||
|
||||
InMemoryConfigurationEntryStoreFactory storeFactory = create();
|
||||
|
||||
XmlGroupV1UpdateStep updateStep;
|
||||
|
||||
private UpdateStepTestUtil testUtil;
|
||||
@@ -46,7 +50,6 @@ class XmlGroupV1UpdateStepTest {
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
testUtil = new UpdateStepTestUtil(tempDir);
|
||||
JAXBConfigurationEntryStoreFactory storeFactory = new JAXBConfigurationEntryStoreFactory(testUtil.getContextProvider(), null, new DefaultKeyGenerator());
|
||||
updateStep = new XmlGroupV1UpdateStep(testUtil.getContextProvider(), groupDAO, storeFactory);
|
||||
}
|
||||
|
||||
@@ -86,19 +89,13 @@ class XmlGroupV1UpdateStepTest {
|
||||
@Test
|
||||
void shouldExtractProperties() throws JAXBException {
|
||||
updateStep.doUpdate();
|
||||
Path propertiesFile = testUtil.getFile("group-properties-v1.xml");
|
||||
assertThat(propertiesFile)
|
||||
.exists();
|
||||
assertThat(linesOf(propertiesFile.toFile()))
|
||||
.extracting(String::trim)
|
||||
.containsSequence(
|
||||
"<key>normals</key>",
|
||||
"<value>",
|
||||
"<item>",
|
||||
"<key>mostly</key>",
|
||||
"<value>humans</value>",
|
||||
"</item>",
|
||||
"</value>");
|
||||
ConfigurationEntryStore<V1Properties> propertiesStore = storeFactory.<V1Properties>get("group-properties-v1");
|
||||
assertThat(propertiesStore.get("normals"))
|
||||
.isNotNull()
|
||||
.extracting(V1Properties::getProperties)
|
||||
.first()
|
||||
.asList()
|
||||
.contains(new V1Property("mostly", "humans"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.security.AssignedPermission;
|
||||
import sonia.scm.security.DefaultKeyGenerator;
|
||||
import sonia.scm.store.ConfigurationEntryStore;
|
||||
import sonia.scm.store.ConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.JAXBConfigurationEntryStoreFactory;
|
||||
import sonia.scm.store.InMemoryConfigurationEntryStoreFactory;
|
||||
import sonia.scm.update.UpdateStepTestUtil;
|
||||
import sonia.scm.update.properties.V1Properties;
|
||||
import sonia.scm.update.properties.V1Property;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.xml.XmlUserDAO;
|
||||
|
||||
@@ -24,11 +24,11 @@ import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.linesOf;
|
||||
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;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ExtendWith(TempDirectory.class)
|
||||
@@ -40,6 +40,8 @@ class XmlUserV1UpdateStepTest {
|
||||
@Captor
|
||||
ArgumentCaptor<User> userCaptor;
|
||||
|
||||
InMemoryConfigurationEntryStoreFactory storeFactory = create();
|
||||
|
||||
XmlUserV1UpdateStep updateStep;
|
||||
|
||||
private UpdateStepTestUtil testUtil;
|
||||
@@ -47,7 +49,6 @@ class XmlUserV1UpdateStepTest {
|
||||
@BeforeEach
|
||||
void mockScmHome(@TempDirectory.TempDir Path tempDir) {
|
||||
testUtil = new UpdateStepTestUtil(tempDir);
|
||||
ConfigurationEntryStoreFactory storeFactory = new JAXBConfigurationEntryStoreFactory(testUtil.getContextProvider(), null, new DefaultKeyGenerator());
|
||||
updateStep = new XmlUserV1UpdateStep(testUtil.getContextProvider(), userDAO, storeFactory);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ class XmlUserV1UpdateStepTest {
|
||||
void shouldCreateNewPermissionsForV1AdminUser() throws JAXBException {
|
||||
updateStep.doUpdate();
|
||||
Optional<AssignedPermission> assignedPermission =
|
||||
getStoreForConfigFile("security")
|
||||
storeFactory.<AssignedPermission>get("security")
|
||||
.getAll()
|
||||
.values()
|
||||
.stream()
|
||||
@@ -103,30 +104,15 @@ class XmlUserV1UpdateStepTest {
|
||||
@Test
|
||||
void shouldExtractProperties() throws JAXBException {
|
||||
updateStep.doUpdate();
|
||||
Path propertiesFile = testUtil.getFile("user-properties-v1.xml");
|
||||
assertThat(propertiesFile)
|
||||
.exists();
|
||||
assertThat(linesOf(propertiesFile.toFile()))
|
||||
.extracting(String::trim)
|
||||
.containsSequence(
|
||||
"<key>dent</key>",
|
||||
"<value>",
|
||||
"<item>",
|
||||
"<key>born.on</key>",
|
||||
"<value>earth</value>",
|
||||
"</item>",
|
||||
"<item>",
|
||||
"<key>last.seen</key>",
|
||||
"<value>end of the universe</value>",
|
||||
"</item>",
|
||||
"</value>");
|
||||
}
|
||||
|
||||
private ConfigurationEntryStore<AssignedPermission> getStoreForConfigFile(String name) {
|
||||
return new JAXBConfigurationEntryStoreFactory(testUtil.getContextProvider(), null, new DefaultKeyGenerator())
|
||||
.withType(AssignedPermission.class)
|
||||
.withName(name)
|
||||
.build();
|
||||
ConfigurationEntryStore<V1Properties> propertiesStore = storeFactory.<V1Properties>get("user-properties-v1");
|
||||
assertThat(propertiesStore.get("dent"))
|
||||
.isNotNull()
|
||||
.extracting(V1Properties::getProperties)
|
||||
.first()
|
||||
.asList()
|
||||
.contains(
|
||||
new V1Property("born.on", "earth"),
|
||||
new V1Property("last.seen", "end of the universe"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user