|
| 1 | +package org.csstudio.display.builder.runtime.test; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertTrue; |
| 4 | +import static org.junit.jupiter.api.Assertions.fail; |
| 5 | + |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.List; |
| 8 | + |
| 9 | +import org.csstudio.display.actions.WritePVAction; |
| 10 | +import org.csstudio.display.builder.model.properties.ActionInfos; |
| 11 | +import org.csstudio.display.builder.model.properties.CommonWidgetProperties; |
| 12 | +import org.csstudio.display.builder.model.spi.ActionInfo; |
| 13 | +import org.csstudio.display.builder.model.widgets.ActionButtonWidget; |
| 14 | +import org.csstudio.display.builder.runtime.WidgetRuntime; |
| 15 | +import org.csstudio.display.builder.runtime.pv.RuntimePV; |
| 16 | +import org.csstudio.display.builder.runtime.script.PVUtil; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | +import org.phoebus.pv.PVPool; |
| 19 | +import org.phoebus.pv.loc.LocalPVFactory; |
| 20 | + |
| 21 | +public class WidgetRuntimeTest { |
| 22 | + |
| 23 | + @Test |
| 24 | + public void testWriteAction() |
| 25 | + { |
| 26 | + //Test for Write action on default pv different from ca see PR |
| 27 | + //https://github.com/ControlSystemStudio/phoebus/pull/3412 |
| 28 | + //Force default data source to loc:// |
| 29 | + PVPool.default_type = LocalPVFactory.TYPE; |
| 30 | + String pv_name = "my_pv"; |
| 31 | + try { |
| 32 | + RuntimePV pv = PVUtil.createPV(pv_name, 0); |
| 33 | + //First init value |
| 34 | + double initValue = 10; |
| 35 | + //VDouble val = VDouble.of(initValue, Alarm.none(), org.epics.vtype.Time.now(), org.epics.vtype.Display.none()); |
| 36 | + pv.write(initValue); |
| 37 | + //PVUtil.writePV(pv_name, initValue, 0); |
| 38 | + double readValue = PVUtil.getDouble(pv); |
| 39 | + //Test in standard way |
| 40 | + assertTrue("Write succeed", readValue == initValue); |
| 41 | + |
| 42 | + //Test with WidgetRuntime (write Action) |
| 43 | + ActionButtonWidget widget = new ActionButtonWidget(); |
| 44 | + widget.setPropertyValue(CommonWidgetProperties.propPVName.getName(), pv_name); |
| 45 | + //Add write action |
| 46 | + //Write new value |
| 47 | + double newValue = 20; |
| 48 | + |
| 49 | + List<ActionInfo> actionList = new ArrayList<ActionInfo>(); |
| 50 | + ActionInfo writeAction = new WritePVAction("Write value", pv_name, String.valueOf(newValue)); |
| 51 | + actionList.add(writeAction); |
| 52 | + ActionInfos actInfos = new ActionInfos(actionList, true); |
| 53 | + widget.setPropertyValue(CommonWidgetProperties.propActions.getName(), actInfos); |
| 54 | + |
| 55 | + //Create Widget Runtime |
| 56 | + WidgetRuntime<ActionButtonWidget> ofWidget = new WidgetRuntime<ActionButtonWidget>(); |
| 57 | + ofWidget.initialize(widget); |
| 58 | + ofWidget.addPV(pv, true); |
| 59 | + ofWidget.start(); |
| 60 | + |
| 61 | + ofWidget.writePV(pv_name, newValue); |
| 62 | + |
| 63 | + //Test the new value |
| 64 | + readValue = PVUtil.getDouble(pv); |
| 65 | + //Test if the new value is ok |
| 66 | + assertTrue("Write succeed", readValue == newValue); |
| 67 | + } catch (Exception e) { |
| 68 | + e.printStackTrace(); |
| 69 | + fail(e); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + } |
| 76 | + |
| 77 | +} |
0 commit comments