Java源码示例:org.netbeans.jemmy.JemmyException
示例1
protected void openProject(String projectName) {
if (pto == null) {
pto = ProjectsTabOperator.invoke();
}
if (testProjectRootNode == null) {
try {
openDataProjects("projects/" + projectName);
testProjectRootNode = pto.getProjectRootNode(projectName);
testProjectRootNode.select();
} catch (IOException ex) {
throw new JemmyException("Open project [" + projectName + "] fails !!!", ex);
}
} else {
log("Project is opened!");
}
}
示例2
/** Mounts <userdir>/sampledir through API
* @return absolute path of mounted dir
*/
public static boolean mountSampledir() {
String userdir = System.getProperty("netbeans.user"); // NOI18N
String mountPoint = userdir+File.separator+"sampledir"; // NOI18N
mountPoint = mountPoint.replace('\\', '/');
FileSystem fs = Repository.getDefault().findFileSystem(mountPoint);
if (fs == null) {
try {
LocalFileSystem lfs= new LocalFileSystem();
lfs.setRootDirectory(new File(mountPoint));
Repository.getDefault().addFileSystem(lfs);
return true;
} catch (IOException ioe) {
throw new JemmyException("Mounting FS: "+mountPoint+" failed.", ioe);
} catch (PropertyVetoException pve) {
throw new JemmyException("Mounting FS: "+mountPoint+" failed.", pve);
}
}
return true;
}
示例3
/**
* Goes through the wizard and fill supplied parameter.
* @param cvsRoot CVS root.
* @param password password - can be null
* @param folderToImport local folder to import
* @param importMessage import message
* @param repositoryFolder repository folder
*/
public void doImport(String repositoryURL, String password, String importMessage, String repositoryFolder) {
if(repositoryURL == null) {
throw new JemmyException("CVS root must not be null."); // NOI18N
}
if(importMessage == null) {
throw new JemmyException("Import message must not be null."); // NOI18N
}
if(repositoryFolder == null) {
throw new JemmyException("Repository Folder must not be null."); // NOI18N
}
ImportWizardOperator.invoke();
RepositoryStepOperator rso = new RepositoryStepOperator();
if(password != null) {
rso.setPassword(password);
}
rso.setRepositoryURL(repositoryURL);
rso.next();
FolderToImportStepOperator folderToImportOper = new FolderToImportStepOperator();
folderToImportOper.setImportMessage(importMessage);
folderToImportOper.setRepositoryFolder(repositoryFolder);
folderToImportOper.finish();
}
示例4
/** Wait process with given name finished.
*/
public static void waitFinished(final String name, long timeout) {
try {
Waiter waiter = new Waiter(new Waitable() {
public Object actionProduced(Object anObject) {
return processInProgress(name) ? null : Boolean.TRUE;
}
public String getDescription() {
return("Wait process "+name+" is finished.");
}
});
waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout);
waiter.waitAction(null);
} catch (InterruptedException e) {
throw new JemmyException("Interrupted.", e);
}
}
示例5
/** Wait process started.
*/
public static void waitStarted(final String name, long timeout) {
try {
Waiter waiter = new Waiter(new Waitable() {
public Object actionProduced(Object anObject) {
return processInProgress(name) ? Boolean.TRUE : null;
}
public String getDescription() {
return("Wait process "+name+" is started.");
}
});
waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout);
waiter.waitAction(null);
} catch (InterruptedException e) {
throw new JemmyException("Interrupted.", e);
}
}
示例6
protected void waitForTextInEditor(final EditorOperator eo, final String text) {
try {
new Waiter(new Waitable() {
@Override
public Object actionProduced(Object obj) {
return eo.contains(text) ? Boolean.TRUE : null; //NOI18N
}
@Override
public String getDescription() {
return ("Editor contains " + text); //NOI18N
}
}).waitAction(null);
} catch (InterruptedException ie) {
throw new JemmyException("Interrupted.", ie); //NOI18N
}
}
示例7
/**
* Waits until profiler is not stopped.
*/
private void waitProfilerStopped() {
try {
new Waiter(new Waitable() {
@Override
public Object actionProduced(Object object) {
final int state = Profiler.getDefault().getProfilingState();
final int mode = Profiler.getDefault().getProfilingMode();
if ((state == Profiler.PROFILING_PAUSED) || (state == Profiler.PROFILING_RUNNING)) {
if (mode == Profiler.MODE_PROFILE) {
return null;
}
}
return Boolean.TRUE;
}
@Override
public String getDescription() {
return ("Wait profiler stopped."); // NOI18N
}
}).waitAction(null);
} catch (InterruptedException ex) {
throw new JemmyException("Waiting for profiler stopped failed.", ex);
}
}
示例8
/** Returns text from this output tab.
* @return text from this output tab.
*/
public String getText() {
final int length = getLength();
return (String) runMapping(new MapAction("getText") {
@Override
public Object map() {
Document document = documentForTab(getSource());
try {
if (getOutputDocumentClass().isInstance(document)) {
Method getTextMethod = getOutputDocumentClass().getDeclaredMethod("getText", new Class[]{int.class, int.class});
getTextMethod.setAccessible(true);
return getTextMethod.invoke(document, new Object[]{Integer.valueOf(0), Integer.valueOf(length)}).toString();
}
} catch (Exception e) {
throw new JemmyException("Getting text by reflection failed.", e);
}
return "";
}
});
}
示例9
/** Returns count of filled lines of this output tab.
* @return count of filled lines of this output tab.
*/
public int getLineCount() {
return ((Integer) runMapping(new MapAction("getLineCount") {
@Override
public Object map() {
Document document = documentForTab(getSource());
try {
if (getOutputDocumentClass().isInstance(document)) {
Method getElementCountMethod = getOutputDocumentClass().getDeclaredMethod("getElementCount", (Class[]) null);
getElementCountMethod.setAccessible(true);
return (Integer) getElementCountMethod.invoke(document, (Object[]) null);
}
} catch (Exception e) {
throw new JemmyException("getElementCount() by reflection failed.", e);
}
return 0;
}
})).intValue();
}
示例10
/**
* Changes selection if necessary. Uses a ButtonDriver registered for this
* operator.
*
* @param newValue a button selection.
*/
public void changeSelection(boolean newValue) {
makeComponentVisible();
if (getState() != newValue) {
try {
waitComponentEnabled();
} catch (InterruptedException e) {
throw (new JemmyException("Interrupted!", e));
}
output.printLine("Change checkbox selection to " + (newValue ? "true" : "false")
+ "\n :" + toStringSource());
output.printGolden("Change checkbox selection to " + (newValue ? "true" : "false"));
driver.push(this);
if (getVerification()) {
waitSelected(newValue);
}
}
}
示例11
/**
* Performs an operation without time control.
*
* @param action an action to execute.
* @param param an action parameters.
*/
protected <R, P> void produceNoBlocking(NoBlockingAction<R, P> action, P param) {
try {
ActionProducer<R, P> noBlockingProducer = new ActionProducer<>(action, false);
noBlockingProducer.setOutput(output.createErrorOutput());
noBlockingProducer.setTimeouts(timeouts);
noBlockingProducer.produceAction(param, null);
} catch (InterruptedException e) {
throw (new JemmyException("Exception during \""
+ action.getDescription()
+ "\" execution",
e));
}
if (action.exception != null) {
throw (new JemmyException("Exception during nonblocking \""
+ action.getDescription() + "\"",
action.exception));
}
}
示例12
/**
* performs action through shortcut
*
* @throws UnsupportedOperationException if no shortcut is defined
*/
public void performShortcut() {
KeyStroke[] strokes = getKeyStrokes();
if (strokes == null) {
throw new UnsupportedOperationException(getClass().toString() + " does not define shortcut");
}
for (int i = 0; i < strokes.length; i++) {
new KeyRobotDriver(null).pushKey(null, strokes[i].getKeyCode(), strokes[i].getModifiers(), JemmyProperties.getCurrentTimeouts().create("ComponentOperator.PushKeyTimeout"));
JemmyProperties.getProperties().getTimeouts().sleep("Action.WaitAfterShortcutTimeout");
}
try {
Thread.sleep(AFTER_ACTION_WAIT_TIME);
} catch (Exception e) {
throw new JemmyException("Sleeping interrupted", e);
}
}
示例13
/**
* performs action through shortcut
*
* @param nodes nodes to be action performed on
* @throws UnsupportedOperationException when action does not support
* shortcut mode
*/
public void performShortcut(Node[] nodes) {
final KeyStroke[] strokes = getKeyStrokes();
if (strokes == null) {
throw new UnsupportedOperationException(getClass().toString() + " does not define shortcut");
}
testNodes(nodes);
nodes[0].select();
for (int i = 1; i < nodes.length; i++) {
nodes[i].addSelectionPath();
}
try {
Thread.sleep(SELECTION_WAIT_TIME);
} catch (Exception e) {
throw new JemmyException("Sleeping interrupted", e);
}
performShortcut();
}
示例14
/** Test of folding methods. */
public static void testFolding() {
eo.waitFolding();
assertFalse("Initial comment at line 2 should be expanded.", eo.isCollapsed(2));
eo.setCaretPositionToLine(3);
assertFalse("Initial comment at line 3 should be expanded.", eo.isCollapsed(3));
try {
eo.setCaretPosition("package sample1;", true); // NOI18N
int line = eo.getLineNumber();
eo.isCollapsed(line);
fail("JemmyException should be thrown because no fold is at line " + line);
} catch (JemmyException e) {
// OK.
}
eo.setCaretPositionToLine(2);
eo.collapseFold();
assertTrue("Initial comment should be collapsed now.", eo.isCollapsed(2));
eo.expandFold();
eo.collapseFold(5);
eo.expandFold(5);
}
示例15
@Override
public void runTest() throws Exception {
if (testFileObj == null) {
return;
}
String ext = testFileObj.getExt();
if (JSP_EXTS.contains(ext)) {
test(testFileObj, "<%--CC", "--%>");
} else if (XML_EXTS.contains(ext)) {
test(testFileObj, "<!--CC", "-->", false);
} else if (JS_EXTS.contains(ext) || ext.equals("java")) {
test(testFileObj, "/**CC", "*/", false);
} else {
throw new JemmyException("File extension of: " + testFileObj.getNameExt() + " is unsupported.");
}
}
示例16
/** Wait process with given name finished.
*/
public static void waitFinished(final String name, long timeout) {
try {
Waiter waiter = new Waiter(new Waitable() {
public Object actionProduced(Object anObject) {
return processInProgress(name) ? null : Boolean.TRUE;
}
public String getDescription() {
return("Wait process "+name+" is finished.");
}
});
waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout);
waiter.waitAction(null);
} catch (InterruptedException e) {
throw new JemmyException("Interrupted.", e);
}
}
示例17
/**
* performs action through main menu
*
* @throws UnsupportedOperationException when action does not support menu
* mode
*/
@Override
public void performMenu() {
if (menuPath == null) {
throw new UnsupportedOperationException(getClass().toString() + " does not define menu path");
}
// Need to wait here to be more reliable.
// TBD - It can be removed after issue 23663 is solved.
new EventTool().waitNoEvent(500);
MainWindowOperator.getDefault().menuBar().pushMenuNoBlock(menuPath, "|");
try {
Thread.sleep(AFTER_ACTION_WAIT_TIME);
} catch (Exception e) {
throw new JemmyException("Sleeping interrupted", e);
}
}
示例18
/**
* performs action through popup menu
*
* @param component component to be action performed on
* @throws UnsupportedOperationException when action does not support popup
* mode
*/
@Override
public void performPopup(ComponentOperator component) {
if (popupPath == null) {
throw new UnsupportedOperationException(getClass().toString() + " does not define popup path");
}
// Need to wait here to be more reliable.
// TBD - It can be removed after issue 23663 is solved.
new EventTool().waitNoEvent(500);
component.clickForPopup();
JPopupMenuOperator popup = new JPopupMenuOperator(component);
popup.setComparator(getComparator());
popup.pushMenuNoBlock(popupPath, "|");
try {
Thread.sleep(AFTER_ACTION_WAIT_TIME);
} catch (Exception e) {
throw new JemmyException("Sleeping interrupted", e);
}
}
示例19
/**
* performs action through shortcut
*
* @throws UnsupportedOperationException when action does not support
* shortcut mode
*/
@Override
public void performShortcut() {
final KeyStroke[] strokes = getKeyStrokes();
if (strokes == null) {
throw new UnsupportedOperationException(getClass().toString() + " does not define shortcut");
}
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < strokes.length; i++) {
new KeyRobotDriver(null).pushKey(null, strokes[i].getKeyCode(), strokes[i].getModifiers(), JemmyProperties.getCurrentTimeouts().create("ComponentOperator.PushKeyTimeout"));
JemmyProperties.getProperties().getTimeouts().sleep("Action.WaitAfterShortcutTimeout");
}
}
}, "thread performing action through shortcut").start();
try {
Thread.sleep(AFTER_ACTION_WAIT_TIME);
} catch (Exception e) {
throw new JemmyException("Sleeping interrupted", e);
}
}
示例20
/** Uses Central.userDroppedTopComponents(ModeImpl mode, TopComponentDraggable draggable, String side)
* to attach source TopComponent to target Mode according to sideConstant
* value.
* @param sourceTc source TopComponent
* @param mode target mode
* @param sideConstant side constant
*/
private static void attachTopComponent(TopComponent sourceTc, Mode mode, String sideConstant) {
try {
Class<?> centralClass = classForName("org.netbeans.core.windows.Central");
Class<?> tcdClass = classForName("org.netbeans.core.windows.view.dnd.TopComponentDraggable");
Class<?> modeImplClass = classForName("org.netbeans.core.windows.ModeImpl");
Method attachMethod = centralClass.getMethod("userDroppedTopComponents", modeImplClass, tcdClass, String.class);
Method getCentralMethod = WindowManager.getDefault().getClass().getDeclaredMethod("getCentral", (Class<?>[]) null);
getCentralMethod.setAccessible(true);
Object centralInstance = getCentralMethod.invoke(WindowManager.getDefault(), (Object[]) null);
Constructor<?> tcdConstructor = tcdClass.getDeclaredConstructor(TopComponent.class);
tcdConstructor.setAccessible(true);
Object tcdInstance = tcdConstructor.newInstance(sourceTc);
attachMethod.setAccessible(true);
attachMethod.invoke(centralInstance, mode, tcdInstance, sideConstant);
} catch (Exception e) {
throw new JemmyException("Cannot attach TopComponent.", e);
}
}
示例21
/** Performs Maximize Window by IDE API on given top component operator
* which is activated before the action.
* @param tco top component operator which should be activated and maximized
*/
public void performAPI(final TopComponentOperator tco) {
tco.makeComponentVisible();
// run in dispatch thread
tco.getQueueTool().invokeSmoothly(new Runnable() {
@Override
public void run() {
WindowManager wm = WindowManager.getDefault();
TopComponent tc = (TopComponent) tco.getSource();
Mode mode = wm.findMode(tc);
if (mode == null) {
throw new JemmyException("Mode not found for " + tc);
}
AttachWindowAction.callWindowManager("switchMaximizedMode", mode);
}
});
}
示例22
/**
* Waits until SaveAllAction is finished.
*/
private void waitFinished() {
try {
new Waiter(new Waitable() {
@Override
public Object actionProduced(Object systemAction) {
return DataObject.getRegistry().getModifiedSet().isEmpty() ? Boolean.TRUE : null;
}
@Override
public String getDescription() {
return "SaveAllAction is finished";
}
}).waitAction(null);
} catch (InterruptedException e) {
throw new JemmyException("Waiting interrupted.", e);
}
}
示例23
/**
* Waits popup defined by {@code popupChooser} parameter.
*
* @param popupChooser a component chooser specifying criteria for
* JPopupMenu.
* @return a JPopupMenu fitting the criteria.
*/
public static JPopupMenuOperator waitJPopupMenu(final ComponentChooser popupChooser) {
try {
WindowOperator wind = new WindowOperator(new WindowWaiter().waitWindow(new ComponentChooser() {
@Override
public boolean checkComponent(Component comp) {
ComponentSearcher searcher = new ComponentSearcher((Container) comp);
searcher.setOutput(JemmyProperties.getCurrentOutput().createErrorOutput());
return searcher.findComponent(popupChooser) != null;
}
@Override
public String getDescription() {
return "Window containing \"" + popupChooser.getDescription() + "\" popup";
}
@Override
public String toString() {
return "JPopupMenuOperator.waitJPopupMenu.ComponentChooser{description = " + getDescription() + '}';
}
}));
return new JPopupMenuOperator(wind);
} catch (InterruptedException e) {
throw (new JemmyException("Popup waiting has been interrupted", e));
}
}
示例24
/** Sets default value for this property. If default value is not available,
* it does nothing.
*/
public void setDefaultValue() {
try {
property.restoreDefaultValue();
} catch (Exception e) {
throw new JemmyException("Exception while restoring default value.", e);
}
/*
nameButtonOperator().clickForPopup();
String menuItem = Bundle.getString("org.openide.explorer.propertysheet.Bundle",
"SetDefaultValue");
new JPopupMenuOperator().pushMenu(menuItem, "|");
// need to wait until value button is changed
new EventTool().waitNoEvent(100);
*/
}
示例25
/** Returns property editor obtained by call PropUtils.getPropertyEditor().
* It should be safe in any circumstancies (e.g. when IDE starts supporting
* XML-based editor registration).
* @return PropertyEditor instance of this property.
*/
private PropertyEditor getPropertyEditor() {
final AtomicReference<PropertyEditor> atomicReference = new AtomicReference<PropertyEditor>();
new QueueTool().invokeSmoothly(new Runnable() {
@Override
public void run() {
try {
Class<?> clazz = Class.forName("org.openide.explorer.propertysheet.PropUtils");
Method getPropertyEditorMethod = clazz.getDeclaredMethod("getPropertyEditor", new Class[]{Node.Property.class});
getPropertyEditorMethod.setAccessible(true);
atomicReference.set((PropertyEditor) getPropertyEditorMethod.invoke(null, new Object[]{property}));
} catch (Exception e) {
throw new JemmyException("PropUtils.getPropertyEditor() by reflection failed.", e);
}
}
});
return atomicReference.get();
}
示例26
/**
* Waits for index-th widget specified by WidgetChooser under given parent
* widget.
*
* @param parentWidget parent Widget
* @param widgetChooser WidgetChooser implementation
* @param index index to be found
* @return Widget instance if found or throws JemmyException if not found.
*/
private static Widget waitWidget(final Widget parentWidget, final WidgetChooser widgetChooser, final int index) {
try {
Waiter waiter = new Waiter(new Waitable() {
@Override
public Object actionProduced(Object obj) {
return findWidget(parentWidget, widgetChooser, index);
}
@Override
public String getDescription() {
return (index > 0 ? index + "-th " : "")
+ (widgetChooser == null ? "Widget " : widgetChooser.getDescription())
+ " displayed";
}
});
Timeouts timeouts = JemmyProperties.getCurrentTimeouts().cloneThis();
timeouts.setTimeout("Waiter.WaitingTime", timeouts.getTimeout("WidgetOperator.WaitWidgetTimeout"));
waiter.setTimeouts(timeouts);
waiter.setOutput(JemmyProperties.getCurrentOutput());
return (Widget) waiter.waitAction(null);
} catch (InterruptedException ex) {
throw new JemmyException("Interrupted.", ex);
}
}
示例27
private void doInitRobot() {
try {
ClassReference robotClassReverence = new ClassReference("java.awt.Robot");
robotReference = new ClassReference(robotClassReverence.newInstance(null, null));
robotReference.invokeMethod("setAutoDelay",
new Object[]{(int) ((autoDelay != null)
? autoDelay.getValue()
: 0)},
new Class<?>[]{Integer.TYPE});
} catch (InvocationTargetException
| IllegalStateException
| NoSuchMethodException
| IllegalAccessException
| ClassNotFoundException
| InstantiationException e) {
throw (new JemmyException("Exception during java.awt.Robot accessing", e));
}
}
示例28
/** Wait process with given name finished.
*/
public static void waitFinished(final String name, long timeout) {
try {
Waiter waiter = new Waiter(new Waitable() {
public Object actionProduced(Object anObject) {
return processInProgress(name) ? null : Boolean.TRUE;
}
public String getDescription() {
return("Wait process "+name+" is finished.");
}
});
waiter.getTimeouts().setTimeout("Waiter.WaitingTime", timeout);
waiter.waitAction(null);
} catch (InterruptedException e) {
throw new JemmyException("Interrupted.", e);
}
}
示例29
/** Test cut */
public static void testClipboard(final Object clipboard1) {
Waiter waiter = new Waiter(new Waitable() {
public Object actionProduced(Object obj) {
Object clipboard2 = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
return clipboard1 != clipboard2 ? Boolean.TRUE : null;
}
public String getDescription() {
return("Wait clipboard contains data"); // NOI18N
}
});
try {
waiter.waitAction(null);
} catch (InterruptedException e) {
throw new JemmyException("Waiting interrupted.", e);
}
}
示例30
/** Saves content of this TopComponent. If it is not applicable or content
* of TopComponent is not modified, it does nothing.
*/
public void save() {
Savable savable = ((TopComponent) getSource()).getLookup().lookup(Savable.class);
if (savable == null) {
// try to find possible enclosing MultiviewTopComponent
TopComponentOperator parentTco = findParentTopComponent();
if (parentTco != null) {
parentTco.save();
}
} else {
try {
savable.save();
} catch (IOException e) {
throw new JemmyException("Saving of TopComponent " + ((TopComponent) getSource()).getDisplayName() + " failed (Savable=" + savable + ").", e); //NOI18N
}
}
}