Skip to content

Commit

Permalink
Add support for Jemmy dispatch model. Updates issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
jussimalinen committed Jan 13, 2014
1 parent ca55cc8 commit be34826
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}


}
23 changes: 23 additions & 0 deletions src/test/resources/robot-tests/dispatchmodel.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit be34826

Please sign in to comment.