mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-28 10:19:08 +01:00
Add test support for plugin migration
This commit is contained in:
@@ -5,6 +5,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Arrays.stream;
|
||||
@@ -27,7 +28,19 @@ public class V1Properties {
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
return properties.stream().filter(p -> key.equals(p.getKey())).map(V1Property::getValue).findFirst().orElse(null);
|
||||
return getOptional(key).orElse(null);
|
||||
}
|
||||
|
||||
public Optional<String> getOptional(String key) {
|
||||
return properties.stream().filter(p -> key.equals(p.getKey())).map(V1Property::getValue).findFirst();
|
||||
}
|
||||
|
||||
public Optional<Boolean> getBoolean(String key) {
|
||||
return getOptional(key).map(Boolean::valueOf);
|
||||
}
|
||||
|
||||
public <T extends Enum<T>> Optional<T> getEnum(String key, Class<T> enumType) {
|
||||
return getOptional(key).map(name -> Enum.valueOf(enumType, name));
|
||||
}
|
||||
|
||||
public boolean hasAny(String[] keys) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package sonia.scm.update;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static org.mockito.ArgumentMatchers.argThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class V1PropertyDaoTestUtil {
|
||||
|
||||
private final V1PropertyDAO propertyDAO = mock(V1PropertyDAO.class);
|
||||
|
||||
public V1PropertyDAO getPropertyDAO() {
|
||||
return propertyDAO;
|
||||
}
|
||||
|
||||
public void mockRepositoryProperties(PropertiesForRepository... mockedPropertiesForRepositories) {
|
||||
Map<String, V1Properties> map = new HashMap<>();
|
||||
stream(mockedPropertiesForRepositories).forEach(p -> map.put(p.repositoryId, p.asProperties()));
|
||||
V1PropertyReader.Instance v1PropertyReader = new MapBasedPropertyReaderInstance(map);
|
||||
when(propertyDAO.getProperties(argThat(argument -> argument instanceof RepositoryV1PropertyReader))).thenReturn(v1PropertyReader);
|
||||
}
|
||||
|
||||
public static class PropertiesForRepository {
|
||||
private final String repositoryId;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public PropertiesForRepository(String repositoryId, Map<String, String> properties) {
|
||||
this.repositoryId = repositoryId;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
V1Properties asProperties() {
|
||||
return new V1Properties(properties.entrySet().stream().map(e -> new V1Property(e.getKey(), e.getValue())).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user