use of org.sakuli.loader.BaseActionLoader 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 org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.
the class ModifySahiTimerAspectTest method testDetermineDelay.
@Test
public void testDetermineDelay() throws Exception {
BaseActionLoader loader = BeanLoader.loadBaseActionLoader();
when(loader.getSahiProxyProperties().getRequestDelayMs()).thenReturn(500);
loader.getActionProperties().setTypeDelay(0.05);
JoinPoint joinPoint = mock(JoinPoint.class);
Signature signature = mock(Signature.class);
when(joinPoint.getSignature()).thenReturn(signature);
when(signature.getName()).thenReturn("pasteSomething");
assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 500);
when(signature.getName()).thenReturn("typeMasked");
when(joinPoint.getArgs()).thenReturn(new String[] { "1", "MOD" });
assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 550);
when(joinPoint.getArgs()).thenReturn(new String[] { "12characters", "MOD" });
assertEquals(testling.determineDelay(joinPoint, loader).intValue(), 12 * 550);
}
use of org.sakuli.loader.BaseActionLoader 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 org.sakuli.loader.BaseActionLoader 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");
}
use of org.sakuli.loader.BaseActionLoader in project sakuli by ConSol.
the class RhinoAspectTest method testDoTestCaseActionLog.
@Test
public void testDoTestCaseActionLog() throws Exception {
initMocks();
BaseActionLoader loader = mock(BaseActionLoader.class);
TestCase sampleTc = new TestCase("test", "testID");
when(loader.getCurrentTestCase()).thenReturn(sampleTc);
TestCaseAction testAction = new TestCaseAction();
ReflectionTestUtils.setField(testAction, "loader", loader, BaseActionLoader.class);
testAction.init("testID", 3, 4, "imagefolder1", "imagefolder2");
assertLastLine(logFile, testAction.getClass().getSimpleName(), LogLevel.INFO, "\"test case [" + sampleTc.getActionValueString() + "]\" TestCaseAction.init() - init a new test case with arg(s) [testID, 3, 4, [imagefolder1, imagefolder2]]");
}
Aggregations