Search in sources :

Example 1 with Report

use of net.sf.sahi.report.Report in project sakuli by ConSol.

the class RhinoAspectTest method verifySahiReport.

private void verifySahiReport(ResultType resultTyp, int initialListSize) {
    if (resultTyp != null) {
        Report sahiReport2 = BeanLoader.loadBaseActionLoader().getSahiReport();
        int newLisSize = sahiReport2.getListResult().size();
        assertEquals(newLisSize, initialListSize + 1);
        TestResult testResult = sahiReport2.getListResult().get(newLisSize - 1);
        assertNotNull(testResult);
        SakuliExceptionHandler sakuliExceptionHandler = BeanLoader.loadBean(SakuliExceptionHandler.class);
        if (resultTyp.equals(ResultType.ERROR) || resultTyp.equals(ResultType.FAILURE)) {
            verify(sakuliExceptionHandler).handleException(any(LogResult.class));
        } else {
            verify(sakuliExceptionHandler, never()).handleException(any(LogResult.class));
        }
    }
}
Also used : Report(net.sf.sahi.report.Report) SakuliExceptionHandler(org.sakuli.exceptions.SakuliExceptionHandler) LogResult(org.sakuli.datamodel.actions.LogResult) TestResult(net.sf.sahi.report.TestResult) JoinPoint(org.aspectj.lang.JoinPoint)

Example 2 with Report

use of net.sf.sahi.report.Report in project sakuli by ConSol.

the class RhinoAspectTest method testDoHandleRhinoExceptionResultString.

@Test(dataProvider = "resultTypes")
public void testDoHandleRhinoExceptionResultString(ResultType resultTyp) throws Exception {
    initMocks();
    /**
         * If the test fails in your IDE, make sure that your compiler use the correct AspectJ-Compiler
         * For IntelliJ you can make a right click on the maven target 'aspectj:compile' and mark it
         * with the option 'Execute After Make'.
         */
    Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport();
    int lisSize = sahiReport.getListResult().size();
    assertNotNull(sahiReport);
    sahiReport.addResult("TEST-ENTRY", resultTyp.getName(), "bla", "TEST-ENTRY");
    verifySahiReport(resultTyp, lisSize);
}
Also used : Report(net.sf.sahi.report.Report) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 3 with Report

use of net.sf.sahi.report.Report in project sakuli by ConSol.

the class RhinoAspectTest method testAddActionLog.

@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);
    //hide args
    when(logToResult.logArgs()).thenReturn(false);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, "\"" + classContent + "\" " + className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]");
    //without class values
    when(logToResult.logClassInstance()).thenReturn(false);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage + " with arg(s) [****, ****]");
    //without args
    when(jp.getArgs()).thenReturn(null);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, className + "." + methodName + "() - " + sampleMessage);
    //without message
    when(logToResult.message()).thenReturn(null);
    testling.addActionLog(jp, logToResult);
    assertLastLine(logFile, className, logLevel, className + "." + methodName + "()");
}
Also used : LogToResult(org.sakuli.actions.logging.LogToResult) Report(net.sf.sahi.report.Report) TestCaseAction(org.sakuli.actions.TestCaseAction) Signature(org.aspectj.lang.Signature) JoinPoint(org.aspectj.lang.JoinPoint) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 4 with Report

use of net.sf.sahi.report.Report in project sakuli by ConSol.

the class RhinoAspectTest method testDoHandleRhinoException.

@Test(dataProvider = "resultTypes")
public void testDoHandleRhinoException(ResultType resultTyp) throws Exception {
    initMocks();
    /**
         * If the test fails in your IDE, make sure that your compiler use the correct AspectJ-Compiler
         * For IntelliJ you can make a right click on the maven target 'aspectj:compile' and mark it
         * with the option 'Execute After Make'.
         */
    Report sahiReport = BeanLoader.loadBaseActionLoader().getSahiReport();
    int lisSize = sahiReport.getListResult().size();
    assertNotNull(sahiReport);
    sahiReport.addResult("TEST-ENTRY", resultTyp, "bla", "TEST-ENTRY");
    verifySahiReport(resultTyp, lisSize);
}
Also used : Report(net.sf.sahi.report.Report) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.testng.annotations.Test)

Example 5 with Report

use of net.sf.sahi.report.Report in project sakuli by ConSol.

the class RhinoAspect method addActionLog.

/**
     * Method to do all Logs for the action classes annotated with {@link org.sakuli.actions.logging.LogToResult}. A log
     * entry will created at the sakuli log files and at the sahi HTML {@link net.sf.sahi.report.Report}.
     *
     * @param joinPoint   {@link JoinPoint} object of the calling aspect
     * @param logToResult {@link LogToResult} Annotation
     */
protected void addActionLog(JoinPoint joinPoint, LogToResult logToResult) {
    Logger logger = getLogger(joinPoint);
    if (logToResult != null) {
        StringBuilder message = createLoggingString(joinPoint, logToResult);
        //log the action to log file and print
        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(), "");
            }
        }
    }
}
Also used : Report(net.sf.sahi.report.Report) Logger(org.slf4j.Logger)

Aggregations

Report (net.sf.sahi.report.Report)5 JoinPoint (org.aspectj.lang.JoinPoint)4 Test (org.testng.annotations.Test)3 TestResult (net.sf.sahi.report.TestResult)1 Signature (org.aspectj.lang.Signature)1 TestCaseAction (org.sakuli.actions.TestCaseAction)1 LogToResult (org.sakuli.actions.logging.LogToResult)1 LogResult (org.sakuli.datamodel.actions.LogResult)1 SakuliExceptionHandler (org.sakuli.exceptions.SakuliExceptionHandler)1 Logger (org.slf4j.Logger)1