diff --git a/src/main/java/org/robotframework/swing/keyword/dispatch/DispatchModelKeywords.java b/src/main/java/org/robotframework/swing/keyword/dispatch/DispatchModelKeywords.java new file mode 100644 index 00000000..5f80f51c --- /dev/null +++ b/src/main/java/org/robotframework/swing/keyword/dispatch/DispatchModelKeywords.java @@ -0,0 +1,58 @@ +package org.robotframework.swing.keyword.dispatch; + +import org.netbeans.jemmy.JemmyProperties; +import org.robotframework.javalib.annotation.ArgumentNames; +import org.robotframework.javalib.annotation.RobotKeyword; +import org.robotframework.javalib.annotation.RobotKeywords; + +import java.util.Arrays; + +@RobotKeywords +public class DispatchModelKeywords { + + public enum DispatchModel { + QUEUE(JemmyProperties.QUEUE_MODEL_MASK), + QUEUE_SHORTCUT(JemmyProperties.QUEUE_MODEL_MASK | JemmyProperties.SHORTCUT_MODEL_MASK), + ROBOT(JemmyProperties.ROBOT_MODEL_MASK), + ROBOT_SMOOTH(JemmyProperties.ROBOT_MODEL_MASK | JemmyProperties.SMOOTH_ROBOT_MODEL_MASK); + + public final int model; + + private DispatchModel(int model) { + this.model = model; + } + + public static DispatchModel fromInt(int model) { + for (DispatchModel value: DispatchModel.values()) { + if (value.model == model) + return value; + } + throw new RuntimeException("Unknown dispatch model "+model); + } + + public static DispatchModel fromString(String model) { + try { + return DispatchModel.valueOf(model); + } catch (IllegalArgumentException iae) { + throw new IllegalArgumentException("Unknown Jemmy dispatch model "+model+".\n" + +"Supported models are " + Arrays.toString(DispatchModel.values())); + } + } + } + + @RobotKeyword("Sets the jemmy dispatch model.\n" + + "Possible models are QUEUE, QUEUE_SHORTCUT, ROBOT, ROBOT_SMOOTH\n" + + "Returns the old dispatch model.\n\n" + + "Example:\n" + + "| Set Jemmy Dispatch Model | ROBOT |\n" + + "| ${old mode}= | Set Jemmy Dispatch Model | ROBOT_SMOOTH |\n") + @ArgumentNames({"dispatch model"}) + public String setJemmyDispatchModel(String model) { + DispatchModel oldModel = DispatchModel.fromInt(JemmyProperties.getCurrentDispatchingModel()); + DispatchModel newModel = DispatchModel.fromString(model); + JemmyProperties.setCurrentDispatchingModel(newModel.model); + return oldModel.name(); + } + + +} diff --git a/src/test/resources/robot-tests/dispatchmodel.txt b/src/test/resources/robot-tests/dispatchmodel.txt new file mode 100644 index 00000000..4fb966b5 --- /dev/null +++ b/src/test/resources/robot-tests/dispatchmodel.txt @@ -0,0 +1,23 @@ +*** Settings *** +Library TestSwingLibrary +Test teardown Set jemmy dispatch model QUEUE_SHORTCUT + + +*** Test Cases *** +Dispatch model is QUEUE_SHORTCUT by default + ${old dispatch model} = Set jemmy dispatch model ROBOT + Should be equal ${old dispatch model} QUEUE_SHORTCUT + +Dispatch model changes + Set jemmy dispatch model ROBOT + ${old dispatch model} = Set jemmy dispatch model ROBOT_SMOOTH + Should be equal ${old dispatch model} ROBOT + +Unknown dispatch model + Run keyword and expect error Unknown Jemmy dispatch model FOO.\nSupported models are * Set jemmy dispatch model FOO + +All dispatch models + Set jemmy dispatch model QUEUE + Set jemmy dispatch model QUEUE_SHORTCUT + Set jemmy dispatch model ROBOT + Set jemmy dispatch model ROBOT_SMOOTH