Add methods to mock stores with raw xml data

This commit is contained in:
René Pfeuffer
2023-06-29 09:13:00 +02:00
parent 0e7a3ec53b
commit e2c823e2c4
3 changed files with 27 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ import sonia.scm.security.UUIDKeyGenerator;
import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -68,6 +69,14 @@ public class InMemoryByteConfigurationEntryStore<V> implements ConfigurationEntr
store.put(id, baos.toByteArray());
}
/**
* This method can be used to mock stores with raw xml data to test update steps or otherwise the compatability of
* objects with old versions.
*/
public void putRawXml(String id, String xml) {
store.put(id, xml.getBytes(StandardCharsets.UTF_8));
}
@Override
public Map<String, V> getAll() {
Map<String, V> all = new HashMap<>();

View File

@@ -27,6 +27,7 @@ package sonia.scm.store;
import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
/**
* In memory store implementation of {@link ConfigurationStore} using a byte array to store the serialized object.
@@ -64,4 +65,12 @@ public class InMemoryByteConfigurationStore<T> implements ConfigurationStore<T>
JAXB.marshal(object, baos);
store = baos.toByteArray();
}
/**
* This method can be used to mock stores with raw xml data to test update steps or otherwise the compatability of
* objects with old versions.
*/
public void setRawXml(String xml) {
store = xml.getBytes(StandardCharsets.UTF_8);
}
}

View File

@@ -30,6 +30,7 @@ import sonia.scm.security.UUIDKeyGenerator;
import javax.xml.bind.JAXB;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -68,6 +69,14 @@ public class InMemoryByteDataStore<T> implements DataStore<T> {
store.put(id, baos.toByteArray());
}
/**
* This method can be used to mock stores with raw xml data to test update steps or otherwise the compatability of
* objects with old versions.
*/
public void putRawXml(String id, String xml) {
store.put(id, xml.getBytes(StandardCharsets.UTF_8));
}
@Override
public Map<String, T> getAll() {
Map<String, T> all = new HashMap<>();