-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Jemmy dispatch model. Updates issue #14
- Loading branch information
1 parent
ca55cc8
commit be34826
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/org/robotframework/swing/keyword/dispatch/DispatchModelKeywords.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |