diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescription.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescription.java index 3d42d5101cdca453ffd40f9b0ba3ba989dc8ef9c..c9887376a706e73a6aacb581f88364aac82e5d25 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescription.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescription.java @@ -17,7 +17,6 @@ package ch.systemsx.cisd.openbis.generic.shared.basic.dto; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; @@ -77,36 +76,12 @@ public class ManagedUiActionDescription implements IManagedUiAction, ISerializab this.inputWidgets = widgetDescriptions; } - public void addInputWidgetDescription(IManagedInputWidgetDescription widgetDescription) + public void addInputWidgets(IManagedInputWidgetDescription... widgetDescriptions) { - inputWidgets.add(widgetDescription); - } - - public IManagedInputWidgetDescription addTextInputField(String label) - { - ManagedTextInputWidgetDescription inputField = new ManagedTextInputWidgetDescription(); - inputField.setLabel(label); - addInputWidgetDescription(inputField); - return inputField; - } - - public IManagedInputWidgetDescription addMultilineTextInputField(String label) - { - ManagedMultilineTextInputWidgetDescription inputField = - new ManagedMultilineTextInputWidgetDescription(); - inputField.setLabel(label); - addInputWidgetDescription(inputField); - return inputField; - } - - public IManagedInputWidgetDescription addComboBoxInputField(String label, String[] values) - { - ManagedComboBoxInputWidgetDescription inputField = - new ManagedComboBoxInputWidgetDescription(); - inputField.setLabel(label); - inputField.setOptions(Arrays.asList(values)); - addInputWidgetDescription(inputField); - return inputField; + for (IManagedInputWidgetDescription widget : widgetDescriptions) + { + inputWidgets.add(widget); + } } public String getInputValue(String inputLabel) diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescriptionFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescriptionFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..183868c00adad202ad79d7c44edabc92adda3247 --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/ManagedUiActionDescriptionFactory.java @@ -0,0 +1,62 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.shared.basic.dto; + +import java.util.Arrays; + +import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory; + +/** + * @author Piotr Buczek + */ +public class ManagedUiActionDescriptionFactory implements IManagedInputWidgetDescriptionFactory, + ISerializable +{ + private static final long serialVersionUID = ServiceVersionHolder.VERSION; + + // for serialization + public ManagedUiActionDescriptionFactory() + { + } + + public IManagedInputWidgetDescription createTextInputField(String label) + { + ManagedTextInputWidgetDescription inputField = new ManagedTextInputWidgetDescription(); + inputField.setLabel(label); + return inputField; + } + + public IManagedInputWidgetDescription createMultilineTextInputField(String label) + { + ManagedMultilineTextInputWidgetDescription inputField = + new ManagedMultilineTextInputWidgetDescription(); + inputField.setLabel(label); + return inputField; + } + + public IManagedInputWidgetDescription createComboBoxInputField(String label, String[] values) + { + ManagedComboBoxInputWidgetDescription inputField = + new ManagedComboBoxInputWidgetDescription(); + inputField.setLabel(label); + inputField.setOptions(Arrays.asList(values)); + return inputField; + } + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedInputWidgetDescriptionFactory.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedInputWidgetDescriptionFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..e08874838eddc0eb9b0572a2a7b4b36b711b401d --- /dev/null +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedInputWidgetDescriptionFactory.java @@ -0,0 +1,47 @@ +/* + * Copyright 2011 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.generic.shared.basic.dto.api; + +import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; + +/** + * Factory for creation of instances of {@link IManagedInputWidgetDescription}. + * <p> + * All methods of this interface are part of the Managed Properties API. + * + * @author Piotr Buczek + */ +public interface IManagedInputWidgetDescriptionFactory extends ISerializable +{ + + /** + * @return a text input field with given <var>label</var> + */ + IManagedInputWidgetDescription createTextInputField(String label); + + /** + * @return a multiline input field with given <var>label</var> + */ + IManagedInputWidgetDescription createMultilineTextInputField(String label); + + /** + * @return a combo box input field with given <var>label</var> and specified list of selectable + * <var>values</var>. + */ + IManagedInputWidgetDescription createComboBoxInputField(String labels, String[] values); + +} diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedUiAction.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedUiAction.java index 80534180ed219b49a347594edcb29e8581a6233b..cfa845f8cc5c126761813c45ab8cd2a1e9490f67 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedUiAction.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/basic/dto/api/IManagedUiAction.java @@ -21,11 +21,7 @@ import java.util.List; import ch.systemsx.cisd.openbis.generic.shared.basic.ISerializable; /** - * <pre> - * action has - * - name (both for display and usage) - * - description (for tooltip/message shown in dialog) - * </pre> + * Description of action that a user can perform on the client side. * <p> * All methods of this interface are part of the Managed Properties API. * @@ -47,23 +43,10 @@ public interface IManagedUiAction extends ISerializable public IManagedUiAction setDescription(String description); /** - * Adds a text input field with given <var>label</var> to input widgets that will be used in - * user interface for modifcation of a managed property. + * Adds specified input widget descriptions that will be used in user interface for modifcation + * of a managed property. */ - public IManagedInputWidgetDescription addTextInputField(String label); - - /** - * Adds a multiline text with given <var>label</var> input field to input widgets that will be - * used in user interface for modification of the managed property. - */ - public IManagedInputWidgetDescription addMultilineTextInputField(String label); - - /** - * Adds a combo box input field with given <var>label</var> to input widgets that will be used - * in user interface for modification of the managed property. The combo box will contain list - * of provided <var>values</var>. - */ - public IManagedInputWidgetDescription addComboBoxInputField(String labels, String[] values); + public void addInputWidgets(IManagedInputWidgetDescription... widgets); /** * Returns list of objects describing input widgets that will be used in user interface user diff --git a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyFunctions.java b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyFunctions.java index 7db779092143f447e91fff39288b2898bc8c4e76..7669ee6e8d7681f7f6284bc1dac7adf764f37ca5 100644 --- a/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyFunctions.java +++ b/openbis/source/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyFunctions.java @@ -5,6 +5,9 @@ import javax.annotation.Resource; import org.springframework.stereotype.Component; import ch.systemsx.cisd.openbis.generic.shared.ResourceNames; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedUiActionDescriptionFactory; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.ValidationException; import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IElement; import ch.systemsx.cisd.openbis.generic.shared.managed_property.api.IElementFactory; @@ -22,6 +25,9 @@ import ch.systemsx.cisd.openbis.generic.shared.managed_property.structured.XmlSt @Component(value = ResourceNames.MANAGED_PROPERTY_SCRIPT_UTILITY_FACTORY) public class ManagedPropertyFunctions { + private static final IManagedInputWidgetDescriptionFactory INPUT_WIDGET_FACTORY_INSTANCE = + new ManagedUiActionDescriptionFactory(); + private static final IElementFactory ELEMENT_FACTORY_INSTANCE = new ElementFactory(); private static final IStructuredPropertyConverter STRUCTURED_PROPERTY_CONVERTER_INSTANCE = @@ -65,6 +71,14 @@ public class ManagedPropertyFunctions return new ValidationException(message); } + /** + * @return a factory object that can be used to create {@link IManagedInputWidgetDescription}-s. + */ + public static IManagedInputWidgetDescriptionFactory inputWidgetFactory() + { + return INPUT_WIDGET_FACTORY_INSTANCE; + } + /** * @return a factory object that can be used to create {@link IElement}-s. */ diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java index 65eff158fbe549a413e3ddf062c7f5c8748d9c41..e3fc5a8e586ed3a317fa8b3dbfcc9f9188c9cf33 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/CommonTestUtils.java @@ -16,10 +16,15 @@ package ch.systemsx.cisd.openbis.generic.shared; +import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.List; +import org.apache.commons.io.FileUtils; + import ch.systemsx.cisd.authentication.Principal; +import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.openbis.generic.shared.basic.TechId; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataTypeCode; import ch.systemsx.cisd.openbis.generic.shared.dto.AttachmentContentPE; @@ -411,4 +416,16 @@ public class CommonTestUtils propertyPE.setEntityTypePropertyType(entityTypePropertyTypePE); propertyPE.setValue(value); } + + public static String getResourceAsString(String path, String resource) + { + File file = new File(path, resource); + try + { + return FileUtils.readFileToString(file); + } catch (IOException ioex) + { + throw CheckedExceptionTunnel.wrapIfNecessary(ioex); + } + } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java index 8cdd02949274304c08b8f3cf98a6a5dd8a8ed119..18626b9d70572d3c162efe177992fb8b103847d5 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/ManagedPropertyEvaluatorTest.java @@ -26,11 +26,13 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.common.evaluator.EvaluatorException; import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedComboBoxInputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedTableWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.TableModel; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescription; +import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedInputWidgetDescriptionFactory; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedOutputWidgetDescription; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedUiAction; @@ -45,6 +47,15 @@ import ch.systemsx.cisd.openbis.generic.shared.util.SimpleTableModelBuilder; */ public class ManagedPropertyEvaluatorTest extends AssertJUnit { + private static final String UPDATE_FROM_UI_TEST_PY = "updateFromUI-test.py"; + + private static final String CONFIGURE_UI_OUTPUT_TEST_PY = "configureUIOutput-test.py"; + + private static final String CONFIGURE_UI_INPUT_TEST_PY = "configureUIInput-test.py"; + + private static final String SCRIPT_FOLDER = + "sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/"; + @Test public void testEmptyScript() { @@ -70,23 +81,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit { IManagedProperty managedProperty = new ManagedProperty(); managedProperty.setOwnTab(false); - ManagedPropertyEvaluator evaluator = - new ManagedPropertyEvaluator("def configureUI():\n" - + " tableBuilder = createTableBuilder()\n" + "\n" - + " tableBuilder.addHeader('column1')\n" - + " tableBuilder.addHeader('column2')\n" - + " tableBuilder.addHeader('column3')\n" + "\n" - + " row1 = tableBuilder.addRow()\n" - + " row1.setCell('column1','v1')\n" + " row1.setCell('column2', 1)\n" - + " row1.setCell('column3', 1.5)\n" + "\n" - + " row2 = tableBuilder.addRow()\n" - + " row2.setCell('column1','v2')\n" + " row2.setCell('column2', 2)\n" - + " row2.setCell('column3', 2.5)\n" - + " row3 = tableBuilder.addRow()\n" - + " row3.setCell('column1','v3')\n" + "\n" - + " property.setOwnTab(True)\n" - + " uiDesc = property.getUiDescription()\n" - + " uiDesc.useTableOutput(tableBuilder.getTableModel())"); + + String script = + CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, CONFIGURE_UI_OUTPUT_TEST_PY); + ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script); + evaluator.configureUI(managedProperty); assertEquals(true, managedProperty.isOwnTab()); IManagedOutputWidgetDescription outputWidgetDescripion = @@ -139,15 +138,11 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit { IManagedProperty managedProperty = new ManagedProperty(); managedProperty.setOwnTab(false); - ManagedPropertyEvaluator evaluator = - new ManagedPropertyEvaluator( - "def configureUI():\n" - + " uiAction = property.getUiDescription().addAction('Create')\n" - + " uiAction.addTextInputField('t1')\n" - + " uiAction.addTextInputField('t2').setValue('default 2')\n" - + " uiAction.addTextInputField('t3').setDescription('description 3')\n" - + " uiAction.addMultilineTextInputField('multi').setValue('default m').setDescription('multiline')\n" - + " uiAction.addComboBoxInputField('combo', ['v1', 'v2', 'v3']).setMandatory(True).setDescription('select from list')\n"); + + String script = + CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, CONFIGURE_UI_INPUT_TEST_PY); + ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script); + evaluator.configureUI(managedProperty); assertEquals(false, managedProperty.isOwnTab()); @@ -186,47 +181,37 @@ public class ManagedPropertyEvaluatorTest extends AssertJUnit { IManagedProperty managedProperty = new ManagedProperty(); IManagedUiDescription uiDescription = managedProperty.getUiDescription(); + IManagedInputWidgetDescriptionFactory widgetFactory = + ManagedPropertyFunctions.inputWidgetFactory(); IManagedUiAction action1 = uiDescription.addAction("a1"); - action1.addTextInputField("t1"); - action1.addTextInputField("t2").setValue("v2"); - action1.addMultilineTextInputField("multi").setValue("multi\nline\ninput"); - action1.addComboBoxInputField("combo", new String[] - { "cv1", "cv2", "cv3" }).setValue("cv1"); + IManagedInputWidgetDescription action1w1 = widgetFactory.createTextInputField("t1"); + IManagedInputWidgetDescription action1w2 = + widgetFactory.createTextInputField("t2").setValue("v2"); + IManagedInputWidgetDescription action1w3 = + widgetFactory.createMultilineTextInputField("multi").setValue("multi\nline\ninput"); + IManagedInputWidgetDescription action1w4 = + widgetFactory.createComboBoxInputField("combo", new String[] + { "cv1", "cv2", "cv3" }).setValue("cv1"); + action1.addInputWidgets(action1w1, action1w2, action1w3, action1w4); assertEquals(null, action1.getInputValue("t1")); assertEquals("v2", action1.getInputValue("t2")); assertEquals(null, action1.getInputValue("t3")); IManagedUiAction action2 = uiDescription.addAction("a2"); - action2.addTextInputField("t1").setValue("v11"); - action2.addTextInputField("t2").setValue("v22"); + IManagedInputWidgetDescription action2w1 = + widgetFactory.createTextInputField("t1").setValue("v11"); + IManagedInputWidgetDescription action2w2 = + widgetFactory.createTextInputField("t2").setValue("v22"); + action2.addInputWidgets(action2w1, action2w2); assertEquals("v11", action2.getInputValue("t1")); assertEquals("v22", action2.getInputValue("t2")); assertEquals(null, action2.getInputValue("t3")); IManagedUiAction action3 = uiDescription.addAction("a3"); - ManagedPropertyEvaluator evaluator = - new ManagedPropertyEvaluator( - "def updateFromUI(action):\n" - + " if action.getName() == 'a1':\n" - + " value = 'a1|'\n" - + " for input in action.getInputWidgetDescriptions():\n" - + " inputValue = input.getValue();\n" - + " if inputValue is None:\n " - + " inputValue = 'null'\n" - + " value = value + input.getLabel() + '=' + inputValue + '|'\n" - + " property.setValue(value)\n" - + " elif action.getName() == 'a2':\n" - + " value = 'a2!'\n" - + " for input in action.getInputWidgetDescriptions():\n" - + " inputValue = input.getValue();\n" - + " if inputValue is None:\n " - + " inputValue = 'null'\n" - + " value = value + input.getLabel() + '=' + inputValue + '!'\n" - + " property.setValue(value)\n" - + " else:\n" - + " raise ValidationException('action ' + action.getName() + ' is not supported')\n"); + String script = CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, UPDATE_FROM_UI_TEST_PY); + ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script); evaluator.updateFromUI(managedProperty, action1); assertNotNull(managedProperty.getValue()); diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/configureUIInput-test.py b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/configureUIInput-test.py new file mode 100644 index 0000000000000000000000000000000000000000..642b1bc897e3c25356c5d6bf45b00dc1dd3c57f7 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/configureUIInput-test.py @@ -0,0 +1,19 @@ +def configureUI(): + factory = inputWidgetFactory() + + widgets = [ + factory.createTextInputField('t1'), + factory.createTextInputField('t2')\ + .setValue('default 2'), + factory.createTextInputField('t3')\ + .setDescription('description 3'), + factory.createMultilineTextInputField('multi')\ + .setValue('default m')\ + .setDescription('multiline'), + factory.createComboBoxInputField('combo', ['v1', 'v2', 'v3'])\ + .setMandatory(True)\ + .setDescription('select from list') + ] + + uiAction = property.getUiDescription().addAction('Create') + uiAction.addInputWidgets(widgets) \ No newline at end of file diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/configureUIOutput-test.py b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/configureUIOutput-test.py new file mode 100644 index 0000000000000000000000000000000000000000..4088c7dca2b42bbb1d1df7353ee6f1b760160c73 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/configureUIOutput-test.py @@ -0,0 +1,22 @@ +def configureUI(): + tableBuilder = createTableBuilder() + tableBuilder.addHeader('column1') + tableBuilder.addHeader('column2') + tableBuilder.addHeader('column3') + + row1 = tableBuilder.addRow() + row1.setCell('column1','v1') + row1.setCell('column2', 1) + row1.setCell('column3', 1.5) + + row2 = tableBuilder.addRow() + row2.setCell('column1','v2') + row2.setCell('column2', 2) + row2.setCell('column3', 2.5) + + row3 = tableBuilder.addRow() + row3.setCell('column1','v3') + + property.setOwnTab(True) + uiDesc = property.getUiDescription() + uiDesc.useTableOutput(tableBuilder.getTableModel()) \ No newline at end of file diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/StructuredPropertyConverterPythonTest.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/StructuredPropertyConverterPythonTest.java index 33806bf1476c78a1b4e56bd2de2e83ed4ee2a3f3..c44864b8c53fadfa915ca2055619f4f73ab129d8 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/StructuredPropertyConverterPythonTest.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/structured/StructuredPropertyConverterPythonTest.java @@ -16,15 +16,12 @@ package ch.systemsx.cisd.openbis.generic.shared.managed_property.structured; -import java.io.File; -import java.io.IOException; import java.util.List; -import org.apache.commons.io.FileUtils; import org.testng.AssertJUnit; import org.testng.annotations.Test; -import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; +import ch.systemsx.cisd.openbis.generic.shared.CommonTestUtils; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.ManagedEntityProperty; import ch.systemsx.cisd.openbis.generic.shared.basic.dto.api.IManagedProperty; @@ -48,7 +45,8 @@ public class StructuredPropertyConverterPythonTest extends AssertJUnit public void testAPIUsageFromJython() { IManagedProperty managedProperty = new ManagedEntityProperty(new EntityProperty()); - String script = getResourceAsString("structured-property-test.py"); + String script = + CommonTestUtils.getResourceAsString(SCRIPT_FOLDER, "structured-property-test.py"); ManagedPropertyEvaluator evaluator = new ManagedPropertyEvaluator(script); evaluator.configureUI(managedProperty); @@ -60,19 +58,4 @@ public class StructuredPropertyConverterPythonTest extends AssertJUnit assertEquals(3, elements.size()); } - /** - * if this becomes a common pattern, we might factor it out. - */ - private String getResourceAsString(String resource) - { - File file = new File(SCRIPT_FOLDER, resource); - try - { - return FileUtils.readFileToString(file); - } catch (IOException ioex) - { - throw CheckedExceptionTunnel.wrapIfNecessary(ioex); - } - - } } diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/updateFromUI-test.py b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/updateFromUI-test.py new file mode 100644 index 0000000000000000000000000000000000000000..0413e96856e601d9ddb8927ad0a93f7e97382810 --- /dev/null +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/shared/managed_property/updateFromUI-test.py @@ -0,0 +1,19 @@ +def updateFromUI(action): + if action.getName() == 'a1': + value = 'a1|' + for input in action.getInputWidgetDescriptions(): + inputValue = input.getValue() + if inputValue is None: + inputValue = 'null' + value = value + input.getLabel() + '=' + inputValue + '|' + property.setValue(value) + elif action.getName() == 'a2': + value = 'a2!' + for input in action.getInputWidgetDescriptions(): + inputValue = input.getValue() + if inputValue is None: + inputValue = 'null' + value = value + input.getLabel() + '=' + inputValue + '!' + property.setValue(value) + else: + raise ValidationException('action ' + action.getName() + ' is not supported') \ No newline at end of file