@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)); testling.modifySahiTimer(mock(JoinPoint.class), true); verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, "1000"); verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Exception.class)); assertLastLine(logFile, "sahi-proxy-timer", LogLevel.INFO, "sahi-proxy-timer modified to 1000 ms"); testling.modifySahiTimer(mock(JoinPoint.class), false); verify(session).setVariable(SahiProxyProperties.SAHI_REQUEST_DELAY_TIME_VAR, null); verify(baseActionLoader.getExceptionHandler(), never()).handleException(any(Exception.class)); assertLastLine(logFile, "sahi-proxy-timer", LogLevel.INFO, "reset sahi-proxy-timer"); }
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()); 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); } } } }
ModifySahiTimerAspect extends BaseSakuliAspect { 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()); 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); } } } } }
ModifySahiTimerAspect extends BaseSakuliAspect { 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()); 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); } } } }  }
ModifySahiTimerAspect extends BaseSakuliAspect { 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()); 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); } } } }  @Before("execution(* org.sakuli.actions.environment.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doEnvironmentBefore(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); @Before("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doScreenbasedBefore(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); @After("execution(* org.sakuli.actions.environment.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doEnvironmentAfter(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); @After("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doScreenbasedAfter(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); }
ModifySahiTimerAspect extends BaseSakuliAspect { 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()); 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); } } } }  @Before("execution(* org.sakuli.actions.environment.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doEnvironmentBefore(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); @Before("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doScreenbasedBefore(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); @After("execution(* org.sakuli.actions.environment.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doEnvironmentAfter(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer); @After("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" + "@annotation(modifySahiTimer)") void doScreenbasedAfter(JoinPoint joinPoint, ModifySahiTimer modifySahiTimer);  }