Skip to content
Snippets Groups Projects
Commit 1fee0d66 authored by OZGCloud's avatar OZGCloud
Browse files

Merge pull request 'OZG-4464: Formcycle Plugin Test Mode' (#16) from...

Merge pull request 'OZG-4464: Formcycle Plugin Test Mode' (#16) from OZG-4464-Formcycle-Plugin-Test-Mode into master

Reviewed-on: https://git.ozg-sh.de/mgm/ozgcloud-formcycle-plugin/pulls/16
parents 3322eef6 3688019a
Branches
Tags
No related merge requests found
......@@ -36,14 +36,8 @@ public class PluginPropertiesMapper {
private final UserErrorDispatcher userErrorDispatcher;
public OzgCloudConfig mapProperties(Properties pluginProperties) {
if (isNull(pluginProperties) || pluginProperties.isEmpty()) {
return OzgCloudConfig.builder().build();
}
return OzgCloudConfig.builder()
.eingangsAdapterUrl(pluginProperties.getProperty(OzgCloudConfig.KEY_EINGANGSADAPTER_URL))
.proxyConfig(mapProxyProperties(pluginProperties))
.build();
public String getEingangsAdapterUrl(Properties pluginProperties) {
return pluginProperties.getProperty(OzgCloudConfig.KEY_EINGANGSADAPTER_URL);
}
public ProxyConfig mapProxyProperties(Properties pluginProperties) {
......
......@@ -66,12 +66,12 @@ public final class WorkflowElementNodePlugin
implements IPluginActionNodeHandler<WorkflowElementNodeProps>, IKeyValueSummarizableNode<WorkflowElementNodeProps> {
private transient IPluginInitializeData initializeData;
private OzgCloudConfig ozgCloudConfig;
private transient PluginPropertiesMapper pluginPropertiesMapper;
@Override
public void initialize(IPluginInitializeData initializeData) {
this.initializeData = initializeData;
this.ozgCloudConfig = createPropertiesMapper().mapProperties(initializeData.getProperties());
this.pluginPropertiesMapper = createPropertiesMapper();
}
PluginPropertiesMapper createPropertiesMapper() {
......@@ -198,12 +198,22 @@ public final class WorkflowElementNodePlugin
}
OzgCloudFormDataHttpClient createOzgClient(WorkflowElementNodeProps formProperties) {
if (formProperties.isUseCustomEingangsAdapterUrl()) {
ozgCloudConfig = ozgCloudConfig.toBuilder().eingangsAdapterUrl(formProperties.getEingangsAdapterUrl()).build();
return new OzgCloudFormDataHttpClient(buildOzgCloudConfig(formProperties), new SystemPropertiesProvider());
}
return new OzgCloudFormDataHttpClient(ozgCloudConfig, new SystemPropertiesProvider());
OzgCloudConfig buildOzgCloudConfig(WorkflowElementNodeProps formProperties) {
return OzgCloudConfig.builder()
.eingangsAdapterUrl(getEingangsAdapterUrl(formProperties))
.proxyConfig(pluginPropertiesMapper.mapProxyProperties(initializeData.getProperties()))
.build();
}
String getEingangsAdapterUrl(WorkflowElementNodeProps formProperties) {
if (formProperties.isUseCustomEingangsAdapterUrl()) {
return formProperties.getEingangsAdapterUrl();
}
return pluginPropertiesMapper.getEingangsAdapterUrl(initializeData.getProperties());
}
private Supplier<List<Attachment>> createAttachmentSupplier(IWorkflowExecutionEnvironmentData environmentData) {
return () -> Optional.ofNullable(environmentData.getFormRecord().getAttachments()).orElse(List.of());
}
......
......@@ -32,6 +32,9 @@
value="#{model.useCustomEingangsAdapterUrl}"
label="#{msg['WorkflowElementNodeProps.useCustomEingangsAdapterUrl']}">
<p:ajax type="change" process="@this" update="wfPropertiesForm:WorkflowElementNode:panelId"/>
<p:ajax event="change" partialSubmit="true"
listener="#{elementPropertiesBean.storeCurrent}" process="@this"
update=":flowchartForm:flowchart" global="false"/>
</xi:selectBooleanCheckbox>
<h:panelGroup id="panelId">
<ui:fragment rendered="#{model.useCustomEingangsAdapterUrl}">
......
......@@ -53,40 +53,6 @@ class PluginPropertiesMapperTest {
mapper = spy(new PluginPropertiesMapper(userErrorDispatcher));
}
@Nested
class TestMapProperties {
@Test
void shouldAcceptNull() {
var result = mapper.mapProperties(null);
assertThat(result.getEingangsAdapterUrl()).isNull();
assertThat(result.getProxyConfig()).isNull();
}
@Test
void shouldAcceptEmptyProperties() {
var result = mapper.mapProperties(createEmpty());
assertThat(result.getEingangsAdapterUrl()).isNull();
assertThat(result.getProxyConfig()).isNull();
}
@Test
void shouldSetEingangsAdapterUrl() {
var result = mapper.mapProperties(properties);
assertThat(result.getEingangsAdapterUrl()).isEqualTo(EINGANGSADAPTER_URL);
}
@Test
void shouldCallMapProxyProperties() {
mapper.mapProxyProperties(properties);
verify(mapper).mapProxyProperties(properties);
}
}
@Nested
class TestMapProxyProperty {
......
......@@ -3,10 +3,13 @@ package de.ozgcloud.formcycle;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;
import java.util.Properties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.springframework.util.ReflectionUtils;
......@@ -20,20 +23,16 @@ import de.xima.fc.interfaces.workflow.value.IValueDescriptorFactory;
class WorkflowElementNodePluginTest {
@Spy
private WorkflowElementNodePlugin plugin = new WorkflowElementNodePlugin();
@Nested
class TestInitialization {
@InjectMocks
private WorkflowElementNodePlugin plugin;
@Mock
private IPluginInitializeData initializeData;
@Mock
private PluginPropertiesMapper propertiesMapper;
@BeforeEach
void setup() {
when(plugin.createPropertiesMapper()).thenReturn(propertiesMapper);
}
@Nested
class TestInitialization {
@Test
void shouldCallCreatePropertiesMapper() {
......@@ -43,14 +42,18 @@ class WorkflowElementNodePluginTest {
}
@Test
void shouldCallMapProperties() {
var properties = PropertiesTestFactory.create();
when(initializeData.getProperties()).thenReturn(properties);
void shouldSetInitializeData() {
plugin.initialize(initializeData);
verify(propertiesMapper).mapProperties(properties);
assertThat(getInitializedData()).isEqualTo(initializeData);
}
private IPluginInitializeData getInitializedData() {
var initializeDataField = ReflectionUtils.findField(WorkflowElementNodePlugin.class, "initializeData");
initializeDataField.setAccessible(true);
return (IPluginInitializeData) ReflectionUtils.getField(initializeDataField, plugin);
}
}
@Nested
......@@ -89,9 +92,13 @@ class WorkflowElementNodePluginTest {
private OzgCloudConfig ozgCloudConfig = OzgCloudConfigTestFactory.create();
@BeforeEach
void setup() {
setOzgCloudConfig(ozgCloudConfig);
@Test
void shouldSetOzgCloudConfig() {
doReturn(ozgCloudConfig).when(plugin).buildOzgCloudConfig(any());
var ozgClient = plugin.createOzgClient(formProperties);
assertThat(getOzgCloudConfig(ozgClient)).isEqualTo(ozgCloudConfig);
}
@Nested
......@@ -99,41 +106,62 @@ class WorkflowElementNodePluginTest {
private static final String CUSTOM_URL = "http://custom.url";
@BeforeEach
void setup() {
@Test
void shouldReturnCustomUrl() {
when(formProperties.getEingangsAdapterUrl()).thenReturn(CUSTOM_URL);
when(formProperties.isUseCustomEingangsAdapterUrl()).thenReturn(true);
}
@Test
void shouldSetCustomValue() {
var ozgClient = plugin.createOzgClient(formProperties);
var eingangsAdapterUrl = plugin.getEingangsAdapterUrl(formProperties);
assertThat(getOzgCloudConfig(ozgClient)).extracting(OzgCloudConfig::getEingangsAdapterUrl).isEqualTo(CUSTOM_URL);
assertThat(eingangsAdapterUrl).isEqualTo(CUSTOM_URL);
}
@Test
void shouldNotOverrideOtherValues() {
var ozgClient = plugin.createOzgClient(formProperties);
void shouldReturnDefaultUrl() {
when(formProperties.isUseCustomEingangsAdapterUrl()).thenReturn(false);
when(propertiesMapper.getEingangsAdapterUrl(any())).thenReturn(PropertiesTestFactory.EINGANGSADAPTER_URL);
var eingangsAdapterUrl = plugin.getEingangsAdapterUrl(formProperties);
assertThat(getOzgCloudConfig(ozgClient)).usingRecursiveComparison().ignoringFields("eingangsAdapterUrl").isEqualTo(ozgCloudConfig);
assertThat(eingangsAdapterUrl).isEqualTo(PropertiesTestFactory.EINGANGSADAPTER_URL);
}
}
@Nested
class TestBuildOzgClientConfig{
@Mock
private Properties properties;
@Test
void shouldSetOzgCloudConfig() {
var ozgClient = plugin.createOzgClient(formProperties);
void shouldSetEingangsAdapterUrl() {
doReturn(PropertiesTestFactory.EINGANGSADAPTER_URL).when(plugin).getEingangsAdapterUrl(any());
assertThat(getOzgCloudConfig(ozgClient)).isEqualTo(ozgCloudConfig);
var ozgClientConfig = plugin.buildOzgCloudConfig(formProperties);
assertThat(ozgClientConfig.getEingangsAdapterUrl()).isEqualTo(PropertiesTestFactory.EINGANGSADAPTER_URL);
}
private void setOzgCloudConfig(OzgCloudConfig ozgCloudConfig) {
var ozgCloudConfigField = ReflectionUtils.findField(WorkflowElementNodePlugin.class, "ozgCloudConfig");
ozgCloudConfigField.setAccessible(true);
ReflectionUtils.setField(ozgCloudConfigField, plugin, ozgCloudConfig);
@Test
void shouldSetProxyConfig() {
var expectedProxyConfig = ProxyConfigTestFactory.create();
when(propertiesMapper.mapProxyProperties(any())).thenReturn(expectedProxyConfig);
var ozgClientConfig = plugin.buildOzgCloudConfig(formProperties);
assertThat(ozgClientConfig.getProxyConfig()).isEqualTo(expectedProxyConfig);
}
@Test
void shouldCallMapProxyProperties() {
when(initializeData.getProperties()).thenReturn(properties);
plugin.buildOzgCloudConfig(formProperties);
verify(propertiesMapper).mapProxyProperties(properties);
}
}
private OzgCloudConfig getOzgCloudConfig(OzgCloudFormDataHttpClient ozgClient) {
var ozgCloudConfigField = ReflectionUtils.findField(OzgCloudFormDataHttpClient.class, "config");
ozgCloudConfigField.setAccessible(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment