I found a solution to run such tests:
The testing logic must be wrapped within a ServerJob.
As ServerJob.getCurrentSession() returns null, an own server session must be instantiated.
@Test(timeout = 5000)
public void testTimeout() throws Throwable {
TestJob job = new TestJob() {
@Override
protected void executeTest() {
//Testing logic with assertions
}
};
job.runAndCheckAssertions();
}
abstract class TestJob extends ServerJob {
private Throwable m_throwable;
public TestJob() {
super("Test", new CoreProductServerTestSession());
m_throwable = null;
}
@Override
protected IStatus runTransaction(IProgressMonitor monitor) throws Exception {
try {
executeTest();
}
catch (Throwable t) {
m_throwable = t;
}
return Status.OK_STATUS;
}
public void runAndCheckAssertions() throws Throwable {
runNow(null);
if (m_throwable != null) {
throw m_throwable;
}
}
protected abstract void executeTest();
}
CoreProductServerTestSession is a class implementing IServerSession.
[Updated on: Mon, 07 July 2014 08:13] by Moderator