Search in sources :

Example 16 with SakuliException

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

the class NagiosOutputBuilderTest method testFormatTestSuiteTableException.

@Test
public void testFormatTestSuiteTableException() throws Exception {
    Date startDate = new Date();
    TestSuite testSuiteExample = new TestSuiteExampleBuilder().withId("sakuli-123").withState(TestSuiteState.ERRORS).withStartDate(startDate).withException(new SakuliException("TEST-ERROR")).withStopDate(DateUtils.addSeconds(startDate, 120)).buildExample();
    String result = testling.formatTestSuiteTableStateMessage(testSuiteExample, gearmanProperties.getTemplateSuiteTable());
    String lastRun = AbstractOutputBuilder.dateFormat.format(testSuiteExample.getStopDate());
    assertEquals(result, "<tr valign=\"top\"><td class=\"serviceCRITICAL\">[CRIT] Sakuli suite \"sakuli-123\"" + " (120.00s) EXCEPTION: 'TEST-ERROR'. (Last suite run: " + lastRun + ")</td></tr>");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) Date(java.util.Date) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 17 with SakuliException

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

the class Icinga2OutputBuilderTest method testBuildErrorInStep.

@Test
public void testBuildErrorInStep() throws Exception {
    TestSuite testSuite = new TestSuiteExampleBuilder().withState(TestSuiteState.ERRORS).withId("TEST-SUITE-ID").withTestCases(Collections.singletonList(new TestCaseExampleBuilder().withId("TEST-CASE-ID").withState(TestCaseState.ERRORS).withTestCaseSteps(Collections.singletonList(new TestCaseStepExampleBuilder().withState(TestCaseStepState.ERRORS).withException(new SakuliException("MY-TEST-ERROR-IN-STEP")).buildExample())).buildExample())).buildExample();
    ReflectionTestUtils.setField(testling, "testSuite", testSuite);
    Assert.assertEquals(testling.build(), "[CRIT] Sakuli suite \"TEST-SUITE-ID\" (120.00s) EXCEPTION: 'CASE \"TEST-CASE-ID\": STEP \"step_for_unit_test\": MY-TEST-ERROR-IN-STEP'. (Last suite run: 17.08.14 14:02:00)\n" + "[CRIT] case \"TEST-CASE-ID\" EXCEPTION: STEP \"step_for_unit_test\": MY-TEST-ERROR-IN-STEP");
}
Also used : TestSuite(org.sakuli.datamodel.TestSuite) SakuliException(org.sakuli.exceptions.SakuliException) TestCaseExampleBuilder(org.sakuli.builder.TestCaseExampleBuilder) TestSuiteExampleBuilder(org.sakuli.builder.TestSuiteExampleBuilder) TestCaseStepExampleBuilder(org.sakuli.builder.TestCaseStepExampleBuilder) Test(org.testng.annotations.Test)

Example 18 with SakuliException

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

the class BaseActionLoaderTest method testInitNoSahiSession.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testInitNoSahiSession() throws Exception {
    String testCaseId = "xyz";
    when(testSuite.getTestCase(testCaseId)).thenReturn(new TestCase("Test", testCaseId));
    when(rhinoScriptRunner.getSession()).thenReturn(null);
    when(sakuliProperties.isLoadJavaScriptEngine()).thenReturn(true);
    ArgumentCaptor<SakuliException> ac = ArgumentCaptor.forClass(SakuliException.class);
    testling.init(testCaseId, ".");
    verify(exceptionHandler).handleException(ac.capture());
    assertEquals(ac.getValue().getMessage(), "cannot init rhino script runner with sakuli custom delay variable 'sakuli-delay-active'");
    verify(session, never()).setVariable(anyString(), anyString());
}
Also used : TestCase(org.sakuli.datamodel.TestCase) SakuliException(org.sakuli.exceptions.SakuliException) Test(org.testng.annotations.Test)

Example 19 with SakuliException

use of org.sakuli.exceptions.SakuliException 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

SakuliException (org.sakuli.exceptions.SakuliException)19 Test (org.testng.annotations.Test)12 TestSuiteExampleBuilder (org.sakuli.builder.TestSuiteExampleBuilder)8 TestCaseExampleBuilder (org.sakuli.builder.TestCaseExampleBuilder)7 TestSuite (org.sakuli.datamodel.TestSuite)7 TestCaseStepExampleBuilder (org.sakuli.builder.TestCaseStepExampleBuilder)4 Date (java.util.Date)3 BaseTest (org.sakuli.BaseTest)3 TestCase (org.sakuli.datamodel.TestCase)3 Path (java.nio.file.Path)2 SakuliExceptionHandler (org.sakuli.exceptions.SakuliExceptionHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ConnectException (java.net.ConnectException)1 TreeSet (java.util.TreeSet)1 Report (net.sf.sahi.ant.Report)1 TestRunner (net.sf.sahi.test.TestRunner)1 DefaultExecutor (org.apache.commons.exec.DefaultExecutor)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1 After (org.aspectj.lang.annotation.After)1 DateTime (org.joda.time.DateTime)1