diff --git a/src/main/java/de/ozgcloud/formcycle/PluginPropertiesMapper.java b/src/main/java/de/ozgcloud/formcycle/PluginPropertiesMapper.java index fa8a25c8a7e444562ffe5afad4ed84f4b159bd93..a721b9770ec8b35e522888bfe83807c9d86c3147 100644 --- a/src/main/java/de/ozgcloud/formcycle/PluginPropertiesMapper.java +++ b/src/main/java/de/ozgcloud/formcycle/PluginPropertiesMapper.java @@ -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) { diff --git a/src/main/java/de/ozgcloud/formcycle/WorkflowElementNodePlugin.java b/src/main/java/de/ozgcloud/formcycle/WorkflowElementNodePlugin.java index e2191a68e3ee00676f23537168052231061793d6..1592189f5b67ac2dd4897d1bc86faffcff5bc2bc 100644 --- a/src/main/java/de/ozgcloud/formcycle/WorkflowElementNodePlugin.java +++ b/src/main/java/de/ozgcloud/formcycle/WorkflowElementNodePlugin.java @@ -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) { + return new OzgCloudFormDataHttpClient(buildOzgCloudConfig(formProperties), 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()) { - ozgCloudConfig = ozgCloudConfig.toBuilder().eingangsAdapterUrl(formProperties.getEingangsAdapterUrl()).build(); + return formProperties.getEingangsAdapterUrl(); } - return new OzgCloudFormDataHttpClient(ozgCloudConfig, new SystemPropertiesProvider()); + return pluginPropertiesMapper.getEingangsAdapterUrl(initializeData.getProperties()); } - private Supplier<List<Attachment>> createAttachmentSupplier(IWorkflowExecutionEnvironmentData environmentData) { return () -> Optional.ofNullable(environmentData.getFormRecord().getAttachments()).orElse(List.of()); } diff --git a/src/main/resources/WEB-INF/ui/WorkflowElementNode.xhtml b/src/main/resources/WEB-INF/ui/WorkflowElementNode.xhtml index b71d69910e0d71f154769f4ff478b36294793a4b..99fa3fa6574bf751f528e90ebf2896c76db72033 100644 --- a/src/main/resources/WEB-INF/ui/WorkflowElementNode.xhtml +++ b/src/main/resources/WEB-INF/ui/WorkflowElementNode.xhtml @@ -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}"> diff --git a/src/test/java/de/ozgcloud/formcycle/PluginPropertiesMapperTest.java b/src/test/java/de/ozgcloud/formcycle/PluginPropertiesMapperTest.java index 618cc58be145343b130034aad1af4ec456faa8dd..1955324effb56cfd9e987eb9eb8d90bceed0dd05 100644 --- a/src/test/java/de/ozgcloud/formcycle/PluginPropertiesMapperTest.java +++ b/src/test/java/de/ozgcloud/formcycle/PluginPropertiesMapperTest.java @@ -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 { diff --git a/src/test/java/de/ozgcloud/formcycle/WorkflowElementNodePluginTest.java b/src/test/java/de/ozgcloud/formcycle/WorkflowElementNodePluginTest.java index ef01d024423f3c8d2b554b1ae411c5edf8e95e7b..9acce43e3b9cebf26d11af7adf52756cec0db08e 100644 --- a/src/test/java/de/ozgcloud/formcycle/WorkflowElementNodePluginTest.java +++ b/src/test/java/de/ozgcloud/formcycle/WorkflowElementNodePluginTest.java @@ -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,21 +23,17 @@ import de.xima.fc.interfaces.workflow.value.IValueDescriptorFactory; class WorkflowElementNodePluginTest { @Spy - private WorkflowElementNodePlugin plugin = new WorkflowElementNodePlugin(); + @InjectMocks + private WorkflowElementNodePlugin plugin; + + @Mock + private IPluginInitializeData initializeData; + @Mock + private PluginPropertiesMapper propertiesMapper; @Nested class TestInitialization { - @Mock - private IPluginInitializeData initializeData; - @Mock - private PluginPropertiesMapper propertiesMapper; - - @BeforeEach - void setup() { - when(plugin.createPropertiesMapper()).thenReturn(propertiesMapper); - } - @Test void shouldCallCreatePropertiesMapper() { plugin.initialize(initializeData); @@ -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); + + var eingangsAdapterUrl = plugin.getEingangsAdapterUrl(formProperties); + + assertThat(eingangsAdapterUrl).isEqualTo(CUSTOM_URL); } @Test - void shouldSetCustomValue() { - 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)).extracting(OzgCloudConfig::getEingangsAdapterUrl).isEqualTo(CUSTOM_URL); + assertThat(eingangsAdapterUrl).isEqualTo(PropertiesTestFactory.EINGANGSADAPTER_URL); } + } + + @Nested + class TestBuildOzgClientConfig{ + + @Mock + private Properties properties; + @Test - void shouldNotOverrideOtherValues() { - var ozgClient = plugin.createOzgClient(formProperties); + void shouldSetEingangsAdapterUrl() { + doReturn(PropertiesTestFactory.EINGANGSADAPTER_URL).when(plugin).getEingangsAdapterUrl(any()); + + var ozgClientConfig = plugin.buildOzgCloudConfig(formProperties); - assertThat(getOzgCloudConfig(ozgClient)).usingRecursiveComparison().ignoringFields("eingangsAdapterUrl").isEqualTo(ozgCloudConfig); + assertThat(ozgClientConfig.getEingangsAdapterUrl()).isEqualTo(PropertiesTestFactory.EINGANGSADAPTER_URL); } - } + @Test + void shouldSetProxyConfig() { + var expectedProxyConfig = ProxyConfigTestFactory.create(); + when(propertiesMapper.mapProxyProperties(any())).thenReturn(expectedProxyConfig); - @Test - void shouldSetOzgCloudConfig() { - var ozgClient = plugin.createOzgClient(formProperties); + var ozgClientConfig = plugin.buildOzgCloudConfig(formProperties); - assertThat(getOzgCloudConfig(ozgClient)).isEqualTo(ozgCloudConfig); - } + assertThat(ozgClientConfig.getProxyConfig()).isEqualTo(expectedProxyConfig); + } - private void setOzgCloudConfig(OzgCloudConfig ozgCloudConfig) { - var ozgCloudConfigField = ReflectionUtils.findField(WorkflowElementNodePlugin.class, "ozgCloudConfig"); - ozgCloudConfigField.setAccessible(true); - ReflectionUtils.setField(ozgCloudConfigField, plugin, ozgCloudConfig); - } + @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);