Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait implementations are rewritten without SWTBot depedencies #94

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.Assert.assertEquals;

import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.jboss.reddeer.eclipse.condition.ProblemsExists;
import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardDialog;
import org.jboss.reddeer.eclipse.jdt.ui.NewJavaClassWizardPage;
Expand All @@ -12,6 +11,7 @@
import org.jboss.reddeer.eclipse.ui.problems.ProblemsView;
import org.jboss.reddeer.swt.test.RedDeerTest;
import org.jboss.reddeer.swt.condition.JobIsRunning;
import org.jboss.reddeer.swt.exception.WaitTimeoutExpiredException;
import org.jboss.reddeer.swt.util.Bot;
import org.jboss.reddeer.swt.wait.TimePeriod;
import org.jboss.reddeer.swt.wait.WaitUntil;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected void tearDown(){
super.tearDown();
}

@Test(expected=TimeoutException.class)
@Test(expected=WaitTimeoutExpiredException.class)
public void testNoErrorNoWarning() {
problemsView.open();
new WaitUntil(new ProblemsExists(), TimePeriod.NORMAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.jboss.reddeer.eclipse.jdt.ui.ide;

import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.jboss.reddeer.eclipse.jface.wizard.NewWizardDialog;
import org.jboss.reddeer.swt.condition.JobIsRunning;
import org.jboss.reddeer.swt.condition.ShellWithTextIsActive;
import org.jboss.reddeer.swt.exception.SWTLayerException;
import org.jboss.reddeer.swt.exception.WaitTimeoutExpiredException;
import org.jboss.reddeer.swt.impl.button.PushButton;
import org.jboss.reddeer.swt.impl.shell.DefaultShell;
import org.jboss.reddeer.swt.wait.TimePeriod;
Expand Down Expand Up @@ -38,10 +39,11 @@ public void finish(boolean openAssociatedPerspective) {
}
new WaitWhile(new ShellWithTextIsActive(shell.getText()), TimePeriod.LONG);
}
// TODO WaitWhile needs to be overwritten to throw SWTLayerException
} catch (RuntimeException te) {
} catch (WaitTimeoutExpiredException wtee) {
log.info("Shell 'Open Associated Perspective' wasn't shown");
}
} catch (SWTLayerException sle) {
log.info("Shell 'Open Associated Perspective' wasn't shown");
}
new WaitWhile(new JobIsRunning(), TimePeriod.LONG);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jboss.reddeer.swt.exception;

/**
* Wait Timeout Exception indicates expired waiting timeout
*
* @author Vlado Pakan
*
*/
public class WaitTimeoutExpiredException extends RuntimeException {

private static final long serialVersionUID = 5905873761753380173L;
/**
* Creates WaitTimeoutExpiredException with specified message
* @param message
*/
public WaitTimeoutExpiredException(String message) {
super(message);
}
/**
* Creates WaitTimeoutExpiredException with specified message and cause
* @param message
* @param cause
*/
public WaitTimeoutExpiredException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.jboss.reddeer.swt.api.Button;
import org.jboss.reddeer.swt.condition.WaitCondition;
import org.jboss.reddeer.swt.exception.WaitTimeoutExpiredException;
import org.jboss.reddeer.swt.util.Display;
import org.jboss.reddeer.swt.util.ResultRunnable;
import org.jboss.reddeer.swt.wait.WaitUntil;
Expand Down Expand Up @@ -41,7 +41,7 @@ public boolean isEnabled() {
// TODO waits need to completely rewritten
try {
waitUntilButtonIsActive();
} catch (TimeoutException e) {
} catch (WaitTimeoutExpiredException wtee) {
}

return button.isEnabled();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jboss.reddeer.swt.impl.shell;

import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.jboss.reddeer.swt.api.Shell;
import org.jboss.reddeer.swt.condition.ShellWithTextIsActive;
import org.jboss.reddeer.swt.condition.ShellIsActive;
import org.jboss.reddeer.swt.exception.SWTLayerException;
import org.jboss.reddeer.swt.exception.WaitTimeoutExpiredException;
import org.jboss.reddeer.swt.reference.ReferenceComposite;
import org.jboss.reddeer.swt.reference.ReferencedComposite;
import org.jboss.reddeer.swt.util.Bot;
Expand Down Expand Up @@ -59,8 +59,8 @@ private void waitForShell(String title) {
} else {
new WaitUntil(new ShellWithTextIsActive(title));
}
}catch(TimeoutException te) {
throw new SWTLayerException(te.getLocalizedMessage());
}catch(WaitTimeoutExpiredException wtee) {
throw new SWTLayerException(wtee.getLocalizedMessage());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.jboss.reddeer.swt.api.Table;
import org.jboss.reddeer.swt.condition.TableHasRows;
import org.jboss.reddeer.swt.exception.SWTLayerException;
import org.jboss.reddeer.swt.exception.WaitTimeoutExpiredException;
import org.jboss.reddeer.swt.wait.WaitUntil;

/**
Expand Down Expand Up @@ -72,8 +72,8 @@ public void check(int itemIndex){
private void waitUntilTableHasRows(Table table) {
try {
new WaitUntil(new TableHasRows(table));
}catch (TimeoutException te) {
throw new SWTLayerException(te.getLocalizedMessage());
}catch (WaitTimeoutExpiredException wtee) {
throw new SWTLayerException(wtee.getLocalizedMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,57 +1,86 @@
package org.jboss.reddeer.swt.wait;

import org.apache.log4j.Logger;
import org.eclipse.swtbot.swt.finder.SWTBot;
import org.eclipse.swtbot.swt.finder.waits.ICondition;
import org.jboss.reddeer.swt.condition.WaitCondition;

/**
* Common ancestor for waiting classes. Contains abstract {@link #wait(WaitCondition)} method
* that is called in the constructor.
* Common ancestor for waiting classes. Contains abstract
* {@link #wait(WaitCondition)} method that is called in the constructor.
*
* @author Vlado Pakan
* @author Lucia Jelinkova
*
*
*/
public abstract class AbstractWait {

// Wait delay in milliseconds
protected static long WAIT_DELAY = 500;

protected final Logger log = Logger.getLogger(this.getClass());

private TimePeriod timeout;

public AbstractWait(WaitCondition condition){

private boolean throwWaitTimeoutExpiredException = true;
/**
* Waits with condition and default timeout
* Throws WaitTimeoutExpiredException when timeout had expired
* @param condition
*/
public AbstractWait(WaitCondition condition) {
this(condition, TimePeriod.NORMAL);
}

public AbstractWait(WaitCondition condition, TimePeriod timeout){
/**
* Waits with condition and timeout
* Throws WaitTimeoutExpiredException when timeout had expired
* @param condition
* @param timeout
*/
public AbstractWait(WaitCondition condition, TimePeriod timePeriod) {
this(condition, timePeriod, true);
}
/**
* Waits with condition and timeout
* Throws WaitTimeoutExpiredException when timeout had expired
* and throwWaitTimeoutExpiredException is true
* @param condition
* @param timeout
* @param throwWaitTimeoutExpiredException
*/
public AbstractWait(WaitCondition condition, TimePeriod timeout,
boolean throwRuntimeException) {
this.timeout = timeout;
this.throwWaitTimeoutExpiredException = throwRuntimeException;
log.info("Waiting with condition: " + condition.description()
+ "\n Timeout=" + timeout.getSeconds() + " seconds"
+ "\n Delay= " + AbstractWait.WAIT_DELAY + " milliseconds"
+ "\n Throw WaitTimeoutExpiredException="
+ throwWaitTimeoutExpiredException);
wait(condition);
log.info("Waiting finished");
}

protected abstract void wait(WaitCondition condition);

protected abstract String description();

protected TimePeriod getTimeout() {
return timeout;
}

protected ICondition wrapCondition(final WaitCondition condition){
return new ICondition() {

@Override
public boolean test() throws Exception {
return condition.test();
}

@Override
public void init(SWTBot bot) {
}

@Override
public String getFailureMessage() {
return "Failed " + AbstractWait.this.description() + ": " + condition.description();
}
};

protected boolean isThrowWaitTimeoutExpiredException() {
return throwWaitTimeoutExpiredException;
}

/**
* Sleeps for millis milliseconds
*
* @param millis
* the time in milliseconds to sleep
*/
protected static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
throw new RuntimeException("Sleep interrupted", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,76 @@
package org.jboss.reddeer.swt.wait;

import org.jboss.reddeer.swt.condition.WaitCondition;
import org.jboss.reddeer.swt.util.Bot;
import org.jboss.reddeer.swt.exception.SWTLayerException;
import org.jboss.reddeer.swt.exception.WaitTimeoutExpiredException;

/**
* Waits until condition is fulfilled
*
* @author Vlado Pakan
* @author Lucia Jelinkova
*
*
*/
public class WaitUntil extends AbstractWait {

/**
* Waits until condition is fulfilled with default timeout
* Throws WaitTimeoutExpiredException when timeout had expired
* @param condition
*/
public WaitUntil(WaitCondition condition) {
super(condition);
}

/**
* Waits until condition is fulfilled with timeout
* Throws WaitTimeoutExpiredException when timeout had expired
* @param condition
* @param timeout
*/
public WaitUntil(WaitCondition condition, TimePeriod timeout) {
super(condition, timeout);
}

/**
* Waits until condition is fulfilled with timeout
* Throws WaitTimeoutExpiredException when timeout had expired
* and throwWaitTimeoutExpiredException is true
* @param condition
* @param timeout
* @param throwWaitTimeoutExpiredException
*/
public WaitUntil(WaitCondition condition, TimePeriod timeout,
boolean throwWaitTimeoutExpiredException) {
super(condition, timeout, throwWaitTimeoutExpiredException);
}

@Override
protected void wait(WaitCondition condition) {
Bot.get().waitUntil(wrapCondition(condition), getTimeout().getSeconds() * 1000);
final long timeout = getTimeout().getSeconds() * 1000;
if (timeout < 0) {
throw new SWTLayerException("timeout value is negative");
}
if (AbstractWait.WAIT_DELAY < 0) {
throw new SWTLayerException("wait delay value is negative");
}
long limit = System.currentTimeMillis() + timeout;
boolean continueSleep = true;
while (continueSleep) {
try {
if (condition.test())
return;
} catch (Throwable e) {
// do nothing
}
sleep(AbstractWait.WAIT_DELAY);
if (System.currentTimeMillis() > limit) {
continueSleep = false;
if (isThrowWaitTimeoutExpiredException()) {
throw new WaitTimeoutExpiredException("Timeout after: "
+ timeout + " ms.: " + condition.description());
}
}
}
}

@Override
protected String description() {
return "waiting until: ";
Expand Down
Loading