Search in sources :

Example 1 with SakuliExceptionHandler

use of org.sakuli.exceptions.SakuliExceptionHandler in project sakuli by ConSol.

the class SahiCommandExecutionAspectTest method testCatchSahiCommandExcecutionErrors.

@Test
public void testCatchSahiCommandExcecutionErrors() throws Exception {
    SakuliExceptionHandler exceptionHandler = BeanLoader.loadBean(SakuliExceptionHandler.class);
    try {
        Utils.executeAndGetProcess(new String[] { "testcommand", "arg1", "arg2" });
    } catch (Exception e) {
    //exception have nothing to with the test
    }
    verify(exceptionHandler).handleException(any(SakuliInitException.class));
}
Also used : SakuliInitException(org.sakuli.exceptions.SakuliInitException) SakuliExceptionHandler(org.sakuli.exceptions.SakuliExceptionHandler) SakuliInitException(org.sakuli.exceptions.SakuliInitException) Test(org.testng.annotations.Test)

Example 2 with SakuliExceptionHandler

use of org.sakuli.exceptions.SakuliExceptionHandler in project sakuli by ConSol.

the class SahiCommandExecutionAspectTest method testCatchSahiCommandExcecutionErrorsKeytool.

@Test
public void testCatchSahiCommandExcecutionErrorsKeytool() throws Exception {
    SakuliExceptionHandler exceptionHandler = BeanLoader.loadBean(SakuliExceptionHandler.class);
    try {
        Utils.executeAndGetProcess(new String[] { "keytool", "arg1", "arg2" });
    } catch (Exception e) {
    //exception have nothing to with the test
    }
    verify(exceptionHandler, never()).handleException(any(SakuliInitException.class));
}
Also used : SakuliInitException(org.sakuli.exceptions.SakuliInitException) SakuliExceptionHandler(org.sakuli.exceptions.SakuliExceptionHandler) SakuliInitException(org.sakuli.exceptions.SakuliInitException) Test(org.testng.annotations.Test)

Example 3 with SakuliExceptionHandler

use of org.sakuli.exceptions.SakuliExceptionHandler 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);
}
Also used : RhinoScriptRunner(net.sf.sahi.rhino.RhinoScriptRunner) SakuliExceptionHandler(org.sakuli.exceptions.SakuliExceptionHandler) SahiScript(net.sf.sahi.playback.SahiScript)

Example 4 with SakuliExceptionHandler

use of org.sakuli.exceptions.SakuliExceptionHandler 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 5 with SakuliExceptionHandler

use of org.sakuli.exceptions.SakuliExceptionHandler in project sakuli by ConSol.

the class ExceptionHandlerAspect method processJavaException.

/**
     * Throw the handled Exception after {@link SakuliExceptionHandler#processException(Throwable)} to stop the current
     * test case execution of an JAVA test.
     */
@After("execution(* org.sakuli.exceptions.SakuliExceptionHandler.processException(..)) ")
public void processJavaException(JoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    if (args != null && args.length == 1) {
        Object e = args[0];
        SakuliExceptionHandler exceptionHandler = BeanLoader.loadBaseActionLoader().getExceptionHandler();
        if (e instanceof SakuliException && exceptionHandler.resumeToTestExcecution((SakuliException) e)) {
            return;
        }
        throw (Throwable) e;
    }
}
Also used : SakuliExceptionHandler(org.sakuli.exceptions.SakuliExceptionHandler) SakuliException(org.sakuli.exceptions.SakuliException) After(org.aspectj.lang.annotation.After)

Aggregations

SakuliExceptionHandler (org.sakuli.exceptions.SakuliExceptionHandler)6 SakuliInitException (org.sakuli.exceptions.SakuliInitException)2 Test (org.testng.annotations.Test)2 SahiScript (net.sf.sahi.playback.SahiScript)1 Report (net.sf.sahi.report.Report)1 TestResult (net.sf.sahi.report.TestResult)1 RhinoScriptRunner (net.sf.sahi.rhino.RhinoScriptRunner)1 JoinPoint (org.aspectj.lang.JoinPoint)1 After (org.aspectj.lang.annotation.After)1 LogResult (org.sakuli.datamodel.actions.LogResult)1 SakuliException (org.sakuli.exceptions.SakuliException)1