use of net.sf.sahi.rhino.RhinoScriptRunner in project sakuli by ConSol.
the class ModifySahiTimerAspect method modifySahiTimer.
void modifySahiTimer(JoinPoint joinPoint, boolean beforeMethod) {
BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
SahiProxyProperties sahiProxyProperties = loader.getSahiProxyProperties();
if (sahiProxyProperties != null && sahiProxyProperties.isRequestDelayActive()) {
RhinoScriptRunner rhinoScriptRunner = loader.getRhinoScriptRunner();
if (rhinoScriptRunner != null && rhinoScriptRunner.getSession() != null) {
getLogger(joinPoint).debug("MODIFY SAHI-TIMER for {}", getClassAndMethodAsString(joinPoint));
Session session = rhinoScriptRunner.getSession();
if (beforeMethod) {
Integer delay = determineDelay(joinPoint, loader);
session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, delay.toString());
//short sleep to ensure that browser context can read out the value
try {
logger.info("wait {}ms for sahi refresh", sahiProxyProperties.getRequestDelayRefreshMs());
Thread.sleep(sahiProxyProperties.getRequestDelayRefreshMs());
} catch (InterruptedException e) {
BeanLoader.loadBaseActionLoader().getExceptionHandler().handleException(e, true);
}
logger.info("sahi-proxy-timer modified to {} ms", delay.toString());
} else {
logger.info("reset sahi-proxy-timer");
session.setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null);
}
}
}
}
use of net.sf.sahi.rhino.RhinoScriptRunner in project sakuli by ConSol.
the class AopBaseTest method initMocks.
protected void initMocks() {
SakuliExceptionHandler sakuliExceptionHandler = BeanLoader.loadBean(SakuliExceptionHandler.class);
reset(sakuliExceptionHandler);
SahiScript sahiScriptMock = mock(SahiScript.class);
when(sahiScriptMock.jsString()).thenReturn("");
new RhinoScriptRunner(sahiScriptMock);
}
use of net.sf.sahi.rhino.RhinoScriptRunner in project sakuli by ConSol.
the class ModifySahiTimerAspectTest method testDisabledModifySahiTimer.
@Test
public void testDisabledModifySahiTimer() throws Exception {
RhinoScriptRunner runner = mock(RhinoScriptRunner.class);
Session session = mock(Session.class);
when(runner.getSession()).thenReturn(session);
BaseActionLoader baseActionLoader = BeanLoader.loadBaseActionLoader();
baseActionLoader.setRhinoScriptRunner(runner);
when(baseActionLoader.getSahiProxyProperties().isRequestDelayActive()).thenReturn(false);
doReturn(LoggerFactory.getLogger(this.getClass())).when(testling).getLogger(any(JoinPoint.class));
doReturn("sig.method()").when(testling).getClassAndMethodAsString(any(JoinPoint.class));
//test modifcation of timer is disabled
testling.modifySahiTimer(mock(JoinPoint.class), true);
testling.modifySahiTimer(mock(JoinPoint.class), false);
verify(session, never()).setVariable(anyString(), anyString());
verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
//test no session available
when(baseActionLoader.getSahiProxyProperties().isRequestDelayActive()).thenReturn(true);
when(runner.getSession()).thenReturn(null);
testling.modifySahiTimer(mock(JoinPoint.class), true);
testling.modifySahiTimer(mock(JoinPoint.class), false);
verify(session, never()).setVariable(anyString(), anyString());
verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
}
use of net.sf.sahi.rhino.RhinoScriptRunner in project sakuli by ConSol.
the class ModifySahiTimerAspectTest method testModifySahiTimer.
@Test
public void testModifySahiTimer() throws Exception {
RhinoScriptRunner runner = mock(RhinoScriptRunner.class);
Session session = mock(Session.class);
when(runner.getSession()).thenReturn(session);
BaseActionLoader baseActionLoader = BeanLoader.loadBaseActionLoader();
baseActionLoader.setRhinoScriptRunner(runner);
when(baseActionLoader.getSahiProxyProperties().isRequestDelayActive()).thenReturn(true);
doReturn(1000).when(testling).determineDelay(any(JoinPoint.class), any(BaseActionLoader.class));
doReturn(LoggerFactory.getLogger(this.getClass())).when(testling).getLogger(any(JoinPoint.class));
doReturn("sig.method()").when(testling).getClassAndMethodAsString(any(JoinPoint.class));
//test modifcation of timer to 1000ms
testling.modifySahiTimer(mock(JoinPoint.class), true);
verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, "1000");
verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
assertLastLine(logFile, "sahi-proxy-timer", LogLevel.INFO, "sahi-proxy-timer modified to 1000 ms");
//test reset timer
testling.modifySahiTimer(mock(JoinPoint.class), false);
verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null);
verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Throwable.class));
assertLastLine(logFile, "sahi-proxy-timer", LogLevel.INFO, "reset sahi-proxy-timer");
}
Aggregations