@Test(dataProvider = "logLevel") public void testAddActionLog(LogLevel logLevel) throws Exception { initMocks(); Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport(); final int lisSize = sahiReport.getListResult().size(); final String classContent = "Test-Action-Content"; final String className = TestCaseAction.class.getSimpleName(); final String methodName = "actionMethod"; final String sampleMessage = "sample-message-for-log"; final String arg1 = "ARG1"; final String arg2 = "NULL"; TestCaseAction testAction = mock(TestCaseAction.class); when(testAction.toString()).thenReturn(classContent); JoinPoint jp = mock(JoinPoint.class); when(jp.getTarget()).thenReturn(testAction); Signature signature = mock(Signature.class); when(jp.getSignature()).thenReturn(signature); when(signature.getDeclaringType()).thenReturn(TestCaseAction.class); when(signature.getName()).thenReturn(methodName); when(signature.getDeclaringTypeName()).thenReturn(TestCaseAction.class.getName()); when(jp.getArgs()).thenReturn(new Object[]{arg1, null}); LogToResult logToResult = mock(LogToResult.class); when(logToResult.logClassInstance()).thenReturn(true); when(logToResult.message()).thenReturn(sampleMessage); when(logToResult.logArgs()).thenReturn(true); when(logToResult.level()).thenReturn(logLevel); RhinoAspect testling = BeanLoader.loadBean(RhinoAspect.class); testling.addActionLog(jp, logToResult); assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [" + arg1 + ", " + arg2 + "]" ); verifySahiReport(logLevel.getResultType(), lisSize); when(logToResult.logArgs()).thenReturn(false); testling.addActionLog(jp, logToResult); assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]" ); when(logToResult.logClassInstance()).thenReturn(false); testling.addActionLog(jp, logToResult); assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]" ); when(jp.getArgs()).thenReturn(null); testling.addActionLog(jp, logToResult); assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage); when(logToResult.message()).thenReturn(null); testling.addActionLog(jp, logToResult); assertLastLine(logFile, className, logLevel, className + "." + methodName + "()"); }
protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) { Logger logger = getLogger(joinPoint); if (logToResult != null) { StringBuilder message = createLoggingString(joinPoint, logToResult); addActionsToCurrentTestCase(extractTestAction(joinPoint, logToResult)); switch (logToResult.level()) { case ERROR: logger.error(message.toString()); break; case INFO: logger.info(message.toString()); break; case DEBUG: logger.debug(message.toString()); break; case WARNING: logger.warn(message.toString()); message.insert(0, "WARNING: "); break; } if (logToResult.level().getResultType() != null) { Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport(); if (sahiReport != null) { sahiReport.addResult( message.toString(), logToResult.level().getResultType(), joinPoint.getSignature().getDeclaringTypeName(), ""); } } } }
RhinoAspect extends BaseSakuliAspect { protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) { Logger logger = getLogger(joinPoint); if (logToResult != null) { StringBuilder message = createLoggingString(joinPoint, logToResult); addActionsToCurrentTestCase(extractTestAction(joinPoint, logToResult)); switch (logToResult.level()) { case ERROR: logger.error(message.toString()); break; case INFO: logger.info(message.toString()); break; case DEBUG: logger.debug(message.toString()); break; case WARNING: logger.warn(message.toString()); message.insert(0, "WARNING: "); break; } if (logToResult.level().getResultType() != null) { Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport(); if (sahiReport != null) { sahiReport.addResult( message.toString(), logToResult.level().getResultType(), joinPoint.getSignature().getDeclaringTypeName(), ""); } } } } }
RhinoAspect extends BaseSakuliAspect { protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) { Logger logger = getLogger(joinPoint); if (logToResult != null) { StringBuilder message = createLoggingString(joinPoint, logToResult); addActionsToCurrentTestCase(extractTestAction(joinPoint, logToResult)); switch (logToResult.level()) { case ERROR: logger.error(message.toString()); break; case INFO: logger.info(message.toString()); break; case DEBUG: logger.debug(message.toString()); break; case WARNING: logger.warn(message.toString()); message.insert(0, "WARNING: "); break; } if (logToResult.level().getResultType() != null) { Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport(); if (sahiReport != null) { sahiReport.addResult( message.toString(), logToResult.level().getResultType(), joinPoint.getSignature().getDeclaringTypeName(), ""); } } } }  }
RhinoAspect extends BaseSakuliAspect { protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) { Logger logger = getLogger(joinPoint); if (logToResult != null) { StringBuilder message = createLoggingString(joinPoint, logToResult); addActionsToCurrentTestCase(extractTestAction(joinPoint, logToResult)); switch (logToResult.level()) { case ERROR: logger.error(message.toString()); break; case INFO: logger.info(message.toString()); break; case DEBUG: logger.debug(message.toString()); break; case WARNING: logger.warn(message.toString()); message.insert(0, "WARNING: "); break; } if (logToResult.level().getResultType() != null) { Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport(); if (sahiReport != null) { sahiReport.addResult( message.toString(), logToResult.level().getResultType(), joinPoint.getSignature().getDeclaringTypeName(), ""); } } } }  @After("execution(* net.sf.sahi.rhino.RhinoScriptRunner.setReporter*(*))") void getRhinoScriptRunner(JoinPoint joinPoint); @Before("execution(* org.sakuli.actions.*.*(..)) &&" + "@annotation(logToResult)") void doTestCaseActionLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" + "@annotation(logToResult)") void doScreenBasedActionLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* org.sakuli.actions.environment.*.*(..)) &&" + "@annotation(logToResult)") void doEnvironmentLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* org.sakuli.actions.logging.*.*(..)) &&" + "@annotation(logToResult)") void doLoggingLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* net.sf.sahi.report.Report.addResult(..))") void doHandleRhinoException(JoinPoint joinPoint); }
RhinoAspect extends BaseSakuliAspect { protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) { Logger logger = getLogger(joinPoint); if (logToResult != null) { StringBuilder message = createLoggingString(joinPoint, logToResult); addActionsToCurrentTestCase(extractTestAction(joinPoint, logToResult)); switch (logToResult.level()) { case ERROR: logger.error(message.toString()); break; case INFO: logger.info(message.toString()); break; case DEBUG: logger.debug(message.toString()); break; case WARNING: logger.warn(message.toString()); message.insert(0, "WARNING: "); break; } if (logToResult.level().getResultType() != null) { Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport(); if (sahiReport != null) { sahiReport.addResult( message.toString(), logToResult.level().getResultType(), joinPoint.getSignature().getDeclaringTypeName(), ""); } } } }  @After("execution(* net.sf.sahi.rhino.RhinoScriptRunner.setReporter*(*))") void getRhinoScriptRunner(JoinPoint joinPoint); @Before("execution(* org.sakuli.actions.*.*(..)) &&" + "@annotation(logToResult)") void doTestCaseActionLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* org.sakuli.actions.screenbased.*.*(..)) &&" + "@annotation(logToResult)") void doScreenBasedActionLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* org.sakuli.actions.environment.*.*(..)) &&" + "@annotation(logToResult)") void doEnvironmentLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* org.sakuli.actions.logging.*.*(..)) &&" + "@annotation(logToResult)") void doLoggingLog(JoinPoint joinPoint, LogToResult logToResult); @Before("execution(* net.sf.sahi.report.Report.addResult(..))") void doHandleRhinoException(JoinPoint joinPoint); static final String ALREADY_PROCESSED; }