Problem with JUnit testing on XML Editor Plugin [message #225960] |
Mon, 05 January 2009 22:53 |
Xavier Coulon Messages: 58 Registered: July 2009 |
Member |
|
|
Hello,
Before all : happy new year to the readers of this post :-)
I'm trying to write some JUnit tests on an extension to the WTP XML Editor
(version 3.0.3).
For now, the extension provides content assist and hyperlinks to the
editor, and while doing some "hand testing" works well, this is not a
satisfying/agile approach (and btw, I would like to apply code coverage
tools such as Clover and EclEmma on my source code).
When I launch the Junit Plugin TestCase, a second instance of Eclipse
starts in a new (and cleaned) workspace, the test setup (creating
JavaProject with build path, etc..) works, but then I get the following
error :
Exception in thread "WorkbenchTestable" org.eclipse.swt.SWTException:
Device is disposed
at org.eclipse.swt.SWT.error(SWT.java:3777)
at org.eclipse.swt.SWT.error(SWT.java:3695)
at org.eclipse.swt.SWT.error(SWT.java:3666)
at org.eclipse.swt.widgets.Display.error(Display.java:1126)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:3952)
at
org.eclipse.ui.internal.testing.WorkbenchTestable.testingFin ished(WorkbenchTestable.java:119)
at
org.eclipse.pde.internal.junit.runtime.UITestApplication.run Tests(UITestApplication.java:117)
at
org.eclipse.ui.internal.testing.WorkbenchTestable$1.run(Work benchTestable.java:68)
at java.lang.Thread.run(Thread.java:613)
This error occurs in the following utility method of a class I developped :
/**
* Retrieve the JavaProject the current edited resource belongs to
*
* @return instance of IJavaProject containing the edited resource
*/
public static final IJavaProject
getCurrentJavaProject(IStructuredDocument document) {
IJavaProject javaProject = null;
IEditorInput input = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor( )
.getEditorInput();
if (input instanceof FileEditorInput) {
IProject project = ((FileEditorInput) input).getFile().getProject();
javaProject = (JavaProject) JavaCore.create(project);
}
return javaProject;
}
This method should return the current Java Project in which the document
given in parameter is located. I need this JavaProject to retrieve
IType(s) in its classpath...
This method woks fine when I perform some "hand testing" since the
workbench is active, but throws a NullPointerException at the following
line :
IEditorInput input = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage().getActiveEditor( )
.getEditorInput();
For now :
- The instance of document given in parameter of this method is retrieved
from the ContentAssistRequest when the extension provides some custom
content assist :
Util.getCurrentJavaProject(contentAssistRequest.getDocumentR egion().getParentDocument());
- The instance of document given in parameter of this method is retrieved
from the TextViewer when the extension provides hyperlinks :
IStructuredDocumentRegion regions =
ContentAssistUtils.getStructuredDocumentRegion(textViewer,
region.getOffset());
Util.getCurrentJavaProject(regions.getParentDocument())
Is there another way to retrieve the current JavaProject from the given
input (ITextViewer and ContentAssistRequest) so that my code works *both*
in JUnit Plugin Tests and User Runtime ?
Thank you in advance
Regards
Xavier
|
|
|
|
Re: Problem with JUnit testing on XML Editor Plugin [message #226014 is a reply to message #225996] |
Tue, 06 January 2009 17:51 |
Eclipse User |
|
|
|
Originally posted by: dcarver.starstandard.org
Xavier Coulon wrote:
> Hello again,
>
> Does anyone know how to solve this problem ? ie, how can you run JUnit
> Tests on Eclipse plugins when you need to find the JavaProject
> associated with the current input/source/document in an editor ?
I'd recommend taking a look at the Unit tests that are in the
org.eclipse.jdt.ui.test package.
They should give you some information on how to retrieve the particular
project given an IFile from an editor.
Dave
|
|
|
|
Re: Problem with JUnit testing on XML Editor Plugin [message #226082 is a reply to message #225996] |
Tue, 06 January 2009 23:40 |
|
Xavier Coulon wrote:
> Hello again,
>
> Does anyone know how to solve this problem ? ie, how can you run JUnit
> Tests on Eclipse plugins when you need to find the JavaProject
> associated with the current input/source/document in an editor ?
While I'm only guessing, it's possible that there isn't an active
editor part during the test, but if you go back to the model manager
through
StructuredModelManager.getModelManager().getExistingModelFor Read(),
with a little maneuvering you can get the resource's path, which
should let you get to the project.
--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational
_
Nitin Dahyabhai
Eclipse Web Tools Platform
|
|
|
Powered by
FUDForum. Page generated in 0.04029 seconds